zsh: Use dictionary for command existence check
Use the `commands` dictionary from zsh instead of always calling `command`. Regex used: s/command -v \([^ ]*\) &>\/dev\/null/(( $+commands[\1] ))/g
This commit is contained in:
@@ -35,17 +35,17 @@ if [[ ! "$PATH" =~ "$HOME/\.local/bin" ]]; then
|
|||||||
export PATH="$HOME/.local/bin${PATH:+:$PATH}"
|
export PATH="$HOME/.local/bin${PATH:+:$PATH}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v nvim &>/dev/null; then
|
if (( $+commands[nvim] )); then
|
||||||
export EDITOR=nvim
|
export EDITOR=nvim
|
||||||
elif command -v vim &>/dev/null; then
|
elif (( $+commands[vim] )); then
|
||||||
export EDITOR=vim
|
export EDITOR=vim
|
||||||
elif command -v vi &>/dev/null; then
|
elif (( $+commands[vi] )); then
|
||||||
export EDITOR=vi
|
export EDITOR=vi
|
||||||
elif command -v nano &>/dev/null; then
|
elif (( $+commands[nano] )); then
|
||||||
export EDITOR=nano
|
export EDITOR=nano
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v nvim &>/dev/null; then
|
if (( $+commands[nvim] )); then
|
||||||
export MANPAGER="nvim -c 'set ft=man' -"
|
export MANPAGER="nvim -c 'set ft=man' -"
|
||||||
else
|
else
|
||||||
# https://www.tecmint.com/view-colored-man-pages-in-linux/
|
# https://www.tecmint.com/view-colored-man-pages-in-linux/
|
||||||
@@ -59,7 +59,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Show also hidden files per default but ignore files in '.git' directories.
|
# Show also hidden files per default but ignore files in '.git' directories.
|
||||||
if command -v rg &>/dev/null; then
|
if (( $+commands[rg] )); then
|
||||||
# Also respect gitignores
|
# Also respect gitignores
|
||||||
FZF_DEFAULT_COMMAND="rg --hidden --files -g '!.git'"
|
FZF_DEFAULT_COMMAND="rg --hidden --files -g '!.git'"
|
||||||
else
|
else
|
||||||
@@ -68,7 +68,7 @@ fi
|
|||||||
export FZF_DEFAULT_COMMAND
|
export FZF_DEFAULT_COMMAND
|
||||||
|
|
||||||
# Setup LS_COLORS
|
# Setup LS_COLORS
|
||||||
if command -v dircolors &>/dev/null; then
|
if (( $+commands[dircolors] )); then
|
||||||
if [[ -e "$XDG_CONFIG_HOME"/dircolors/dircolors ]]; then
|
if [[ -e "$XDG_CONFIG_HOME"/dircolors/dircolors ]]; then
|
||||||
eval "$(dircolors -b "$XDG_CONFIG_HOME"/dircolors/dircolors)"
|
eval "$(dircolors -b "$XDG_CONFIG_HOME"/dircolors/dircolors)"
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ conf() {
|
|||||||
local CONF_EDITOR
|
local CONF_EDITOR
|
||||||
if [[ -n "$EDITOR" ]]; then
|
if [[ -n "$EDITOR" ]]; then
|
||||||
CONF_EDITOR="$EDITOR"
|
CONF_EDITOR="$EDITOR"
|
||||||
elif command -v vim &>/dev/null; then
|
elif (( $+commands[vim] )); then
|
||||||
CONF_EDITOR=vim
|
CONF_EDITOR=vim
|
||||||
elif command -v nano &>/dev/null; then
|
elif (( $+commands[nano] )); then
|
||||||
CONF_EDITOR=nano
|
CONF_EDITOR=nano
|
||||||
else
|
else
|
||||||
CONF_EDITOR=cat
|
CONF_EDITOR=cat
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
! command -v direnv &>/dev/null || eval "$(direnv hook zsh)"
|
! (( $+commands[direnv] )) || eval "$(direnv hook zsh)"
|
||||||
|
|||||||
Reference in New Issue
Block a user