Skip to content
Merged
6 changes: 6 additions & 0 deletions docs/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ Show remote tracking branch together with diverge/sync state
set -g @dracula-git-show-remote-status true
```

Show the current repository name in the status bar
```bash
# default is false
set -g @dracula-git-show-repo-name true
```

### gpu-info - [up](#table-of-contents)
These widgets display the current computational, ram, and power usage of installed graphics cards.
They are split into widgets with the names: `gpu-usage, gpu-ram-usage, gpu-power-draw`.
Expand Down
26 changes: 18 additions & 8 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,36 +130,45 @@ 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=""
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Pipe placement & “empty-repo” glitch – output does not match spec
getRepoName returns the bare repo name, but a hard-coded " | " is appended later (repo_name="$(getRepoName) | ").
• When the option is disabled or you’re not in a Git repo, getRepoName returns nothing, yet you still inject " | " → stray bar.
• When the option is enabled, the final status becomes "Main | …" whereas the spec shows "| Main …" (bar precedes the name).

-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
-}
+getRepoName() {
+  if [ "$show_repo_name" = "true" ] && [ "$(checkForGitDir)" = "true" ]; then
+    repo="$(basename "$(git -C "$path" --no-optional-locks rev-parse --show-toplevel 2>/dev/null)")"
+    # Prepend the bar only when a repo name is present
+    echo "| $repo"
+  fi
+}
 
-        repo_name="$(getRepoName) | "
+        repo_name="$(getRepoName)"

This delivers the correct "| Main" format and avoids stray separators.

🧰 Tools
🪛 Shellcheck (0.10.0)

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

(SC2046)

🤖 Prompt for AI Agents
In scripts/git.sh around lines 133 to 147, the getRepoName function returns the
repo name without a preceding pipe, but the calling code appends a hard-coded "
| " after it, causing stray separators when the repo name is empty and incorrect
formatting compared to the spec. To fix this, remove the " | " from the
assignment of repo_name and instead prepend the pipe inside getRepoName or in
the output formatting logic so that the pipe appears before the repo name only
when it exists, ensuring no stray separators and matching the spec format "|
Main".


if [ $(checkForChanges) == "true" ]; then

changes="$(getChanges)"

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

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Still expanding an array as a scalar – SC2128 resurfaces
$diff_symbol is an array; using it unindexed ("$repo_name$diff_symbol $branch") expands only the first element and revives word-splitting warnings.

-         output=$(echo "$repo_name$diff_symbol $branch")
+         output="$repo_name${diff_symbol[0]} $branch"

Update any other occurrences to keep ShellCheck quiet and behaviour predictable.

📝 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[0]}")" = "true" ]; then
output=$(echo "$repo_name$branch")
else
output=$(echo "$diff_symbol $branch")
output=$(echo "$repo_name$diff_symbol $branch")
fi
if [ "$(checkEmptySymbol "${diff_symbol[0]}")" = "true" ]; then
output=$(echo "$repo_name$branch")
else
output="$repo_name${diff_symbol[0]} $branch"
fi
🧰 Tools
🪛 Shellcheck (0.10.0)

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

(SC2128)

🤖 Prompt for AI Agents
In scripts/git.sh around lines 160 to 164, the code uses the array diff_symbol
as a scalar without indexing, causing ShellCheck SC2128 warnings and
unpredictable word splitting. Fix this by explicitly referencing the intended
element of diff_symbol with an index (e.g., diff_symbol[0]) wherever it is used,
including in the else branch, to ensure consistent and predictable expansion and
silence ShellCheck warnings.

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
Comment on lines 168 to 172
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

current_symbol suffers from the same indexing / quoting issue.

checkEmptySymbol $current_symbol expands only the first element and drops quotes, triggering both SC2128 and SC2046.

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

Mirror this fix everywhere current_symbol is referenced.

📝 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 $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
if [ "$(checkEmptySymbol "${current_symbol[0]}")" = "true" ]; then
output=$(echo "$repo_name$branch")
else
output="$repo_name${current_symbol[0]} $branch"
fi
🧰 Tools
🪛 Shellcheck (0.10.0)

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

(SC2046)


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

(SC2128)

🤖 Prompt for AI Agents
In scripts/git.sh around lines 168 to 172, the variable current_symbol is used
without proper quoting and indexing, causing shellcheck warnings SC2128 and
SC2046. To fix this, always reference current_symbol with explicit indexing and
proper quoting, for example use "${current_symbol[0]}" instead of
$current_symbol. Apply this quoting and indexing fix consistently wherever
current_symbol is referenced in this code block.

fi

Expand Down