From 8997d9cae03a7a589cba277fa05a768e52f0eea2 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Fri, 23 Aug 2019 21:11:56 +0100 Subject: [PATCH] Add zsh-completions The [zsh-completions](https://github.com/zsh-users/zsh-completions) repo contains completions for various commands but not all of these are useful so the `update-completion-links.zsh` script inspects the `PATH` to determine which of the completions should be symlinked to `~/.local/share/zsh/site-functions` which resides on the `fpath`. --- .conduit.yaml | 3 +++ update-completion-links.zsh | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100755 update-completion-links.zsh diff --git a/.conduit.yaml b/.conduit.yaml index 5e461e7..bedbaac 100644 --- a/.conduit.yaml +++ b/.conduit.yaml @@ -29,10 +29,13 @@ - https://github.com/zsh-users/zsh-autosuggestions.git - https://github.com/zsh-users/zsh-history-substring-search.git - https://github.com/zsh-users/zsh-syntax-highlighting.git + - https://github.com/zsh-users/zsh-completions.git - https://github.com/junegunn/fzf.git - command: - fzf/install --bin - symlink: - {src: fzf/bin/fzf, dst: ~/.local/bin/fzf} - {src: fzf/bin/fzf-tmux, dst: ~/.local/bin/fzf-tmux} +- command: + - zsh update-completion-links.zsh - message: zsh will be the default prompt after next login diff --git a/update-completion-links.zsh b/update-completion-links.zsh new file mode 100755 index 0000000..80f4c33 --- /dev/null +++ b/update-completion-links.zsh @@ -0,0 +1,19 @@ +#!/usr/bin/env zsh + +# Check if third party completions are present. +local zsh_completions=~/.config/zsh/zsh-completions +[ ! -d $zsh_completions ] && return 0 + +# Loop over all completions. +for completion in $zsh_completions/src/_*; do + local name=`basename $completion` + local symlink=~/.local/share/zsh/site-functions/$name + # Remove existing completion file if it exists. + [ -f $symlink ] && rm $symlink + # Check if the command exists on the PATH. + if which ${name:1} &> /dev/null; then + # Symlink the completion for the existing command. + [ `uname` = Darwin ] && \ + ln -s $completion $symlink || ln -sr $completion $symlink + fi +done