Skip to content

Commit cf447a6

Browse files
authored
feat(completions): add completion for fish (#344)
fish's builtin git completion automatically registers git-forgit completions as completions for forgit subcommand of git. Therefore this PR provides completions for both formats git-forgit and git forgit. Simple subcommands get the completion list from __fish_git_* functions, while others requiring more than 1 __fish_git_* completion sources reuse the completion items from the corresponding git commands.
1 parent 714f6df commit cf447a6

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

completions/git-forgit.fish

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
# forgit completions for fish plugin
3+
#
4+
# Place this file inside your <fish_config_dir>/completions/ directory.
5+
# It's usually located at ~/.config/fish/completions/. The file is lazily
6+
# sourced when git-forgit command or forgit subcommand of git is invoked.
7+
8+
function __fish_forgit_needs_subcommand
9+
for subcmd in add blame branch_delete checkout_branch checkout_commit checkout_file checkout_tag \
10+
cherry_pick cherry_pick_from_branch clean diff fixup ignore log rebase reset_head revert_commit \
11+
stash_show stash_push
12+
if contains -- $subcmd (commandline -opc)
13+
return 1
14+
end
15+
end
16+
return 0
17+
end
18+
19+
# Load helper functions in git completion file
20+
not functions -q __fish_git && source $__fish_data_dir/completions/git.fish
21+
22+
# No file completion by default
23+
complete -c git-forgit -x
24+
25+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a add -d 'git add selector'
26+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a blame -d 'git blame viewer'
27+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a branch_delete -d 'git branch deletion selector'
28+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a checkout_branch -d 'git checkout branch selector'
29+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a checkout_commit -d 'git checkout commit selector'
30+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a checkout_file -d 'git checkout-file selector'
31+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a checkout_tag -d 'git checkout tag selector'
32+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a cherry_pick -d 'git cherry-picking'
33+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a cherry_pick_from_branch -d 'git cherry-picking with interactive branch selection'
34+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a clean -d 'git clean selector'
35+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a diff -d 'git diff viewer'
36+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a fixup -d 'git fixup'
37+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a ignore -d 'git ignore generator'
38+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a log -d 'git commit viewer'
39+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a rebase -d 'git rebase'
40+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a reset_head -d 'git reset HEAD (unstage) selector'
41+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a revert_commit -d 'git revert commit selector'
42+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a stash_show -d 'git stash viewer'
43+
complete -c git-forgit -n __fish_forgit_needs_subcommand -a stash_push -d 'git stash push selector'
44+
45+
complete -c git-forgit -n '__fish_seen_subcommand_from add' -a "(complete -C 'git add ')"
46+
complete -c git-forgit -n '__fish_seen_subcommand_from branch_delete' -a "(__fish_git_local_branches)"
47+
complete -c git-forgit -n '__fish_seen_subcommand_from checkout_branch' -a "(complete -C 'git switch ')"
48+
complete -c git-forgit -n '__fish_seen_subcommand_from checkout_commit' -a "(__fish_git_commits)"
49+
complete -c git-forgit -n '__fish_seen_subcommand_from checkout_file' -a "(__fish_git_files modified)"
50+
complete -c git-forgit -n '__fish_seen_subcommand_from checkout_tag' -a "(__fish_git_tags)" -d Tag
51+
complete -c git-forgit -n '__fish_seen_subcommand_from cherry_pick' -a "(complete -C 'git cherry-pick ')"
52+
complete -c git-forgit -n '__fish_seen_subcommand_from clean' -a "(__fish_git_files untracked ignored)"
53+
complete -c git-forgit -n '__fish_seen_subcommand_from fixup' -a "(__fish_git_local_branches)"
54+
complete -c git-forgit -n '__fish_seen_subcommand_from log' -a "(complete -C 'git log ')"
55+
complete -c git-forgit -n '__fish_seen_subcommand_from rebase' -a "(complete -C 'git rebase ')"
56+
complete -c git-forgit -n '__fish_seen_subcommand_from reset_head' -a "(__fish_git_files all-staged)"
57+
complete -c git-forgit -n '__fish_seen_subcommand_from revert_commit' -a "(__fish_git_commits)"
58+
complete -c git-forgit -n '__fish_seen_subcommand_from stash_show' -a "(__fish_git_complete_stashes)"
59+
complete -c git-forgit -n '__fish_seen_subcommand_from stash_push' -a "(__fish_git_files modified deleted modified-staged-deleted)"

0 commit comments

Comments
 (0)