zsh: Use $+commands[] instead of command -v

This commit is contained in:
2022-03-31 00:46:46 +02:00
parent 8008cb1a63
commit 0ba0c04c56
6 changed files with 15 additions and 16 deletions

View File

@@ -102,7 +102,7 @@ fi
# Automatically start X on login after boot.
# Do not use exec so that the zlogout is still read.
if command -v startx &>/dev/null && [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then
if (( $+commands[startx] )) && [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then
startx
exit $?
fi

View File

@@ -9,7 +9,7 @@
emulate -L zsh -o extendedglob
# Return if fzf is not available
if ! command -v fzf &>/dev/null; then
if (( ! $+commands[fzf] )); then
printf "command not found: fzf" >&2
return 1
fi
@@ -38,9 +38,9 @@ fzf_preview[log]="$fzf_preview[construct] { $REPLY }"
# Put the commit hash into the clipboard
# (If no known clipboard tool is available, just print it)
local fzf_copy_command="$fzf_preview[construct] echo -n \"\$out\""
if [[ $OSTYPE =~ darwin ]] && command -v pbcopy &>/dev/null; then
if [[ $OSTYPE =~ darwin ]] && (( $+commands[pbcopy] )); then
fzf_copy_command+=" | pbcopy"
elif command -v xclip &>/dev/null; then
elif (( $+commands[xclip] )); then
fzf_copy_command+=" | xclip -selection c"
fi

View File

@@ -9,7 +9,7 @@
emulate -L zsh -o extendedglob
# Return if fzf is not available
if ! command -v fzf &>/dev/null; then
if (( ! $+commands[fzf] )); then
printf "command not found: fzf" >&2
return 1
fi
@@ -56,9 +56,8 @@ read -r -d '' <<EOT
git show "${(j:%n:)format}" "$date" --color=always --patch-with-stat "\$out"
EOT
fzf_preview[patch]="$fzf_preview[construct] { $REPLY"
if command -v diff-so-fancy &>/dev/null; then
(( ! $+commands[diff-so-fancy] )) ||
fzf_preview[patch]+=" | diff-so-fancy --color=always"
fi
fzf_preview[patch]+="; }"
read -r -d '' <<EOT
@@ -69,9 +68,9 @@ fzf_preview[stat]="$fzf_preview[construct] { $REPLY; }"
# Put the commit hash into the clipboard
# (If no known clipboard tool is available, just print it)
local fzf_copy_command="$fzf_preview[construct] echo -n \"\$out\""
if [[ $OSTYPE =~ darwin ]] && command -v pbcopy &>/dev/null; then
if [[ $OSTYPE =~ darwin ]] && (( $+commands[pbcopy] )); then
fzf_copy_command+=" | pbcopy"
elif command -v xclip &>/dev/null; then
elif (( $+commands[xclip] )); then
fzf_copy_command+=" | xclip -selection c"
fi

View File

@@ -9,7 +9,7 @@
emulate -L zsh -o extendedglob
# Return if fzf is not available
if ! command -v fzf &>/dev/null; then
if (( ! $+commands[fzf] )); then
printf "command not found: fzf" >&2
return 1
fi
@@ -56,9 +56,8 @@ read -r -d '' <<EOT
git show "${(j:%n:)format}" "$date" --color=always --patch-with-stat "\$out"
EOT
fzf_preview[patch]="$fzf_preview[construct] { $REPLY"
if command -v diff-so-fancy &>/dev/null; then
(( ! $+commands[diff-so-fancy] )) ||
fzf_preview[patch]+=" | diff-so-fancy --color=always"
fi
fzf_preview[patch]+=" }"
read -r -d '' <<EOT
@@ -69,9 +68,9 @@ fzf_preview[stat]="$fzf_preview[construct] { $REPLY }"
# Put the commit hash into the clipboard
# (If no known clipboard tool is available, just print it)
local fzf_copy_command="$fzf_preview[construct] echo -n \"\$out\""
if [[ $OSTYPE =~ darwin ]] && command -v pbcopy &>/dev/null; then
if [[ $OSTYPE =~ darwin ]] && (( $+commands[pbcopy] )); then
fzf_copy_command+=" | pbcopy"
elif command -v xclip &>/dev/null; then
elif (( $+commands[xclip] )); then
fzf_copy_command+=" | xclip -selection c"
fi

View File

@@ -15,7 +15,8 @@ builtin emulate -L zsh -o no_glob_dots -o null_glob
builtin local LS_SHOW_ALL_DIRS=${LS_SHOW_ALL_DIRS:-"dotfiles|\.config"}
builtin local LS_COMMAND=ls
if [[ $OSTYPE =~ darwin ]] && command -v gls &>/dev/null; then
# Use GNU version if available under MacOS
if [[ $OSTYPE =~ darwin ]] && (( $+commands[gls] )); then
LS_COMMAND=gls
fi

View File

@@ -1,6 +1,6 @@
# Bold red
if command -v tput >/dev/null 2>&1; then
if (( $+commands[tput] )); then
STDERRED_ESC_CODE="$(tput bold && tput setaf 1)"
else
STDERRED_ESC_CODE="\e[1m\e31m"