Dr D's Abode

Tag: completion

SSH Tab completion!

by on Nov.29, 2008, under Computers, Linux

So I was using stuble upon and I found a cool one.  Adding tab completion to SSH/SCP!

The original code is at http://drawohara.com/post/6584031/life-changing-shell-function

But I propose a slightly different egrep line, which helps me at work (as our hostnames have numbers in them)

Basically, edit your .bash_profile or .bashrc files ( I prefer .bash_profile ), and add in the following lines:

SSH_COMPLETE=( $(cat ~/.ssh/known_hosts | \
sed -e 's/ .*//g' -e 's/,.*//g' | \
uniq | egrep -v "^([0-9]{1,3}.){4}$") )
complete -o default -W "${SSH_COMPLETE[*]}" ssh
complete -o default -W "${SSH_COMPLETE[*]}" scp

Once added, type source ~/.bash_profile (or ~/.bashrc)

This will parse the ~/.ssh/known_hosts file on login, and find any hostnames (but not IPs) and store them in a temporary variable.  This variable is parsed to add tab completion to the ssh and scp commands.

To use, type ssh dan-[tab] and it will auto complete the domain (if it was previously listed in the known_hosts file!)

Comments Off on SSH Tab completion! :, , , , , more...

Geek Code

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GIT d-(+) s:+ a C++ BL++++ P++>+++ L++(+++) E--- W++ N o K- w O M V-- PS
PE Y+ PGP+ t+ 5 X+ R tv b DI D+ G e+ h+ r-- y+
------END GEEK CODE BLOCK------

Linux Counter

Certifications


 

PSN Portable ID

Powered by

Hacker
 
Powered by Gentoo Linux