From 99fcc57675bf8831857b71c26d808d2bbdfd6b9d Mon Sep 17 00:00:00 2001 From: Christian Emmer <10749361+emmercm@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:35:30 -0500 Subject: [PATCH] 11/27/2024 (#44) --- .10_macos.bash | 8 ++++---- .20_docker.bash | 10 +++++----- .20_git.bash | 8 ++++---- .20_kubernetes.bash | 12 ++++++------ .20_python.bash | 2 +- .20_temporal.bash | 4 ++-- .20_terraform.bash | 10 +++++----- .90_powerline.bash | 2 +- .everythingrc | 16 ++++++++-------- install.sh | 2 +- settings.sh | 2 +- 11 files changed, 38 insertions(+), 38 deletions(-) diff --git a/.10_macos.bash b/.10_macos.bash index 4ccc093..67fdecf 100755 --- a/.10_macos.bash +++ b/.10_macos.bash @@ -24,7 +24,7 @@ fi ##### App installs ##### # Homebrew packages -if [[ -x "$(command -v brew)" ]]; then +if command -v brew &> /dev/null; then command -v gawk > /dev/null || brew install gawk command -v gdate > /dev/null || brew install coreutils command -v gsed > /dev/null || brew install gnu-sed @@ -34,18 +34,18 @@ if [[ -x "$(command -v brew)" ]]; then command -v watch > /dev/null || brew install watch command -v wget > /dev/null || brew install wget - if [[ ! -x "$(command -v hstr)" ]]; then + if ! command -v hstr &> /dev/null; then brew install hstr hstr --show-configuration >> ~/.bashrc fi fi # App store applications -if [[ -x "$(command -v brew)" && ! -x "$(command -v mas)" ]]; then +if command -v brew &> /dev/null && ! command -v mas &> /dev/null; then brew install mas # Installed applications aren't enumerated immediately, `mas list` may return nothing fi -# if [[ -x "$(command -v mas)" ]]; then +# if command -v mas &> /dev/null; then # mas_list=$(mas list) # # 1Password for Safari # # echo "${mas_list}" | grep '^1569813296 ' &> /dev/null || mas install 1569813296 diff --git a/.20_docker.bash b/.20_docker.bash index 9d081f5..225316a 100755 --- a/.20_docker.bash +++ b/.20_docker.bash @@ -3,7 +3,7 @@ export PROGRESS_NO_TRUNC=1 __docker_completions() { - if [[ -x "$(command -v brew)" && -d "/Applications/Docker.app" && -z "$(find "$(brew --prefix)/etc/bash_completion.d" -maxdepth 1 -name "docker*")" ]]; then + if command -v brew &> /dev/null && [[ -d "/Applications/Docker.app" && -z "$(find "$(brew --prefix)/etc/bash_completion.d" -maxdepth 1 -name "docker*")" ]]; then find "/Applications/Docker.app" -follow -type f -name "*.bash-completion" -exec ln -sf "{}" "$(brew --prefix)/etc/bash_completion.d/" \; fi } @@ -12,7 +12,7 @@ __docker_completions __docker_funcs() { # Auto/lazy-start Docker if it's not running - if [[ -x "$(command -v docker)" ]]; then + if command -v docker &> /dev/null; then docker() { if [[ "${OSTYPE:-}" == "darwin"* ]]; then # macOS @@ -28,7 +28,7 @@ __docker_funcs() { } alias docker-compose="docker compose --compatibility" - elif [[ -x "$(command -v docker-compose)" ]]; then + elif command -v docker-compose &> /dev/null; then docker-compose() { docker ps &> /dev/null # start command docker-compose "$@" @@ -47,7 +47,7 @@ __docker_funcs() { # Get the digest hash of a Docker image # @param {string} $1 name[:tag][@digest] ddigest() { - if [[ -x "$(command -v skopeo)" ]]; then + if command -v skopeo &> /dev/null; then skopeo inspect --raw "docker://$1" | shasum --algorithm 256 | awk '{print "sha256:"$1}' else docker pull "$1" &> /dev/null || true @@ -139,7 +139,7 @@ __docker_containers() { # Execute `jshell` interactively in a Java JDK container # @param {string=} $1 Image tag djava() { - if [[ "${1:-}" == "" && -x "$(command -v java)" ]]; then + if [[ "${1:-}" == "" ]] && command -v java &> /dev/null; then set -- "$(java --version | head -1 | sed 's/"//g' | sed -E 's/(.* )?([0-9]+)\.[0-9]+\.[0-9]+.*/\2/')" fi diff --git a/.20_git.bash b/.20_git.bash index e731646..636b8ae 100755 --- a/.20_git.bash +++ b/.20_git.bash @@ -1,17 +1,17 @@ # Don't use the git from macOS, use the Homebrew version instead -if [[ -x "$(command -v brew)" && ! -f "$(brew --prefix)/bin/git" ]]; then +if command -v brew &> /dev/null && [[ ! -f "$(brew --prefix)/bin/git" ]]; then brew install git brew link --overwrite git fi -if [[ ! -x "$(command -v git)" ]]; then +if ! command -v git &> /dev/null; then return 0 fi __git_completions() { # Bash completions - if [[ -x "$(command -v brew)" && -f "/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash" && ! -f "$(brew --prefix)/etc/bash_completion.d/git-completion.bash" ]]; then + if command -v brew &> /dev/null && [[ -f "/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash" && ! -f "$(brew --prefix)/etc/bash_completion.d/git-completion.bash" ]]; then ln -sf "/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash" "$(brew --prefix)/etc/bash_completion.d/" fi } @@ -26,7 +26,7 @@ __git_funcs() { fi # Shell alias Git aliases from the .gitconfig - for al in $(git --list-cmds=alias); do + for al in $(git --list-cmds=alias; git --list-cmds=main); do # shellcheck disable=SC2139 alias g${al}="git ${al}" if type __git_aliased_command &> /dev/null; then diff --git a/.20_kubernetes.bash b/.20_kubernetes.bash index de34822..2726705 100755 --- a/.20_kubernetes.bash +++ b/.20_kubernetes.bash @@ -4,7 +4,7 @@ __kube_completions() { # NOTE: `autoload -Uz compinit && compinit` will need to happen before sourcing any of these! - if [[ -x "$(command -v helm)" ]]; then + if command -v helm &> /dev/null; then helm() { unset -f "$0" # shellcheck disable=SC1090 @@ -13,7 +13,7 @@ __kube_completions() { } fi - if [[ -x "$(command -v kops)" ]]; then + if command -v kops &> /dev/null; then kops() { unset -f "$0" # shellcheck disable=SC1090 @@ -22,7 +22,7 @@ __kube_completions() { } fi - if [[ -x "$(command -v kubectl)" ]]; then + if command -v kubectl &> /dev/null; then kubectl() { unset -f "$0" # shellcheck disable=SC1090 @@ -31,7 +31,7 @@ __kube_completions() { } fi - if [[ -x "$(command -v minikube)" ]]; then + if command -v minikube &> /dev/null; then minikube() { unset -f "$0" # shellcheck disable=SC1090 @@ -40,7 +40,7 @@ __kube_completions() { } fi - if [[ -x "$(command -v stern)" ]]; then + if command -v stern &> /dev/null; then stern() { unset -f "$0" # shellcheck disable=SC1090 @@ -163,7 +163,7 @@ __kube_funcs() { # @param {number=} $2 Tail length # @param {...string} Additional kubectl options klogs() { - if [[ -x "$(command -v stern)" ]]; then + if command -v stern &> /dev/null; then stern --timestamps --tail "${2:-0}" --selector "app=$1" else kubectl logs --all-containers --timestamps --follow --max-log-requests=9999 "--tail=${2:-0}" --selector="app=$1" diff --git a/.20_python.bash b/.20_python.bash index b66123f..3df402c 100755 --- a/.20_python.bash +++ b/.20_python.bash @@ -39,7 +39,7 @@ __python_pyenv() { __python_pyenv __python_pip() { - if [[ ! -x "$(command -v pip)" && -x "$(command -v pip3)" ]]; then + if ! command -v pip &> /dev/null && command -v pip3 &> /dev/null; then alias pip=pip3 fi } diff --git a/.20_temporal.bash b/.20_temporal.bash index c68af29..98e1ba0 100755 --- a/.20_temporal.bash +++ b/.20_temporal.bash @@ -1,5 +1,5 @@ # Reset back to non-beta functionality -if [[ -x "$(command -v tctl)" ]]; then +if command -v tctl &> /dev/null; then tctl config set version current fi @@ -11,7 +11,7 @@ fi __temporal_completions() { # NOTE: `autoload -Uz compinit && compinit` will need to happen before sourcing any of these! - if [[ -x "$(command -v tctl)" ]]; then + if command -v tctl &> /dev/null; then tctl() { unset -f "$0" # shellcheck disable=SC1090 diff --git a/.20_terraform.bash b/.20_terraform.bash index cc92b7f..94bce92 100755 --- a/.20_terraform.bash +++ b/.20_terraform.bash @@ -1,10 +1,10 @@ __terraform_install() { - if [[ -x "$(command -v terraform)" ]]; then + if command -v terraform &> /dev/null; then return 0 fi # Lazy install terraform() { - if [[ -x "$(command -v brew)" ]]; then + if command -v brew &> /dev/null; then brew tap hashicorp/tap brew install hashicorp/tap/terraform fi @@ -16,14 +16,14 @@ __terraform_install __tflint_install() { - if [[ -x "$(command -v tflint)" ]]; then + if command -v tflint &> /dev/null; then return 0 fi # Lazy install tflint() { - if [[ -x "$(command -v brew)" ]]; then + if command -v brew &> /dev/null; then brew install tflint - elif [[ -x "$(command -v docker)" ]]; then + elif command -v docker &> /dev/null; then docker run --rm --volume "$(pwd):/data" --tty "ghcr.io/terraform-linters/tflint" "$@" return $? fi diff --git a/.90_powerline.bash b/.90_powerline.bash index 477614f..8954862 100755 --- a/.90_powerline.bash +++ b/.90_powerline.bash @@ -15,7 +15,7 @@ if [[ -d ~/Library/Fonts && "$(find ~/Library/Fonts -maxdepth 1 -follow -type f fi # If installed run it -if [[ -x "$(command -v powerline-daemon)" ]]; then +if command -v powerline-daemon &> /dev/null; then powerline-daemon --quiet export POWERLINE_BASH_CONTINUATION=1 export POWERLINE_BASH_SELECT=1 diff --git a/.everythingrc b/.everythingrc index 57fd7d4..44e1694 100755 --- a/.everythingrc +++ b/.everythingrc @@ -1,19 +1,19 @@ # Bash: .bash_profile (macOS default) -> .profile (Ubuntu default) -> .bashrc -> .everythingrc # zsh: .zshrc (always executed) -> .everythingrc -: ${SHELL:=$(which "$(ps -o comm= $$ | sed 's/^-*//')")} +SHELL=$(which "$(ps -o comm= $$ | sed 's/^-*//')") # https://docs.brew.sh/Shell-Completion : ${HOMEBREW_PREFIX:=$(if type brew &> /dev/null; then brew --prefix; fi)} -if [[ ! -x "$(command -v brew)" && -f /opt/homebrew/bin/brew ]]; then +if ! command -v brew &> /dev/null && [[ -f /opt/homebrew/bin/brew ]]; then eval "$(/opt/homebrew/bin/brew shellenv)" fi ##### Bash ##### -if [[ -x "$(command -v brew)" ]]; then +if command -v brew &> /dev/null; then # Load bash-completion if [[ "$(basename "${SHELL}")" == "bash" ]]; then __bash_completion() { @@ -69,7 +69,7 @@ __bashrc_misc() { } # Don't be a savage - if [[ -x "$(command -v nano)" ]]; then + if command -v nano &> /dev/null; then EDITOR=$(pinpoint nano) export EDITOR fi @@ -115,7 +115,7 @@ __bashrc_misc() { alias yeet="rm -rf" # Polyfills - if [[ ! -x "$(command -v beep)" ]]; then + if ! command -v beep &> /dev/null; then alias beep="echo -ne '\007'" fi } @@ -145,7 +145,7 @@ __bashrc_ides __bashrc_golang() { # Set path environment variables - if [[ -x "$(command -v go)" ]]; then + if command -v go &> /dev/null; then if [[ ! -d "${GOROOT}" ]]; then GOROOT=$(realpath "$(which go)" | sed 's/\/bin\/go$//') export GOROOT @@ -188,7 +188,7 @@ __bashrc_java __bashrc_mysql() { # Set path environment variables - if [[ -x "$(command -v brew)" ]]; then + if command -v brew &> /dev/null; then while read -r DIR; do if [[ -d "${DIR}/bin" ]]; then export PATH="${DIR}/bin:${PATH}" @@ -230,7 +230,7 @@ __bashrc_ruby() { fi # Auto-load the latest Ruby version - if [[ -x "$(command -v chruby)" && -d ~/.rubies ]]; then + if command -v chruby &> /dev/null && [[ -d ~/.rubies ]]; then chruby "$(ls -1 ~/.rubies/ | sort | tail -1)" fi } diff --git a/install.sh b/install.sh index feb0026..1e533d8 100755 --- a/install.sh +++ b/install.sh @@ -62,6 +62,6 @@ find "${HOME}" -maxdepth 1 -name ".*.bash" -type l ! -exec test -e {} \; -delete link "$(pwd)" ".*" # Reload powerline if installed -if [[ -x "$(command -v powerline-daemon)" ]]; then +if command -v powerline-daemon &> /dev/null; then powerline-daemon --quiet --replace fi diff --git a/settings.sh b/settings.sh index 474f9e7..e7f0b97 100755 --- a/settings.sh +++ b/settings.sh @@ -5,7 +5,7 @@ set -euo pipefail # Git settings -if [[ -x "$(command -v git)" && -s ~/.gitignore_global ]]; then +if command -v git &> /dev/null && [[ -s ~/.gitignore_global ]]; then git config --global core.excludesfile ~/.gitignore_global fi