gitbash 1.9.0 → 2.0.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.
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env bash
2
- # shellcheck disable=SC2155
3
2
 
4
3
  # Source common utilities
5
- SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
4
+ SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
5
  # shellcheck source=_utils.sh
7
6
  source "$SOURCE_DIR/_utils.sh"
8
7
 
@@ -92,8 +91,7 @@ Actions:
92
91
  ⬆️ Update - Update current branch with latest main/master
93
92
 
94
93
  Requirements:
95
- - fzf (fuzzy finder) - will prompt to install if not found
96
- - create, switch, and update functions must be available
94
+ - fzf (fuzzy finder)
97
95
 
98
96
  See also:
99
97
  create -h Show help for create command
@@ -131,20 +129,19 @@ EOF
131
129
  # 3. Run fzf menu
132
130
  # -----------------------------
133
131
  local selection
134
- selection=$(fzf --prompt="Branch action > " \
132
+ selection=$(run_fzf --prompt="Branch action > " \
135
133
  -i \
136
134
  --reverse \
137
135
  --border \
138
136
  --header="What would you like to do?" \
139
137
  --no-multi \
140
- --bind=enter:accept \
141
138
  <<< "$choices"
142
- ) </dev/tty || true
139
+ ) || true
143
140
 
144
141
  # ESC or Ctrl-C
145
142
  if [[ -z "$selection" ]]; then
146
143
  echo "Aborted."
147
- return 1
144
+ return 0
148
145
  fi
149
146
 
150
147
  # -----------------------------
@@ -152,17 +149,17 @@ EOF
152
149
  # -----------------------------
153
150
  case "$selection" in
154
151
  "$create_option")
155
- gitbash create
152
+ gb_run create
156
153
  ;;
157
154
  "$switch_option")
158
- gitbash switch
155
+ gb_run switch
159
156
  ;;
160
157
  "$update_option")
161
- gitbash update
158
+ gb_run update
162
159
  ;;
163
160
  "$abort_label")
164
161
  echo "Aborted."
165
- return 1
162
+ return 0
166
163
  ;;
167
164
  *)
168
165
  echo "Unknown selection."
@@ -1,15 +1,13 @@
1
1
  #!/usr/bin/env bash
2
- # shellcheck disable=SC2155
3
2
 
4
3
  # Source common utilities
5
- SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
4
+ SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
5
  # shellcheck source=_utils.sh
7
6
  source "$SOURCE_DIR/_utils.sh"
7
+ # shellcheck source=unstash.sh
8
+ source "$SOURCE_DIR/unstash.sh"
8
9
 
