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