diff options
Diffstat (limited to 'bash')
-rw-r--r-- | bash/bashrc.d/ftp.bash | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bash/bashrc.d/ftp.bash b/bash/bashrc.d/ftp.bash new file mode 100644 index 00000000..8952cbb8 --- /dev/null +++ b/bash/bashrc.d/ftp.bash @@ -0,0 +1,31 @@ +# Completion for ftp with .netrc machines +_ftp() { + local netrc=$HOME/.netrc + local word=${COMP_WORDS[COMP_CWORD]} + local -a machines + + # Bail if the .netrc file is illegible + if [[ ! -r $netrc ]]; then + return 1 + fi + + # Tokenize the file + local -a tokens + IFS=$' \t\n' read -a tokens -d '' -r < "$netrc" + + # Iterate through tokens and collect machine names + local machine=0 + for token in "${tokens[@]}"; do + if ((machine)); then + machines=("${machines[@]}" "$token") + machine=0 + elif [[ $token == machine ]]; then + machine=1 + fi + done + + # Generate completion reply + COMPREPLY=( $(compgen -W "${machines[*]}" -- "$word") ) +} +complete -F _ftp ftp + |