| 1 |
|
| 2 |
|
| 3 |
function __git_lfs_debug |
| 4 |
set -l file "$BASH_COMP_DEBUG_FILE" |
| 5 |
if test -n "$file" |
| 6 |
echo "$argv" >> $file |
| 7 |
end |
| 8 |
end |
| 9 |
|
| 10 |
function __git_lfs_perform_completion |
| 11 |
__git_lfs_debug "Starting __git_lfs_perform_completion" |
| 12 |
|
| 13 |
|
| 14 |
set -l args (commandline -opc) |
| 15 |
|
| 16 |
set -l lastArg (string escape -- (commandline -ct)) |
| 17 |
|
| 18 |
__git_lfs_debug "args: $args" |
| 19 |
__git_lfs_debug "last arg: $lastArg" |
| 20 |
|
| 21 |
|
| 22 |
set -l requestComp "GIT_LFS_ACTIVE_HELP=0 $args[1] __completeNoDesc $args[2..-1] $lastArg" |
| 23 |
|
| 24 |
__git_lfs_debug "Calling $requestComp" |
| 25 |
set -l results (eval $requestComp 2> /dev/null) |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
for line in $results[-1..1] |
| 31 |
if test (string trim -- $line) = "" |
| 32 |
|
| 33 |
set results $results[1..-2] |
| 34 |
else |
| 35 |
|
| 36 |
break |
| 37 |
end |
| 38 |
end |
| 39 |
|
| 40 |
set -l comps $results[1..-2] |
| 41 |
set -l directiveLine $results[-1] |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
set -l flagPrefix (string match -r -- '-.*=' "$lastArg") |
| 46 |
|
| 47 |
__git_lfs_debug "Comps: $comps" |
| 48 |
__git_lfs_debug "DirectiveLine: $directiveLine" |
| 49 |
__git_lfs_debug "flagPrefix: $flagPrefix" |
| 50 |
|
| 51 |
for comp in $comps |
| 52 |
printf "%s%s\n" "$flagPrefix" "$comp" |
| 53 |
end |
| 54 |
|
| 55 |
printf "%s\n" "$directiveLine" |
| 56 |
end |
| 57 |
|
| 58 |
|
| 59 |
function __git_lfs_perform_completion_once |
| 60 |
__git_lfs_debug "Starting __git_lfs_perform_completion_once" |
| 61 |
|
| 62 |
if test -n "$__git_lfs_perform_completion_once_result" |
| 63 |
__git_lfs_debug "Seems like a valid result already exists, skipping __git_lfs_perform_completion" |
| 64 |
return 0 |
| 65 |
end |
| 66 |
|
| 67 |
set --global __git_lfs_perform_completion_once_result (__git_lfs_perform_completion) |
| 68 |
if test -z "$__git_lfs_perform_completion_once_result" |
| 69 |
__git_lfs_debug "No completions, probably due to a failure" |
| 70 |
return 1 |
| 71 |
end |
| 72 |
|
| 73 |
__git_lfs_debug "Performed completions and set __git_lfs_perform_completion_once_result" |
| 74 |
return 0 |
| 75 |
end |
| 76 |
|
| 77 |
|
| 78 |
function __git_lfs_clear_perform_completion_once_result |
| 79 |
__git_lfs_debug "" |
| 80 |
__git_lfs_debug "========= clearing previously set __git_lfs_perform_completion_once_result variable ==========" |
| 81 |
set --erase __git_lfs_perform_completion_once_result |
| 82 |
__git_lfs_debug "Successfully erased the variable __git_lfs_perform_completion_once_result" |
| 83 |
end |
| 84 |
|
| 85 |
function __git_lfs_requires_order_preservation |
| 86 |
__git_lfs_debug "" |
| 87 |
__git_lfs_debug "========= checking if order preservation is required ==========" |
| 88 |
|
| 89 |
__git_lfs_perform_completion_once |
| 90 |
if test -z "$__git_lfs_perform_completion_once_result" |
| 91 |
__git_lfs_debug "Error determining if order preservation is required" |
| 92 |
return 1 |
| 93 |
end |
| 94 |
|
| 95 |
set -l directive (string sub --start 2 $__git_lfs_perform_completion_once_result[-1]) |
| 96 |
__git_lfs_debug "Directive is: $directive" |
| 97 |
|
| 98 |
set -l shellCompDirectiveKeepOrder 32 |
| 99 |
set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2) |
| 100 |
__git_lfs_debug "Keeporder is: $keeporder" |
| 101 |
|
| 102 |
if test $keeporder -ne 0 |
| 103 |
__git_lfs_debug "This does require order preservation" |
| 104 |
return 0 |
| 105 |
end |
| 106 |
|
| 107 |
__git_lfs_debug "This doesn't require order preservation" |
| 108 |
return 1 |
| 109 |
end |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
function __git_lfs_prepare_completions |
| 116 |
__git_lfs_debug "" |
| 117 |
__git_lfs_debug "========= starting completion logic ==========" |
| 118 |
|
| 119 |
|
| 120 |
set --erase __git_lfs_comp_results |
| 121 |
|
| 122 |
__git_lfs_perform_completion_once |
| 123 |
__git_lfs_debug "Completion results: $__git_lfs_perform_completion_once_result" |
| 124 |
|
| 125 |
if test -z "$__git_lfs_perform_completion_once_result" |
| 126 |
__git_lfs_debug "No completion, probably due to a failure" |
| 127 |
|
| 128 |
return 1 |
| 129 |
end |
| 130 |
|
| 131 |
set -l directive (string sub --start 2 $__git_lfs_perform_completion_once_result[-1]) |
| 132 |
set --global __git_lfs_comp_results $__git_lfs_perform_completion_once_result[1..-2] |
| 133 |
|
| 134 |
__git_lfs_debug "Completions are: $__git_lfs_comp_results" |
| 135 |
__git_lfs_debug "Directive is: $directive" |
| 136 |
|
| 137 |
set -l shellCompDirectiveError 1 |
| 138 |
set -l shellCompDirectiveNoSpace 2 |
| 139 |
set -l shellCompDirectiveNoFileComp 4 |
| 140 |
set -l shellCompDirectiveFilterFileExt 8 |
| 141 |
set -l shellCompDirectiveFilterDirs 16 |
| 142 |
|
| 143 |
if test -z "$directive" |
| 144 |
set directive 0 |
| 145 |
end |
| 146 |
|
| 147 |
set -l compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2) |
| 148 |
if test $compErr -eq 1 |
| 149 |
__git_lfs_debug "Received error directive: aborting." |
| 150 |
|
| 151 |
return 1 |
| 152 |
end |
| 153 |
|
| 154 |
set -l filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2) |
| 155 |
set -l dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2) |
| 156 |
if test $filefilter -eq 1; or test $dirfilter -eq 1 |
| 157 |
__git_lfs_debug "File extension filtering or directory filtering not supported" |
| 158 |
|
| 159 |
return 1 |
| 160 |
end |
| 161 |
|
| 162 |
set -l nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2) |
| 163 |
set -l nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2) |
| 164 |
|
| 165 |
__git_lfs_debug "nospace: $nospace, nofiles: $nofiles" |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
if test $nospace -ne 0; or test $nofiles -eq 0 |
| 173 |
set -l prefix (commandline -t | string escape --style=regex) |
| 174 |
__git_lfs_debug "prefix: $prefix" |
| 175 |
|
| 176 |
set -l completions (string match -r -- "^$prefix.*" $__git_lfs_comp_results) |
| 177 |
set --global __git_lfs_comp_results $completions |
| 178 |
__git_lfs_debug "Filtered completions are: $__git_lfs_comp_results" |
| 179 |
|
| 180 |
|
| 181 |
set -l numComps (count $__git_lfs_comp_results) |
| 182 |
__git_lfs_debug "numComps: $numComps" |
| 183 |
|
| 184 |
if test $numComps -eq 1; and test $nospace -ne 0 |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
set -l split (string split --max 1 \t $__git_lfs_comp_results[1]) |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
set -l lastChar (string sub -s -1 -- $split) |
| 194 |
if not string match -r -q "[@=/:.,]" -- "$lastChar" |
| 195 |
|
| 196 |
|
| 197 |
__git_lfs_debug "Adding second completion to perform nospace directive" |
| 198 |
set --global __git_lfs_comp_results $split[1] $split[1]. |
| 199 |
__git_lfs_debug "Completions are now: $__git_lfs_comp_results" |
| 200 |
end |
| 201 |
end |
| 202 |
|
| 203 |
if test $numComps -eq 0; and test $nofiles -eq 0 |
| 204 |
|
| 205 |
|
| 206 |
__git_lfs_debug "Requesting file completion" |
| 207 |
return 1 |
| 208 |
end |
| 209 |
end |
| 210 |
|
| 211 |
return 0 |
| 212 |
end |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
if type -q "git-lfs" |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
complete --do-complete "git-lfs " > /dev/null 2>&1 |
| 223 |
end |
| 224 |
|
| 225 |
|
| 226 |
complete -c git-lfs -e |
| 227 |
|
| 228 |
|
| 229 |
complete -c git-lfs -n '__git_lfs_clear_perform_completion_once_result' |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
complete -c git-lfs -n 'not __git_lfs_requires_order_preservation && __git_lfs_prepare_completions' -f -a '$__git_lfs_comp_results' |
| 234 |
|
| 235 |
complete -k -c git-lfs -n '__git_lfs_requires_order_preservation && __git_lfs_prepare_completions' -f -a '$__git_lfs_comp_results' |