9
10
  cleanstash() {
10
- # -----------------------------
11
- # 0. Check for help/version flag
12
- # -----------------------------
13
11
  if [[ "${1:-}" == "-v" || "${1:-}" == "--version" ]]; then
14
12
  echo "gitbash ${FUNCNAME[0]} v$VERSION"
15
13
  return 0
@@ -24,155 +22,82 @@ Interactive fuzzy finder (fzf) with preview and multi-select support.
24
22
  Options:
25
23
  -h, --help Show this help message
26
24
 
27
- Features:
28
- - Multi-select support (use TAB to select multiple stashes)
29
- - Preview stash contents before deletion
30
- - Confirmation prompt before deletion
31
- - Safe deletion (deletes in reverse order to maintain indices)
32
-
33
25
  Navigation:
34
- ↑/↓ or j/k Navigate through stashes
26
+ ↑/↓ Navigate through stashes
35
27
  TAB Select/deselect stash (multi-select)
36
28
  Enter Confirm selection
37
29
  ESC/Ctrl-C Abort
38
30
 
39
- Examples:
40
- $ cleanstash
41
- Available stashes >
42
- > stash@{0}: WIP on main: 1a2b3c4 commit message
43
- stash@{1}: WIP on feature: 5d6e7f8 another commit
44
- stash@{2}: On dev: 9a8b7c6 old work
45
- ✖ Abort
46
-
47
- # Select stash@{0} and stash@{2} using TAB, then press Enter
48
-
49
- Selected stashes to delete:
50
- - stash@{0}
51
- - stash@{2}
52
-
53
- Delete these 2 stash(es)? (y/N): y
54
- Deleting stashes...
55
- Dropping stash@{2} ...
56
- ✓ Deleted stash@{2}
57
- Dropping stash@{0} ...
58
- ✓ Deleted stash@{0}
59
-
60
- Requirements:
61
- - fzf (fuzzy finder) - will prompt to install if not found
62
- - git stash list with at least one stash
63
-
64
31
  Notes:
65
- - Stashes are deleted in reverse order to prevent index shifts
66
- - Preview shows the full diff of the selected stash
32
+ - Asks for confirmation before deleting
33
+ - Stashes are deleted from the highest index down, so indices stay valid
67
34
  - No changes are applied to your working directory
68
35
 
36
+ Requirements:
37
+ - fzf (fuzzy finder)
38
+
69
39
  EOF
70
40
  return 0
71
41
  fi
72
42
 
73
- # -----------------------------
74
- # 1. Check for fzf
75
- # -----------------------------
43
+ require_git_repo || return 1
44
+
45
+ local stash_list
46
+ stash_list=$(git stash list)
47
+ if [[ -z "$stash_list" ]]; then
48
+ echo "No stashes."
49
+ return 0
50
+ fi
51
+
76
52
  require_fzf || return 1
77
53
 
78
- # -----------------------------
79
- # 2. Build menu entries
80
- # -----------------------------
81
- local abort_label="✖ Abort"
82
-
83
- local choices
84
- choices=$(
85
- {
86
- git stash list
87
- echo "$abort_label"
88
- }
89
- )
90
-
91
- # -----------------------------
92
- # 3. Run fzf full-screen picker with preview (multi-select)
93
- # -----------------------------
94
54
  local selection
95
- selection=$(fzf --prompt="Available stashes > " \
55
+ selection=$(run_fzf --prompt="Available stashes > " \
96
56
  -i \
97
57
  --reverse \
98
58
  --border \
99
59
  --header="Select stashes to delete (TAB for multi-select)" \
100
60
  --multi \
101
- --bind=enter:accept \
102
- --preview='
103
- sel=$(echo {} | grep -o "stash@{[0-9]\+}" || true);
104
- if [[ -n "$sel" ]]; then
105
- git stash show -p "$sel" | delta --light 2>/dev/null || git stash show -p "$sel";
106
- else
107
- echo "No preview";
108
- fi
109
- ' \
110
- <<< "$choices"
111
- ) </dev/tty || true
112
-
113
- # ESC or Ctrl-C
114
- if [[ -z "$selection" ]]; then
115
- echo "Aborted."
116
- return 1
117
- fi
61
+ --preview="$(_stash_preview)" \
62
+ <<< "$stash_list"
63
+ ) || true
118
64
 
119
- # Abort option
120
- if echo "$selection" | grep -q "^$abort_label$"; then
65
+ if [[ -z "$selection" ]]; then
121
66
  echo "Aborted."
122
- return 1
67
+ return 0
123
68
  fi
124
69
 
125
- # -----------------------------
126
- # 4. Extract stash IDs safely
127
- # -----------------------------
128
- local stash_ids=()
129
- local stash_id line
70
+ local stash_ids=() stash_id line
130
71
  while IFS= read -r line; do
131
- stash_id=$(echo "$line" | grep -o 'stash@{[0-9]\+}' || true)
132
- if [[ -n "$stash_id" ]]; then
133
- stash_ids+=("$stash_id")
134
- fi
72
+ stash_id=$(printf '%s' "$line" | grep -o '^stash@{[0-9]*}' || true)
73
+ [[ -n "$stash_id" ]] && stash_ids+=("$stash_id")
135
74
  done <<< "$selection"
136
75
 
137
76
  if [[ ${#stash_ids[@]} -eq 0 ]]; then
138
- echo "Error: Could not determine any stash IDs."
77
+ print_error "Could not determine any stash IDs."
139
78
  return 1
140
79
  fi
141
80
 
142
- # -----------------------------
143
- # 5. Confirm before deletion
144
- # -----------------------------
145
81
  echo "Selected stashes to delete:"
146
- for stash_id in "${stash_ids[@]}"; do
147
- echo " - $stash_id"
148
- done
82
+ printf ' - %s\n' "${stash_ids[@]}"
149
83
  echo
150
84
 
151
- prompt_read "Delete these ${#stash_ids[@]} stash(es)? (y/N): " confirm_ans
152
- case "$confirm_ans" in
153
- [yY][eE][sS]|[yY])
154
- # -----------------------------
155
- # 6. Delete stashes (in reverse order to maintain indices)
156
- # -----------------------------
157
- echo "Deleting stashes..."
158
- # Sort by stash number in descending order to delete safely
159
- local sorted_ids=()
160
- local id
161
- while IFS= read -r id; do
162
- sorted_ids+=("$id")
163
- done < <(printf '%s\n' "${stash_ids[@]}" | sort -t'{' -k2 -rn)
164
-
165
- for stash_id in "${sorted_ids[@]}"; do
166
- echo "Dropping $stash_id ..."
167
- if git stash drop "$stash_id"; then
168
- echo "✓ Deleted $stash_id"
169
- else
170
- echo "✗ Failed to delete $stash_id"
171
- fi
172
- done
173
- ;;
174
- *)
175
- echo "Deletion cancelled. No stashes were removed."
176
- ;;
177
- esac
85
+ if ! gb_confirm "Delete these ${#stash_ids[@]} stash(es)?" n; then
86
+ echo "Deletion cancelled. No stashes were removed."
87
+ return 0
88
+ fi
89
+
90
+ # Highest index first, so the remaining indices don't shift
91
+ local sorted_ids=() id
92
+ while IFS= read -r id; do
93
+ sorted_ids+=("$id")
94
+ done < <(printf '%s\n' "${stash_ids[@]}" | sort -t'{' -k2 -rn)
95
+
96
+ for stash_id in "${sorted_ids[@]}"; do
97
+ if git stash drop --quiet "$stash_id"; then
98
+ print_success "Deleted $stash_id"
99
+ else
100
+ print_error "Failed to delete $stash_id"
101
+ fi
102
+ done
178
103
  }