zsh: Use $+commands[] instead of command -v
This commit is contained in:
@@ -102,7 +102,7 @@ fi
|
|||||||
|
|
||||||
# Automatically start X on login after boot.
|
# Automatically start X on login after boot.
|
||||||
# Do not use exec so that the zlogout is still read.
|
# 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
|
startx
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
emulate -L zsh -o extendedglob
|
emulate -L zsh -o extendedglob
|
||||||
|
|
||||||
# Return if fzf is not available
|
# Return if fzf is not available
|
||||||
if ! command -v fzf &>/dev/null; then
|
if (( ! $+commands[fzf] )); then
|
||||||
printf "command not found: fzf" >&2
|
printf "command not found: fzf" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -38,9 +38,9 @@ fzf_preview[log]="$fzf_preview[construct] { $REPLY }"
|
|||||||
# Put the commit hash into the clipboard
|
# Put the commit hash into the clipboard
|
||||||
# (If no known clipboard tool is available, just print it)
|
# (If no known clipboard tool is available, just print it)
|
||||||
local fzf_copy_command="$fzf_preview[construct] echo -n \"\$out\""
|
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"
|
fzf_copy_command+=" | pbcopy"
|
||||||
elif command -v xclip &>/dev/null; then
|
elif (( $+commands[xclip] )); then
|
||||||
fzf_copy_command+=" | xclip -selection c"
|
fzf_copy_command+=" | xclip -selection c"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
emulate -L zsh -o extendedglob
|
emulate -L zsh -o extendedglob
|
||||||
|
|
||||||
# Return if fzf is not available
|
# Return if fzf is not available
|
||||||
if ! command -v fzf &>/dev/null; then
|
if (( ! $+commands[fzf] )); then
|
||||||
printf "command not found: fzf" >&2
|
printf "command not found: fzf" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -56,9 +56,8 @@ read -r -d '' <<EOT
|
|||||||
git show "${(j:%n:)format}" "$date" --color=always --patch-with-stat "\$out"
|
git show "${(j:%n:)format}" "$date" --color=always --patch-with-stat "\$out"
|
||||||
EOT
|
EOT
|
||||||
fzf_preview[patch]="$fzf_preview[construct] { $REPLY"
|
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"
|
fzf_preview[patch]+=" | diff-so-fancy --color=always"
|
||||||
fi
|
|
||||||
fzf_preview[patch]+="; }"
|
fzf_preview[patch]+="; }"
|
||||||
|
|
||||||
read -r -d '' <<EOT
|
read -r -d '' <<EOT
|
||||||
@@ -69,9 +68,9 @@ fzf_preview[stat]="$fzf_preview[construct] { $REPLY; }"
|
|||||||
# Put the commit hash into the clipboard
|
# Put the commit hash into the clipboard
|
||||||
# (If no known clipboard tool is available, just print it)
|
# (If no known clipboard tool is available, just print it)
|
||||||
local fzf_copy_command="$fzf_preview[construct] echo -n \"\$out\""
|
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"
|
fzf_copy_command+=" | pbcopy"
|
||||||
elif command -v xclip &>/dev/null; then
|
elif (( $+commands[xclip] )); then
|
||||||
fzf_copy_command+=" | xclip -selection c"
|
fzf_copy_command+=" | xclip -selection c"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
emulate -L zsh -o extendedglob
|
emulate -L zsh -o extendedglob
|
||||||
|
|
||||||
# Return if fzf is not available
|
# Return if fzf is not available
|
||||||
if ! command -v fzf &>/dev/null; then
|
if (( ! $+commands[fzf] )); then
|
||||||
printf "command not found: fzf" >&2
|
printf "command not found: fzf" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -56,9 +56,8 @@ read -r -d '' <<EOT
|
|||||||
git show "${(j:%n:)format}" "$date" --color=always --patch-with-stat "\$out"
|
git show "${(j:%n:)format}" "$date" --color=always --patch-with-stat "\$out"
|
||||||
EOT
|
EOT
|
||||||
fzf_preview[patch]="$fzf_preview[construct] { $REPLY"
|
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"
|
fzf_preview[patch]+=" | diff-so-fancy --color=always"
|
||||||
fi
|
|
||||||
fzf_preview[patch]+=" }"
|
fzf_preview[patch]+=" }"
|
||||||
|
|
||||||
read -r -d '' <<EOT
|
read -r -d '' <<EOT
|
||||||
@@ -69,9 +68,9 @@ fzf_preview[stat]="$fzf_preview[construct] { $REPLY }"
|
|||||||
# Put the commit hash into the clipboard
|
# Put the commit hash into the clipboard
|
||||||
# (If no known clipboard tool is available, just print it)
|
# (If no known clipboard tool is available, just print it)
|
||||||
local fzf_copy_command="$fzf_preview[construct] echo -n \"\$out\""
|
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"
|
fzf_copy_command+=" | pbcopy"
|
||||||
elif command -v xclip &>/dev/null; then
|
elif (( $+commands[xclip] )); then
|
||||||
fzf_copy_command+=" | xclip -selection c"
|
fzf_copy_command+=" | xclip -selection c"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -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_SHOW_ALL_DIRS=${LS_SHOW_ALL_DIRS:-"dotfiles|\.config"}
|
||||||
|
|
||||||
builtin local LS_COMMAND=ls
|
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
|
LS_COMMAND=gls
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Bold red
|
# Bold red
|
||||||
|
|
||||||
if command -v tput >/dev/null 2>&1; then
|
if (( $+commands[tput] )); then
|
||||||
STDERRED_ESC_CODE="$(tput bold && tput setaf 1)"
|
STDERRED_ESC_CODE="$(tput bold && tput setaf 1)"
|
||||||
else
|
else
|
||||||
STDERRED_ESC_CODE="\e[1m\e31m"
|
STDERRED_ESC_CODE="\e[1m\e31m"
|
||||||
|
|||||||
Reference in New Issue
Block a user