From 158c3f99f08a2ddc4551f5ae1f509436a21040b6 Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Thu, 3 Sep 2026 12:47:39 +0200 Subject: [PATCH] perf: remove unnecessary subshells in command -v checks Replace 'if (command -v x &>/dev/null); then' with 'if command -v x &>/dev/null; then' across completion.d, rc.d and profile.d. Parentheses forced a subshell fork for every 'if' check, which is unnecessary overhead since command -v runs fine in the current shell. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- completion.d/aws | 2 +- completion.d/chezmoi | 2 +- completion.d/flux | 2 +- completion.d/glab | 2 +- completion.d/helm | 2 +- completion.d/k3d | 2 +- completion.d/kind | 2 +- completion.d/kubectl | 2 +- completion.d/minikube | 2 +- completion.d/mise | 2 +- completion.d/podman | 2 +- completion.d/poetry | 2 +- completion.d/stern | 2 +- completion.d/taskwarrior | 2 +- completion.d/tea | 2 +- profile.d/keychain | 2 +- profile.d/krew | 2 +- rc.d/anyenv | 2 +- rc.d/broot | 2 +- rc.d/direnv | 4 ++-- rc.d/fzf | 2 +- rc.d/git | 2 +- rc.d/history | 6 +++--- rc.d/lsd | 2 +- rc.d/prompt | 6 +++--- rc.d/screen | 2 +- rc.d/startx | 4 ++-- rc.d/tmux | 2 +- rc.d/vivid | 2 +- rc.d/zoxide | 2 +- 30 files changed, 36 insertions(+), 36 deletions(-) diff --git a/completion.d/aws b/completion.d/aws index 02a9557..1c46019 100644 --- a/completion.d/aws +++ b/completion.d/aws @@ -1,3 +1,3 @@ -if (command -v aws && command -v aws_completer) &>/dev/null; then +if command -v aws &>/dev/null && command -v aws_completer &>/dev/null; then complete -C aws_completer aws fi diff --git a/completion.d/chezmoi b/completion.d/chezmoi index 6afc737..b606ee4 100644 --- a/completion.d/chezmoi +++ b/completion.d/chezmoi @@ -1,3 +1,3 @@ -if (command -v chezmoi &>/dev/null); then +if command -v chezmoi &>/dev/null; then source <(chezmoi completion bash) fi diff --git a/completion.d/flux b/completion.d/flux index c1e9cc8..f4038bf 100644 --- a/completion.d/flux +++ b/completion.d/flux @@ -1,3 +1,3 @@ -if (command -v flux &>/dev/null); then +if command -v flux &>/dev/null; then source <(flux completion bash) fi diff --git a/completion.d/glab b/completion.d/glab index 3f5be3d..5adfb00 100644 --- a/completion.d/glab +++ b/completion.d/glab @@ -1,3 +1,3 @@ -if (command -v glab &>/dev/null); then +if command -v glab &>/dev/null; then source <(glab completion) fi diff --git a/completion.d/helm b/completion.d/helm index 56cc855..0d1c06b 100644 --- a/completion.d/helm +++ b/completion.d/helm @@ -1,4 +1,4 @@ -if (command -v helm &> /dev/null) +if command -v helm &> /dev/null then source <( helm completion bash ) fi diff --git a/completion.d/k3d b/completion.d/k3d index 61e606b..0958aa9 100644 --- a/completion.d/k3d +++ b/completion.d/k3d @@ -1,3 +1,3 @@ -if (command -v k3d &>/dev/null); then +if command -v k3d &>/dev/null; then source <(k3d completion bash) fi diff --git a/completion.d/kind b/completion.d/kind index 29e919b..1c94ade 100644 --- a/completion.d/kind +++ b/completion.d/kind @@ -1,3 +1,3 @@ -if (command -v kind &>/dev/null); then +if command -v kind &>/dev/null; then source <(kind completion bash) fi diff --git a/completion.d/kubectl b/completion.d/kubectl index 5c5e277..90794b3 100644 --- a/completion.d/kubectl +++ b/completion.d/kubectl @@ -1,4 +1,4 @@ -if (command -v kubectl &> /dev/null) +if command -v kubectl &> /dev/null then source <(kubectl completion bash) fi diff --git a/completion.d/minikube b/completion.d/minikube index afdab95..71dbd01 100644 --- a/completion.d/minikube +++ b/completion.d/minikube @@ -1,3 +1,3 @@ -if (command -v minikube &>/dev/null); then +if command -v minikube &>/dev/null; then source <(minikube completion bash) fi diff --git a/completion.d/mise b/completion.d/mise index 36f824d..7da79d4 100644 --- a/completion.d/mise +++ b/completion.d/mise @@ -1,3 +1,3 @@ -if (command -v mise &>/dev/null); then +if command -v mise &>/dev/null; then source <(mise completion bash) fi diff --git a/completion.d/podman b/completion.d/podman index 9e25c67..e06cc60 100644 --- a/completion.d/podman +++ b/completion.d/podman @@ -1,3 +1,3 @@ -if (command -v podman &>/dev/null); then +if command -v podman &>/dev/null; then source <(podman completion bash) fi diff --git a/completion.d/poetry b/completion.d/poetry index 93309e9..d99f44d 100644 --- a/completion.d/poetry +++ b/completion.d/poetry @@ -1,4 +1,4 @@ -if ( command -v poetry &> /dev/null ) +if command -v poetry &> /dev/null then source <(poetry completions bash) fi diff --git a/completion.d/stern b/completion.d/stern index c705424..63ff540 100644 --- a/completion.d/stern +++ b/completion.d/stern @@ -1,4 +1,4 @@ -if (command -v stern &> /dev/null) +if command -v stern &> /dev/null then source <(stern --completion bash) fi diff --git a/completion.d/taskwarrior b/completion.d/taskwarrior index 8953bd7..b81268b 100644 --- a/completion.d/taskwarrior +++ b/completion.d/taskwarrior @@ -1,7 +1,7 @@ # # Completion for taskwarrior # -if (command -v task &> /dev/null) +if command -v task &> /dev/null then complete -o nospace -F _task t fi diff --git a/completion.d/tea b/completion.d/tea index 0666c99..2e886ee 100644 --- a/completion.d/tea +++ b/completion.d/tea @@ -1,3 +1,3 @@ -if (command -v tea &>/dev/null); then +if command -v tea &>/dev/null; then source <(tea completion bash) fi diff --git a/profile.d/keychain b/profile.d/keychain index f795a65..1acdb25 100644 --- a/profile.d/keychain +++ b/profile.d/keychain @@ -1,3 +1,3 @@ -if (command -v keychain &>/dev/null); then +if command -v keychain &>/dev/null; then eval "$(keychain --inherit any --quiet --noask ~/.ssh/id_{rsa,ed25519})" fi diff --git a/profile.d/krew b/profile.d/krew index e570dfb..dbe6b57 100644 --- a/profile.d/krew +++ b/profile.d/krew @@ -1,3 +1,3 @@ -if (command -v krew &>/dev/null); then +if command -v krew &>/dev/null; then _path_prepend "${KREW_ROOT:-${HOME}/.krew}/bin" fi diff --git a/rc.d/anyenv b/rc.d/anyenv index 582740f..2f8ca3a 100644 --- a/rc.d/anyenv +++ b/rc.d/anyenv @@ -2,6 +2,6 @@ # git clone https://github.com/riywo/anyenv ${HOME}/.anyenv -if (command -v anyenv &>/dev/null); then +if command -v anyenv &>/dev/null; then eval "$(anyenv init -)" fi diff --git a/rc.d/broot b/rc.d/broot index c226a8e..c29c7a3 100644 --- a/rc.d/broot +++ b/rc.d/broot @@ -1,4 +1,4 @@ -if (command -v broot &>/dev/null); then +if command -v broot &>/dev/null; then # This script was automatically generated by the broot program # More information can be found in https://github.com/Canop/broot # This function starts broot and executes the command diff --git a/rc.d/direnv b/rc.d/direnv index 933b92f..0768568 100644 --- a/rc.d/direnv +++ b/rc.d/direnv @@ -1,4 +1,4 @@ -if (asdf which direnv &>/dev/null); then +if asdf which direnv &>/dev/null; then # Hook direnv into your shell. eval "$(asdf exec direnv hook bash)" @@ -7,7 +7,7 @@ if (asdf which direnv &>/dev/null); then return -elif (command -v direnv &>/dev/null); then +elif command -v direnv &>/dev/null; then # Hook direnv into your shell. eval "$(direnv hook bash)" diff --git a/rc.d/fzf b/rc.d/fzf index 947b168..c796a24 100644 --- a/rc.d/fzf +++ b/rc.d/fzf @@ -1,4 +1,4 @@ -if (command -v fzf &>/dev/null); then +if command -v fzf &>/dev/null; then # Shell integration source <(fzf --bash) diff --git a/rc.d/git b/rc.d/git index 2d6882a..16eab7a 100644 --- a/rc.d/git +++ b/rc.d/git @@ -1,3 +1,3 @@ -if (command -v git && command -v fzf) &>/dev/null; then +if command -v git &>/dev/null && command -v fzf &>/dev/null; then function gsb { git checkout "$(git branch --all | fzf | tr -d '[:space:]')"; } fi diff --git a/rc.d/history b/rc.d/history index b6336b8..82a36ea 100644 --- a/rc.d/history +++ b/rc.d/history @@ -5,7 +5,7 @@ MY_HISTORY_TOOLS="atuin mcfly" for tool in ${MY_HISTORY_TOOLS}; do - if (command -v "${tool}" &>/dev/null); then + if command -v "${tool}" &>/dev/null; then USE_HISTORY_TOOL="${tool}" break fi @@ -15,7 +15,7 @@ case "${USE_HISTORY_TOOL}" in # https://atuin.sh/ "atuin") - if (command -v atuin &>/dev/null); then + if command -v atuin &>/dev/null; then eval "$(atuin init bash)" else echo "${USE_HISTORY_TOOL} command not found" @@ -24,7 +24,7 @@ case "${USE_HISTORY_TOOL}" in # https://github.com/cantino/mcfly "mcfly") - if (command -v mcfly &>/dev/null); then + if command -v mcfly &>/dev/null; then export MCFLY_PROMPT="❯ " export MCFLY_INTERFACE_VIEW=BOTTOM export MCFLY_RESULTS=50 diff --git a/rc.d/lsd b/rc.d/lsd index 6809d6f..90fef7a 100644 --- a/rc.d/lsd +++ b/rc.d/lsd @@ -1,4 +1,4 @@ -if (which lsd &> /dev/null) +if which lsd &> /dev/null then # create a aliases diff --git a/rc.d/prompt b/rc.d/prompt index 59e6685..b1ee506 100644 --- a/rc.d/prompt +++ b/rc.d/prompt @@ -5,7 +5,7 @@ MY_PROMPT_TOOLS="starship powerline-go" for prompt in ${MY_PROMPT_TOOLS}; do - if (command -v "${prompt}" &>/dev/null); then + if command -v "${prompt}" &>/dev/null; then USE_PROMPT="${prompt}" break fi @@ -15,7 +15,7 @@ case "${USE_PROMPT}" in # https://starship.rs/ "starship") - if (command -v starship &>/dev/null); then + if command -v starship &>/dev/null; then eval "$(starship init bash)" else echo "${USE_PROMPT} command not found" @@ -24,7 +24,7 @@ case "${USE_PROMPT}" in # https://github.com/justjanne/powerline-go "powerline-go") - if (command -v powerline-go &>/dev/null); then + if command -v powerline-go &>/dev/null; then function _update_ps1() { PS1=$(powerline-go -jobs "$(jobs -p | wc -l)" -error $? -modules "ssh,host,wsl,user,cwd,direnv,venv,perms,git,jobs,exit,root" -modules-right "docker,docker-context,kube,terraform-workspace,termtitle" -newline) } diff --git a/rc.d/screen b/rc.d/screen index 9c025be..9e70c27 100644 --- a/rc.d/screen +++ b/rc.d/screen @@ -1,5 +1,5 @@ # GNU Screen stuff -if ( command -v screen &> /dev/null ) +if command -v screen &> /dev/null then if [[ ${TERM} != screen* ]] then diff --git a/rc.d/startx b/rc.d/startx index 4370d35..d78d61a 100644 --- a/rc.d/startx +++ b/rc.d/startx @@ -13,12 +13,12 @@ if [[ -z "${DISPLAY}" && $(id -u) -ge 1000 ]] ; then 3) VT=vt3 ;; esac - if ( command -v ck-launch-session &> /dev/null ) + if command -v ck-launch-session &> /dev/null then EXEC="exec ck-launch-session" fi - if ( command -v startx &> /dev/null ) + if command -v startx &> /dev/null then ${EXEC} startx 1> ~/.log/xsession-errors 2>&1 -- "${VT}" fi diff --git a/rc.d/tmux b/rc.d/tmux index 634ad0d..1b75333 100644 --- a/rc.d/tmux +++ b/rc.d/tmux @@ -1,5 +1,5 @@ # GNU Screen stuff -if (command -v tmux &>/dev/null); then +if command -v tmux &>/dev/null; then if [ "$(pgrep -u "${UID}" "tmux" | wc -l)" -gt 0 ]; then if [[ ${TERM} != screen* ]]; then nb_sessions=$(tmux list-session | wc -l) diff --git a/rc.d/vivid b/rc.d/vivid index 539ddd1..de96b93 100644 --- a/rc.d/vivid +++ b/rc.d/vivid @@ -3,7 +3,7 @@ # ➜ https://github.com/sharkdp/vivid # 💡Use command `vivid themes` to see available themes -if (command -v vivid &>/dev/null); then +if command -v vivid &>/dev/null; then THEME=tokyonight-moon LS_COLORS="$(vivid generate ${THEME})" export LS_COLORS diff --git a/rc.d/zoxide b/rc.d/zoxide index 5ad5379..3711acb 100644 --- a/rc.d/zoxide +++ b/rc.d/zoxide @@ -1,3 +1,3 @@ -if (command -v zoxide &>/dev/null); then +if command -v zoxide &>/dev/null; then eval "$(zoxide init bash)" fi