Add command-exists shell helper

This commit is contained in:
2020-05-23 19:16:06 +01:00
parent ba559be4bc
commit d4d64f654e
7 changed files with 16 additions and 8 deletions

View File

@@ -27,7 +27,7 @@ alias di="colordiff"
alias devnullsmtp="java -jar $DOTBIN/DevNullSmtp.jar" alias devnullsmtp="java -jar $DOTBIN/DevNullSmtp.jar"
# Homebrew # Homebrew
if (( $+commands[brew] )); then if command-exists brew; then
alias br="brew" alias br="brew"
alias ca="brew cask" alias ca="brew cask"
alias cask="brew cask" alias cask="brew cask"
@@ -36,7 +36,7 @@ if (( $+commands[brew] )); then
fi fi
# Flutter # Flutter
if (( $+commands[flutter] )); then if command-exists flutter; then
alias fl="flutter" alias fl="flutter"
fi fi

View File

@@ -10,7 +10,7 @@ docker_remove_exited () {
docker rm "$(docker ps -f='status=exited' -q)" docker rm "$(docker ps -f='status=exited' -q)"
} }
if (( $+commands[docker] )); then if command-exists docker; then
zinit ice from'gh-r' as'program' mv'ctop-* -> ctop' zinit ice from'gh-r' as'program' mv'ctop-* -> ctop'
zinit light bcicen/ctop zinit light bcicen/ctop
fi fi

View File

@@ -6,7 +6,7 @@ alias kc="kubectl"
alias hl="helm" alias hl="helm"
alias mk="minikube" alias mk="minikube"
if (( $+commands[kubectl] )); then if command-exists kubectl; then
# lazy-load kubectl setup # lazy-load kubectl setup
_kubectl() { _kubectl() {
unset -f _kubectl unset -f _kubectl

View File

@@ -5,7 +5,7 @@
alias le="less" alias le="less"
# Enable syntax highlighting via source-highlight # Enable syntax highlighting via source-highlight
if (( $+commands[src-hilite-lesspipe.sh] )); then if command-exists "src-hilite-lesspipe.sh"; then
export LESSOPEN="| src-hilite-lesspipe.sh %s" export LESSOPEN="| src-hilite-lesspipe.sh %s"
export LESS=" -R " export LESS=" -R "
elif [ -f "/usr/share/source-highlight/src-hilite-lesspipe.sh" ]; then elif [ -f "/usr/share/source-highlight/src-hilite-lesspipe.sh" ]; then

View File

@@ -10,12 +10,12 @@ install_python_global_packages () {
'yamllint' 'yamllint'
) )
if [[ "$OSTYPE" == "darwin"* ]] && (( $+commands[brew] )); then if [[ "$OSTYPE" == "darwin"* ]] && command-exists brew; then
brew list python >/dev/null || brew install python brew list python >/dev/null || brew install python
fi fi
local pipcmd="pip" local pipcmd="pip"
if (( $+commands[pip3] )); then; pipcmd="pip3"; fi if command-exists pip3; then pipcmd="pip3"; fi
"$pipcmd" install --upgrade setuptools "$pipcmd" install --upgrade setuptools
"$pipcmd" install --upgrade "${packages[@]}" "$pipcmd" install --upgrade "${packages[@]}"

View File

@@ -50,7 +50,7 @@ alias bo="bundle open"
alias bp="bundle package" alias bp="bundle package"
alias bu="bundle update" alias bu="bundle update"
if (( $+commands[rbenv] )); then if command-exists rbenv; then
# lazy-load rbenv # lazy-load rbenv
rbenv() { rbenv() {
load-rbenv load-rbenv

8
zshrc
View File

@@ -9,6 +9,14 @@ if [[ "$OSTYPE" == "darwin"* ]] && [ -f "/etc/zshrc" ]; then
source "/etc/zshrc" source "/etc/zshrc"
fi fi
# ==============================================================================
# Helpers
# ==============================================================================
command-exists() {
command -v "$1" &> /dev/null
return $?
}
# ============================================================================== # ==============================================================================
# Zinit # Zinit