mirror of
https://github.com/ohmybash/oh-my-bash.git
synced 2024-05-11 05:55:37 +00:00
* OMB - Major Refactor - Aliases and completions now works like plugins (need to enabled in .bashrc) - Removed the compatible check in spectrum.sh, OMB now works with Bash v3.x like the old days. - Removed core plugin, added those bash functions into base.sh and load during startup. - Updated OSH template for new installations - Added history config and few other stuff from #17 @TODO: Added a shell script to update old version of .bashrc to new one. * Fixed ShellCheck issues * Fixed ShellCheck issues
36 lines
1.3 KiB
Bash
36 lines
1.3 KiB
Bash
#!/usr/bin/env bash
|
|
# Bash completion support for ssh.
|
|
|
|
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
|
|
|
|
_sshcomplete() {
|
|
local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}"
|
|
if [[ ${CURRENT_PROMPT} == *@* ]] ; then
|
|
local OPTIONS="-P ${CURRENT_PROMPT/@*/}@ -- ${CURRENT_PROMPT/*@/}"
|
|
else
|
|
local OPTIONS=" -- ${CURRENT_PROMPT}"
|
|
fi
|
|
|
|
|
|
# parse all defined hosts from .ssh/config
|
|
if [ -r "$HOME/.ssh/config" ]; then
|
|
COMPREPLY=($(compgen -W "$(grep ^Host "$HOME/.ssh/config" | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) )
|
|
fi
|
|
|
|
# parse all hosts found in .ssh/known_hosts
|
|
if [ -r "$HOME/.ssh/known_hosts" ]; then
|
|
if grep -v -q -e '^ ssh-rsa' "$HOME/.ssh/known_hosts" ; then
|
|
COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$( awk '{print $1}' "$HOME/.ssh/known_hosts" | grep -v ^\| | cut -d, -f 1 | sed -e 's/\[//g' | sed -e 's/\]//g' | cut -d: -f1 | grep -v ssh-rsa)" ${OPTIONS}) )
|
|
fi
|
|
fi
|
|
|
|
# parse hosts defined in /etc/hosts
|
|
if [ -r /etc/hosts ]; then
|
|
COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$( grep -v '^[[:space:]]*$' /etc/hosts | grep -v '^#' | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) )
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
complete -o default -o nospace -F _sshcomplete ssh scp
|