Skip to content
22 changes: 16 additions & 6 deletions scripts/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-git-show-diff-sym
IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-git-no-repo-message" "")
IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-git-no-untracked-files" "false")
IFS=' ' read -r -a show_remote_status <<< $(get_tmux_option "@dracula-git-show-remote-status" "false")
show_repo_name="$(get_tmux_option "@dracula-git-show-repo-name" "false")"

# Get added, modified, updated and deleted files from git status
getChanges()
Expand Down Expand Up @@ -129,11 +130,20 @@ getRemoteInfo()
echo "$out"
}

getRepoName()
{
if [ "$show_repo_name" = "true" ] && [ "$(checkForGitDir)" = "true" ]; then
repo="$(basename "$(git -C "$path" --no-optional-locks rev-parse --show-toplevel 2>/dev/null)")"
echo "$repo |"
fi
}

# return the final message for the status bar
getMessage()
{
if [ $(checkForGitDir) == "true" ]; then
branch="$(getBranch)"
repo_name="$(getRepoName)"
output=""

if [ $(checkForChanges) == "true" ]; then
Expand All @@ -142,23 +152,23 @@ getMessage()

if [ "${hide_status}" == "false" ]; then
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
output=$(echo "${changes} $branch")
output="$repo_name${changes:+ ${changes}} $branch"
else
output=$(echo "$diff_symbol ${changes} $branch")
output="$repo_name ${diff_symbol[0]} ${changes:+$changes }$branch"
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Array still expanded as scalar & double-space risk
$diff_symbol is an array; $diff_symbol[0] is already used in line 157, but the empty-symbol check on 154 still passes the entire array unquoted → SC2128/SC2046.
While here, redundant echo concatenation and inconsistent spacing creep in.

-                if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
+                if [ "$(checkEmptySymbol "${diff_symbol[0]}")" = "true" ]; then

(Apply the same quoting/indexing pattern everywhere checkEmptySymbol is called.)
Consider building output via plain assignment instead of echo to avoid accidental double spaces.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
output=$(echo "${changes} $branch")
output="$repo_name${changes:+ ${changes}} $branch"
else
output=$(echo "$diff_symbol ${changes} $branch")
output="$repo_name ${diff_symbol[0]} ${changes:+$changes }$branch"
fi
if [ "$(checkEmptySymbol "${diff_symbol[0]}")" = "true" ]; then
output="$repo_name${changes:+ ${changes}} $branch"
else
output="$repo_name ${diff_symbol[0]} ${changes:+$changes }$branch"
fi
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 154-154: Quote this to prevent word splitting.

(SC2046)


[warning] 154-154: Expanding an array without an index only gives the first element.

(SC2128)

🤖 Prompt for AI Agents
In scripts/git.sh around lines 154 to 158, the checkEmptySymbol function is
called with the entire diff_symbol array unquoted, causing array expansion
issues and potential double spaces in output. Fix this by passing only the first
element of diff_symbol properly quoted to checkEmptySymbol. Also, revise the
output variable assignment to use plain variable assignment with consistent
spacing instead of echo concatenation to prevent accidental double spaces. Apply
this quoting and indexing pattern consistently wherever checkEmptySymbol is
called with arrays.

else
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
output=$(echo "$branch")
output=$(echo "$repo_name $branch")
else
output=$(echo "$diff_symbol $branch")
output=$(echo "$repo_name $diff_symbol $branch")
fi
fi

else
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
output=$(echo "$branch")
output=$(echo "$repo_name $branch")
else
output=$(echo "$current_symbol $branch")
output="$repo_name ${current_symbol[0]} $branch"
fi
fi

Expand Down