Skip to content

Commit

Permalink
gm: New completion, commands only for now
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed May 12, 2017
1 parent c936d99 commit 1ac39db
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions completions/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ bashcomp_DATA = 2to3 \
genisoimage \
getent \
gkrellm \
gm \
gnatmake \
gnokii \
gnome-mplayer \
Expand Down
40 changes: 40 additions & 0 deletions completions/gm
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# bash completion for gm(1) -*- shell-script -*-

_gm_commands()
{
COMPREPLY+=( $( compgen -W '$( "$1" help |
awk "/^ +[^ ]+ +- / { print \$1 }" )' -- "$cur" ) )
}

_gm()
{
local cur prev words cword
_init_completion || return

if [[ $cword -eq 1 ]]; then
_gm_commands "$1"
return
elif [[ $cword -eq 2 && ${words[1]} == time ]]; then
_gm_commands "$1"
return
fi

local gmcmd=${words[1]}
[[ $gmcmd == time ]] && gmcmd=${words[2]}

case $gmcmd in
help)
[[ $prev == help ]] && _gm_commands "$1"
return
;;
version)
return
;;
esac

# TODO... defer some commnds to the imagemagick "gm"less completions etc?
compopt -o default
} &&
complete -F _gm gm

# ex: filetype=sh
1 change: 1 addition & 0 deletions test/completion/gm.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assert_source_completions gm
1 change: 1 addition & 0 deletions test/docker/Dockerfile-ubuntu14
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ RUN apt-get update && \
gnome-mplayer \
gperf \
gphoto2 \
graphicsmagick \
graphicsmagick-imagemagick-compat \
graphviz \
growisofs \
Expand Down
27 changes: 27 additions & 0 deletions test/lib/completions/gm.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
proc setup {} {
save_env
}


proc teardown {} {
assert_env_unmodified
}


setup


assert_complete_any "gm "
sync_after_int

assert_complete_any "gm help "
sync_after_int

assert_complete_any "gm time "
sync_after_int

assert_no_complete "gm version "
sync_after_int


teardown

0 comments on commit 1ac39db

Please sign in to comment.