mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-07 18:46:25 +00:00
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:
@@ -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/<name>/ 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user