mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 13:46:41 +00:00
chore(zsh/completion): improve completion setup for various commands
This commit is contained in:
@@ -32,19 +32,5 @@ fi
|
|||||||
|
|
||||||
if command-exists orb; then
|
if command-exists orb; then
|
||||||
alias oc="orb"
|
alias oc="orb"
|
||||||
|
setup-completions orb "$(command -v orb)" orb completion zsh
|
||||||
_setup-orb-completion() {
|
|
||||||
local target
|
|
||||||
target="${ZSH_COMPLETIONS}/_orb"
|
|
||||||
|
|
||||||
if [ ! -f "$target" ] || [ "$target" -ot "$(command -v orb)" ]; then
|
|
||||||
echo "Setting up completion for orb -- $target"
|
|
||||||
mkdir -p "$(dirname "$target")"
|
|
||||||
orb completion zsh > "$target"
|
|
||||||
chmod +x "$target"
|
|
||||||
autoload -U compinit && compinit
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
_setup-orb-completion
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -9,19 +9,7 @@ alias hl="helm"
|
|||||||
alias mk="minikube"
|
alias mk="minikube"
|
||||||
|
|
||||||
if command-exists kubectl; then
|
if command-exists kubectl; then
|
||||||
_setup-kubectl-completion() {
|
setup-completions kubectl "$(command -v kubectl)" kubectl completion zsh
|
||||||
local target
|
|
||||||
target="$ZSH_COMPLETIONS/_kubectl"
|
|
||||||
|
|
||||||
if [ ! -f "$target" ] || [ "$target" -ot "$(command -v kubectl)" ]; then
|
|
||||||
echo "Setting up completion for kubectl -- $target"
|
|
||||||
mkdir -p "$ZSH_COMPLETIONS"
|
|
||||||
kubectl completion zsh > "$target"
|
|
||||||
chmod +x "$target"
|
|
||||||
autoload -U compinit && compinit
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
_setup-kubectl-completion
|
|
||||||
|
|
||||||
if command-exists brew-prefix; then
|
if command-exists brew-prefix; then
|
||||||
switch() {
|
switch() {
|
||||||
|
|||||||
12
zsh/rust.zsh
12
zsh/rust.zsh
@@ -22,18 +22,10 @@ fi
|
|||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
if command-exists rustup; then
|
if command-exists rustup; then
|
||||||
_rustup() {
|
setup-completions rustup "$(command -v rustup)" rustup completions zsh
|
||||||
unset -f _rustup
|
|
||||||
eval "$(rustup completions zsh)"
|
|
||||||
}
|
|
||||||
compctl -K _rustup rustup
|
|
||||||
|
|
||||||
if command-exists cargo; then
|
if command-exists cargo; then
|
||||||
_cargo() {
|
setup-completions cargo "$(command -v cargo)" rustup completions zsh cargo
|
||||||
unset -f _cargo
|
|
||||||
eval "$(rustup completions zsh cargo)"
|
|
||||||
}
|
|
||||||
compctl -K _cargo cargo
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
44
zshrc
44
zshrc
@@ -67,6 +67,42 @@ zstyle ':completion:*:make:*' tag-order targets
|
|||||||
if [ -d "$ZSH_COMPLETIONS" ]; then fpath=("$ZSH_COMPLETIONS" $fpath); fi
|
if [ -d "$ZSH_COMPLETIONS" ]; then fpath=("$ZSH_COMPLETIONS" $fpath); fi
|
||||||
if [ -d "$DOTZSH_SITEFUNS" ]; then fpath=("$DOTZSH_SITEFUNS" $fpath); fi
|
if [ -d "$DOTZSH_SITEFUNS" ]; then fpath=("$DOTZSH_SITEFUNS" $fpath); fi
|
||||||
|
|
||||||
|
# setup-completions is a helper function to setup completions for a given
|
||||||
|
# command. It takes the command name, the source of the completion, and the
|
||||||
|
# command to run to generate the completions.
|
||||||
|
#
|
||||||
|
# Source should be a file that the completions are generated from. For example,
|
||||||
|
# for rustup, the source is the rustup binary. If completions file has already
|
||||||
|
# been generated, the source file is used to determine if the completions need
|
||||||
|
# to be re-generated.
|
||||||
|
#
|
||||||
|
# The command to run to generate the completions should be a command that
|
||||||
|
# generates zsh completions. For example, for rustup, the command is:
|
||||||
|
#
|
||||||
|
# rustup completions zsh
|
||||||
|
#
|
||||||
|
# Example usage:
|
||||||
|
#
|
||||||
|
# setup-completions rustup "$(command -v rustup)" rustup completions zsh
|
||||||
|
#
|
||||||
|
# This will generate the completions for rustup and place them in the
|
||||||
|
# ZSH_COMPLETIONS directory.
|
||||||
|
setup-completions() {
|
||||||
|
local cmd="$1"
|
||||||
|
local source="$2"
|
||||||
|
shift 2
|
||||||
|
local target
|
||||||
|
target="${ZSH_COMPLETIONS}/_${cmd}"
|
||||||
|
|
||||||
|
if [ ! -f "$target" ] || [ "$target" -ot "$source" ]; then
|
||||||
|
echo "Setting up completion for $cmd -- $target"
|
||||||
|
mkdir -p "$(dirname "$target")"
|
||||||
|
"$@" > "$target"
|
||||||
|
chmod +x "$target"
|
||||||
|
autoload -U compinit && compinit
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Edit command line
|
# Edit command line
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
@@ -94,7 +130,6 @@ fi
|
|||||||
|
|
||||||
MISE_HOME="$HOME/.local/share/mise"
|
MISE_HOME="$HOME/.local/share/mise"
|
||||||
MISE_ZSH_INIT="$MISE_HOME/shell/init.zsh"
|
MISE_ZSH_INIT="$MISE_HOME/shell/init.zsh"
|
||||||
MISE_COMPLETIONS_PATH="${ZSH_COMPLETIONS}/_mise"
|
|
||||||
export MISE_INSTALL_PATH="$MISE_HOME/bin/mise"
|
export MISE_INSTALL_PATH="$MISE_HOME/bin/mise"
|
||||||
|
|
||||||
if ! command-exists mise; then
|
if ! command-exists mise; then
|
||||||
@@ -111,12 +146,7 @@ if command-exists mise; then
|
|||||||
fi
|
fi
|
||||||
source "$MISE_ZSH_INIT"
|
source "$MISE_ZSH_INIT"
|
||||||
|
|
||||||
if [ ! -f "$MISE_COMPLETIONS_PATH" ] || [ "$MISE_COMPLETIONS_PATH" -ot "$MISE_INSTALL_PATH" ]; then
|
setup-completions mise "$MISE_INSTALL_PATH" mise completions zsh
|
||||||
echo "Setting up completion for mise -- $MISE_COMPLETIONS_PATH"
|
|
||||||
mkdir -p "$(dirname "$MISE_COMPLETIONS_PATH")"
|
|
||||||
mise completions zsh > "$MISE_COMPLETIONS_PATH"
|
|
||||||
chmod +x "$MISE_COMPLETIONS_PATH"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user