diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2013-08-29 01:31:56 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2013-08-29 01:31:56 +1200 |
commit | 47fc78a581f5710cc2e587d3c369f2e731135ec7 (patch) | |
tree | 3b86ab31769c957e016c54cc0ce1f53220b03e4d /bash/bashrc.d/completion.bash | |
parent | Hook prevents loading unwanted bash-completion (diff) | |
download | dotfiles-47fc78a581f5710cc2e587d3c369f2e731135ec7.tar.gz dotfiles-47fc78a581f5710cc2e587d3c369f2e731135ec7.zip |
Committing start at basic completion
Diffstat (limited to 'bash/bashrc.d/completion.bash')
-rw-r--r-- | bash/bashrc.d/completion.bash | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/bash/bashrc.d/completion.bash b/bash/bashrc.d/completion.bash new file mode 100644 index 00000000..d51557ae --- /dev/null +++ b/bash/bashrc.d/completion.bash @@ -0,0 +1,49 @@ +# builtin with builtins +complete -b builtin + +# cd/pushd with directories +complete -d cd pushd + +# command/hash/type with commands +complete -c command hash type + +# set with options +complete -A setopt set + +# shopt with shell options +complete -A shopt shopt + +# 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 + |