[git completions] Minor cleanup

This commit is contained in:
Fabian Homborg 2018-03-13 13:45:37 +01:00
parent bc976a913c
commit 4057cfdce5

View file

@ -171,7 +171,7 @@ function __fish_git_ranges
return 0 return 0
end end
set -l to (set -q both[2]; and echo $both[2]) set -l to $both[2]
# Remove description from the from-ref, not the to-ref. # Remove description from the from-ref, not the to-ref.
for from_ref in (__fish_git_refs | string match "$from" | string replace -r \t'.*$' '') for from_ref in (__fish_git_refs | string match "$from" | string replace -r \t'.*$' '')
for to_ref in (__fish_git_refs | string match "*$to*") # if $to is empty, this correctly matches everything for to_ref in (__fish_git_refs | string match "*$to*") # if $to is empty, this correctly matches everything
@ -182,38 +182,34 @@ end
function __fish_git_needs_command function __fish_git_needs_command
set cmd (commandline -opc) set cmd (commandline -opc)
if [ (count $cmd) -eq 1 ] set -l skip_next 1
return 0 set -q cmd[2]; or return 0
else # Skip first word because it's "git" or a wrapper
set -l skip_next 1 for c in $cmd[2..-1]
# Skip first word because it's "git" or a wrapper test $skip_next -eq 0
for c in $cmd[2..-1] and set skip_next 1
test $skip_next -eq 0 and continue
and set skip_next 1 # git can only take a few options before a command, these are the ones mentioned in the "git" man page
and continue # e.g. `git --follow log` is wrong, `git --help log` is okay (and `git --help log $branch` is superfluous but works)
# git can only take a few options before a command, these are the ones mentioned in the "git" man page # In case any other option is used before a command, we'll fail, but that's okay since it's invalid anyway
# e.g. `git --follow log` is wrong, `git --help log` is okay (and `git --help log $branch` is superfluous but works) switch $c
# In case any other option is used before a command, we'll fail, but that's okay since it's invalid anyway # General options that can still take a command
switch $c case "--help" "-p" "--paginate" "--no-pager" "--bare" "--no-replace-objects" --{literal,glob,noglob,icase}-pathspecs --{exec-path,git-dir,work-tree,namespace}"=*"
# General options that can still take a command continue
case "--help" "-p" "--paginate" "--no-pager" "--bare" "--no-replace-objects" --{literal,glob,noglob,icase}-pathspecs --{exec-path,git-dir,work-tree,namespace}"=*" # General options with an argument we need to skip. The option=value versions have already been handled above
continue case --{exec-path,git-dir,work-tree,namespace}
# General options with an argument we need to skip. The option=value versions have already been handled above set skip_next 0
case --{exec-path,git-dir,work-tree,namespace} continue
set skip_next 0 # General options that cause git to do something and exit - these behave like commands and everything after them is ignored
continue case "--version" --{html,man,info}-path
# General options that cause git to do something and exit - these behave like commands and everything after them is ignored return 1
case "--version" --{html,man,info}-path # We assume that any other token that's not an argument to a general option is a command
return 1 case "*"
# We assume that any other token that's not an argument to a general option is a command echo $c
case "*" return 1
echo $c
return 1
end
end end
return 0
end end
return 1 return 0
end end
@ -906,8 +902,7 @@ complete -f -c git -n '__fish_git_using_command tag' -s v -l verify -d 'Verify s
complete -f -c git -n '__fish_git_using_command tag' -s f -l force -d 'Force overwriting exising tag' complete -f -c git -n '__fish_git_using_command tag' -s f -l force -d 'Force overwriting exising tag'
complete -f -c git -n '__fish_git_using_command tag' -s l -l list -d 'List tags' complete -f -c git -n '__fish_git_using_command tag' -s l -l list -d 'List tags'
complete -f -c git -n '__fish_git_using_command tag' -l contains -xa '(__fish_git_commits)' -d 'List tags that contain a commit' complete -f -c git -n '__fish_git_using_command tag' -l contains -xa '(__fish_git_commits)' -d 'List tags that contain a commit'
complete -f -c git -n '__fish_git_using_command tag; and __fish_contains_opt -s d' -a '(__fish_git_tags)' -d 'Tag' complete -f -c git -n '__fish_git_using_command tag; and __fish_contains_opt -s d delete -s v verify' -a '(__fish_git_tags)' -d 'Tag'
complete -f -c git -n '__fish_git_using_command tag; and __fish_contains_opt -s v' -a '(__fish_git_tags)' -d 'Tag'
# TODO options # TODO options
### stash ### stash