diff options
author | 6543 <6543@obermui.de> | 2020-10-27 14:38:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 14:38:55 +0100 |
commit | 86faedc966ed02507b98b28010bb6c85e0ecb55f (patch) | |
tree | f15d191ec304b6aace032b589a6a2806cb140bde /misc | |
parent | ce41f96aff27e60d5da35c83e84c198bff203d58 (diff) | |
download | git-bug-86faedc966ed02507b98b28010bb6c85e0ecb55f.tar.gz |
Vendor: upgrade spf13/cobra to v1.1.1 (#479)
* build(deps): bump github.com/spf13/cobra from 1.0.0 to 1.1.1
* update doc (man & md)
* update bash|fish|zsh completion
Diffstat (limited to 'misc')
-rw-r--r-- | misc/bash_completion/git-bug | 112 | ||||
-rw-r--r-- | misc/fish_completion/git-bug | 129 | ||||
-rw-r--r-- | misc/zsh_completion/git-bug | 628 |
3 files changed, 342 insertions, 527 deletions
diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 8e2de8df..912e87b4 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -40,6 +40,12 @@ __git-bug_handle_go_custom_completion() { __git-bug_debug "${FUNCNAME[0]}: cur is ${cur}, words[*] is ${words[*]}, #words[@] is ${#words[@]}" + local shellCompDirectiveError=1 + local shellCompDirectiveNoSpace=2 + local shellCompDirectiveNoFileComp=4 + local shellCompDirectiveFilterFileExt=8 + local shellCompDirectiveFilterDirs=16 + local out requestComp lastParam lastChar comp directive args # Prepare the command to request completions for the program. @@ -73,24 +79,50 @@ __git-bug_handle_go_custom_completion() __git-bug_debug "${FUNCNAME[0]}: the completion directive is: ${directive}" __git-bug_debug "${FUNCNAME[0]}: the completions are: ${out[*]}" - if [ $((directive & 1)) -ne 0 ]; then + if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then # Error code. No completion. __git-bug_debug "${FUNCNAME[0]}: received error from custom completion go code" return else - if [ $((directive & 2)) -ne 0 ]; then + if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then if [[ $(type -t compopt) = "builtin" ]]; then __git-bug_debug "${FUNCNAME[0]}: activating no space" compopt -o nospace fi fi - if [ $((directive & 4)) -ne 0 ]; then + if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then if [[ $(type -t compopt) = "builtin" ]]; then __git-bug_debug "${FUNCNAME[0]}: activating no file completion" compopt +o default fi fi + fi + if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then + # File extension filtering + local fullFilter filter filteringCmd + # Do not use quotes around the $out variable or else newline + # characters will be kept. + for filter in ${out[*]}; do + fullFilter+="$filter|" + done + + filteringCmd="_filedir $fullFilter" + __git-bug_debug "File filtering command: $filteringCmd" + $filteringCmd + elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then + # File completion for directories only + local subDir + # Use printf to strip any trailing newline + subdir=$(printf "%s" "${out[0]}") + if [ -n "$subdir" ]; then + __git-bug_debug "Listing directories in $subdir" + __git-bug_handle_subdirs_in_dir_flag "$subdir" + else + __git-bug_debug "Listing directories in ." + _filedir -d + fi + else while IFS='' read -r comp; do COMPREPLY+=("$comp") done < <(compgen -W "${out[*]}" -- "$cur") @@ -159,10 +191,9 @@ __git-bug_handle_reply() local completions completions=("${commands[@]}") if [[ ${#must_have_one_noun[@]} -ne 0 ]]; then - completions=("${must_have_one_noun[@]}") + completions+=("${must_have_one_noun[@]}") elif [[ -n "${has_completion_function}" ]]; then # if a go completion function is provided, defer to that function - completions=() __git-bug_handle_go_custom_completion fi if [[ ${#must_have_one_flag[@]} -ne 0 ]]; then @@ -344,15 +375,21 @@ _git-bug_add() flags+=("--title=") two_word_flags+=("--title") two_word_flags+=("-t") + local_nonpersistent_flags+=("--title") local_nonpersistent_flags+=("--title=") + local_nonpersistent_flags+=("-t") flags+=("--message=") two_word_flags+=("--message") two_word_flags+=("-m") + local_nonpersistent_flags+=("--message") local_nonpersistent_flags+=("--message=") + local_nonpersistent_flags+=("-m") flags+=("--file=") two_word_flags+=("--file") two_word_flags+=("-F") + local_nonpersistent_flags+=("--file") local_nonpersistent_flags+=("--file=") + local_nonpersistent_flags+=("-F") must_have_one_flag=() must_have_one_noun=() @@ -376,15 +413,21 @@ _git-bug_bridge_auth_add-token() flags+=("--target=") two_word_flags+=("--target") two_word_flags+=("-t") + local_nonpersistent_flags+=("--target") local_nonpersistent_flags+=("--target=") + local_nonpersistent_flags+=("-t") flags+=("--login=") two_word_flags+=("--login") two_word_flags+=("-l") + local_nonpersistent_flags+=("--login") local_nonpersistent_flags+=("--login=") + local_nonpersistent_flags+=("-l") flags+=("--user=") two_word_flags+=("--user") two_word_flags+=("-u") + local_nonpersistent_flags+=("--user") local_nonpersistent_flags+=("--user=") + local_nonpersistent_flags+=("-u") must_have_one_flag=() must_have_one_noun=() @@ -471,40 +514,57 @@ _git-bug_bridge_configure() flags+=("--name=") two_word_flags+=("--name") two_word_flags+=("-n") + local_nonpersistent_flags+=("--name") local_nonpersistent_flags+=("--name=") + local_nonpersistent_flags+=("-n") flags+=("--target=") two_word_flags+=("--target") two_word_flags+=("-t") + local_nonpersistent_flags+=("--target") local_nonpersistent_flags+=("--target=") + local_nonpersistent_flags+=("-t") flags+=("--url=") two_word_flags+=("--url") two_word_flags+=("-u") + local_nonpersistent_flags+=("--url") local_nonpersistent_flags+=("--url=") + local_nonpersistent_flags+=("-u") flags+=("--base-url=") two_word_flags+=("--base-url") two_word_flags+=("-b") + local_nonpersistent_flags+=("--base-url") local_nonpersistent_flags+=("--base-url=") + local_nonpersistent_flags+=("-b") flags+=("--login=") two_word_flags+=("--login") two_word_flags+=("-l") + local_nonpersistent_flags+=("--login") local_nonpersistent_flags+=("--login=") + local_nonpersistent_flags+=("-l") flags+=("--credential=") two_word_flags+=("--credential") two_word_flags+=("-c") + local_nonpersistent_flags+=("--credential") local_nonpersistent_flags+=("--credential=") + local_nonpersistent_flags+=("-c") flags+=("--token=") two_word_flags+=("--token") + local_nonpersistent_flags+=("--token") local_nonpersistent_flags+=("--token=") flags+=("--token-stdin") local_nonpersistent_flags+=("--token-stdin") flags+=("--owner=") two_word_flags+=("--owner") two_word_flags+=("-o") + local_nonpersistent_flags+=("--owner") local_nonpersistent_flags+=("--owner=") + local_nonpersistent_flags+=("-o") flags+=("--project=") two_word_flags+=("--project") two_word_flags+=("-p") + local_nonpersistent_flags+=("--project") local_nonpersistent_flags+=("--project=") + local_nonpersistent_flags+=("-p") must_have_one_flag=() must_have_one_noun=() @@ -528,10 +588,13 @@ _git-bug_bridge_pull() flags+=("--no-resume") flags+=("-n") local_nonpersistent_flags+=("--no-resume") + local_nonpersistent_flags+=("-n") flags+=("--since=") two_word_flags+=("--since") two_word_flags+=("-s") + local_nonpersistent_flags+=("--since") local_nonpersistent_flags+=("--since=") + local_nonpersistent_flags+=("-s") must_have_one_flag=() must_have_one_noun=() @@ -620,6 +683,7 @@ _git-bug_commands() flags+=("--pretty") flags+=("-p") local_nonpersistent_flags+=("--pretty") + local_nonpersistent_flags+=("-p") must_have_one_flag=() must_have_one_noun=() @@ -643,11 +707,15 @@ _git-bug_comment_add() flags+=("--file=") two_word_flags+=("--file") two_word_flags+=("-F") + local_nonpersistent_flags+=("--file") local_nonpersistent_flags+=("--file=") + local_nonpersistent_flags+=("-F") flags+=("--message=") two_word_flags+=("--message") two_word_flags+=("-m") + local_nonpersistent_flags+=("--message") local_nonpersistent_flags+=("--message=") + local_nonpersistent_flags+=("-m") must_have_one_flag=() must_have_one_noun=() @@ -774,43 +842,63 @@ _git-bug_ls() flags+=("--status=") two_word_flags+=("--status") two_word_flags+=("-s") + local_nonpersistent_flags+=("--status") local_nonpersistent_flags+=("--status=") + local_nonpersistent_flags+=("-s") flags+=("--author=") two_word_flags+=("--author") two_word_flags+=("-a") + local_nonpersistent_flags+=("--author") local_nonpersistent_flags+=("--author=") + local_nonpersistent_flags+=("-a") flags+=("--participant=") two_word_flags+=("--participant") two_word_flags+=("-p") + local_nonpersistent_flags+=("--participant") local_nonpersistent_flags+=("--participant=") + local_nonpersistent_flags+=("-p") flags+=("--actor=") two_word_flags+=("--actor") two_word_flags+=("-A") + local_nonpersistent_flags+=("--actor") local_nonpersistent_flags+=("--actor=") + local_nonpersistent_flags+=("-A") flags+=("--label=") two_word_flags+=("--label") two_word_flags+=("-l") + local_nonpersistent_flags+=("--label") local_nonpersistent_flags+=("--label=") + local_nonpersistent_flags+=("-l") flags+=("--title=") two_word_flags+=("--title") two_word_flags+=("-t") + local_nonpersistent_flags+=("--title") local_nonpersistent_flags+=("--title=") + local_nonpersistent_flags+=("-t") flags+=("--no=") two_word_flags+=("--no") two_word_flags+=("-n") + local_nonpersistent_flags+=("--no") local_nonpersistent_flags+=("--no=") + local_nonpersistent_flags+=("-n") flags+=("--by=") two_word_flags+=("--by") two_word_flags+=("-b") + local_nonpersistent_flags+=("--by") local_nonpersistent_flags+=("--by=") + local_nonpersistent_flags+=("-b") flags+=("--direction=") two_word_flags+=("--direction") two_word_flags+=("-d") + local_nonpersistent_flags+=("--direction") local_nonpersistent_flags+=("--direction=") + local_nonpersistent_flags+=("-d") flags+=("--format=") two_word_flags+=("--format") two_word_flags+=("-f") + local_nonpersistent_flags+=("--format") local_nonpersistent_flags+=("--format=") + local_nonpersistent_flags+=("-f") must_have_one_flag=() must_have_one_noun=() @@ -953,11 +1041,14 @@ _git-bug_show() flags+=("--field=") two_word_flags+=("--field") + local_nonpersistent_flags+=("--field") local_nonpersistent_flags+=("--field=") flags+=("--format=") two_word_flags+=("--format") two_word_flags+=("-f") + local_nonpersistent_flags+=("--format") local_nonpersistent_flags+=("--format=") + local_nonpersistent_flags+=("-f") must_have_one_flag=() must_have_one_noun=() @@ -1063,7 +1154,9 @@ _git-bug_title_edit() flags+=("--title=") two_word_flags+=("--title") two_word_flags+=("-t") + local_nonpersistent_flags+=("--title") local_nonpersistent_flags+=("--title=") + local_nonpersistent_flags+=("-t") must_have_one_flag=() must_have_one_noun=() @@ -1148,7 +1241,9 @@ _git-bug_user_ls() flags+=("--format=") two_word_flags+=("--format") two_word_flags+=("-f") + local_nonpersistent_flags+=("--format") local_nonpersistent_flags+=("--format=") + local_nonpersistent_flags+=("-f") must_have_one_flag=() must_have_one_noun=() @@ -1175,7 +1270,9 @@ _git-bug_user() flags+=("--field=") two_word_flags+=("--field") two_word_flags+=("-f") + local_nonpersistent_flags+=("--field") local_nonpersistent_flags+=("--field=") + local_nonpersistent_flags+=("-f") must_have_one_flag=() must_have_one_noun=() @@ -1199,12 +1296,15 @@ _git-bug_version() flags+=("--number") flags+=("-n") local_nonpersistent_flags+=("--number") + local_nonpersistent_flags+=("-n") flags+=("--commit") flags+=("-c") local_nonpersistent_flags+=("--commit") + local_nonpersistent_flags+=("-c") flags+=("--all") flags+=("-a") local_nonpersistent_flags+=("--all") + local_nonpersistent_flags+=("-a") must_have_one_flag=() must_have_one_noun=() @@ -1232,7 +1332,9 @@ _git-bug_webui() flags+=("--port=") two_word_flags+=("--port") two_word_flags+=("-p") + local_nonpersistent_flags+=("--port") local_nonpersistent_flags+=("--port=") + local_nonpersistent_flags+=("-p") flags+=("--read-only") local_nonpersistent_flags+=("--read-only") diff --git a/misc/fish_completion/git-bug b/misc/fish_completion/git-bug index edbfa81b..28e66532 100644 --- a/misc/fish_completion/git-bug +++ b/misc/fish_completion/git-bug @@ -1,30 +1,36 @@ # fish completion for git-bug -*- shell-script -*- -function __git-bug_debug +function __git_bug_debug set file "$BASH_COMP_DEBUG_FILE" if test -n "$file" echo "$argv" >> $file end end -function __git-bug_perform_completion - __git-bug_debug "Starting __git-bug_perform_completion with: $argv" +function __git_bug_perform_completion + __git_bug_debug "Starting __git_bug_perform_completion with: $argv" set args (string split -- " " "$argv") set lastArg "$args[-1]" - __git-bug_debug "args: $args" - __git-bug_debug "last arg: $lastArg" + __git_bug_debug "args: $args" + __git_bug_debug "last arg: $lastArg" set emptyArg "" if test -z "$lastArg" - __git-bug_debug "Setting emptyArg" + __git_bug_debug "Setting emptyArg" set emptyArg \"\" end - __git-bug_debug "emptyArg: $emptyArg" + __git_bug_debug "emptyArg: $emptyArg" + + if not type -q "$args[1]" + # This can happen when "complete --do-complete git-bug" is called when running this script. + __git_bug_debug "Cannot find $args[1]. No completions." + return + end set requestComp "$args[1] __complete $args[2..-1] $emptyArg" - __git-bug_debug "Calling $requestComp" + __git_bug_debug "Calling $requestComp" set results (eval $requestComp 2> /dev/null) set comps $results[1..-2] @@ -34,9 +40,9 @@ function __git-bug_perform_completion # completions must be prefixed with the flag set flagPrefix (string match -r -- '-.*=' "$lastArg") - __git-bug_debug "Comps: $comps" - __git-bug_debug "DirectiveLine: $directiveLine" - __git-bug_debug "flagPrefix: $flagPrefix" + __git_bug_debug "Comps: $comps" + __git_bug_debug "DirectiveLine: $directiveLine" + __git_bug_debug "flagPrefix: $flagPrefix" for comp in $comps printf "%s%s\n" "$flagPrefix" "$comp" @@ -46,92 +52,113 @@ function __git-bug_perform_completion end # This function does three things: -# 1- Obtain the completions and store them in the global __git-bug_comp_results -# 2- Set the __git-bug_comp_do_file_comp flag if file completion should be performed +# 1- Obtain the completions and store them in the global __git_bug_comp_results +# 2- Set the __git_bug_comp_do_file_comp flag if file completion should be performed # and unset it otherwise # 3- Return true if the completion results are not empty -function __git-bug_prepare_completions +function __git_bug_prepare_completions # Start fresh - set --erase __git-bug_comp_do_file_comp - set --erase __git-bug_comp_results + set --erase __git_bug_comp_do_file_comp + set --erase __git_bug_comp_results # Check if the command-line is already provided. This is useful for testing. - if not set --query __git-bug_comp_commandLine - set __git-bug_comp_commandLine (commandline) + if not set --query __git_bug_comp_commandLine + # Use the -c flag to allow for completion in the middle of the line + set __git_bug_comp_commandLine (commandline -c) end - __git-bug_debug "commandLine is: $__git-bug_comp_commandLine" + __git_bug_debug "commandLine is: $__git_bug_comp_commandLine" - set results (__git-bug_perform_completion "$__git-bug_comp_commandLine") - set --erase __git-bug_comp_commandLine - __git-bug_debug "Completion results: $results" + set results (__git_bug_perform_completion "$__git_bug_comp_commandLine") + set --erase __git_bug_comp_commandLine + __git_bug_debug "Completion results: $results" if test -z "$results" - __git-bug_debug "No completion, probably due to a failure" + __git_bug_debug "No completion, probably due to a failure" # Might as well do file completion, in case it helps - set --global __git-bug_comp_do_file_comp 1 - return 0 + set --global __git_bug_comp_do_file_comp 1 + return 1 end set directive (string sub --start 2 $results[-1]) - set --global __git-bug_comp_results $results[1..-2] + set --global __git_bug_comp_results $results[1..-2] + + __git_bug_debug "Completions are: $__git_bug_comp_results" + __git_bug_debug "Directive is: $directive" - __git-bug_debug "Completions are: $__git-bug_comp_results" - __git-bug_debug "Directive is: $directive" + set shellCompDirectiveError 1 + set shellCompDirectiveNoSpace 2 + set shellCompDirectiveNoFileComp 4 + set shellCompDirectiveFilterFileExt 8 + set shellCompDirectiveFilterDirs 16 if test -z "$directive" set directive 0 end - set compErr (math (math --scale 0 $directive / 1) % 2) + set compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2) if test $compErr -eq 1 - __git-bug_debug "Received error directive: aborting." + __git_bug_debug "Received error directive: aborting." # Might as well do file completion, in case it helps - set --global __git-bug_comp_do_file_comp 1 - return 0 + set --global __git_bug_comp_do_file_comp 1 + return 1 end - set nospace (math (math --scale 0 $directive / 2) % 2) - set nofiles (math (math --scale 0 $directive / 4) % 2) + set filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2) + set dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2) + if test $filefilter -eq 1; or test $dirfilter -eq 1 + __git_bug_debug "File extension filtering or directory filtering not supported" + # Do full file completion instead + set --global __git_bug_comp_do_file_comp 1 + return 1 + end + + set nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2) + set nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2) - __git-bug_debug "nospace: $nospace, nofiles: $nofiles" + __git_bug_debug "nospace: $nospace, nofiles: $nofiles" # Important not to quote the variable for count to work - set numComps (count $__git-bug_comp_results) - __git-bug_debug "numComps: $numComps" + set numComps (count $__git_bug_comp_results) + __git_bug_debug "numComps: $numComps" if test $numComps -eq 1; and test $nospace -ne 0 # To support the "nospace" directive we trick the shell # by outputting an extra, longer completion. - __git-bug_debug "Adding second completion to perform nospace directive" - set --append __git-bug_comp_results $__git-bug_comp_results[1]. + __git_bug_debug "Adding second completion to perform nospace directive" + set --append __git_bug_comp_results $__git_bug_comp_results[1]. end if test $numComps -eq 0; and test $nofiles -eq 0 - __git-bug_debug "Requesting file completion" - set --global __git-bug_comp_do_file_comp 1 + __git_bug_debug "Requesting file completion" + set --global __git_bug_comp_do_file_comp 1 end # If we don't want file completion, we must return true even if there # are no completions found. This is because fish will perform the last # completion command, even if its condition is false, if no other # completion command was triggered - return (not set --query __git-bug_comp_do_file_comp) + return (not set --query __git_bug_comp_do_file_comp) end -# Remove any pre-existing completions for the program since we will be handling all of them -# TODO this cleanup is not sufficient. Fish completions are only loaded once the user triggers -# them, so the below deletion will not work as it is run too early. What else can we do? +# Since Fish completions are only loaded once the user triggers them, we trigger them ourselves +# so we can properly delete any completions provided by another script. +# The space after the the program name is essential to trigger completion for the program +# and not completion of the program name itself. +complete --do-complete "git-bug " > /dev/null 2>&1 +# Using '> /dev/null 2>&1' since '&>' is not supported in older versions of fish. + +# Remove any pre-existing completions for the program since we will be handling all of them. complete -c git-bug -e -# The order in which the below two lines are defined is very important so that __git-bug_prepare_completions -# is called first. It is __git-bug_prepare_completions that sets up the __git-bug_comp_do_file_comp variable. +# The order in which the below two lines are defined is very important so that __git_bug_prepare_completions +# is called first. It is __git_bug_prepare_completions that sets up the __git_bug_comp_do_file_comp variable. # # This completion will be run second as complete commands are added FILO. -# It triggers file completion choices when __git-bug_comp_do_file_comp is set. -complete -c git-bug -n 'set --query __git-bug_comp_do_file_comp' +# It triggers file completion choices when __git_bug_comp_do_file_comp is set. +complete -c git-bug -n 'set --query __git_bug_comp_do_file_comp' # This completion will be run first as complete commands are added FILO. -# The call to __git-bug_prepare_completions will setup both __git-bug_comp_results abd __git-bug_comp_do_file_comp. +# The call to __git_bug_prepare_completions will setup both __git_bug_comp_results and __git_bug_comp_do_file_comp. # It provides the program's completion choices. -complete -c git-bug -n '__git-bug_prepare_completions' -f -a '$__git-bug_comp_results' +complete -c git-bug -n '__git_bug_prepare_completions' -f -a '$__git_bug_comp_results' diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index 4ae10382..e0a6d8a1 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -1,473 +1,159 @@ #compdef _git-bug git-bug - -function _git-bug { - local -a commands - - _arguments -C \ - "1: :->cmnds" \ - "*::arg:->args" - - case $state in - cmnds) - commands=( - "add:Create a new bug." - "bridge:Configure and use bridges to other bug trackers." - "commands:Display available commands." - "comment:Display or add comments to a bug." - "deselect:Clear the implicitly selected bug." - "label:Display, add or remove labels to/from a bug." - "ls:List bugs." - "ls-id:List bug identifiers." - "ls-label:List valid labels." - "pull:Pull bugs update from a git remote." - "push:Push bugs update to a git remote." - "rm:Remove an existing bug." - "select:Select a bug for implicit use in future commands." - "show:Display the details of a bug." - "status:Display or change a bug status." - "termui:Launch the terminal UI." - "title:Display or change a title of a bug." - "user:Display or change the user identity." - "version:Show git-bug version information." - "webui:Launch the web UI." - ) - _describe "command" commands - ;; - esac - - case "$words[1]" in - add) - _git-bug_add - ;; - bridge) - _git-bug_bridge - ;; - commands) - _git-bug_commands - ;; - comment) - _git-bug_comment - ;; - deselect) - _git-bug_deselect - ;; - label) - _git-bug_label - ;; - ls) - _git-bug_ls - ;; - ls-id) - _git-bug_ls-id - ;; - ls-label) - _git-bug_ls-label - ;; - pull) - _git-bug_pull - ;; - push) - _git-bug_push - ;; - rm) - _git-bug_rm - ;; - select) - _git-bug_select - ;; - show) - _git-bug_show - ;; - status) - _git-bug_status - ;; - termui) - _git-bug_termui - ;; - title) - _git-bug_title - ;; - user) - _git-bug_user - ;; - version) - _git-bug_version - ;; - webui) - _git-bug_webui - ;; - esac -} - -function _git-bug_add { - _arguments \ - '(-t --title)'{-t,--title}'[Provide a title to describe the issue]:' \ - '(-m --message)'{-m,--message}'[Provide a message to describe the issue]:' \ - '(-F --file)'{-F,--file}'[Take the message from the given file. Use - to read the message from the standard input]:' -} - - -function _git-bug_bridge { - local -a commands - - _arguments -C \ - "1: :->cmnds" \ - "*::arg:->args" - - case $state in - cmnds) - commands=( - "auth:List all known bridge authentication credentials." - "configure:Configure a new bridge." - "pull:Pull updates." - "push:Push updates." - "rm:Delete a configured bridge." - ) - _describe "command" commands - ;; - esac - - case "$words[1]" in - auth) - _git-bug_bridge_auth - ;; - configure) - _git-bug_bridge_configure - ;; - pull) - _git-bug_bridge_pull - ;; - push) - _git-bug_bridge_push - ;; - rm) - _git-bug_bridge_rm - ;; - esac -} - - -function _git-bug_bridge_auth { - local -a commands - - _arguments -C \ - "1: :->cmnds" \ - "*::arg:->args" - - case $state in - cmnds) - commands=( - "add-token:Store a new token" - "rm:Remove a credential." - "show:Display an authentication credential." - ) - _describe "command" commands - ;; - esac - - case "$words[1]" in - add-token) - _git-bug_bridge_auth_add-token - ;; - rm) - _git-bug_bridge_auth_rm - ;; - show) - _git-bug_bridge_auth_show - ;; - esac -} - -function _git-bug_bridge_auth_add-token { - _arguments \ - '(-t --target)'{-t,--target}'[The target of the bridge. Valid values are [github,gitlab,jira,launchpad-preview]]:' \ - '(-l --login)'{-l,--login}'[The login in the remote bug-tracker]:' \ - '(-u --user)'{-u,--user}'[The user to add the token to. Default is the current user]:' -} - -function _git-bug_bridge_auth_rm { - _arguments -} - -function _git-bug_bridge_auth_show { - _arguments -} - -function _git-bug_bridge_configure { - _arguments \ - '(-n --name)'{-n,--name}'[A distinctive name to identify the bridge]:' \ - '(-t --target)'{-t,--target}'[The target of the bridge. Valid values are [github,gitlab,jira,launchpad-preview]]:' \ - '(-u --url)'{-u,--url}'[The URL of the remote repository]:' \ - '(-b --base-url)'{-b,--base-url}'[The base URL of your remote issue tracker]:' \ - '(-l --login)'{-l,--login}'[The login on your remote issue tracker]:' \ - '(-c --credential)'{-c,--credential}'[The identifier or prefix of an already known credential for your remote issue tracker (see "git-bug bridge auth")]:' \ - '--token[A raw authentication token for the remote issue tracker]:' \ - '--token-stdin[Will read the token from stdin and ignore --token]' \ - '(-o --owner)'{-o,--owner}'[The owner of the remote repository]:' \ - '(-p --project)'{-p,--project}'[The name of the remote repository]:' -} - -function _git-bug_bridge_pull { - _arguments \ - '(-n --no-resume)'{-n,--no-resume}'[force importing all bugs]' \ - '(-s --since)'{-s,--since}'[import only bugs updated after the given date (ex: "200h" or "june 2 2019")]:' -} - -function _git-bug_bridge_push { - _arguments -} - -function _git-bug_bridge_rm { - _arguments -} - -function _git-bug_commands { - _arguments \ - '(-p --pretty)'{-p,--pretty}'[Output the command description as well as Markdown compatible comment]' -} - - -function _git-bug_comment { - local -a commands - - _arguments -C \ - "1: :->cmnds" \ - "*::arg:->args" - - case $state in - cmnds) - commands=( - "add:Add a new comment to a bug." - ) - _describe "command" commands - ;; - esac - - case "$words[1]" in - add) - _git-bug_comment_add - ;; - esac -} - -function _git-bug_comment_add { - _arguments \ - '(-F --file)'{-F,--file}'[Take the message from the given file. Use - to read the message from the standard input]:' \ - '(-m --message)'{-m,--message}'[Provide the new message from the command line]:' -} - -function _git-bug_deselect { - _arguments -} - - -function _git-bug_label { - local -a commands - - _arguments -C \ - "1: :->cmnds" \ - "*::arg:->args" - - case $state in - cmnds) - commands=( - "add:Add a label to a bug." - "rm:Remove a label from a bug." - ) - _describe "command" commands - ;; - esac - - case "$words[1]" in - add) - _git-bug_label_add - ;; - rm) - _git-bug_label_rm - ;; - esac -} - -function _git-bug_label_add { - _arguments -} - -function _git-bug_label_rm { - _arguments -} - -function _git-bug_ls { - _arguments \ - '(*-s *--status)'{\*-s,\*--status}'[Filter by status. Valid values are [open,closed]]:' \ - '(*-a *--author)'{\*-a,\*--author}'[Filter by author]:' \ - '(*-p *--participant)'{\*-p,\*--participant}'[Filter by participant]:' \ - '(*-A *--actor)'{\*-A,\*--actor}'[Filter by actor]:' \ - '(*-l *--label)'{\*-l,\*--label}'[Filter by label]:' \ - '(*-t *--title)'{\*-t,\*--title}'[Filter by title]:' \ - '(*-n *--no)'{\*-n,\*--no}'[Filter by absence of something. Valid values are [label]]:' \ - '(-b --by)'{-b,--by}'[Sort the results by a characteristic. Valid values are [id,creation,edit]]:' \ - '(-d --direction)'{-d,--direction}'[Select the sorting direction. Valid values are [asc,desc]]:' \ - '(-f --format)'{-f,--format}'[Select the output formatting style. Valid values are [default,plain,json,org-mode]]:' -} - -function _git-bug_ls-id { - _arguments -} - -function _git-bug_ls-label { - _arguments -} - -function _git-bug_pull { - _arguments -} - -function _git-bug_push { - _arguments -} - -function _git-bug_rm { - _arguments -} - -function _git-bug_select { - _arguments -} - -function _git-bug_show { - _arguments \ - '--field[Select field to display. Valid values are [author,authorEmail,createTime,lastEdit,humanId,id,labels,shortId,status,title,actors,participants]]:' \ - '(-f --format)'{-f,--format}'[Select the output formatting style. Valid values are [default,json,org-mode]]:' -} - - -function _git-bug_status { - local -a commands - - _arguments -C \ - "1: :->cmnds" \ - "*::arg:->args" - - case $state in - cmnds) - commands=( - "close:Mark a bug as closed." - "open:Mark a bug as open." - ) - _describe "command" commands - ;; - esac - - case "$words[1]" in - close) - _git-bug_status_close - ;; - open) - _git-bug_status_open - ;; - esac -} - -function _git-bug_status_close { - _arguments -} - -function _git-bug_status_open { - _arguments -} - -function _git-bug_termui { - _arguments -} - - -function _git-bug_title { - local -a commands - - _arguments -C \ - "1: :->cmnds" \ - "*::arg:->args" - - case $state in - cmnds) - commands=( - "edit:Edit a title of a bug." - ) - _describe "command" commands - ;; - esac - - case "$words[1]" in - edit) - _git-bug_title_edit - ;; - esac -} - -function _git-bug_title_edit { - _arguments \ - '(-t --title)'{-t,--title}'[Provide a title to describe the issue]:' -} - - -function _git-bug_user { - local -a commands - - _arguments -C \ - '(-f --field)'{-f,--field}'[Select field to display. Valid values are [email,humanId,id,lastModification,lastModificationLamport,login,metadata,name]]:' \ - "1: :->cmnds" \ - "*::arg:->args" - - case $state in - cmnds) - commands=( - "adopt:Adopt an existing identity as your own." - "create:Create a new identity." - "ls:List identities." - ) - _describe "command" commands - ;; - esac - - case "$words[1]" in - adopt) - _git-bug_user_adopt - ;; - create) - _git-bug_user_create - ;; - ls) - _git-bug_user_ls - ;; - esac -} - -function _git-bug_user_adopt { - _arguments -} - -function _git-bug_user_create { - _arguments -} - -function _git-bug_user_ls { - _arguments \ - '(-f --format)'{-f,--format}'[Select the output formatting style. Valid values are [default,json]]:' -} - -function _git-bug_version { - _arguments \ - '(-n --number)'{-n,--number}'[Only show the version number]' \ - '(-c --commit)'{-c,--commit}'[Only show the commit hash]' \ - '(-a --all)'{-a,--all}'[Show all version information]' -} - -function _git-bug_webui { - _arguments \ - '--open[Automatically open the web UI in the default browser]' \ - '--no-open[Prevent the automatic opening of the web UI in the default browser]' \ - '(-p --port)'{-p,--port}'[Port to listen to (default is random)]:' \ - '--read-only[Whether to run the web UI in read-only mode]' -} - +# zsh completion for git-bug -*- shell-script -*- + +__git-bug_debug() +{ + local file="$BASH_COMP_DEBUG_FILE" + if [[ -n ${file} ]]; then + echo "$*" >> "${file}" + fi +} + +_git-bug() +{ + local shellCompDirectiveError=1 + local shellCompDirectiveNoSpace=2 + local shellCompDirectiveNoFileComp=4 + local shellCompDirectiveFilterFileExt=8 + local shellCompDirectiveFilterDirs=16 + + local lastParam lastChar flagPrefix requestComp out directive compCount comp lastComp + local -a completions + + __git-bug_debug "\n========= starting completion logic ==========" + __git-bug_debug "CURRENT: ${CURRENT}, words[*]: ${words[*]}" + + # The user could have moved the cursor backwards on the command-line. + # We need to trigger completion from the $CURRENT location, so we need + # to truncate the command-line ($words) up to the $CURRENT location. + # (We cannot use $CURSOR as its value does not work when a command is an alias.) + words=("${=words[1,CURRENT]}") + __git-bug_debug "Truncated words[*]: ${words[*]}," + + lastParam=${words[-1]} + lastChar=${lastParam[-1]} + __git-bug_debug "lastParam: ${lastParam}, lastChar: ${lastChar}" + + # For zsh, when completing a flag with an = (e.g., git-bug -n=<TAB>) + # completions must be prefixed with the flag + setopt local_options BASH_REMATCH + if [[ "${lastParam}" =~ '-.*=' ]]; then + # We are dealing with a flag with an = + flagPrefix="-P ${BASH_REMATCH}" + fi + + # Prepare the command to obtain completions + requestComp="${words[1]} __complete ${words[2,-1]}" + if [ "${lastChar}" = "" ]; then + # If the last parameter is complete (there is a space following it) + # We add an extra empty parameter so we can indicate this to the go completion code. + __git-bug_debug "Adding extra empty parameter" + requestComp="${requestComp} \"\"" + fi + + __git-bug_debug "About to call: eval ${requestComp}" + + # Use eval to handle any environment variables and such + out=$(eval ${requestComp} 2>/dev/null) + __git-bug_debug "completion output: ${out}" + + # Extract the directive integer following a : from the last line + local lastLine + while IFS='\n' read -r line; do + lastLine=${line} + done < <(printf "%s\n" "${out[@]}") + __git-bug_debug "last line: ${lastLine}" + + if [ "${lastLine[1]}" = : ]; then + directive=${lastLine[2,-1]} + # Remove the directive including the : and the newline + local suffix + (( suffix=${#lastLine}+2)) + out=${out[1,-$suffix]} + else + # There is no directive specified. Leave $out as is. + __git-bug_debug "No directive found. Setting do default" + directive=0 + fi + + __git-bug_debug "directive: ${directive}" + __git-bug_debug "completions: ${out}" + __git-bug_debug "flagPrefix: ${flagPrefix}" + + if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then + __git-bug_debug "Completion received error. Ignoring completions." + return + fi + + compCount=0 + while IFS='\n' read -r comp; do + if [ -n "$comp" ]; then + # If requested, completions are returned with a description. + # The description is preceded by a TAB character. + # For zsh's _describe, we need to use a : instead of a TAB. + # We first need to escape any : as part of the completion itself. + comp=${comp//:/\\:} + + local tab=$(printf '\t') + comp=${comp//$tab/:} + + ((compCount++)) + __git-bug_debug "Adding completion: ${comp}" + completions+=${comp} + lastComp=$comp + fi + done < <(printf "%s\n" "${out[@]}") + + if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then + # File extension filtering + local filteringCmd + filteringCmd='_files' + for filter in ${completions[@]}; do + if [ ${filter[1]} != '*' ]; then + # zsh requires a glob pattern to do file filtering + filter="\*.$filter" + fi + filteringCmd+=" -g $filter" + done + filteringCmd+=" ${flagPrefix}" + + __git-bug_debug "File filtering command: $filteringCmd" + _arguments '*:filename:'"$filteringCmd" + elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then + # File completion for directories only + local subDir + subdir="${completions[1]}" + if [ -n "$subdir" ]; then + __git-bug_debug "Listing directories in $subdir" + pushd "${subdir}" >/dev/null 2>&1 + else + __git-bug_debug "Listing directories in ." + fi + + _arguments '*:dirname:_files -/'" ${flagPrefix}" + if [ -n "$subdir" ]; then + popd >/dev/null 2>&1 + fi + elif [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ] && [ ${compCount} -eq 1 ]; then + __git-bug_debug "Activating nospace." + # We can use compadd here as there is no description when + # there is only one completion. + compadd -S '' "${lastComp}" + elif [ ${compCount} -eq 0 ]; then + if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then + __git-bug_debug "deactivating file completion" + else + # Perform file completion + __git-bug_debug "activating file completion" + _arguments '*:filename:_files'" ${flagPrefix}" + fi + else + _describe "completions" completions $(echo $flagPrefix) + fi +} + +# don't run the completion function when being source-ed or eval-ed +if [ "$funcstack[1]" = "_git-bug" ]; then + _git-bug +fi |