diff --git a/add-submodules.sh b/add-submodules.sh index c395c1e..96e7f25 100755 --- a/add-submodules.sh +++ b/add-submodules.sh @@ -54,7 +54,7 @@ remove_old_submodule() { local name="$1" path="$2" # Remove working tree - if [ -d "$path" ]; then + if [[ -d "$path" ]]; then rm -rf "$path" _log "Removed $path" fi @@ -66,13 +66,13 @@ remove_old_submodule() { git config --remove-section "submodule.$path" 2> /dev/null || true # Skip name-based cleanup if no submodule name provided - [ -z "$name" ] && return 0 + [[ -z "$name" ]] && return 0 # Remove .git/config section keyed by name git config --remove-section "submodule.$name" 2> /dev/null || true # Remove .git/modules// cached repository - if [ -d ".git/modules/$name" ]; then + if [[ -d ".git/modules/$name" ]]; then rm -rf ".git/modules/$name" _log "Removed .git/modules/$name" fi diff --git a/config/husky/init.sh b/config/husky/init.sh index fbb782e..b7e59c2 100755 --- a/config/husky/init.sh +++ b/config/husky/init.sh @@ -1,4 +1,4 @@ #!/bin/env bash -[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.config/nvm" -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm +[[ -z "$NVM_DIR" ]] && export NVM_DIR="$HOME/.config/nvm" +[[ -s "$NVM_DIR/nvm.sh" ]] && \. "$NVM_DIR/nvm.sh" # This loads nvm diff --git a/config/shared.sh b/config/shared.sh index ecffc60..309444e 100755 --- a/config/shared.sh +++ b/config/shared.sh @@ -5,7 +5,7 @@ # shellcheck shell=bash # Defaults -[ -z "$DOTFILES" ] && export DOTFILES="$HOME/.dotfiles" +[[ -z "$DOTFILES" ]] && export DOTFILES="$HOME/.dotfiles" DOTFILES_CURRENT_SHELL=$(basename "$SHELL") export DOTFILES_CURRENT_SHELL @@ -15,7 +15,7 @@ VERBOSE="${VERBOSE:-0}" DEBUG="${DEBUG:-0}" # Enable debugging with DEBUG=1 -[ "${DEBUG:-0}" -eq 1 ] && set -x +[[ "${DEBUG:-0}" -eq 1 ]] && set -x # Detect the current shell CURRENT_SHELL=$(ps -p $$ -ocomm= | awk -F/ '{print $NF}') @@ -74,7 +74,7 @@ x-path-prepend "$DOTFILES/local/bin" x-path-prepend "$XDG_BIN_HOME" # Custom completion paths -[ -z "$ZSH_CUSTOM_COMPLETION_PATH" ] && export ZSH_CUSTOM_COMPLETION_PATH="$XDG_CONFIG_HOME/zsh/completion" +[[ -z "$ZSH_CUSTOM_COMPLETION_PATH" ]] && export ZSH_CUSTOM_COMPLETION_PATH="$XDG_CONFIG_HOME/zsh/completion" x-dc "$ZSH_CUSTOM_COMPLETION_PATH" export FPATH="$ZSH_CUSTOM_COMPLETION_PATH:$FPATH" @@ -83,7 +83,7 @@ if ! declare -f msg > /dev/null; then # $1 - message (string) msg() { - [ "$VERBOSE" -eq 1 ] && msgr msg "$1" + [[ "$VERBOSE" -eq 1 ]] && msgr msg "$1" return 0 } msg "msg was not defined, defined it now" diff --git a/config/tmux/rename-session.sh b/config/tmux/rename-session.sh index 84aaf7e..7696107 100755 --- a/config/tmux/rename-session.sh +++ b/config/tmux/rename-session.sh @@ -7,13 +7,13 @@ DEFAULT_NAME="main" CURRENT_SESSION=$(tmux display-message -p "#{session_name}") # Check that the session has a name -if [ "$CURRENT_SESSION" = "#{session_name}" ] || [ "$CURRENT_SESSION" = "0" ]; then +if [[ "$CURRENT_SESSION" = "#{session_name}" ]] || [[ "$CURRENT_SESSION" = "0" ]]; then # Check if the default name is already in use if tmux has-session -t "$DEFAULT_NAME" 2> /dev/null; then # Query the user for a new name echo "Session name '$DEFAULT_NAME' is already in use. Enter a new name:" read -r NEW_NAME - while tmux has-session -t "$NEW_NAME" 2> /dev/null || [ -z "$NEW_NAME" ]; do + while tmux has-session -t "$NEW_NAME" 2> /dev/null || [[ -z "$NEW_NAME" ]]; do echo "Name '$NEW_NAME' is invalid or already in use. Enter a new name:" read -r NEW_NAME done diff --git a/scripts/install-cheat-purebashbible.sh b/scripts/install-cheat-purebashbible.sh index fc6606a..5759be1 100755 --- a/scripts/install-cheat-purebashbible.sh +++ b/scripts/install-cheat-purebashbible.sh @@ -24,7 +24,7 @@ check_required_tools() clone_or_update_repo() { - if [ ! -d "$PBB_TEMP_DIR/.git" ]; then + if [[ ! -d "$PBB_TEMP_DIR/.git" ]]; then msg_run "Starting to clone $PBB_GIT" git clone --depth 1 --single-branch -q "$PBB_GIT" "$PBB_TEMP_DIR" \ && msg_yay "Cloned $PBB_GIT" @@ -41,7 +41,7 @@ prepare_cheat_dest() local cheat_dest cheat_dest="$(cheat -d | grep pure-bash-bible | head -1 | awk '{print $2}')" - if [ ! -d "$cheat_dest" ]; then + if [[ ! -d "$cheat_dest" ]]; then mkdir -p "$cheat_dest" fi @@ -83,7 +83,7 @@ process_chapters() LC_ALL=C perl -pi.bak -e 's/\<\!-- CHAPTER END --\>//' "$cheat_file" rm "$cheat_file.bak" - if [ '---' != "$(head -1 < "$cheat_file")" ]; then + if [[ '---' != "$(head -1 < "$cheat_file")" ]]; then local metadata metadata="$PBB_SYNTAX\n$PBB_TAGS\n$PBB_SOURCE\n" printf '%s\n%b%s\n%s' "---" "$metadata" "---" "$(cat "$cheat_file")" > "$cheat_file" diff --git a/scripts/install-composer.sh b/scripts/install-composer.sh index b708b00..d23c094 100755 --- a/scripts/install-composer.sh +++ b/scripts/install-composer.sh @@ -14,7 +14,7 @@ EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "p php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" -if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then +if [[ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]]; then echo >&2 'ERROR: Invalid installer checksum' rm composer-setup.php exit 1 @@ -23,7 +23,7 @@ fi php composer-setup.php --quiet RESULT=$? rm composer-setup.php -if [ $RESULT -eq 0 ]; then +if [[ $RESULT -eq 0 ]]; then mv composer.phar ~/.local/bin/composer fi exit $RESULT diff --git a/scripts/install-fonts.sh b/scripts/install-fonts.sh index 910a474..aa6eff8 100755 --- a/scripts/install-fonts.sh +++ b/scripts/install-fonts.sh @@ -18,7 +18,7 @@ fonts=( # Function to clone or update the NerdFonts repository clone_or_update_repo() { - if [ ! -d "$TMP_PATH" ]; then + if [[ ! -d "$TMP_PATH" ]]; then git clone --quiet --filter=blob:none --sparse --depth=1 "$GIT_REPO" "$TMP_PATH" fi diff --git a/scripts/install-git-crypt.sh b/scripts/install-git-crypt.sh index 575146c..86ad529 100755 --- a/scripts/install-git-crypt.sh +++ b/scripts/install-git-crypt.sh @@ -15,7 +15,7 @@ if ! command -v git-crypt &> /dev/null; then BUILD_PATH="$(mktemp -d)" trap 'rm -rf "$BUILD_PATH"' EXIT - if [ ! -f "$CHECK_PATH" ]; then + if [[ ! -f "$CHECK_PATH" ]]; then git clone --depth 1 "$REPO_URL" "$BUILD_PATH" || { msgr err "Failed to clone $REPO_URL"; exit 1; } cd "$BUILD_PATH" || { msgr err "$BUILD_PATH not found"; exit 1; } make && make install PREFIX="$HOME/.local" diff --git a/scripts/install-macos-defaults.sh b/scripts/install-macos-defaults.sh index 6e7fef2..9b049d1 100755 --- a/scripts/install-macos-defaults.sh +++ b/scripts/install-macos-defaults.sh @@ -5,7 +5,7 @@ set -uo pipefail # This script contains large portions from following scripts: # - https://github.com/freekmurze/dotfiles/blob/main/macos/set-defaults.sh -[ "$(uname)" != "Darwin" ] && echo "Not a macOS system" && exit 0 +[[ "$(uname)" != "Darwin" ]] && echo "Not a macOS system" && exit 0 # shellcheck source=shared.sh source "$DOTFILES/config/shared.sh" diff --git a/scripts/install-ntfy.sh b/scripts/install-ntfy.sh index 0dfeb7e..1dcadd2 100755 --- a/scripts/install-ntfy.sh +++ b/scripts/install-ntfy.sh @@ -43,7 +43,7 @@ install_ntfy() mkdir -p ~/.config/ntfy # Copy config only if it does not exist - if [ ! -f "$HOME/.config/ntfy/client.yml" ]; then + if [[ ! -f "$HOME/.config/ntfy/client.yml" ]]; then cp "$tmpdir/${NTFY_DIR}/client/client.yml" ~/.config/ntfy/client.yml fi } diff --git a/scripts/install-xcode-cli-tools.sh b/scripts/install-xcode-cli-tools.sh index e9172db..55d816d 100755 --- a/scripts/install-xcode-cli-tools.sh +++ b/scripts/install-xcode-cli-tools.sh @@ -5,7 +5,7 @@ set -euo pipefail # # Check if the script is running on macOS -if [ "$(uname)" != "Darwin" ]; then +if [[ "$(uname)" != "Darwin" ]]; then msgr warn "Not a macOS system" exit 0 fi @@ -40,7 +40,7 @@ prompt_xcode_install() 'tell app "System Events" to display dialog "Please click install when Command Line Developer Tools appears"' )" - if [ "$XCODE_MESSAGE" = "button returned:OK" ]; then + if [[ "$XCODE_MESSAGE" = "button returned:OK" ]]; then xcode-select --install else msgr warn "You have cancelled the installation, please rerun the installer." @@ -53,13 +53,13 @@ main() { keep_alive_sudo - if [ -x "$XCODE_SWIFT_PATH" ]; then + if [[ -x "$XCODE_SWIFT_PATH" ]]; then msgr run "You have swift from xcode-select. Continuing..." else prompt_xcode_install fi - until [ -f "$XCODE_SWIFT_PATH" ]; do + until [[ -f "$XCODE_SWIFT_PATH" ]]; do echo -n "." sleep 1 done diff --git a/scripts/install-z.sh b/scripts/install-z.sh index 0d6e192..3e63920 100755 --- a/scripts/install-z.sh +++ b/scripts/install-z.sh @@ -14,7 +14,7 @@ clone_z_repo() local git_path=$1 local bin_path=$2 - if [ ! -d "$bin_path" ]; then + if [[ ! -d "$bin_path" ]]; then git clone "$git_path" "$bin_path" msgr run_done "z installed at $bin_path" else diff --git a/scripts/shared.sh b/scripts/shared.sh index 5baf586..6775c06 100755 --- a/scripts/shared.sh +++ b/scripts/shared.sh @@ -5,7 +5,7 @@ : "${VERBOSE:=0}" # Source the main shared config if not already loaded -if [ -z "${SHARED_SCRIPTS_SOURCED:-}" ]; then +if [[ -z "${SHARED_SCRIPTS_SOURCED:-}" ]]; then source "${DOTFILES}/config/shared.sh" export SHARED_SCRIPTS_SOURCED=1 fi diff --git a/test-all.sh b/test-all.sh index 3ff0d54..d05b5d3 100755 --- a/test-all.sh +++ b/test-all.sh @@ -3,7 +3,7 @@ set -euo pipefail -if [ -x "node_modules/bats/bin/bats" ]; then +if [[ -x "node_modules/bats/bin/bats" ]]; then git ls-files '*.bats' -z | xargs -0 node_modules/bats/bin/bats elif command -v npx > /dev/null; then git ls-files '*.bats' -z | xargs -0 npx --yes bats