Created
April 11, 2012 07:57
-
-
Save fieg/2357723 to your computer and use it in GitHub Desktop.
.bash_profile for OSX including autocomplete for ssh hosts, default variables and some aliases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export PATH=~/bin:/usr/local/bin:/usr/local/mysql/bin:/usr/local/sbin:$PATH | |
export EDITOR=vim | |
export APPLICATION_ENV="development" | |
export CLICOLOR=1 | |
export LSCOLORS=dxfxcxdxbxegedabagacad | |
alias composer="php /usr/local/bin/composer.phar" | |
_complete_ssh_hosts () | |
{ | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \ | |
cut -f 1 -d ' ' | \ | |
sed -e s/,.*//g | \ | |
grep -v ^# | \ | |
uniq | \ | |
grep -v "\[" ; | |
cat ~/.ssh/config | \ | |
grep "^Host " | \ | |
awk '{print $2}' | |
` | |
COMPREPLY=( $(compgen -W "${comp_ssh_hosts}" -- $cur)) | |
return 0 | |
} | |
complete -F _complete_ssh_hosts ssh |
Saved me a bit of fussing with bash. Thanks!
Nice. Thanks.
Nice workaround. Thnks
great !! thanks :-)
This was great! Thanks!
+1
I've got strange '^M' suffixes after each hostname in autocomplete. Like 'my-demo-stand-1^M' instead of 'my-demo-stand-1'
Can anybody help?
@vladislav-vorobev-epam did you manage to solve this issue?
My /.bash_profile looks as follows:
export PATH=~/bin:/usr/local/bin:/usr/local/mysql/bin:/usr/local/sbin:$PATH
export EDITOR=vim
export APPLICATION_ENV="development"
export CLICOLOR=1
export LSCOLORS=dxfxcxdxbxegedabagacad
alias composer="php /usr/local/bin/composer.phar"
ulimit -n 4096
_complete_ssh_hosts ()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
grep -v ^# | \
uniq | \
grep -v "\[" ;
cat ~/.ssh/config | \
grep "^Host " | \
awk '{print $2}'
`
COMPREPLY=( $(compgen -W "${comp_ssh_hosts}" -- $cur))
return 0
}
complete -F _complete_ssh_hosts ssh
And it does not work for me??
I have entries in both config and known_hosts
Changed cat ~/.ssh/config --> ~/.ssh/known_host as I don't have ~/.ssh/config file.
Now it works perfectly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to cut the cat ~/.ssh/config part for it to work on my end since the file didn't exist. It works flawlessly now. Thanks!