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}"
|
||||
fi
|
||||
|
||||
if command -v nvim &>/dev/null; then
|
||||
if (( $+commands[nvim] )); then
|
||||
export EDITOR=nvim
|
||||
elif command -v vim &>/dev/null; then
|
||||
elif (( $+commands[vim] )); then
|
||||
export EDITOR=vim
|
||||
elif command -v vi &>/dev/null; then
|
||||
elif (( $+commands[vi] )); then
|
||||
export EDITOR=vi
|
||||
elif command -v nano &>/dev/null; then
|
||||
elif (( $+commands[nano] )); then
|
||||
export EDITOR=nano
|
||||
fi
|
||||
|
||||
if command -v nvim &>/dev/null; then
|
||||
if (( $+commands[nvim] )); then
|
||||
export MANPAGER="nvim -c 'set ft=man' -"
|
||||
else
|
||||
# https://www.tecmint.com/view-colored-man-pages-in-linux/
|
||||
@@ -59,7 +59,7 @@ else
|
||||
fi
|
||||
|
||||
# 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
|
||||
FZF_DEFAULT_COMMAND="rg --hidden --files -g '!.git'"
|
||||
else
|
||||
@@ -68,7 +68,7 @@ fi
|
||||
export FZF_DEFAULT_COMMAND
|
||||
|
||||
# Setup LS_COLORS
|
||||
if command -v dircolors &>/dev/null; then
|
||||
if (( $+commands[dircolors] )); then
|
||||
if [[ -e "$XDG_CONFIG_HOME"/dircolors/dircolors ]]; then
|
||||
eval "$(dircolors -b "$XDG_CONFIG_HOME"/dircolors/dircolors)"
|
||||
else
|
||||
|
||||
@@ -48,9 +48,9 @@ conf() {
|
||||
local CONF_EDITOR
|
||||
if [[ -n "$EDITOR" ]]; then
|
||||
CONF_EDITOR="$EDITOR"
|
||||
elif command -v vim &>/dev/null; then
|
||||
elif (( $+commands[vim] )); then
|
||||
CONF_EDITOR=vim
|
||||
elif command -v nano &>/dev/null; then
|
||||
elif (( $+commands[nano] )); then
|
||||
CONF_EDITOR=nano
|
||||
else
|
||||
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