aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--bash/bashrc.d/ftp.bash31
2 files changed, 32 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 5a749c56..40f82fb4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@ bash/bashrc.d/*
!bash/bashrc.d/cd.bash
!bash/bashrc.d/completion.bash
!bash/bashrc.d/ed.bash
+!bash/bashrc.d/ftp.bash
!bash/bashrc.d/grep.bash
!bash/bashrc.d/ls.bash
!bash/bashrc.d/mysql.bash
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
+