summaryrefslogtreecommitdiff
path: root/Completion
diff options
context:
space:
mode:
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Base/Utility/_values2
-rw-r--r--Completion/Linux/Command/_htop66
-rw-r--r--Completion/Unix/Command/_gradle114
3 files changed, 117 insertions, 65 deletions
diff --git a/Completion/Base/Utility/_values b/Completion/Base/Utility/_values
index 688ada848..5ed79e890 100644
--- a/Completion/Base/Utility/_values
+++ b/Completion/Base/Utility/_values
@@ -60,7 +60,7 @@ if compvalues -i "$keep[@]" "$@"; then
_describe "$descr" \
noargs "$sep[@]" -M 'r:|[_-]=* r:|=*' -- \
args -S "${argsep}" -M 'r:|[_-]=* r:|=*' -- \
- opts -qS "${argsep}" -r "${argsep}${sep} \\t\\n\\-" -M 'r:|[_-]=* r:|=*'
+ opts -qS "${argsep}" -r "${argsep}${sep[2]} \\t\\n\\-" -M 'r:|[_-]=* r:|=*'
curcontext="$oldcontext"
diff --git a/Completion/Linux/Command/_htop b/Completion/Linux/Command/_htop
index 28c7512bf..e8d2fffb1 100644
--- a/Completion/Linux/Command/_htop
+++ b/Completion/Linux/Command/_htop
@@ -1,11 +1,55 @@
-#compdef htop
-
-_arguments -S : \
- '(-d --delay)'{-d+,--delay=}'[update frequency]:duration (tenths of seconds)' \
- '(-C --no-color --no-colour)'{-C,--no-colo{,u}r}'[monochrome mode]' \
- '(-)'{-h,--help}'[display usage information]' \
- \*{-p+,--pid=}'[show given pids]: : _sequence -n ${$(</proc/sys/kernel/pid_max)\:-32768} _pids' \
- '(-s --sort-key)'{-s+,--sort-key=}'[sort by key]:key:( ${(f)"$(_call_program sort-keys $words[1] --sort-key help)"} )' \
- '(-t --tree)'{-t,--tree}'[show tree view of processes]' \
- '(-u --user)'{-u+,--user=}'[show processes of user]: : _users' \
- '(-)'{-v,--version}'[display version information]'
+#compdef htop pcp-htop
+
+# Notes:
+# - htop allows long options to be passed with a single dash; we don't account
+# for this
+# - htop parses optional arguments to -H and -u 'cleverly' by allowing the next
+# word to be the optarg if it doesn't begin with a '-'; this should work here
+# - There is a special version of htop designed to be used with PCP (Performance
+# CoPilot); we don't fully account for this
+# - Some of the ranges and defaults listed here had to be found in the source
+
+local MATCH MBEGIN MEND ret=1
+local -a context line state state_descr args tmp
+
+args=(
+ '(-d --delay)'{-d+,--delay=}'[specify update frequency]:delay (tenths of seconds) (1-100) [15]'
+ '(-C --no-color --no-colour)'{-C,--no-colo{,u}r}'[use monochrome colour scheme]'
+ '(-F --filter)'{-F+,--filter=}'[show only commands matching specified filter]:case-insensitive command-line sub-string:_process_names -a'
+ '(-)'{-h,--help}'[display usage information]'
+ '(-H --highlight-changes)'{-H+,--highlight-changes=}'[highlight new and old processes (optionally specify delay)]::delay (seconds) (1-86400) [5]'
+ '(-M --no-mouse)'{-M,--no-mouse}'[disable mouse]'
+ \*{-p+,--pid=}'[show only specified PIDs]: : _sequence _pids'
+ '--readonly[disable all system and process changing features]'
+ '(-s --sort-key)'{-s+,--sort-key=}'[sort by specified column]: :->sort-keys'
+ '(-t --tree)'{-t,--tree}'[show tree view of processes]'
+ '(-u --user)'{-u+,--user=}'[show only processes of current or specified user]:: : _users'
+ '(-U --no-unicode)'{-U,--no-unicode}'[disable Unicode]'
+ '(-)'{-V,--version}'[display version information]'
+)
+
+[[ $OSTYPE == linux* ]] &&
+(( ! EUID || $+_comp_priv_prefix )) &&
+_pick_variant libcap=drop-capabilities $OSTYPE --help &&
+args+=(
+ '--drop-capabilities=-[drop specified capabilities]::mode [basic]:((
+ off\:"do not drop capabilities"
+ basic\:"drop capabilities not needed for standard functionality (retains kill, renice, etc.)"
+ strict\:"drop capabilities not needed for core functionality"
+ ))'
+)
+
+_arguments -s -S : $args && ret=0
+
+case $state in
+ sort-keys)
+ tmp=( ${(f)"$(_call_program sort-keys $words[1] --sort-key help)"} )
+ tmp=( ${tmp/#[[:space:]]##} )
+ tmp=( ${tmp//:/\\:} )
+ tmp=( ${tmp/[[:space:]]##/:} )
+ tmp=( ${tmp/(#m):[A-Z]/${(L)MATCH}} )
+ _describe -t sort-keys 'column (key)' tmp && ret=0
+ ;;
+esac
+
+return ret
diff --git a/Completion/Unix/Command/_gradle b/Completion/Unix/Command/_gradle
index a1d9381cb..c1f7c05ee 100644
--- a/Completion/Unix/Command/_gradle
+++ b/Completion/Unix/Command/_gradle
@@ -1,13 +1,24 @@
#compdef gradle gradlew
-local curcontext="$curcontext" ret=1 state state_descr line
-local gradle_inspect=yes cache_policy tag_order filter=
-local -A opt_args
-local -aU gradle_group_tasks gradle_all_tasks tasks
+local -i ret=1
+local curcontext="$curcontext" state state_descr outputline
+local gradle_inspect=yes gradle_buildfile cache_policy cache_name tag_order filter
+local -A opt_args task_map
+local -aU gradle_subprojects gradle_tasks tasks
+local -a match mbegin mend
-# Set the caching policy to invalidate cache if the build file is newer than the cache.
_gradle_caching_policy() {
- [[ $gradle_buildfile -nt $1 ]]
+ # Invalidate the cache if it cannot be read.
+ [[ -r "$1" ]] ||
+ return 0
+
+ # Invalidate the cache if it's older than the build file.
+ [[ $gradle_buildfile -nt $1 ]] &&
+ return
+
+ # Invalidate the cache if it doesn't contain the required arrays.
+ local cache="$( < $1 )"
+ [[ "$cache" != *'gradle_subprojects=('*')'* || "$cache" != *'gradle_tasks=('*')'* ]]
}
zstyle -s ":completion:*:*:$service:*" cache-policy cache_policy || \
@@ -59,76 +70,73 @@ _arguments -C \
'(-)--stop[Stops the Gradle daemon if it is running.]' \
{-u,--no-search-upward}"[Don't search in parent folders for a settings.gradle file.]" \
'(-)'{-v,--version}'[Print version info.]' \
- {-x,--exclude-task}'[Specify a task to be excluded from execution.]:task to exclude:->alltask' \
+ {-x,--exclude-task}'[Specify a task to be excluded from execution.]:task to exclude:->task' \
'*:task:->task' \
&& ret=0
-if [[ $words[CURRENT] != -* ]]; then
+if [[ $state == task && ! -prefix - ]]; then
+ # :<task> runs <task> in the root project only.
+ # :<subproject>:<task> is the same as <subproject>:<task> (without the leading colon).
+ compset -P \:
+
if [[ $gradle_inspect == yes ]]; then
# If a build file is specified after '-b' or '--build-file', use this file. Otherwise,
# default is the file 'build.gradle' in the current directory.
- local gradle_buildfile=${${(v)opt_args[(i)-b|--build-file]}:-build.gradle}
+ gradle_buildfile=${${(v)opt_args[(i)-b|--build-file]}:-build.gradle}
if [[ -f $gradle_buildfile ]]; then
# Cache name is constructed from the absolute path of the build file.
- local cache_name=${${gradle_buildfile:a}//[^[:alnum:]]/_}
+ cache_name=${${gradle_buildfile:a}//[^[:alnum:]]/_}
+
if _cache_invalid $cache_name || ! _retrieve_cache $cache_name; then
zle -R "Generating cache from $gradle_buildfile"
- local outputline
- local -a match mbegin mend
+
# Run gradle/gradlew and retrieve possible tasks.
for outputline in ${(f)"$($service --build-file $gradle_buildfile -q tasks --all)"}; do
- # Subproject tasks are prefixed with one or more instances of [[:alnum:]]##\:
- # Leaving out the prefix runs the task in all subprojects where it exists.
- if [[ $outputline ==
- [[:blank:]]#(#b)([[:alnum:]]##\:)#([[:alnum:]]##)' - '(*) ]]; then
- # The descriptions of main tasks start at beginning of line, descriptions of
- # secondary tasks are indented.
- if [[ $outputline == [[:alnum:]]* ]]; then
- gradle_group_tasks+=(
- "$match[-2]:$match[-1]"
- "${${(j::)match[1,-2]}//:/\:}:$match[-1]"
- )
+
+ # Tasks and subprojects each start with a lowercase letter, but whereas tasks are in camelCase, each
+ # subproject consists of one or more sections of kebab-case, with each section ending in a ':'.
+ # A subproject task is a task prefixed with a subproject and runs in that project only.
+ # Specifying a task without a subproject prefix runs the task in all subprojects where it exists.
+ # Tasks prefixed by whitespace are dependencies of the task above them and should be ignored.
+ if [[ $outputline == (#b)([[:lower:]][-[:lower:][:digit:]]#\:)#([[:lower:]][[:alnum:]]#)(|' - '*) ]]
+ then
+ task=$match[-2]
+ task_descr=${match[-1]# - }
+ shift -p 2 match
+ subproject=${(j::)match//:/'\:'}
+
+ if [[ -n $subproject ]]; then
+ gradle_subprojects+=( ${subproject%'\:'} )
+ task_map[$subproject$task]=$task_descr
+
+ # We cannot count on the description of a subproject task to be representative of the task
+ # in general.
+ : ${task_map[$task]=}
else
- gradle_all_tasks+=(
- "${${(j::)match[1,-2]}//:/\:}:$match[-1]"
- )
+ task_map[$task]=$task_descr
fi
fi
done
- _store_cache $cache_name gradle_group_tasks gradle_all_tasks
+ printf -v gradle_tasks '%s:%s' "${(kv@)task_map}"
+ _store_cache $cache_name gradle_subprojects gradle_tasks
fi
- filter=
- zstyle -T ":completion:${curcontext}:tasks" prefix-needed &&
- [[ $PREFIX != ([[:alnum:]]##\:)## ]] &&
- filter+="*\:*"
- if [[ $state == task ]]; then
- _tags gradle_group gradle_all
- while _tags; do
- # Offer main tasks and secondary tasks in different tags.
- if _requested gradle_group; then
- tasks=( ${gradle_group_tasks:#$~filter} )
- _describe -t tasks 'group task' tasks &&
- ret=0
- fi
- if _requested gradle_all; then
- tasks=( ${gradle_all_tasks:#$~filter} )
- _describe -t tasks 'secondary task' tasks &&
- ret=0
- fi
- (( ret )) || break
- done
- elif [[ $state == alltask ]]; then
- # After '--exclude-task', we don't make a distinction between main tasks and
- # secondary tasks.
- tasks=( ${gradle_group_tasks:#$~filter} ${gradle_all_tasks:#$~filter} )
- _describe -t tasks 'task' tasks &&
+ if [[ $IPREFIX == *: ]] || ! zstyle -T ":completion:${curcontext}:subprojects" prefix-needed; then
+ _describe -t subprojects 'gradle subproject' gradle_subprojects -S \: &&
ret=0
fi
+ if [[ $PREFIX == *:* ]] || ! zstyle -T ":completion:${curcontext}:tasks" prefix-needed; then
+ tasks=( $gradle_tasks[@] )
+ else
+ # If no subproject is specified, then filter out all subproject tasks.
+ tasks=( ${gradle_tasks[@]:#*'\:'*} )
+ fi
+ _describe -t tasks 'gradle task' tasks &&
+ ret=0
fi
else
- _describe 'built-in task' '(
+ _describe -t tasks 'built-in task' '(
"dependencies:Displays all dependencies declared in root project."
"dependencyInsight:Displays the insight into a specific dependency in root project."
"help:Displays a help message."