diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile index bac1643..eda7bc7 100644 --- a/.config/zsh/.zprofile +++ b/.config/zsh/.zprofile @@ -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 diff --git a/.config/zsh/autoload/git/gbranch b/.config/zsh/autoload/git/gbranch index 0acb6cd..6232e43 100755 --- a/.config/zsh/autoload/git/gbranch +++ b/.config/zsh/autoload/git/gbranch @@ -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 diff --git a/.config/zsh/autoload/git/glog b/.config/zsh/autoload/git/glog index ffab567..4b1ecb1 100755 --- a/.config/zsh/autoload/git/glog +++ b/.config/zsh/autoload/git/glog @@ -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 '' </dev/null; then +(( ! $+commands[diff-so-fancy] )) || fzf_preview[patch]+=" | diff-so-fancy --color=always" -fi fzf_preview[patch]+="; }" read -r -d '' </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 diff --git a/.config/zsh/autoload/git/gstash b/.config/zsh/autoload/git/gstash index 87606f2..8e98b10 100755 --- a/.config/zsh/autoload/git/gstash +++ b/.config/zsh/autoload/git/gstash @@ -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 '' </dev/null; then +(( ! $+commands[diff-so-fancy] )) || fzf_preview[patch]+=" | diff-so-fancy --color=always" -fi fzf_preview[patch]+=" }" read -r -d '' </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 diff --git a/.config/zsh/autoload/ls-show-hidden b/.config/zsh/autoload/ls-show-hidden index 6e49137..ed68175 100755 --- a/.config/zsh/autoload/ls-show-hidden +++ b/.config/zsh/autoload/ls-show-hidden @@ -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 diff --git a/.config/zsh/zshrc.d/90-external-plugins/65-stderred.theme b/.config/zsh/zshrc.d/90-external-plugins/65-stderred.theme index 24991a9..c1b16a8 100644 --- a/.config/zsh/zshrc.d/90-external-plugins/65-stderred.theme +++ b/.config/zsh/zshrc.d/90-external-plugins/65-stderred.theme @@ -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"