mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-07 21:50:41 +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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user