commit bb7d664fbd635131afe88686deb0564f827988a1
parent fa6ea9834c0838e24a961894f1ab875fc4b44359
Author: MichaĆ M. Sapka <michal@sapka.me>
Date: Fri, 2 Sep 2022 12:56:39 +0200
feat: add ghq fish completitions
Diffstat:
4 files changed, 94 insertions(+), 1 deletion(-)
diff --git a/fish/.config/fish/completions/ghq.fish b/fish/.config/fish/completions/ghq.fish
@@ -0,0 +1,66 @@
+function __fish_ghq_needs_command
+ set cmd (commandline -opc)
+ if [ (count $cmd) -eq 1 -a $cmd[1] = "ghq" ]
+ return 0
+ end
+ return 1
+end
+
+function __fish_ghq_using_command
+ set cmd (commandline -opc)
+ if [ (count $cmd) -gt 1 ]
+ if [ $argv[1] = $cmd[2] ]
+ return 0
+ end
+ end
+ return 1
+end
+
+# Help
+function __fish_ghq_help_topics
+ for c in get list root create
+ printf "%s\thelp topic\n" $c
+ end
+end
+
+function __fish_ghq_vcs
+ for c in git subversion git-svn mercurial darcs
+ printf "%s\tVCS\n" $c
+ end
+ printf "github\tAlias for git\n"
+ printf "svn\tAlias for subversion\n"
+ printf "hg\tAlias for mercurial\n"
+end
+
+complete -f -c ghq -n "__fish_ghq_needs_command" -a help -d "Shows a list of commands or help for one command"
+complete -f -c ghq -n "__fish_ghq_using_command help" -a "(__fish_ghq_help_topics)"
+
+complete -f -c ghq -n "__fish_ghq_needs_command" -a get -d "Clone/sync with a remote repository"
+complete -f -c ghq -n "__fish_ghq_using_command get" -l update -s u -d "Update local repository if cloned already"
+complete -f -c ghq -n "__fish_ghq_using_command get" -s p -d "Clone with SSH"
+complete -f -c ghq -n "__fish_ghq_using_command get" -l shallow -d "Do a shallow clone"
+complete -f -c ghq -n "__fish_ghq_using_command get" -l look -s l -d "Look after get"
+complete -f -c ghq -n "__fish_ghq_using_command get" -l vcs -d "Specify VCS backend for cloning" -r -a "(__fish_ghq_vcs)"
+complete -f -c ghq -n "__fish_ghq_using_command get" -l silent -s s -d "Clone or update silently"
+complete -f -c ghq -n "__fish_ghq_using_command get" -l no-recursive -d "Prevent recursive fetching"
+complete -f -c ghq -n "__fish_ghq_using_command get" -l branch -s b -d "Specify branch name. This flag implies --single-branch on Git"
+complete -f -c ghq -n "__fish_ghq_using_command get" -l parallel -s P -d "Import parallely"
+complete -f -c ghq -n "__fish_ghq_using_command get" -l help -s h -d "Show help"
+
+complete -f -c ghq -n "__fish_ghq_needs_command" -a list -d "List local repositories"
+complete -f -c ghq -n "__fish_ghq_using_command list" -l exact -s e -d "Perform an exact match"
+complete -f -c ghq -n "__fish_ghq_using_command list" -l vcs -d "Specify VCS backend for matching" -r -a "(__fish_ghq_vcs)"
+complete -f -c ghq -n "__fish_ghq_using_command list" -l full-path -s p -d "Print full paths"
+complete -f -c ghq -n "__fish_ghq_using_command list" -l unique -d "Print unique subpaths"
+complete -f -c ghq -n "__fish_ghq_using_command list" -l help -s h -d "Show help"
+
+complete -f -c ghq -n "__fish_ghq_needs_command" -a root -d "Show repositories' root"
+complete -f -c ghq -n "__fish_ghq_using_command root" -l all -d "Show all roots"
+complete -f -c ghq -n "__fish_ghq_using_command root" -l help -s h -d "Show help"
+
+complete -f -c ghq -n "__fish_ghq_needs_command" -a create -d "Create a new repository"
+complete -f -c ghq -n "__fish_ghq_using_command create" -l vcs -d "Specify VCS backend explicitly" -r -a "(__fish_ghq_vcs)"
+complete -f -c ghq -n "__fish_ghq_using_command create" -l help -s h -d "Show help"
+
+complete -f -c ghq -n "__fish_ghq_needs_command" -l help -s h -d "Show help"
+complete -f -c ghq -n "__fish_ghq_needs_command" -l version -s v -d "Print the version"
diff --git a/fish/.config/fish/conf.d/ghq_key_bindings.fish b/fish/.config/fish/conf.d/ghq_key_bindings.fish
@@ -0,0 +1,4 @@
+bind \cg '__ghq_repository_search'
+if bind -M insert >/dev/null 2>/dev/null
+ bind -M insert \cg '__ghq_repository_search'
+end
diff --git a/fish/.config/fish/fish_plugins b/fish/.config/fish/fish_plugins
@@ -1,2 +1,3 @@
jethrokuan/z
-patrickf1/fzf.fish
+/Users/msapka/install
+decors/fish-ghq
diff --git a/fish/.config/fish/functions/__ghq_repository_search.fish b/fish/.config/fish/functions/__ghq_repository_search.fish
@@ -0,0 +1,22 @@
+function __ghq_repository_search -d 'Repository search'
+ set -l selector
+ [ -n "$GHQ_SELECTOR" ]; and set selector $GHQ_SELECTOR; or set selector fzf
+ set -l selector_options
+ [ -n "$GHQ_SELECTOR_OPTS" ]; and set selector_options $GHQ_SELECTOR_OPTS
+
+ if not type -qf $selector
+ printf "\nERROR: '$selector' not found.\n"
+ return 1
+ end
+
+ set -l query (commandline -b)
+ [ -n "$query" ]; and set flags --query="$query"; or set flags
+ switch "$selector"
+ case fzf fzf-tmux peco percol fzy sk
+ ghq list --full-path | "$selector" $selector_options $flags | read select
+ case \*
+ printf "\nERROR: plugin-ghq is not support '$selector'.\n"
+ end
+ [ -n "$select" ]; and cd "$select"
+ commandline -f repaint
+end