diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2015-07-05 17:04:20 +0200 |
---|---|---|
committer | Martyn Russell <martyn@lanedo.com> | 2015-07-31 15:51:09 +0100 |
commit | b222fdba41ddbb9ed3b870276dce2313d279156c (patch) | |
tree | 40a7f43acbd8fec0baa9236bba8b9e7c290acb69 | |
parent | de0596f8757aedb7ea7173fd3e8c9b3db00c9281 (diff) | |
download | tracker-b222fdba41ddbb9ed3b870276dce2313d279156c.tar.gz |
cli: Improve bash completion script
We now autocomplete files where it applies (various -f/--file options,
tracker info) and '-' prefixed switches.
-rw-r--r-- | src/tracker/bash-completion/tracker | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/tracker/bash-completion/tracker b/src/tracker/bash-completion/tracker index 8022b6a66..12749cdc7 100644 --- a/src/tracker/bash-completion/tracker +++ b/src/tracker/bash-completion/tracker @@ -2,9 +2,39 @@ tracker_cmds() { - possible=`tracker | egrep " [a-z].* " | awk '{ print ($1) }'` - local cur=${COMP_WORDS[COMP_CWORD]} - COMPREPLY=( $(compgen -W "$possible" -- $cur) ) + local cur prev words cword + _init_completion -s || return + + cur=${COMP_WORDS[COMP_CWORD]} + + if [[ $cword == 1 ]]; then + possible=`tracker | egrep " [a-z].* " | awk '{ print ($1) }'` + COMPREPLY=( $(compgen -W "$possible" -- $cur) ) + return 0; + fi + + case $prev in + -h|--help) + return 0; + ;; + info|-f|--file) + if [[ $cur != -* ]]; then + _filedir + return 0; + fi + ;; + *) + ;; + esac + + if [[ $cword -lt 2 ]]; then + return 0; + fi + + if [[ -z $cur ]] || [[ $cur == -* ]]; then + possible=`${words[0]} ${words[1]} -h | egrep "^ *-" | sed "s/^ *//" | sed "s/ [^-].*//" | sed "s/,/\n/g" | sed "s/=.*//"` + COMPREPLY=( $(compgen -W "$possible" -- $cur) ) + fi } complete -F tracker_cmds tracker |