gitbash 1.1.0 → 1.2.0
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/LICENSE +1 -1
- package/README.md +25 -27
- package/bin/gitbash +45 -1
- package/commands/_utils.sh +121 -2
- package/commands/branch.sh +1 -25
- package/commands/cleanstash.sh +1 -25
- package/commands/cleanup.sh +51 -34
- package/commands/commit.sh +121 -20
- package/commands/commits.sh +6 -27
- package/commands/create.sh +137 -40
- package/commands/stale.sh +33 -36
- package/commands/stash.sh +11 -3
- package/commands/stashes.sh +1 -25
- package/commands/status.sh +2 -30
- package/commands/switch.sh +4 -32
- package/commands/unstash.sh +1 -25
- package/package.json +1 -1
package/commands/stale.sh
CHANGED
|
@@ -13,6 +13,7 @@ stale() {
|
|
|
13
13
|
local json_mode=false
|
|
14
14
|
local my_mode=false
|
|
15
15
|
local filter_args=()
|
|
16
|
+
local stale_months="${GITBASH_STALE_MONTHS:-3}"
|
|
16
17
|
|
|
17
18
|
while [[ $# -gt 0 ]]; do
|
|
18
19
|
case "$1" in
|
|
@@ -31,18 +32,22 @@ Arguments:
|
|
|
31
32
|
FILTER... Optional search filter words to pre-fill fzf (joined with spaces)
|
|
32
33
|
|
|
33
34
|
Options:
|
|
34
|
-
-h, --help
|
|
35
|
-
-m, --my
|
|
36
|
-
--json
|
|
35
|
+
-h, --help Show this help message
|
|
36
|
+
-m, --my Pre-fill filter with your git username (from git config user.name)
|
|
37
|
+
--json Output branch data as JSON (non-interactive)
|
|
38
|
+
--age=N Override stale threshold in months (default: 3, configurable via GITBASH_STALE_MONTHS)
|
|
37
39
|
|
|
38
40
|
Features:
|
|
39
41
|
- Lists all remote branches sorted by last commit date (oldest first)
|
|
40
|
-
- By default, only shows branches older than
|
|
42
|
+
- By default, only shows branches older than N months (default 3)
|
|
41
43
|
- Shows branch name, relative date, and author
|
|
42
44
|
- Interactive selection with fzf
|
|
43
45
|
- Preview shows recent commits on the selected branch
|
|
44
46
|
- Delete selected branches directly from the list
|
|
45
47
|
|
|
48
|
+
Configuration:
|
|
49
|
+
GITBASH_STALE_MONTHS - Set default threshold in months (run 'gitbash --config')
|
|
50
|
+
|
|
46
51
|
Navigation:
|
|
47
52
|
↑/↓ or j/k Navigate through branches
|
|
48
53
|
TAB Select/deselect branch (multi-select)
|
|
@@ -58,6 +63,12 @@ Examples:
|
|
|
58
63
|
feature/old-feature 3 months ago John Doe
|
|
59
64
|
✖ Abort
|
|
60
65
|
|
|
66
|
+
$ stale --age=1
|
|
67
|
+
# Show branches older than 1 month
|
|
68
|
+
|
|
69
|
+
$ stale --age=6
|
|
70
|
+
# Show branches older than 6 months
|
|
71
|
+
|
|
61
72
|
# Press Ctrl-A to show all branches including recent ones
|
|
62
73
|
# Select branches with TAB, press Enter to delete
|
|
63
74
|
|
|
@@ -88,6 +99,14 @@ EOF
|
|
|
88
99
|
my_mode=true
|
|
89
100
|
shift
|
|
90
101
|
;;
|
|
102
|
+
--age=*)
|
|
103
|
+
stale_months="${1#--age=}"
|
|
104
|
+
if ! [[ "$stale_months" =~ ^[0-9]+$ ]] || [[ "$stale_months" -lt 1 ]]; then
|
|
105
|
+
print_error "Invalid age value: $stale_months"
|
|
106
|
+
return 1
|
|
107
|
+
fi
|
|
108
|
+
shift
|
|
109
|
+
;;
|
|
91
110
|
*)
|
|
92
111
|
filter_args+=("$1")
|
|
93
112
|
shift
|
|
@@ -108,29 +127,7 @@ EOF
|
|
|
108
127
|
fi
|
|
109
128
|
|
|
110
129
|
if [[ "$json_mode" == false ]]; then
|
|
111
|
-
|
|
112
|
-
echo "fzf is not installed."
|
|
113
|
-
|
|
114
|
-
prompt_read "Install fzf with Homebrew? (y/N): " ans
|
|
115
|
-
case "$ans" in
|
|
116
|
-
[yY][eE][sS]|[yY])
|
|
117
|
-
echo "Installing fzf with brew..."
|
|
118
|
-
if ! command -v brew >/dev/null 2>&1; then
|
|
119
|
-
echo "Homebrew is not installed. Aborting."
|
|
120
|
-
return 1
|
|
121
|
-
fi
|
|
122
|
-
brew install fzf || { echo "fzf install failed. Aborting."; return 1; }
|
|
123
|
-
if [[ -f "$(brew --prefix)/opt/fzf/install" ]]; then
|
|
124
|
-
echo "Running fzf install script..."
|
|
125
|
-
yes | "$(brew --prefix)/opt/fzf/install"
|
|
126
|
-
fi
|
|
127
|
-
;;
|
|
128
|
-
*)
|
|
129
|
-
echo "Aborted (skipped fzf installation)."
|
|
130
|
-
return 1
|
|
131
|
-
;;
|
|
132
|
-
esac
|
|
133
|
-
fi
|
|
130
|
+
require_fzf || return 1
|
|
134
131
|
fi
|
|
135
132
|
|
|
136
133
|
# -----------------------------
|
|
@@ -164,9 +161,9 @@ EOF
|
|
|
164
161
|
local abort_label="✖ Abort"
|
|
165
162
|
local max_branch_length=65
|
|
166
163
|
|
|
167
|
-
# Calculate date
|
|
168
|
-
local
|
|
169
|
-
|
|
164
|
+
# Calculate date N months ago (based on stale_months)
|
|
165
|
+
local threshold_ago
|
|
166
|
+
threshold_ago=$(date -v-"${stale_months}m" +%s 2>/dev/null || date -d "${stale_months} months ago" +%s 2>/dev/null)
|
|
170
167
|
|
|
171
168
|
# Build full branch list (all branches)
|
|
172
169
|
# Format: display_branch | date | author | full_branch (tab-separated, last field is full branch for operations)
|
|
@@ -193,7 +190,7 @@ EOF
|
|
|
193
190
|
grep -v '^origin$' | \
|
|
194
191
|
while IFS='|' read -r branch date author timestamp; do
|
|
195
192
|
# Only include if older than 3 months
|
|
196
|
-
if [[ "$timestamp" -lt "$
|
|
193
|
+
if [[ "$timestamp" -lt "$threshold_ago" ]]; then
|
|
197
194
|
# Remove origin/ prefix for display
|
|
198
195
|
local full_branch="${branch#origin/}"
|
|
199
196
|
local display_branch="$full_branch"
|
|
@@ -238,7 +235,7 @@ EOF
|
|
|
238
235
|
while IFS='|' read -r branch rel_date author_name author_email timestamp; do
|
|
239
236
|
[[ -z "$branch" ]] && continue
|
|
240
237
|
# Only include if older than 3 months
|
|
241
|
-
if [[ "$timestamp" -lt "$
|
|
238
|
+
if [[ "$timestamp" -lt "$threshold_ago" ]]; then
|
|
242
239
|
local name="${branch#origin/}"
|
|
243
240
|
# Remove angle brackets from email
|
|
244
241
|
author_email="${author_email#<}"
|
|
@@ -302,7 +299,7 @@ TOGGLE_EOF
|
|
|
302
299
|
#!/bin/bash
|
|
303
300
|
state=\$(cat "$state_file")
|
|
304
301
|
if [[ "\$state" == "stale" ]]; then
|
|
305
|
-
echo "Stale branches (
|
|
302
|
+
echo "Stale branches (>${stale_months}mo, oldest first) > "
|
|
306
303
|
else
|
|
307
304
|
echo "All branches (oldest first) > "
|
|
308
305
|
fi
|
|
@@ -316,7 +313,7 @@ PROMPT_EOF
|
|
|
316
313
|
state=\$(cat "$state_file")
|
|
317
314
|
if [[ "\$state" == "stale" ]]; then
|
|
318
315
|
echo "[TAB] select | [Ctrl-A] toggle all/stale | [Enter] delete | [ESC] exit
|
|
319
|
-
Showing $stale_count stale branches (older than
|
|
316
|
+
Showing $stale_count stale branches (older than ${stale_months} months)"
|
|
320
317
|
else
|
|
321
318
|
echo "[TAB] select | [Ctrl-A] toggle all/stale | [Enter] delete | [ESC] exit
|
|
322
319
|
Showing all $all_count branches"
|
|
@@ -327,13 +324,13 @@ HEADER_EOF
|
|
|
327
324
|
local selection
|
|
328
325
|
selection=$(
|
|
329
326
|
fzf \
|
|
330
|
-
--prompt="Stale branches (
|
|
327
|
+
--prompt="Stale branches (>${stale_months}mo, oldest first) > " \
|
|
331
328
|
--query="$filter" \
|
|
332
329
|
-i \
|
|
333
330
|
--reverse \
|
|
334
331
|
--border \
|
|
335
332
|
--header="[TAB] select | [Ctrl-A] toggle all/stale | [Enter] delete | [ESC] exit
|
|
336
|
-
Showing $stale_count stale branches (older than
|
|
333
|
+
Showing $stale_count stale branches (older than ${stale_months} months)" \
|
|
337
334
|
--multi \
|
|
338
335
|
--delimiter=$'\t' \
|
|
339
336
|
--with-nth=1 \
|
package/commands/stash.sh
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck disable=SC2155
|
|
3
|
+
|
|
4
|
+
# Source common utilities
|
|
5
|
+
SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
6
|
+
# shellcheck source=_utils.sh
|
|
7
|
+
source "$SOURCE_DIR/_utils.sh"
|
|
8
|
+
|
|
1
9
|
stash() {
|
|
2
10
|
# -----------------------------
|
|
3
11
|
# 0. Check for help/version flag
|
|
@@ -80,7 +88,7 @@ EOF
|
|
|
80
88
|
read -r stash_name
|
|
81
89
|
|
|
82
90
|
if [[ -z "$stash_name" ]]; then
|
|
83
|
-
|
|
91
|
+
print_error "Stash name cannot be empty."
|
|
84
92
|
return 1
|
|
85
93
|
fi
|
|
86
94
|
fi
|
|
@@ -89,9 +97,9 @@ EOF
|
|
|
89
97
|
# 4. Create the stash
|
|
90
98
|
# -----------------------------
|
|
91
99
|
if git stash push -u -m "$stash_name"; then
|
|
92
|
-
|
|
100
|
+
print_success "Created stash: $stash_name"
|
|
93
101
|
else
|
|
94
|
-
|
|
102
|
+
print_error "Failed to create stash."
|
|
95
103
|
return 1
|
|
96
104
|
fi
|
|
97
105
|
}
|
package/commands/stashes.sh
CHANGED
|
@@ -106,31 +106,7 @@ EOF
|
|
|
106
106
|
# -----------------------------
|
|
107
107
|
# 1. Check for fzf
|
|
108
108
|
# -----------------------------
|
|
109
|
-
|
|
110
|
-
echo "fzf is not installed."
|
|
111
|
-
|
|
112
|
-
# Ask whether to install with Homebrew
|
|
113
|
-
prompt_read "Install fzf with Homebrew? (y/N): " ans
|
|
114
|
-
case "$ans" in
|
|
115
|
-
[yY][eE][sS]|[yY])
|
|
116
|
-
echo "Installing fzf with brew..."
|
|
117
|
-
if ! command -v brew >/dev/null 2>&1; then
|
|
118
|
-
echo "Homebrew is not installed. Aborting."
|
|
119
|
-
return 1
|
|
120
|
-
fi
|
|
121
|
-
brew install fzf || { echo "fzf install failed. Aborting."; return 1; }
|
|
122
|
-
# Optional: install shell integrations automatically
|
|
123
|
-
if [[ -f "$(brew --prefix)/opt/fzf/install" ]]; then
|
|
124
|
-
echo "Running fzf install script..."
|
|
125
|
-
yes | "$(brew --prefix)/opt/fzf/install"
|
|
126
|
-
fi
|
|
127
|
-
;;
|
|
128
|
-
*)
|
|
129
|
-
echo "Aborted (skipped fzf installation)."
|
|
130
|
-
return 1
|
|
131
|
-
;;
|
|
132
|
-
esac
|
|
133
|
-
fi
|
|
109
|
+
require_fzf || return 1
|
|
134
110
|
|
|
135
111
|
# -----------------------------
|
|
136
112
|
# 2. Build action menu
|
package/commands/status.sh
CHANGED
|
@@ -74,36 +74,8 @@ EOF
|
|
|
74
74
|
# -----------------------------
|
|
75
75
|
# 1. Check prerequisites
|
|
76
76
|
# -----------------------------
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return 1
|
|
80
|
-
fi
|
|
81
|
-
|
|
82
|
-
if ! command -v fzf >/dev/null 2>&1; then
|
|
83
|
-
echo "fzf is not installed."
|
|
84
|
-
|
|
85
|
-
# Ask whether to install with Homebrew
|
|
86
|
-
prompt_read "Install fzf with Homebrew? (y/N): " ans
|
|
87
|
-
case "$ans" in
|
|
88
|
-
[yY][eE][sS]|[yY])
|
|
89
|
-
echo "Installing fzf with brew..."
|
|
90
|
-
if ! command -v brew >/dev/null 2>&1; then
|
|
91
|
-
echo "Homebrew is not installed. Aborting."
|
|
92
|
-
return 1
|
|
93
|
-
fi
|
|
94
|
-
brew install fzf || { echo "fzf install failed. Aborting."; return 1; }
|
|
95
|
-
# Optional: install shell integrations automatically
|
|
96
|
-
if [[ -f "$(brew --prefix)/opt/fzf/install" ]]; then
|
|
97
|
-
echo "Running fzf install script..."
|
|
98
|
-
yes | "$(brew --prefix)/opt/fzf/install"
|
|
99
|
-
fi
|
|
100
|
-
;;
|
|
101
|
-
*)
|
|
102
|
-
echo "Aborted (skipped fzf installation)."
|
|
103
|
-
return 1
|
|
104
|
-
;;
|
|
105
|
-
esac
|
|
106
|
-
fi
|
|
77
|
+
require_git_repo || return 1
|
|
78
|
+
require_fzf || return 1
|
|
107
79
|
|
|
108
80
|
# -----------------------------
|
|
109
81
|
# 2. Get git status and format with staging info
|
package/commands/switch.sh
CHANGED
|
@@ -59,36 +59,8 @@ EOF
|
|
|
59
59
|
# -----------------------------
|
|
60
60
|
# 1. Check prerequisites
|
|
61
61
|
# -----------------------------
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return 1
|
|
65
|
-
fi
|
|
66
|
-
|
|
67
|
-
if ! command -v fzf >/dev/null 2>&1; then
|
|
68
|
-
echo "fzf is not installed."
|
|
69
|
-
|
|
70
|
-
# Ask whether to install with Homebrew
|
|
71
|
-
prompt_read "Install fzf with Homebrew? (y/N): " ans
|
|
72
|
-
case "$ans" in
|
|
73
|
-
[yY][eE][sS]|[yY])
|
|
74
|
-
echo "Installing fzf with brew..."
|
|
75
|
-
if ! command -v brew >/dev/null 2>&1; then
|
|
76
|
-
echo "Homebrew is not installed. Aborting."
|
|
77
|
-
return 1
|
|
78
|
-
fi
|
|
79
|
-
brew install fzf || { echo "fzf install failed. Aborting."; return 1; }
|
|
80
|
-
# Optional: install shell integrations automatically
|
|
81
|
-
if [[ -f "$(brew --prefix)/opt/fzf/install" ]]; then
|
|
82
|
-
echo "Running fzf install script..."
|
|
83
|
-
yes | "$(brew --prefix)/opt/fzf/install"
|
|
84
|
-
fi
|
|
85
|
-
;;
|
|
86
|
-
*)
|
|
87
|
-
echo "Aborted (skipped fzf installation)."
|
|
88
|
-
return 1
|
|
89
|
-
;;
|
|
90
|
-
esac
|
|
91
|
-
fi
|
|
62
|
+
require_git_repo || return 1
|
|
63
|
+
require_fzf || return 1
|
|
92
64
|
|
|
93
65
|
# -----------------------------
|
|
94
66
|
# 2. Get current branch and filter
|
|
@@ -183,9 +155,9 @@ EOF
|
|
|
183
155
|
fi
|
|
184
156
|
|
|
185
157
|
if [[ $? -eq 0 ]]; then
|
|
186
|
-
|
|
158
|
+
print_success "Successfully switched to branch: $(git rev-parse --abbrev-ref HEAD)"
|
|
187
159
|
else
|
|
188
|
-
|
|
160
|
+
print_error "Failed to switch branch."
|
|
189
161
|
return 1
|
|
190
162
|
fi
|
|
191
163
|
}
|
package/commands/unstash.sh
CHANGED
|
@@ -76,31 +76,7 @@ EOF
|
|
|
76
76
|
# -----------------------------
|
|
77
77
|
# 1. Check for fzf
|
|
78
78
|
# -----------------------------
|
|
79
|
-
|
|
80
|
-
echo "fzf is not installed."
|
|
81
|
-
|
|
82
|
-
# Ask whether to install with Homebrew
|
|
83
|
-
prompt_read "Install fzf with Homebrew? (y/N): " ans
|
|
84
|
-
case "$ans" in
|
|
85
|
-
[yY][eE][sS]|[yY])
|
|
86
|
-
echo "Installing fzf with brew..."
|
|
87
|
-
if ! command -v brew >/dev/null 2>&1; then
|
|
88
|
-
echo "Homebrew is not installed. Aborting."
|
|
89
|
-
return 1
|
|
90
|
-
fi
|
|
91
|
-
brew install fzf || { echo "fzf install failed. Aborting."; return 1; }
|
|
92
|
-
# Optional: install shell integrations automatically
|
|
93
|
-
if [[ -f "$(brew --prefix)/opt/fzf/install" ]]; then
|
|
94
|
-
echo "Running fzf install script..."
|
|
95
|
-
yes | "$(brew --prefix)/opt/fzf/install"
|
|
96
|
-
fi
|
|
97
|
-
;;
|
|
98
|
-
*)
|
|
99
|
-
echo "Aborted (skipped fzf installation)."
|
|
100
|
-
return 1
|
|
101
|
-
;;
|
|
102
|
-
esac
|
|
103
|
-
fi
|
|
79
|
+
require_fzf || return 1
|
|
104
80
|
|
|
105
81
|
# -----------------------------
|
|
106
82
|
# 2. Build menu entries
|