aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-07-22 01:54:47 -0400
committerTeddy Wing2016-07-22 01:54:47 -0400
commit70f810bc7877918d09346673de6d4906c7f82f51 (patch)
tree9e42d17451a60f059a0ca07b7978a595f0f7a2fd
parent950c61432dd973bb0ba2c19a0483740d9e1f7d01 (diff)
downloadqcd-70f810bc7877918d09346673de6d4906c7f82f51.tar.bz2
Update Bash completion file to work with database-enabled version
Bash completion now works for the new database-backed `qcd`. Arguments 1 and 2 are completed by searching the `qcd` database. Argument 3 is completed using default Bash completion by setting `COMPREPLY` to `()` and adding `-o default` to the `complete` call as recommended here: http://stackoverflow.com/questions/12933362/getting-compgen-to-include-slashes-on-directories-when-looking-for-files/19062943#19062943 Copied over the directory variables from the `qcd` script. Not sure if I should be putting them somewhere else so they're not in two different places. I probably should. I was also concerned that once the scripts are sourced, these variables will be in a user's shell environment. That doesn't feel right, but I'm going to ignore it for now.
-rw-r--r--qcd.bash-completion19
1 files changed, 14 insertions, 5 deletions
diff --git a/qcd.bash-completion b/qcd.bash-completion
index f0099e0..c42d077 100644
--- a/qcd.bash-completion
+++ b/qcd.bash-completion
@@ -1,17 +1,26 @@
# Bash completion for the qcd() function
+XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-"${HOME}/.config"}
+QCD_CONFIG_DIR=${QCD_CONFIG_DIR:-"${XDG_CONFIG_HOME}/qcd"}
+QCD_DATABASE_FILE=${QCD_DATABASE_FILE:-"${QCD_CONFIG_DIR}/database"}
+
_qcd () {
local cur
- local commands=(
- shortcut
- )
+ local shortcuts=$(awk '{ print $1 }' $QCD_DATABASE_FILE)
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
- COMPREPLY=( $( compgen -W "${commands[*]}" -- $cur ) )
+ case "$COMP_CWORD" in
+ 1|2)
+ COMPREPLY=( $( compgen -W "$shortcuts" -- $cur ) )
+ ;;
+ 3)
+ COMPREPLY=()
+ ;;
+ esac
return 0
}
-complete -F _qcd qcd
+complete -o default -F _qcd qcd