diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | bash/bashrc.d/completion.bash | 31 | ||||
-rw-r--r-- | bash/bashrc.d/ssh.bash | 31 |
3 files changed, 32 insertions, 31 deletions
@@ -8,6 +8,7 @@ bash/bashrc.d/* !bash/bashrc.d/prompt.bash !bash/bashrc.d/pushd.bash !bash/bashrc.d/sprunge.bash +!bash/bashrc.d/ssh.bash !bash/bashrc.d/tmux.bash gnupg/* !gnupg/*.conf diff --git a/bash/bashrc.d/completion.bash b/bash/bashrc.d/completion.bash index a921770b..6a382a37 100644 --- a/bash/bashrc.d/completion.bash +++ b/bash/bashrc.d/completion.bash @@ -22,34 +22,3 @@ complete -c sudo # unset with shell variables and functions complete -v -A function unset -# ssh/sftp/ssh-copy-id with config hostnames -_ssh() { - local word config hosts option value - word=${COMP_WORDS[COMP_CWORD]} - config=$HOME/.ssh/config - hosts=() - - # Bail if the configuration file is illegible - if [[ ! -r $config ]]; then - return 1 - fi - - # Read hostnames from the file, no asterisks - while read -r option value _; do - if [[ $option == Host && $value != *'*'* ]]; then - hosts[${#hosts[@]}]=$value - fi - done < "$config" - - # Generate completion reply - COMPREPLY=( $(compgen -W "${hosts[*]}" -- "$word") ) -} -complete -F _ssh ssh sftp ssh-copy-id - -# scp/rsync with local files and hostnames (colon suffixes) -_scp() { - _ssh - COMPREPLY=( "${COMPREPLY[@]/%/:}" ) -} -complete -f -F _scp scp - diff --git a/bash/bashrc.d/ssh.bash b/bash/bashrc.d/ssh.bash new file mode 100644 index 00000000..fda88b30 --- /dev/null +++ b/bash/bashrc.d/ssh.bash @@ -0,0 +1,31 @@ +# Commpletion for ssh/sftp/ssh-copy-id with config hostnames +_ssh() { + local word config hosts option value + word=${COMP_WORDS[COMP_CWORD]} + config=$HOME/.ssh/config + hosts=() + + # Bail if the configuration file is illegible + if [[ ! -r $config ]]; then + return 1 + fi + + # Read hostnames from the file, no asterisks + while read -r option value _; do + if [[ $option == Host && $value != *'*'* ]]; then + hosts[${#hosts[@]}]=$value + fi + done < "$config" + + # Generate completion reply + COMPREPLY=( $(compgen -W "${hosts[*]}" -- "$word") ) +} +complete -F _ssh ssh sftp ssh-copy-id + +# Completion for scp/rsync with local files and hostnames (colon suffixes) +_scp() { + _ssh + COMPREPLY=( "${COMPREPLY[@]/%/:}" ) +} +complete -f -F _scp scp + |