diff options
author | Igor Murzov <e-mail@date.by> | 2012-03-18 03:04:07 +0400 |
---|---|---|
committer | Igor Murzov <e-mail@date.by> | 2012-03-18 03:04:07 +0400 |
commit | 644020ab575f4d4cffa043282c54689c0f882a4c (patch) | |
tree | 94cccb61bdf7c748afc74f06e402200b5d8672ec | |
parent | 199a63bd4db2020c8d6aaad6723cf881c023c0ff (diff) | |
download | bash-completion-644020ab575f4d4cffa043282c54689c0f882a4c.tar.gz |
cmake: New completion.
-rw-r--r-- | completions/Makefile.am | 1 | ||||
-rw-r--r-- | completions/cmake | 149 | ||||
-rw-r--r-- | test/completion/cmake.exp | 1 | ||||
-rw-r--r-- | test/lib/completions/cmake.exp | 18 |
4 files changed, 169 insertions, 0 deletions
diff --git a/completions/Makefile.am b/completions/Makefile.am index 03165cf4..4173b1dc 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -46,6 +46,7 @@ bashcomp_DATA = a2x \ cleanarch \ clisp \ clone_member \ + cmake \ complete \ config_list \ configure \ diff --git a/completions/cmake b/completions/cmake new file mode 100644 index 00000000..59b565ac --- /dev/null +++ b/completions/cmake @@ -0,0 +1,149 @@ +# bash completion for cmake(1) -*- shell-script -*- + +_cmake() +{ + local cur prev words cword split=false + _init_completion -n := || return + + # Workaround for options like -DCMAKE_BUILD_TYPE=Release + local prefix= + if [[ $cur == -D* ]]; then + prev=-D + prefix=-D + cur="${cur#-D}" + elif [[ $cur == -U* ]]; then + prev=-U + prefix=-U + cur="${cur#-U}" + fi + + case "$prev" in + -D) + if [[ $cur == *=* ]]; then + # complete values for variables + local var type value + var="${cur%%[:=]*}" + value="${cur#*=}" + + if [[ $cur == CMAKE_BUILD_TYPE* ]]; then # most widely used case + COMPREPLY=( $( compgen -W 'Debug Release RelWithDebInfo + MinSizeRel' -- "$value" ) ) + return + fi + + if [[ $cur == *:* ]]; then + type="${cur#*:}" + type="${type%%=*}" + else # get type from cache if it's not set explicitly + type=$( cmake -LA -N 2>/dev/null | grep "$var:" \ + 2>/dev/null ) + type="${type#*:}" + type="${type%%=*}" + fi + case "$type" in + FILEPATH) + cur="$value" + _filedir + return + ;; + PATH) + cur="$value" + _filedir -d + return + ;; + BOOL) + COMPREPLY=( $( compgen -W 'ON OFF TRUE FALSE' -- \ + "$value" ) ) + return + ;; + STRING|INTERNAL) + # no completion available + return + ;; + esac + elif [[ $cur == *:* ]]; then + # complete types + local type="${cur#*:}" + COMPREPLY=( $( compgen -W 'FILEPATH PATH STRING BOOL INTERNAL'\ + -S = -- "$type" ) ) + compopt -o nospace + else + # complete variable names + COMPREPLY=( $( compgen -W '$( cmake -LA -N | tail -n +2 | + cut -f1 -d: )' -P "$prefix" -- "$cur" ) ) + compopt -o nospace + fi + return + ;; + -U) + COMPREPLY=( $( compgen -W '$( cmake -LA -N | tail -n +2 | + cut -f1 -d: )' -P "$prefix" -- "$cur" ) ) + return + ;; + esac + + _split_longopt && split=true + + case "$prev" in + -C|-P|--graphviz|--system-information) + _filedir + return + ;; + --build) + _filedir -d + return + ;; + -E) + COMPREPLY=( $( compgen -W "$( cmake -E help |& sed -n \ + '/^ /{s|^ \([^ ]\{1,\}\) .*$|\1|;p}' 2>/dev/null )" \ + -- "$cur" ) ) + return + ;; + -G) + # FIXME: doesn't work properly + local IFS=$'\n' + COMPREPLY=( $( compgen -W '$( cmake --help 2>/dev/null | sed -n \ + "/^.*[^ ].*= Generates/{s|^ *\(.*[^ ]\) *= Generates.*$|\1|;s| |\\\\ |g;p}" \ + 2>/dev/null )' -- "$cur" ) ) + return + ;; + --help-command) + COMPREPLY=( $( compgen -W '$( cmake --help-command-list 2>/dev/null| + tail -n +2 )' -- "$cur" ) ) + return + ;; + --help-module) + COMPREPLY=( $( compgen -W '$( cmake --help-module-list 2>/dev/null| + tail -n +2 )' -- "$cur" ) ) + return + ;; + --help-policy) + COMPREPLY=( $( compgen -W '$( cmake --help-policies 2>/dev/null | + grep "^ CMP" 2>/dev/null )' -- "$cur" ) ) + return + ;; + --help-property) + COMPREPLY=( $( compgen -W '$( cmake --help-property-list \ + 2>/dev/null | tail -n +2 )' -- "$cur" ) ) + return + ;; + --help-variable) + COMPREPLY=( $( compgen -W '$( cmake --help-variable-list \ + 2>/dev/null | tail -n +2 )' -- "$cur" ) ) + return + ;; + esac + + $split && return + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $(compgen -W '$( _parse_help "$1" --help )' -- ${cur}) ) + [[ $COMPREPLY == *= ]] && compopt -o nospace + [[ $COMPREPLY ]] && return + fi + + _filedir +} && +complete -F _cmake cmake + +# ex: ts=4 sw=4 et filetype=sh diff --git a/test/completion/cmake.exp b/test/completion/cmake.exp new file mode 100644 index 00000000..cbb1db3a --- /dev/null +++ b/test/completion/cmake.exp @@ -0,0 +1 @@ +assert_source_completions cmake diff --git a/test/lib/completions/cmake.exp b/test/lib/completions/cmake.exp new file mode 100644 index 00000000..28981eb2 --- /dev/null +++ b/test/lib/completions/cmake.exp @@ -0,0 +1,18 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup +assert_complete_any "cmake " + + +sync_after_int + + +teardown |