Fossil SCM
Added zsh fossil autocompletion, as discussed in [https://fossil-scm.org/forum/forumpost/47a180c815].
Commit
e299531d5b450607774f832d59af311a30a915245d519353207c6e98d4bc282c
Parent
68a78b895e91f10…
1 file changed
+186
| --- a/tools/fossil-autocomplete.zsh | ||
| +++ b/tools/fossil-autocomplete.zsh | ||
| @@ -0,0 +1,186 @@ | ||
| 1 | +#compdef fossil | |
| 2 | +# Origin: https://chiselapp.com/user/lifepillar/repository/fossil-zsh-completion | |
| 3 | +################################################################################# | |
| 4 | +# # | |
| 5 | +# Copyright 2020 Lifepillar # | |
| 6 | +# # | |
| 7 | +# Permission is hereby granted, free of charge, to any person obtaining a copy # | |
| 8 | +# of this software and associated documentation files (the "Software"), to deal # | |
| 9 | +# in the Software without restriction, including without limitation the rights # | |
| 10 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # | |
| 11 | +# copies of the Software, and to permit persons to whom the Software is # | |
| 12 | +# furnished to do so, subject to the following conditions: # | |
| 13 | +# # | |
| 14 | +# The above copyright notice and this permission notice shall be included in # | |
| 15 | +# all copies or substantial portions of the Software. # | |
| 16 | +# # | |
| 17 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # | |
| 18 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # | |
| 19 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # | |
| 20 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # | |
| 21 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # | |
| 22 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # | |
| 23 | +# SOFTWARE. # | |
| 24 | +# # | |
| 25 | +################################################################################# | |
| 26 | + | |
| 27 | +# To reload the completion function after it has been modified: | |
| 28 | +# | |
| 29 | +# $ unfunction _fossil | |
| 30 | +# $ autoload -U _fossil | |
| 31 | +# | |
| 32 | +# See also: http://zsh.sourceforge.net/Doc/Release/Completion-System.html | |
| 33 | +# See also: https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org | |
| 34 | + | |
| 35 | +################################################################################ | |
| 36 | +# Functions that help build this completion file # | |
| 37 | +################################################################################ | |
| 38 | + | |
| 39 | +# This function can be used to generate scaffolding code for the options of all | |
| 40 | +# the commands. Copy and paste the result at the suitable spot in this script | |
| 41 | +# to update it. To parse all commands: | |
| 42 | +# | |
| 43 | +# __fossil_parse_help -a | |
| 44 | +# | |
| 45 | +# To parse all test commands: | |
| 46 | +# | |
| 47 | +# __fossil_parse_help -t | |
| 48 | +# | |
| 49 | +# NOTE: The code must be adapted manually. Diff with previous version! | |
| 50 | +function __fossil_parse_help() { | |
| 51 | + echo ' case "$words[1]" in' | |
| 52 | + for c in `fossil help $1 | xargs -n1 | sort`; | |
| 53 | + do | |
| 54 | + echo " ($c)" | |
| 55 | + echo ' _arguments \\' | |
| 56 | + __fossil_format_options $c; | |
| 57 | + echo " '(- *)'--help'[Show help and exit]' \\" | |
| 58 | + echo " '*:files:_files'" | |
| 59 | + echo '' | |
| 60 | + echo ' ;;' | |
| 61 | + done; | |
| 62 | + echo ' esac' | |
| 63 | + echo ' ;;' | |
| 64 | +} | |
| 65 | + | |
| 66 | +# Extract the options of a command and format it in a way that can be used in | |
| 67 | +# a ZSH completion script. | |
| 68 | +# Use `__fossil_format_options -o` to extract the common options. | |
| 69 | +function __fossil_format_options() { | |
| 70 | + fossil help $1 2>&1 \ | |
| 71 | + | grep '^\s\{1,3\}-' \ | |
| 72 | + | sed -E 's/^ +//' \ | |
| 73 | + | awk -F ' +' '{ | |
| 74 | + v=match($1,/\|/) | |
| 75 | + split($1,y,"|") | |
| 76 | + printf " " | |
| 77 | + if (v>0) | |
| 78 | + printf "\"(--help %s %s)\"{%s,%s}",y[1],y[2],y[1],y[2]; | |
| 79 | + else | |
| 80 | + printf "\"(--help %s)\"%s",y[1],y[1]; | |
| 81 | + $1="" | |
| 82 | + gsub(/^ +| +$/,"",$0); | |
| 83 | + gsub(/^ +| +$/,"",$0); | |
| 84 | + gsub(/\x27/,"\x27\"\x27\"\x27",$0); | |
| 85 | + print "\x27["$0"]\x27 \\"; | |
| 86 | + }' | |
| 87 | +} | |
| 88 | + | |
| 89 | + | |
| 90 | +################################################################################ | |
| 91 | +# Helper functions used for completion. # | |
| 92 | +################################################################################ | |
| 93 | + | |
| 94 | +function __fossil_commands() { | |
| 95 | + fossil help --all | |
| 96 | +} | |
| 97 | + | |
| 98 | +function __fossil_test_commands() { | |
| 99 | + fossil help --test | |
| 100 | +} | |
| 101 | + | |
| 102 | +function __fossil_all_commands() { | |
| 103 | + __fossil_commands | |
| 104 | + __fossil_test_commands | |
| 105 | +} | |
| 106 | + | |
| 107 | +function __fossil_users() { | |
| 108 | + fossil user ls 2>/dev/null | awk '{print $1}' | |
| 109 | +} | |
| 110 | + | |
| 111 | +function __fossil_branches() { | |
| 112 | + fossil branch ls -a 2>/dev/null | sed 's/\* *//' | |
| 113 | +} | |
| 114 | + | |
| 115 | +function __fossil_tags() { | |
| 116 | + fossil tag ls 2>/dev/null | |
| 117 | +} | |
| 118 | + | |
| 119 | +function __fossil_repos() { | |
| 120 | + ls | grep .fossil | |
| 121 | + fossil all ls 2>/dev/null | |
| 122 | +} | |
| 123 | + | |
| 124 | +function __fossil_remotes() { | |
| 125 | + fossil remote list 2>/dev/null | awk '{print $1}' | |
| 126 | +} | |
| 127 | + | |
| 128 | +function __fossil_wiki_pages() { | |
| 129 | + fossil wiki list 2>/dev/null | |
| 130 | +} | |
| 131 | + | |
| 132 | +function __fossil_areas() { | |
| 133 | + compadd all email project shun skin ticket user alias subscriber | |
| 134 | + return 0 | |
| 135 | +} | |
| 136 | + | |
| 137 | +function __fossil_settings() { | |
| 138 | + fossil help --setting | |
| 139 | +} | |
| 140 | + | |
| 141 | +function __fossil_urls() { | |
| 142 | + local u | |
| 143 | + u=($(__fossil_remotes)) | |
| 144 | + compadd -a u | |
| 145 | + compadd -S '' file:// http:// https:// ssh:// | |
| 146 | + return 0 | |
| 147 | +} | |
| 148 | + | |
| 149 | +################################################################################ | |
| 150 | +# Main # | |
| 151 | +################################################################################ | |
| 152 | + | |
| 153 | +function _fossil() { | |
| 154 | + local context state state_descr line | |
| 155 | + typeset -A opt_args | |
| 156 | + | |
| 157 | + local -a _common_options | |
| 158 | + # Scaffolding code for common options can be generated with `__fossil_format_options -o`. | |
| 159 | + _common_options=( | |
| 160 | + "(--help --args)"--args'[FILENAME Read additional arguments and options from FILENAME]:file:_files' | |
| 161 | + "(--help --cgitrace)"--cgitrace'[Active CGI tracing]' | |
| 162 | + "(--help --comfmtflags --comment-format)"--comfmtflags'[VALUE Set comment formatting flags to VALUE]:value:' | |
| 163 | + "(--help --comment-format --comfmtflags)"--comment-format'[VALUE Alias for --comfmtflags]:value:' | |
| 164 | + "(--help --errorlog)"--errorlog'[FILENAME Log errors to FILENAME]:file:_files' | |
| 165 | + "(- --help ;; | |
| 166 | + (zip) | |
| 167 | + on the command rather than running it]' | |
| 168 | + "(--help --httptrace)"--httptrace'[Trace outbound HTTP requests]' | |
| 169 | + "(--help --localtime)"--localtime'[Display times using the local timezone]' | |
| 170 | + "(--help --no-th-hook)"--no-th-hook'[Do not run TH1 hooks]' | |
| 171 | + "(--help --quiet)"--quiet'[Reduce the amount of output]' | |
| 172 | + "(--help --sqlstats)"--sqlstats'[Show SQL usage statistics when done]' | |
| 173 | + "(--help --sqltrace)"--sqltrace'[Trace all SQL commands]' | |
| 174 | + "(--help --sshtrace)"--sshtrace'[Trace SSH activity]' | |
| 175 | + "(--help --ssl-identity)"--ssl-identity'[NAME Set the SSL identity to NAME]:name:' | |
| 176 | + "(--help --systemtrace)"--systemtrace'[Trace calls to system()]' | |
| 177 | + "(--help --user -U)"{--user,-U}'[USER Make the default user be USER]:user:($(__fossil_users))' | |
| 178 | + "(--help --utc)"--utc'[Display times using UTC]' | |
| 179 | + "(--help --vfs)"--vfs'[NAME Cause SQLite to use the NAME VFS]:name:' | |
| 180 | + ) | |
| 181 | + | |
| 182 | + local -a _fossil_clean_options | |
| 183 | + _fossil_clean_options=( | |
| 184 | + "(--help --allckouts)"--allckouts'[Check for empty directories within any checkouts]' | |
| 185 | + "(--help --case-sensitive)"--case-sensitive'[BOOL Override case-sensitive setting]:bool:(yes no)' | |
| 186 | + "(--help --dirsonl |
| --- a/tools/fossil-autocomplete.zsh | |
| +++ b/tools/fossil-autocomplete.zsh | |
| @@ -0,0 +1,186 @@ | |
| --- a/tools/fossil-autocomplete.zsh | |
| +++ b/tools/fossil-autocomplete.zsh | |
| @@ -0,0 +1,186 @@ | |
| 1 | #compdef fossil |
| 2 | # Origin: https://chiselapp.com/user/lifepillar/repository/fossil-zsh-completion |
| 3 | ################################################################################# |
| 4 | # # |
| 5 | # Copyright 2020 Lifepillar # |
| 6 | # # |
| 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy # |
| 8 | # of this software and associated documentation files (the "Software"), to deal # |
| 9 | # in the Software without restriction, including without limitation the rights # |
| 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # |
| 11 | # copies of the Software, and to permit persons to whom the Software is # |
| 12 | # furnished to do so, subject to the following conditions: # |
| 13 | # # |
| 14 | # The above copyright notice and this permission notice shall be included in # |
| 15 | # all copies or substantial portions of the Software. # |
| 16 | # # |
| 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # |
| 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # |
| 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # |
| 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # |
| 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # |
| 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # |
| 23 | # SOFTWARE. # |
| 24 | # # |
| 25 | ################################################################################# |
| 26 | |
| 27 | # To reload the completion function after it has been modified: |
| 28 | # |
| 29 | # $ unfunction _fossil |
| 30 | # $ autoload -U _fossil |
| 31 | # |
| 32 | # See also: http://zsh.sourceforge.net/Doc/Release/Completion-System.html |
| 33 | # See also: https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org |
| 34 | |
| 35 | ################################################################################ |
| 36 | # Functions that help build this completion file # |
| 37 | ################################################################################ |
| 38 | |
| 39 | # This function can be used to generate scaffolding code for the options of all |
| 40 | # the commands. Copy and paste the result at the suitable spot in this script |
| 41 | # to update it. To parse all commands: |
| 42 | # |
| 43 | # __fossil_parse_help -a |
| 44 | # |
| 45 | # To parse all test commands: |
| 46 | # |
| 47 | # __fossil_parse_help -t |
| 48 | # |
| 49 | # NOTE: The code must be adapted manually. Diff with previous version! |
| 50 | function __fossil_parse_help() { |
| 51 | echo ' case "$words[1]" in' |
| 52 | for c in `fossil help $1 | xargs -n1 | sort`; |
| 53 | do |
| 54 | echo " ($c)" |
| 55 | echo ' _arguments \\' |
| 56 | __fossil_format_options $c; |
| 57 | echo " '(- *)'--help'[Show help and exit]' \\" |
| 58 | echo " '*:files:_files'" |
| 59 | echo '' |
| 60 | echo ' ;;' |
| 61 | done; |
| 62 | echo ' esac' |
| 63 | echo ' ;;' |
| 64 | } |
| 65 | |
| 66 | # Extract the options of a command and format it in a way that can be used in |
| 67 | # a ZSH completion script. |
| 68 | # Use `__fossil_format_options -o` to extract the common options. |
| 69 | function __fossil_format_options() { |
| 70 | fossil help $1 2>&1 \ |
| 71 | | grep '^\s\{1,3\}-' \ |
| 72 | | sed -E 's/^ +//' \ |
| 73 | | awk -F ' +' '{ |
| 74 | v=match($1,/\|/) |
| 75 | split($1,y,"|") |
| 76 | printf " " |
| 77 | if (v>0) |
| 78 | printf "\"(--help %s %s)\"{%s,%s}",y[1],y[2],y[1],y[2]; |
| 79 | else |
| 80 | printf "\"(--help %s)\"%s",y[1],y[1]; |
| 81 | $1="" |
| 82 | gsub(/^ +| +$/,"",$0); |
| 83 | gsub(/^ +| +$/,"",$0); |
| 84 | gsub(/\x27/,"\x27\"\x27\"\x27",$0); |
| 85 | print "\x27["$0"]\x27 \\"; |
| 86 | }' |
| 87 | } |
| 88 | |
| 89 | |
| 90 | ################################################################################ |
| 91 | # Helper functions used for completion. # |
| 92 | ################################################################################ |
| 93 | |
| 94 | function __fossil_commands() { |
| 95 | fossil help --all |
| 96 | } |
| 97 | |
| 98 | function __fossil_test_commands() { |
| 99 | fossil help --test |
| 100 | } |
| 101 | |
| 102 | function __fossil_all_commands() { |
| 103 | __fossil_commands |
| 104 | __fossil_test_commands |
| 105 | } |
| 106 | |
| 107 | function __fossil_users() { |
| 108 | fossil user ls 2>/dev/null | awk '{print $1}' |
| 109 | } |
| 110 | |
| 111 | function __fossil_branches() { |
| 112 | fossil branch ls -a 2>/dev/null | sed 's/\* *//' |
| 113 | } |
| 114 | |
| 115 | function __fossil_tags() { |
| 116 | fossil tag ls 2>/dev/null |
| 117 | } |
| 118 | |
| 119 | function __fossil_repos() { |
| 120 | ls | grep .fossil |
| 121 | fossil all ls 2>/dev/null |
| 122 | } |
| 123 | |
| 124 | function __fossil_remotes() { |
| 125 | fossil remote list 2>/dev/null | awk '{print $1}' |
| 126 | } |
| 127 | |
| 128 | function __fossil_wiki_pages() { |
| 129 | fossil wiki list 2>/dev/null |
| 130 | } |
| 131 | |
| 132 | function __fossil_areas() { |
| 133 | compadd all email project shun skin ticket user alias subscriber |
| 134 | return 0 |
| 135 | } |
| 136 | |
| 137 | function __fossil_settings() { |
| 138 | fossil help --setting |
| 139 | } |
| 140 | |
| 141 | function __fossil_urls() { |
| 142 | local u |
| 143 | u=($(__fossil_remotes)) |
| 144 | compadd -a u |
| 145 | compadd -S '' file:// http:// https:// ssh:// |
| 146 | return 0 |
| 147 | } |
| 148 | |
| 149 | ################################################################################ |
| 150 | # Main # |
| 151 | ################################################################################ |
| 152 | |
| 153 | function _fossil() { |
| 154 | local context state state_descr line |
| 155 | typeset -A opt_args |
| 156 | |
| 157 | local -a _common_options |
| 158 | # Scaffolding code for common options can be generated with `__fossil_format_options -o`. |
| 159 | _common_options=( |
| 160 | "(--help --args)"--args'[FILENAME Read additional arguments and options from FILENAME]:file:_files' |
| 161 | "(--help --cgitrace)"--cgitrace'[Active CGI tracing]' |
| 162 | "(--help --comfmtflags --comment-format)"--comfmtflags'[VALUE Set comment formatting flags to VALUE]:value:' |
| 163 | "(--help --comment-format --comfmtflags)"--comment-format'[VALUE Alias for --comfmtflags]:value:' |
| 164 | "(--help --errorlog)"--errorlog'[FILENAME Log errors to FILENAME]:file:_files' |
| 165 | "(- --help ;; |
| 166 | (zip) |
| 167 | on the command rather than running it]' |
| 168 | "(--help --httptrace)"--httptrace'[Trace outbound HTTP requests]' |
| 169 | "(--help --localtime)"--localtime'[Display times using the local timezone]' |
| 170 | "(--help --no-th-hook)"--no-th-hook'[Do not run TH1 hooks]' |
| 171 | "(--help --quiet)"--quiet'[Reduce the amount of output]' |
| 172 | "(--help --sqlstats)"--sqlstats'[Show SQL usage statistics when done]' |
| 173 | "(--help --sqltrace)"--sqltrace'[Trace all SQL commands]' |
| 174 | "(--help --sshtrace)"--sshtrace'[Trace SSH activity]' |
| 175 | "(--help --ssl-identity)"--ssl-identity'[NAME Set the SSL identity to NAME]:name:' |
| 176 | "(--help --systemtrace)"--systemtrace'[Trace calls to system()]' |
| 177 | "(--help --user -U)"{--user,-U}'[USER Make the default user be USER]:user:($(__fossil_users))' |
| 178 | "(--help --utc)"--utc'[Display times using UTC]' |
| 179 | "(--help --vfs)"--vfs'[NAME Cause SQLite to use the NAME VFS]:name:' |
| 180 | ) |
| 181 | |
| 182 | local -a _fossil_clean_options |
| 183 | _fossil_clean_options=( |
| 184 | "(--help --allckouts)"--allckouts'[Check for empty directories within any checkouts]' |
| 185 | "(--help --case-sensitive)"--case-sensitive'[BOOL Override case-sensitive setting]:bool:(yes no)' |
| 186 | "(--help --dirsonl |