fix(shell): use [[ instead of [ for conditional tests

Replace single brackets with double brackets in bash conditional
expressions across 14 files (28 changes). All scripts use bash
shebangs so [[ is safe everywhere (SonarCloud rule shelldre:S7688).
This commit is contained in:
2026-02-07 13:59:08 +02:00
parent 89aeb29c04
commit 63a21d08b4
14 changed files with 27 additions and 27 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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"

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

View File

@@ -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