aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Bobov <anton@bobov.name>2023-08-29 20:52:12 +0500
committerAnton Bobov <anton@bobov.name>2023-08-29 20:52:46 +0500
commit951f9d198e4f02be4fd4cf74fbc0676a190cd127 (patch)
treef013905b4545ba4a90685bdd0e8c48f71237f1e6
parentcca7b2932ff9860155687f803e46a77f0f1940e2 (diff)
[zsh] Add completion generation
-rw-r--r--.gitmodules2
-rw-r--r--files/.zsh/rc/S20_environment1
-rw-r--r--files/.zsh/rc/S40_completion29
m---------files/.zsh/zsh-completions0
-rw-r--r--files/.zsh/zsh-completions-cached/.gitignore3
5 files changed, 30 insertions, 5 deletions
diff --git a/.gitmodules b/.gitmodules
index 6b849d7..4651a94 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -3,7 +3,7 @@
url = https://github.com/abobov/bin.git
[submodule "zsh-completions"]
path = files/.zsh/zsh-completions
- url = https://github.com/abobov/zsh-completions.git
+ url = https://github.com/zsh-users/zsh-completions.git
[submodule "files/.zsh/z"]
path = files/.zsh/z
url = https://github.com/rupa/z.git
diff --git a/files/.zsh/rc/S20_environment b/files/.zsh/rc/S20_environment
index 115ae1f..e6c47e2 100644
--- a/files/.zsh/rc/S20_environment
+++ b/files/.zsh/rc/S20_environment
@@ -8,6 +8,7 @@ fi
path=(~/bin ~/.local/bin $path)
fpath=($HOME/.zsh/zsh-completions/src $fpath)
+fpath=($HOME/.zsh/zsh-completions-cached $fpath)
# To force rebuild zcompdump:
# rm -f ~/.zcompdump; compinit
diff --git a/files/.zsh/rc/S40_completion b/files/.zsh/rc/S40_completion
index 195c16b..233eeb4 100644
--- a/files/.zsh/rc/S40_completion
+++ b/files/.zsh/rc/S40_completion
@@ -40,20 +40,41 @@ zstyle ':completion:*:*:vi(m|):*:*files' ignored-patterns '*?.(aux|dvi|ps|pdf|bb
# Ledger completion like hledger
compdef ledger=hledger
-compdef fdfind=fd
-
# Completing generic gnu commands
# https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org
-compdef _gnu_generic lshw df duplicity tldr
+compdef _gnu_generic lshw df duplicity
compdef _gnu_generic -p 'pg_*'
+compdef _command tldr
+
__load_completion_if_exists() {
[[ -f "$1" ]] && source "$1"
}
+__load_or_generate() {
+ if ! command -v "$1" >/dev/null ; then
+ return
+ fi
+ local target_file="/home/anton/.zsh/zsh-completions-cached/_$1"
+ local generate_command="$2"
+ if [ ! -f "$target_file" ] ; then
+ eval "$generate_command" > "$target_file"
+ fi
+}
+
__load_completion_if_exists /etc/bash_completion.d/youtube-dl.bash-completion
__load_completion_if_exists /usr/share/zsh/vendor-completions/_git-extras
-unset -f __load_completion_if_exists
+__load_or_generate kubectl "kubectl completion zsh"
+__load_or_generate helm "helm completion zsh"
+__load_or_generate fdfind 'curl -sL "https://raw.githubusercontent.com/sharkdp/fd/master/contrib/completion/_fd"'
+__load_or_generate restic 'restic generate --zsh-completion /dev/stdout'
+__load_or_generate docker 'curl -sL "https://raw.githubusercontent.com/docker/cli/master/contrib/completion/zsh/_docker"'
+__load_or_generate docker-compose 'curl -sL "https://raw.githubusercontent.com/docker/compose/1.28.x/contrib/completion/zsh/_docker-compose"'
+__load_or_generate watson 'curl -sL "https://raw.githubusercontent.com/TailorDev/Watson/master/watson.zsh-completion"'
+
+compdef fdfind=fd
+
+unset -f __load_completion_if_exists __load_or_generate
# vim: et ft=zsh fdm=marker :
diff --git a/files/.zsh/zsh-completions b/files/.zsh/zsh-completions
-Subproject 279b5c24efdc273315c3c890d3201105aa97a34
+Subproject 67921bc12502c1e7b0f156533fbac2cb51f6943
diff --git a/files/.zsh/zsh-completions-cached/.gitignore b/files/.zsh/zsh-completions-cached/.gitignore
new file mode 100644
index 0000000..655c60b
--- /dev/null
+++ b/files/.zsh/zsh-completions-cached/.gitignore
@@ -0,0 +1,3 @@
+# Directory for generated completions.
+*
+!.gitignore