Skip to content

Commit

Permalink
Use type instead of command -v, use single bracket
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxattax97 committed Jul 16, 2024
1 parent ce36726 commit 87a21b0
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions .zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ zshrc_probe() {
}

zshrc_enter_tmux() {
if [[ -n "$(command -v tmux)" ]]; then
if [[ -n "$(type tmux > /dev/null 2>&1)" ]]; then
local session_count=$(tmux ls 2>/dev/null | grep "^Main" | wc -l)
if [[ "$session_count" -eq "0" ]]; then
if [ -x "$(command -v tmuxp)" ]; then
if [ -x "$(type tmuxp > /dev/null 2>&1)" ]; then
tmuxp load "${HOME}/.tmuxp/main.yaml"
else
tmux -2 new-session -s "Main"
Expand Down Expand Up @@ -295,30 +295,30 @@ zshrc_setup_completion() {

zstyle :compinstall filename '/home/max/.zshrc'

if [[ -x "$(command -v rustup)" ]]; then
if [ -x "$(type rustup > /dev/null 2>&1)" ]; then
if [[ ! -s "${HOME}/.zsh_completions/_rustup" ]]; then
rustup completions zsh > "${HOME}/.zsh_completions/_rustup"
fi

if [[ -x "$(command -v cargo)" ]] && [[ ! -s "${HOME}/.zsh_completions/_cargo" ]]; then
if [[ -x "$(type cargo > /dev/null 2>&1)" ]] && [[ ! -s "${HOME}/.zsh_completions/_cargo" ]]; then
rustup completions zsh cargo > "${HOME}/.zsh_completions/_cargo"
fi
fi

# Load `awscli`'s completions if available.
# NOTE: These are bash completions!
local aws_completer_path="$(command -v aws_completer)"
local aws_completer_path="$(type aws_completer > /dev/null 2>&1)"
if [ -x $aws_completer_path ]; then
complete -C "$aws_completer_path" aws
fi

if [[ -x "$(command -v gh)" ]]; then
if [ -x "$(type gh > /dev/null 2>&1)" ]; then
if [[ ! -s "${HOME}/.zsh_completions/_gh" ]]; then
gh completion -s zsh > "${HOME}/.zsh_completions/_gh"
fi
fi

if [[ -x "$(command -v activate-global-python-argcomplete)" ]]; then
if [ -x "$(type activate-global-python-argcomplete > /dev/null 2>&1)" ]; then
if [[ ! -s "${HOME}/.zsh_completions/_python-argcomplete" ]]; then
activate-global-python-argcomplete --dest "${HOME}/.zsh_completions/"
fi
Expand All @@ -330,7 +330,7 @@ zshrc_autoload() {
mkdir -p "${HOME}/.zsh_completions"
fpath+="${HOME}/.zsh_completions"

if [[ -x "$(command -v brew)" ]]; then
if [ -x "$(type brew > /dev/null 2>&1)" ]; then
fpath+="$(brew --prefix)/share/zsh/site-functions"
fi

Expand Down Expand Up @@ -651,11 +651,11 @@ zshrc_zplug() {
}
zshrc_extensions() {
if [[ -x "$(command -v navi)" ]]; then
if [ -x "$(type navi > /dev/null 2>&1)" ]; then
eval "$(navi widget zsh)"
fi
if [[ -x "$(command -v keychain)" ]]; then
if [ -x "$(type keychain > /dev/null 2>&1)" ]; then
eval "$(keychain --eval -q)"
fi
Expand All @@ -671,16 +671,16 @@ zshrc_extensions() {
zshrc_display_banner() {
if ( ! "$zshrc_low_power" ); then
if [[ -x "$(command -v fastfetch)" ]]; then
if [ -x "$(type fastfetch > /dev/null 2>&1)" ]; then
fastfetch
elif [[ -x "$(command -v neofetch)" ]]; then
elif [ -x "$(type neofetch > /dev/null 2>&1)" ]; then
neofetch --disable "packages"
elif [[ -x "$(command -v screenfetch)" ]]; then
elif [ -x "$(type screenfetch > /dev/null 2>&1)" ]; then
screenfetch -d '-pkgs,wm,de,res,gtk;+disk' -E
echo
fi
if [[ -x "$(command -v mikaelasay)" ]] && [[ "$CHASSIS" != "laptop" ]]; then
if [[ -x "$(type mikaelasay > /dev/null 2>&1)" ]] && [[ "$CHASSIS" != "laptop" ]]; then
mikaelasay
echo
fi
Expand Down Expand Up @@ -744,7 +744,7 @@ zshrc_set_path() {
zshrc_add_path "/sbin" after
# Override macOS's outdated curl version. This has to be prefixed so it overrides the /usr/bin/curl path.
if [ -x "$(command -v brew)" ]; then
if [ -x "$(type brew > /dev/null 2>&1)" ]; then
if [ -s "$(brew --prefix)/opt/curl/bin/curl" ]; then
zshrc_add_path "$(brew --prefix)/opt/curl/bin:${PATH}" before
fi
Expand All @@ -761,7 +761,7 @@ zshrc_set_path() {
export CPPFLAGS
fi
if [ -x "$(command -v gsed)" ]; then
if [ -x "$(type gsed > /dev/null 2>&1)" ]; then
alias sed='gsed'
fi
fi
Expand All @@ -785,7 +785,7 @@ zshrc_set_path() {
fi
# Dynamically add the ruby gem paths.
if [ -x "$(command -v gem)" ]; then
if [ -x "$(type gem > /dev/null 2>&1)" ]; then
# Sometimes this path doesn't exist.
local user_gem_path=$(gem env user_gemdir 2>/dev/null)
if [ $? -eq 0 ]; then
Expand Down Expand Up @@ -1452,7 +1452,7 @@ zshrc_set_aliases() {
alias l='k -Ah --no-vcs' # ls -lah
# Fix tmux 256 colors:
#if [[ -x "$(command -v tmux-next)" ]]; then
#if [ -x "$(type tmux-next > /dev/null 2>&1)" ]; then
#alias tmux='tmux-next -2'
#else
alias tmux='tmux -2'
Expand All @@ -1469,7 +1469,7 @@ zshrc_set_aliases() {
alias ddd='dd iflag=nocache oflag=nocache bs=64K status=progress'
alias sudo ddd='sudo dd iflag=nocache oflag=nocache bs=64K status=progress'
if [[ -x "$(command -v gpg2)" ]]; then
if [ -x "$(type gpg2 > /dev/null 2>&1)" ]; then
alias gpg='gpg2 --with-subkey-fingerprints'
alias gpgls='gpg2 --list-secret-keys --with-subkey-fingerprints'
fi
Expand All @@ -1486,26 +1486,26 @@ zshrc_set_aliases() {
alias clip='xclip -selection clipboard'
# btop > htop > top
if [[ -x "$(command -v htop)" ]]; then
if [ -x "$(type htop > /dev/null 2>&1)" ]; then
alias top='htop'
fi
if [[ -x "$(command -v btop)" ]]; then
if [ -x "$(type btop > /dev/null 2>&1)" ]; then
alias top='btop'
alias htop='btop'
fi
alias e="$EDITOR"
if [ -x "$(command -v rofi)" ]; then
if [ -x "$(type rofi > /dev/null 2>&1)" ]; then
alias dmenu="rofi -dmenu"
fi
alias rcat='find . -type f -exec sh -c '\''for file; do printf "\033[0;92m=== BEGIN $file ===\033[0m\n"; cat "$file"; printf "\n\033[0;91m=== END $file ===\033[0m\n"; done'\'' sh {} +'
alias awsp="source _awsp"
if [[ -x "$(command -v bat)" ]]; then
if [ -x "$(type bat > /dev/null 2>&1)" ]; then
alias bat='bat --theme=base16'
alias cat='bat'
fi
Expand Down Expand Up @@ -1540,18 +1540,18 @@ zshrc_set_aliases() {
zshrc_set_default_programs() {
# For heavyweight purposes.
if [[ -x "$(command -v nvim)" ]]; then
if [ -x "$(type nvim > /dev/null 2>&1)" ]; then
export VISUAL="$(which nvim)"
if [[ -d "${HOME}/.SpaceVim" ]]; then
alias vim="nvim"
fi
elif [[ -x "$(command -v vim)" ]]; then
elif [ -x "$(type vim > /dev/null 2>&1)" ]; then
export VISUAL="$(which vim)"
alias nvim="vim"
elif [[ -x "$(command -v vi)" ]]; then
elif [ -x "$(type vi > /dev/null 2>&1)" ]; then
export VISUAL="$(which vi)"
alias nvim="vi"
elif [[ -x "$(command -v nano)" ]]; then
elif [ -x "$(type nano > /dev/null 2>&1)" ]; then
export VISUAL="$(which nano)"
fi
Expand All @@ -1561,37 +1561,37 @@ zshrc_set_default_programs() {
export PAGER="less"
export MANPAGER="less"
if [[ -x "$(command -v brave)" ]]; then
if [ -x "$(type brave > /dev/null 2>&1)" ]; then
export BROWSER="$(which brave)"
elif [[ -x "$(command -v brave-browser)" ]]; then
elif [ -x "$(type brave-browser > /dev/null 2>&1)" ]; then
export BROWSER="$(which brave-browser)"
elif [[ -x "$(command -v firefox)" ]]; then
elif [ -x "$(type firefox > /dev/null 2>&1)" ]; then
export BROWSER="$(which firefox)"
elif [[ -x "$(command -v chromium)" ]]; then
elif [ -x "$(type chromium > /dev/null 2>&1)" ]; then
export BROWSER="$(which chromium)"
elif [[ -x "$(command -v google-chrome-stable)" ]]; then
elif [ -x "$(type google-chrome-stable > /dev/null 2>&1)" ]; then
export BROWSER="$(which google-chrome-stable)"
fi
if [[ -x "$(command -v st)" ]]; then
if [ -x "$(type st > /dev/null 2>&1)" ]; then
export TERMINAL="$(which st)"
elif [[ -x "$(command -v urxvt-256color)" ]]; then
elif [ -x "$(type urxvt-256color > /dev/null 2>&1)" ]; then
export TERMINAL="$(which urxvt-256color)"
elif [[ -x "$(command -v konsole)" ]]; then
elif [ -x "$(type konsole > /dev/null 2>&1)" ]; then
export TERMINAL="$(which konsole)"
fi
export P4IGNORE="/home/max/Perforce/mocull/Engineering/Software/Linux/Code/.p4ignore"
if [[ -x "$(command -v fastfetch)" ]]; then
if [ -x "$(type fastfetch > /dev/null 2>&1)" ]; then
alias neofetch="fastfetch"
alias screenfetch="fastfetch"
alias fetch="fastfetch"
elif [[ -x "$(command -v neofetch)" ]]; then
elif [ -x "$(type neofetch > /dev/null 2>&1)" ]; then
alias fastfetch="neofetch"
alias screenfetch="neofetch"
alias fetch="neofetch"
elif [[ -x "$(command -v screenfetch)" ]]; then
elif [ -x "$(type screenfetch > /dev/null 2>&1)" ]; then
alias fastfetch="screenfetch"
alias neofetch="screenfetch"
alias fetch="screenfetch"
Expand Down

0 comments on commit 87a21b0

Please sign in to comment.