gitbash 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/gitbash +4 -1
- package/commands/branch.sh +12 -12
- package/commands/pr.sh +53 -0
- package/commands/stale.sh +10 -11
- package/commands/stashes.sh +12 -12
- package/commands/status.sh +23 -12
- package/commands/switch.sh +3 -1
- package/commands/unstash.sh +6 -6
- package/package.json +2 -2
package/bin/gitbash
CHANGED
|
@@ -325,8 +325,11 @@ while [[ -L "$SOURCE" ]]; do
|
|
|
325
325
|
done
|
|
326
326
|
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")/.." && pwd)"
|
|
327
327
|
|
|
328
|
+
# Export so sourced command files can use it
|
|
329
|
+
export SCRIPT_DIR
|
|
330
|
+
|
|
328
331
|
COMMANDS_DIR="$SCRIPT_DIR/commands"
|
|
329
|
-
VERSION="$(grep -o '"version": *"[^"]*"' "$SCRIPT_DIR/package.json" | cut -d'"' -f4)"
|
|
332
|
+
VERSION="$(grep -o '"version": *"[^"]*"' "$SCRIPT_DIR/package.json" | head -1 | cut -d'"' -f4)"
|
|
330
333
|
|
|
331
334
|
# Available commands
|
|
332
335
|
COMMANDS=(
|
package/commands/branch.sh
CHANGED
|
@@ -152,25 +152,25 @@ EOF
|
|
|
152
152
|
# -----------------------------
|
|
153
153
|
case "$selection" in
|
|
154
154
|
"$create_option")
|
|
155
|
-
#
|
|
156
|
-
if
|
|
157
|
-
|
|
155
|
+
# Use SCRIPT_DIR from parent or compute it
|
|
156
|
+
if [[ -z "${SCRIPT_DIR:-}" ]]; then
|
|
157
|
+
SCRIPT_DIR="$(cd "$SOURCE_DIR/.." && pwd)"
|
|
158
158
|
fi
|
|
159
|
-
create
|
|
159
|
+
"$SCRIPT_DIR/bin/gitbash" create
|
|
160
160
|
;;
|
|
161
161
|
"$switch_option")
|
|
162
|
-
#
|
|
163
|
-
if
|
|
164
|
-
|
|
162
|
+
# Use SCRIPT_DIR from parent or compute it
|
|
163
|
+
if [[ -z "${SCRIPT_DIR:-}" ]]; then
|
|
164
|
+
SCRIPT_DIR="$(cd "$SOURCE_DIR/.." && pwd)"
|
|
165
165
|
fi
|
|
166
|
-
switch
|
|
166
|
+
"$SCRIPT_DIR/bin/gitbash" switch
|
|
167
167
|
;;
|
|
168
168
|
"$update_option")
|
|
169
|
-
#
|
|
170
|
-
if
|
|
171
|
-
|
|
169
|
+
# Use SCRIPT_DIR from parent or compute it
|
|
170
|
+
if [[ -z "${SCRIPT_DIR:-}" ]]; then
|
|
171
|
+
SCRIPT_DIR="$(cd "$SOURCE_DIR/.." && pwd)"
|
|
172
172
|
fi
|
|
173
|
-
update
|
|
173
|
+
"$SCRIPT_DIR/bin/gitbash" update
|
|
174
174
|
;;
|
|
175
175
|
"$abort_label")
|
|
176
176
|
echo "Aborted."
|
package/commands/pr.sh
CHANGED
|
@@ -71,6 +71,59 @@ EOF
|
|
|
71
71
|
return 1
|
|
72
72
|
fi
|
|
73
73
|
|
|
74
|
+
# Check for uncommitted changes or untracked files
|
|
75
|
+
local has_changes=false
|
|
76
|
+
if ! git diff-index --quiet HEAD -- 2>/dev/null || [[ -n "$(git ls-files --others --exclude-standard)" ]]; then
|
|
77
|
+
has_changes=true
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
if [[ "$has_changes" == true ]]; then
|
|
81
|
+
echo "You have uncommitted changes or untracked files."
|
|
82
|
+
echo ""
|
|
83
|
+
|
|
84
|
+
# Source _utils.sh for prompt_read
|
|
85
|
+
if ! declare -f prompt_read >/dev/null 2>&1; then
|
|
86
|
+
SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
87
|
+
source "$SOURCE_DIR/_utils.sh"
|
|
88
|
+
fi
|
|
89
|
+
|
|
90
|
+
prompt_read "Would you like to commit them first? (Y/n): " commit_answer
|
|
91
|
+
case "$commit_answer" in
|
|
92
|
+
[nN][oO]|[nN])
|
|
93
|
+
echo "Continuing without committing..."
|
|
94
|
+
;;
|
|
95
|
+
*)
|
|
96
|
+
# Use SCRIPT_DIR from parent or compute it
|
|
97
|
+
if [[ -z "${SCRIPT_DIR:-}" ]]; then
|
|
98
|
+
SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
99
|
+
SCRIPT_DIR="$(cd "$SOURCE_DIR/.." && pwd)"
|
|
100
|
+
fi
|
|
101
|
+
|
|
102
|
+
# Run status command for interactive staging and committing
|
|
103
|
+
"$SCRIPT_DIR/bin/gitbash" status
|
|
104
|
+
if [[ $? -ne 0 ]]; then
|
|
105
|
+
echo "Commit cancelled or failed. Aborting PR creation."
|
|
106
|
+
return 1
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
# If -p wasn't specified, offer to push the fresh commit
|
|
110
|
+
if [[ "$should_push" != true ]]; then
|
|
111
|
+
echo ""
|
|
112
|
+
prompt_read "Push the fresh commit to origin? (Y/n): " push_answer
|
|
113
|
+
case "$push_answer" in
|
|
114
|
+
[nN][oO]|[nN])
|
|
115
|
+
echo "Continuing without pushing..."
|
|
116
|
+
;;
|
|
117
|
+
*)
|
|
118
|
+
should_push=true
|
|
119
|
+
;;
|
|
120
|
+
esac
|
|
121
|
+
fi
|
|
122
|
+
;;
|
|
123
|
+
esac
|
|
124
|
+
echo ""
|
|
125
|
+
fi
|
|
126
|
+
|
|
74
127
|
# Remote URL (e.g. git@github.com:user/repo.git or https://github.com/user/repo.git)
|
|
75
128
|
remote=$(git config --get remote.origin.url)
|
|
76
129
|
|
package/commands/stale.sh
CHANGED
|
@@ -237,12 +237,12 @@ EOF
|
|
|
237
237
|
echo "$str"
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
# Build JSON from stale
|
|
240
|
+
# Build JSON from branches (all or stale based on --all flag)
|
|
241
241
|
{
|
|
242
242
|
while IFS='|' read -r branch rel_date author_name author_email timestamp; do
|
|
243
243
|
[[ -z "$branch" ]] && continue
|
|
244
|
-
#
|
|
245
|
-
if [[ "$timestamp" -lt "$threshold_ago" ]]; then
|
|
244
|
+
# Include based on all_mode flag
|
|
245
|
+
if [[ "$all_mode" == true ]] || [[ "$timestamp" -lt "$threshold_ago" ]]; then
|
|
246
246
|
local name="${branch#origin/}"
|
|
247
247
|
# Remove angle brackets from email
|
|
248
248
|
author_email="${author_email#<}"
|
|
@@ -273,10 +273,14 @@ EOF
|
|
|
273
273
|
local stale_file=$(mktemp)
|
|
274
274
|
local all_file=$(mktemp)
|
|
275
275
|
local state_file=$(mktemp)
|
|
276
|
+
local toggle_script=$(mktemp)
|
|
277
|
+
|
|
278
|
+
# Ensure cleanup on exit
|
|
279
|
+
trap 'rm -f "$stale_file" "$all_file" "$state_file" "$toggle_script"' EXIT INT TERM
|
|
276
280
|
|
|
277
281
|
# Write stale branches with header
|
|
278
282
|
{
|
|
279
|
-
echo "══ Stale branches (>${stale_months}mo, oldest first) ══"
|
|
283
|
+
echo "══ Stale branches (>${stale_months}mo, oldest first) ══ [TAB] select | [Ctrl-A] toggle all/stale | [Enter] delete | [ESC] exit"
|
|
280
284
|
if [[ -n "$stale_branch_list" ]]; then
|
|
281
285
|
echo "$stale_branch_list"
|
|
282
286
|
fi
|
|
@@ -285,7 +289,7 @@ EOF
|
|
|
285
289
|
|
|
286
290
|
# Write all branches with header
|
|
287
291
|
{
|
|
288
|
-
echo "══ All branches (oldest first) ══"
|
|
292
|
+
echo "══ All branches (oldest first) ══ [TAB] select | [Ctrl-A] toggle all/stale | [Enter] delete | [ESC] exit"
|
|
289
293
|
if [[ -n "$all_branch_list" ]]; then
|
|
290
294
|
echo "$all_branch_list"
|
|
291
295
|
fi
|
|
@@ -305,8 +309,7 @@ EOF
|
|
|
305
309
|
local stale_count=$(echo "$stale_branch_list" | grep -c . || echo "0")
|
|
306
310
|
local all_count=$(echo "$all_branch_list" | grep -c . || echo "0")
|
|
307
311
|
|
|
308
|
-
# Create toggle script
|
|
309
|
-
local toggle_script=$(mktemp)
|
|
312
|
+
# Create toggle script
|
|
310
313
|
cat > "$toggle_script" << TOGGLE_EOF
|
|
311
314
|
#!/bin/bash
|
|
312
315
|
state=\$(cat "$state_file" | tr -d '\n')
|
|
@@ -338,7 +341,6 @@ TOGGLE_EOF
|
|
|
338
341
|
-i \
|
|
339
342
|
--reverse \
|
|
340
343
|
--border \
|
|
341
|
-
--header="[TAB] select | [Ctrl-A] toggle all/stale | [Enter] delete | [ESC] exit" \
|
|
342
344
|
--header-lines=1 \
|
|
343
345
|
--multi \
|
|
344
346
|
--delimiter=$'\t' \
|
|
@@ -361,9 +363,6 @@ TOGGLE_EOF
|
|
|
361
363
|
--preview-window=right:35% \
|
|
362
364
|
< "$initial_input_file"
|
|
363
365
|
) </dev/tty || true
|
|
364
|
-
|
|
365
|
-
# Cleanup temp files
|
|
366
|
-
rm -f "$stale_file" "$all_file" "$state_file" "$toggle_script" "$prompt_script" "$header_script"
|
|
367
366
|
|
|
368
367
|
# ESC or Ctrl-C
|
|
369
368
|
if [[ -z "$selection" ]]; then
|
package/commands/stashes.sh
CHANGED
|
@@ -151,25 +151,25 @@ EOF
|
|
|
151
151
|
# -----------------------------
|
|
152
152
|
case "$selection" in
|
|
153
153
|
"$stash_option")
|
|
154
|
-
#
|
|
155
|
-
if
|
|
156
|
-
|
|
154
|
+
# Use SCRIPT_DIR from parent or compute it
|
|
155
|
+
if [[ -z "${SCRIPT_DIR:-}" ]]; then
|
|
156
|
+
SCRIPT_DIR="$(cd "$SOURCE_DIR/.." && pwd)"
|
|
157
157
|
fi
|
|
158
|
-
stash
|
|
158
|
+
"$SCRIPT_DIR/bin/gitbash" stash
|
|
159
159
|
;;
|
|
160
160
|
"$unstash_option")
|
|
161
|
-
#
|
|
162
|
-
if
|
|
163
|
-
|
|
161
|
+
# Use SCRIPT_DIR from parent or compute it
|
|
162
|
+
if [[ -z "${SCRIPT_DIR:-}" ]]; then
|
|
163
|
+
SCRIPT_DIR="$(cd "$SOURCE_DIR/.." && pwd)"
|
|
164
164
|
fi
|
|
165
|
-
unstash
|
|
165
|
+
"$SCRIPT_DIR/bin/gitbash" unstash
|
|
166
166
|
;;
|
|
167
167
|
"$cleanup_option")
|
|
168
|
-
#
|
|
169
|
-
if
|
|
170
|
-
|
|
168
|
+
# Use SCRIPT_DIR from parent or compute it
|
|
169
|
+
if [[ -z "${SCRIPT_DIR:-}" ]]; then
|
|
170
|
+
SCRIPT_DIR="$(cd "$SOURCE_DIR/.." && pwd)"
|
|
171
171
|
fi
|
|
172
|
-
cleanstash
|
|
172
|
+
"$SCRIPT_DIR/bin/gitbash" cleanstash
|
|
173
173
|
;;
|
|
174
174
|
"$abort_label")
|
|
175
175
|
echo "Aborted."
|
package/commands/status.sh
CHANGED
|
@@ -131,20 +131,31 @@ EOF
|
|
|
131
131
|
bat --color=always --style=numbers --theme=\"GitHub\" "$file" 2>/dev/null || cat "$file" 2>/dev/null || echo "Cannot preview file";
|
|
132
132
|
elif [[ "$file_status" =~ ^[MAC] ]]; then
|
|
133
133
|
# Staged file - show cached diff
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
staged_diff=$(git diff --cached --color=always "$file" 2>/dev/null);
|
|
135
|
+
unstaged_diff=$(git diff --color=always "$file" 2>/dev/null);
|
|
136
|
+
|
|
137
|
+
# Only show staged section if there are staged changes
|
|
138
|
+
if [[ -n "$staged_diff" ]]; then
|
|
139
|
+
echo "=== STAGED CHANGES ===";
|
|
138
140
|
echo;
|
|
141
|
+
echo "$staged_diff" | delta --light 2>/dev/null || echo "$staged_diff";
|
|
142
|
+
fi
|
|
143
|
+
|
|
144
|
+
# Only show unstaged section if there are unstaged changes
|
|
145
|
+
if [[ -n "$unstaged_diff" ]]; then
|
|
146
|
+
[[ -n "$staged_diff" ]] && echo;
|
|
139
147
|
echo "=== UNSTAGED CHANGES ===";
|
|
140
148
|
echo;
|
|
141
|
-
|
|
149
|
+
echo "$unstaged_diff" | delta --light 2>/dev/null || echo "$unstaged_diff";
|
|
142
150
|
fi
|
|
143
151
|
else
|
|
144
152
|
# Unstaged changes
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
153
|
+
unstaged_diff=$(git diff --color=always "$file" 2>/dev/null);
|
|
154
|
+
if [[ -n "$unstaged_diff" ]]; then
|
|
155
|
+
echo "=== UNSTAGED CHANGES ===";
|
|
156
|
+
echo;
|
|
157
|
+
echo "$unstaged_diff" | delta --light 2>/dev/null || echo "$unstaged_diff";
|
|
158
|
+
fi
|
|
148
159
|
fi
|
|
149
160
|
' \
|
|
150
161
|
--preview-window=right:60% \
|
|
@@ -295,12 +306,12 @@ EOF
|
|
|
295
306
|
echo "Ready to commit and push staged changes."
|
|
296
307
|
echo "Press Ctrl+C to abort."
|
|
297
308
|
echo
|
|
298
|
-
#
|
|
299
|
-
if
|
|
300
|
-
|
|
309
|
+
# Use SCRIPT_DIR from parent or compute it
|
|
310
|
+
if [[ -z "${SCRIPT_DIR:-}" ]]; then
|
|
311
|
+
SCRIPT_DIR="$(cd "$SOURCE_DIR/.." && pwd)"
|
|
301
312
|
fi
|
|
302
313
|
# Directly prompt for commit message (user can Ctrl+C to abort)
|
|
303
|
-
commit -s -p
|
|
314
|
+
"$SCRIPT_DIR/bin/gitbash" commit -s -p
|
|
304
315
|
break
|
|
305
316
|
fi
|
|
306
317
|
done
|
package/commands/switch.sh
CHANGED
|
@@ -110,7 +110,9 @@ EOF
|
|
|
110
110
|
local matching_branches
|
|
111
111
|
matching_branches=$(echo "$branch_list" | grep -iv '───' | grep -i "$filter" || true)
|
|
112
112
|
local match_count
|
|
113
|
-
match_count=$(echo "$matching_branches" | grep -c . || echo "0")
|
|
113
|
+
match_count=$(echo "$matching_branches" | grep -c . 2>/dev/null || echo "0")
|
|
114
|
+
# Ensure match_count is numeric
|
|
115
|
+
[[ -z "$match_count" ]] && match_count=0
|
|
114
116
|
|
|
115
117
|
if [[ "$match_count" -eq 1 ]]; then
|
|
116
118
|
# Single match - skip fzf
|
package/commands/unstash.sh
CHANGED
|
@@ -146,17 +146,17 @@ EOF
|
|
|
146
146
|
fi
|
|
147
147
|
|
|
148
148
|
# -----------------------------
|
|
149
|
-
# 6. Confirm before dropping
|
|
149
|
+
# 6. Confirm before dropping (default: Yes)
|
|
150
150
|
# -----------------------------
|
|
151
151
|
echo
|
|
152
|
-
prompt_read "Drop $stash_id now? (
|
|
152
|
+
prompt_read "Drop $stash_id now? (Y/n): " drop_ans
|
|
153
153
|
case "$drop_ans" in
|
|
154
|
-
[
|
|
155
|
-
echo "
|
|
156
|
-
git stash drop "$stash_id"
|
|
154
|
+
[nN][oO]|[nN])
|
|
155
|
+
echo "Stash NOT dropped."
|
|
157
156
|
;;
|
|
158
157
|
*)
|
|
159
|
-
echo "
|
|
158
|
+
echo "Dropping $stash_id ..."
|
|
159
|
+
git stash drop "$stash_id"
|
|
160
160
|
;;
|
|
161
161
|
esac
|
|
162
162
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gitbash",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Opinionated git utilities for bash with fzf-powered menus",
|
|
5
5
|
"author": "jaggli",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"scripts": {
|
|
44
44
|
"changeset": "changeset",
|
|
45
45
|
"version": "changeset version",
|
|
46
|
-
"release": "
|
|
46
|
+
"release": "npm run version && VERSION=$(node -p \"require('./package.json').version\") && git tag \"v$VERSION\" && ./bin/gitbash commit -p \"chore: release v$VERSION\" && git push --tags && npm publish"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@changesets/cli": "^2.29.8"
|