summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Hunter <m@lfurio.us>2026-03-08 15:55:16 -0400
committerMatt Hunter <m@lfurio.us>2026-03-16 04:36:28 -0400
commit8960c6297eece7494da8d94076ecda87b02a9402 (patch)
tree4d357134f2d1f0ed8e9bb9c4a26044b5cb09411b
parent62c225c40ffebcd3c35f3a9917f1a4dff4b81137 (diff)
downloadgit-sonar-8960c6297eece7494da8d94076ecda87b02a9402.tar.gz
git-sonar-8960c6297eece7494da8d94076ecda87b02a9402.zip
Remove use of "local" keyword
The "local" keyword for scoping variables is undefined in POSIX shell. Signed-off-by: Matt Hunter <m@lfurio.us>
-rwxr-xr-xgit-sonar81
1 files changed, 29 insertions, 52 deletions
diff --git a/git-sonar b/git-sonar
index 31b6c6f..12b3fea 100755
--- a/git-sonar
+++ b/git-sonar
@@ -69,12 +69,9 @@ branch_name() {
}
remote_branch_name() {
- local localRef
- local remote
localRef="$(branch_name)"
remote="$(git config --get "branch.${localRef}.remote")"
if [ -n "$remote" ]; then
- local remoteBranch
remoteBranch="$(git config --get "branch.${localRef}.merge" | sed -e 's/^refs\/heads\///')"
if [ -n "$remoteBranch" ]; then
printf '%s/%s' "$remote" "$remoteBranch"
@@ -145,17 +142,11 @@ porcelain_status() {
}
staged_status() {
- local gitStatus=${1:-"$(porcelain_status)"}
- local prefix=${2:-""}
- local suffix=${3:-""}
-
- local staged_string=""
- local filesModified
- local filesAdded
- local filesDeleted
- local filesRenamed
- local filesCopied
- local typeChanged
+ gitStatus="${1:-"$(porcelain_status)"}"
+ prefix="${2:-""}"
+ suffix="${3:-""}"
+ staged_string=""
+
filesModified="$(printf '%s' "$gitStatus" | grep -oE "M[ACDRM ] " | wc -l | grep -oEi '[1-9][0-9]*')"
filesAdded="$(printf '%s' "$gitStatus" | grep -oE "A[MCDR ] " | wc -l | grep -oEi '[1-9][0-9]*')"
filesDeleted="$(printf '%s' "$gitStatus" | grep -oE "D[AMCR ] " | wc -l | grep -oEi '[1-9][0-9]*')"
@@ -185,14 +176,11 @@ staged_status() {
}
conflicted_status() {
- local gitStatus=${1:-"$(porcelain_status)"}
- local prefix=${2:-""}
- local suffix=${3:-""}
- local conflicted_string=""
-
- local filesUs
- local filesThem
- local filesBoth
+ gitStatus="${1:-"$(porcelain_status)"}"
+ prefix="${2:-""}"
+ suffix="${3:-""}"
+ conflicted_string=""
+
filesUs="$(printf '%s' "$gitStatus" | grep -oE "[AD]U " | wc -l | grep -oEi '[1-9][0-9]*')"
filesThem="$(printf '%s' "$gitStatus" | grep -oE "U[AD] " | wc -l | grep -oEi '[1-9][0-9]*')"
filesBoth="$(printf '%s' "$gitStatus" | grep -oE "(UU|AA|DD) " | wc -l | grep -oEi '[1-9][0-9]*')"
@@ -210,14 +198,11 @@ conflicted_status() {
}
unstaged_status() {
- local gitStatus=${1:-"$(porcelain_status)"}
- local prefix=${2:-""}
- local suffix=${3:-""}
- local unstaged_string=""
-
- local filesModified
- local filesDeleted
- local typeChanged
+ gitStatus="${1:-"$(porcelain_status)"}"
+ prefix="${2:-""}"
+ suffix="${3:-""}"
+ unstaged_string=""
+
filesModified="$(printf '%s' "$gitStatus" | grep -oE "[ACDRM ]M " | wc -l | grep -oEi '[1-9][0-9]*')"
filesDeleted="$(printf '%s' "$gitStatus" | grep -oE "[AMCR ]D " | wc -l | grep -oEi '[1-9][0-9]*')"
typeChanged="$(printf '%s' "$gitStatus" | grep -oE "[AMDR ]T " | wc -l | grep -oEi '[1-9][0-9]*')"
@@ -235,12 +220,11 @@ unstaged_status() {
}
untracked_status() {
- local gitStatus=${1:-"$(porcelain_status)"}
- local prefix=${2:-""}
- local suffix=${3:-""}
- local untracked_string=""
+ gitStatus="${1:-"$(porcelain_status)"}"
+ prefix="${2:-""}"
+ suffix="${3:-""}"
+ untracked_string=""
- local filesUntracked
filesUntracked="$(printf '%s' "$gitStatus" | grep "?? " | wc -l | grep -oEi '[1-9][0-9]*')"
if [ -n "$filesUntracked" ]; then
@@ -250,17 +234,11 @@ untracked_status() {
}
color_changes_status() {
- local separator="${1:- }"
-
- local porcelain
+ separator="${1:- }"
porcelain="$(porcelain_status)"
- local changes=""
+ changes=""
if [ -n "$porcelain" ]; then
- local staged_changes
- local unstaged_changes
- local untracked_changes
- local conflicted_changes
staged_changes="$(staged_status "$porcelain" "$COLOR_CHANGES_STAGED" "$RESET_COLOR_CHANGES")"
unstaged_changes="$(unstaged_status "$porcelain" "$COLOR_CHANGES_UNSTAGED" "$RESET_COLOR_CHANGES")"
untracked_changes="$(untracked_status "$porcelain" "$COLOR_CHANGES_UNTRACKED" "$RESET_COLOR_CHANGES")"
@@ -287,11 +265,11 @@ color_changes_status() {
}
color_local_commits() {
- local green_ahead_arrow="${COLOR_LOCAL_AHEAD}↑$RESET_COLOR_LOCAL"
- local red_behind_arrow="${COLOR_LOCAL_BEHIND}↓$RESET_COLOR_LOCAL"
- local yellow_diverged_arrow="${COLOR_LOCAL_DIVERGED}⇵$RESET_COLOR_LOCAL"
+ green_ahead_arrow="${COLOR_LOCAL_AHEAD}↑$RESET_COLOR_LOCAL"
+ red_behind_arrow="${COLOR_LOCAL_BEHIND}↓$RESET_COLOR_LOCAL"
+ yellow_diverged_arrow="${COLOR_LOCAL_DIVERGED}⇵$RESET_COLOR_LOCAL"
+ local_commits=""
- local local_commits=""
if remote_branch="$(remote_branch_name)"; then
local_ahead="$(commits_ahead_of_remote "$remote_branch")"
local_behind="$(commits_behind_of_remote "$remote_branch")"
@@ -308,7 +286,7 @@ color_local_commits() {
}
color_missing_upstream() {
- local not_upstream="${COLOR_REMOTE_NOT_UPSTREAM}⚡$RESET_COLOR_REMOTE"
+ not_upstream="${COLOR_REMOTE_NOT_UPSTREAM}⚡$RESET_COLOR_REMOTE"
if remote_branch="$(remote_branch_name)"; then
if ! git rev-parse "$remote_branch" -- >/dev/null 2>&1; then
@@ -318,9 +296,9 @@ color_missing_upstream() {
}
color_remote_commits() {
- local green_ahead_arrow="${COLOR_REMOTE_AHEAD}↑$RESET_COLOR_REMOTE" # "←"
- local red_behind_arrow="${COLOR_REMOTE_BEHIND}↓$RESET_COLOR_REMOTE" # "→"
- local yellow_diverged_arrow="${COLOR_REMOTE_DIVERGED}⇵$RESET_COLOR_REMOTE" # "⇄"
+ green_ahead_arrow="${COLOR_REMOTE_AHEAD}↑$RESET_COLOR_REMOTE" # "←"
+ red_behind_arrow="${COLOR_REMOTE_BEHIND}↓$RESET_COLOR_REMOTE" # "→"
+ yellow_diverged_arrow="${COLOR_REMOTE_DIVERGED}⇵$RESET_COLOR_REMOTE" # "⇄"
remote=""
if remote_branch="$(remote_branch_name)"; then
@@ -348,7 +326,6 @@ stashed_status() {
}
stash_status() {
- local number_stashes
number_stashes="$(stashed_status)"
if [ "$number_stashes" -gt 0 ]; then
printf $PRINT_F_OPTION "${number_stashes}${COLOR_STASH}≡${RESET_COLOR_STASH}"