implement fish autocomplete

This commit is contained in:
Tin Lai 2020-05-28 01:36:17 +10:00
parent dd86c8a691
commit f0a8f31d1b
No known key found for this signature in database
GPG Key ID: 3DFF94D0127B09D6
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
#!/usr/bin/fish
function __fish_yadm_first_arg
set cmd (commandline -opc)
if [ (count $cmd) -eq 1 -a $cmd[1] = 'yadm' ]
return 0
end
return 1
end
function __fish_yadm_using_command
set cmd (commandline -opc)
if [ (count $cmd) -gt 1 -a "x$argv[1]" = "x$cmd[-1]" ]
return 0
end
return 1
end
# no dirs in complete list
complete -c yadm -x
# yadm's specific autocomplete
complete -f -c yadm -n '__fish_yadm_first_arg' -a 'clone' -d 'Clone an existing repository'
complete -f -c yadm -n '__fish_yadm_first_arg' -a 'alt' -d 'Create links for alternates'
complete -f -c yadm -n '__fish_yadm_first_arg' -a 'bootstrap' -d 'Execute $HOME/.config/yadm/bootstrap'
complete -f -c yadm -n '__fish_yadm_first_arg' -a 'encrypt' -d 'Encrypt files'
complete -f -c yadm -n '__fish_yadm_first_arg' -a 'perms' -d 'Fix perms for private files'
complete -f -c yadm -n '__fish_yadm_first_arg' -a 'enter' -d 'Run sub-shell with GIT variables set'
complete -f -c yadm -n '__fish_yadm_first_arg' -a 'git-crypt' -d 'Run git-crypt commands for the yadm repo'
complete -f -c yadm -n '__fish_yadm_first_arg' -a 'init' -d 'Initialize an empty repository'
complete -f -c yadm -n '__fish_yadm_using_command init' -s f
complete -f -c yadm -n '__fish_yadm_first_arg' -a 'list' -d 'List tracked files'
complete -f -c yadm -n '__fish_yadm_using_command list' -s a
complete -f -c yadm -n '__fish_yadm_first_arg' -a 'decrypt' -d 'Decrypt files'
complete -f -c yadm -n '__fish_yadm_using_command decrypt' -s l
complete -f -c yadm -n '__fish_yadm_first_arg' -a 'introspect'
complete -f -c yadm -n '__fish_yadm_using_command introspect' -a "commands"
complete -f -c yadm -n '__fish_yadm_using_command introspect' -a "configs"
complete -f -c yadm -n '__fish_yadm_using_command introspect' -a "repo"
complete -f -c yadm -n '__fish_yadm_using_command introspect' -a "switches"
complete -f -c yadm -n '__fish_yadm_first_arg' -a 'config' -d 'Configure a setting'
for name in (yadm introspect configs)
complete -f -c yadm -n "__fish_yadm_using_command config" -a "$name" -d "yadm config"
end
# wraps git's autocomplete
set -l GIT_DIR (yadm introspect repo)
complete -c yadm -w "git --git-dir $GIT_DIR"