From 47fc78a581f5710cc2e587d3c369f2e731135ec7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 29 Aug 2013 01:31:56 +1200 Subject: Committing start at basic completion --- bash/bashrc.d/completion.bash | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 bash/bashrc.d/completion.bash (limited to 'bash/bashrc.d/completion.bash') 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 + -- cgit v1.2.3