gitbash 0.2.4 → 0.2.6

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/README.md CHANGED
@@ -16,6 +16,7 @@ npm i -g gitbash
16
16
  gitbash --help # Show help
17
17
  gitbash --version # Show version
18
18
  gitbash --init # Print shell init code
19
+ gitbash --config # Interactive configuration wizard
19
20
  ```
20
21
 
21
22
  ### Shell Aliases
@@ -56,6 +57,20 @@ brew install git-delta # Better diff highlighting
56
57
  brew install bat # File preview with syntax highlighting
57
58
  ```
58
59
 
60
+ ### Configuration
61
+
62
+ gitbash reads configuration from `~/.gitbashrc` if it exists. You can set the following variables:
63
+
64
+ ```bash
65
+ # Prefix for feature branches (default: "feature/")
66
+ GITBASH_FEATURE_BRANCH_PREFIX="feature/"
67
+
68
+ # Command for merging (default: "merge")
69
+ GITBASH_MERGE_COMMAND="merge"
70
+ ```
71
+
72
+ You can create this file manually or use `gitbash --config` to configure interactively.
73
+
59
74
  ## Commands
60
75
 
61
76
  ### branch
package/bin/gitbash CHANGED
@@ -3,6 +3,42 @@
3
3
 
4
4
  set -euo pipefail
5
5
 
6
+ CONFIG_FILE="$HOME/.gitbashrc"
7
+
8
+ load_config() {
9
+ if [[ -f "$CONFIG_FILE" ]]; then
10
+ # shellcheck disable=SC1090
11
+ source "$CONFIG_FILE"
12
+ fi
13
+ }
14
+
15
+ configure_gitbash() {
16
+ load_config
17
+
18
+ local current_prefix="${GITBASH_FEATURE_BRANCH_PREFIX:-feature/}"
19
+ local current_merge="${GITBASH_MERGE_COMMAND:-fork}"
20
+
21
+ echo "Configure gitbash (writes to $CONFIG_FILE)"
22
+
23
+ local input prefix merge_cmd
24
+
25
+ read -e -p "Feature branch prefix (used by create) [${current_prefix}]: " input
26
+ prefix=${input:-$current_prefix}
27
+
28
+ read -e -p "Merge tool command (used by update on conflicts) [${current_merge}]: " input
29
+ merge_cmd=${input:-$current_merge}
30
+
31
+ cat > "$CONFIG_FILE" <<EOF
32
+ # gitbash configuration
33
+ # Prefix for feature branches created by 'create'
34
+ GITBASH_FEATURE_BRANCH_PREFIX="$prefix"
35
+ # Merge tool command invoked by 'update' when conflicts occur
36
+ GITBASH_MERGE_COMMAND="$merge_cmd"
37
+ EOF
38
+
39
+ echo "Saved configuration to $CONFIG_FILE"
40
+ }
41
+
6
42
  # Resolve symlinks to get the actual script location
7
43
  SOURCE="${BASH_SOURCE[0]}"
8
44
  while [[ -L "$SOURCE" ]]; do
@@ -38,9 +74,10 @@ show_help() {
38
74
  gitbash - Interactive git utilities for bash
39
75
 
40
76
  Usage:
41
- gitbash <command> [args...]
42
- gitbash --help
43
- gitbash --init
77
+ gitbash <command> [args...]
78
+ gitbash --help
79
+ gitbash --init
80
+ gitbash --config
44
81
 
45
82
  Commands:
46
83
  branch Interactive menu for branch operations
@@ -62,6 +99,7 @@ Options:
62
99
  -h, --help Show this help message
63
100
  -v, --version Show version number
64
101
  --init Print shell initialization code (for sourcing)
102
+ --config Configure gitbash and save to ~/.gitbashrc
65
103
 
66
104
  Examples:
67
105
  gitbash commit fix bug -p # Commit and push
@@ -102,6 +140,7 @@ EOF
102
140
 
103
141
  # Main entry point
104
142
  main() {
143
+ load_config
105
144
  case "${1:-}" in
106
145
  -h|--help|"")
107
146
  show_help
@@ -115,6 +154,10 @@ main() {
115
154
  show_init
116
155
  exit 0
117
156
  ;;
157
+ --config)
158
+ configure_gitbash
159
+ exit 0
160
+ ;;
118
161
  *)
119
162
  local cmd="$1"
120
163
  shift
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck disable=SC2155
3
+ # Common utilities for gitbash commands - compatible with bash and zsh
4
+
5
+ # Portable read with prompt that works in both bash and zsh
6
+ # Usage: prompt_read "prompt text" variable_name
7
+ # The result is stored in the variable name provided
8
+ prompt_read() {
9
+ local prompt="$1"
10
+ local varname="$2"
11
+
12
+ if [[ -n "${ZSH_VERSION:-}" ]]; then
13
+ # zsh: use read with ?prompt syntax
14
+ read -r "${varname}?${prompt}"
15
+ else
16
+ # bash: use read -p
17
+ read -rp "$prompt" "$varname"
18
+ fi
19
+ }
20
+
21
+ # Portable read with readline editing (for defaults)
22
+ # Usage: prompt_read_edit "prompt text" variable_name
23
+ prompt_read_edit() {
24
+ local prompt="$1"
25
+ local varname="$2"
26
+
27
+ if [[ -n "${ZSH_VERSION:-}" ]]; then
28
+ # zsh: use vared or read with ?prompt
29
+ read -r "${varname}?${prompt}"
30
+ else
31
+ # bash: use read -e -p
32
+ read -e -rp "$prompt" "$varname"
33
+ fi
34
+ }
@@ -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
  branch() {
2
10
  # -----------------------------
3
11
  # 0. Check for help/version flag
@@ -103,7 +111,7 @@ EOF
103
111
  echo "fzf is not installed."
104
112
 
105
113
  # Ask whether to install with Homebrew
106
- read -rp "Install fzf with Homebrew? (y/N): " ans
114
+ prompt_read "Install fzf with Homebrew? (y/N): " ans
107
115
  case "$ans" in
108
116
  [yY][eE][sS]|[yY])
109
117
  echo "Installing fzf with brew..."
@@ -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
  cleanstash() {
2
10
  # -----------------------------
3
11
  # 0. Check for help/version flag
@@ -69,7 +77,7 @@ EOF
69
77
  echo "fzf is not installed."
70
78
 
71
79
  # Ask whether to install with Homebrew
72
- read -r -p "Install fzf with Homebrew? (y/N): " ans
80
+ prompt_read "Install fzf with Homebrew? (y/N): " ans
73
81
  case "$ans" in
74
82
  [yY][eE][sS]|[yY])
75
83
  echo "Installing fzf with brew..."
@@ -164,7 +172,7 @@ EOF
164
172
  done
165
173
  echo
166
174
 
167
- read -rp "Delete these ${#stash_ids[@]} stash(es)? (y/N): " confirm_ans
175
+ prompt_read "Delete these ${#stash_ids[@]} stash(es)? (y/N): " confirm_ans
168
176
  case "$confirm_ans" in
169
177
  [yY][eE][sS]|[yY])
170
178
  # -----------------------------
@@ -172,8 +180,10 @@ EOF
172
180
  # -----------------------------
173
181
  echo "Deleting stashes..."
174
182
  # Sort by stash number in descending order to delete safely
175
- local sorted_ids
176
- mapfile -t sorted_ids < <(printf '%s\n' "${stash_ids[@]}" | sort -t'{' -k2 -rn)
183
+ local sorted_ids=()
184
+ while IFS= read -r id; do
185
+ sorted_ids+=("$id")
186
+ done < <(printf '%s\n' "${stash_ids[@]}" | sort -t'{' -k2 -rn)
177
187
 
178
188
  for stash_id in "${sorted_ids[@]}"; do
179
189
  echo "Dropping $stash_id ..."
@@ -1,6 +1,11 @@
1
1
  #!/usr/bin/env bash
2
2
  # shellcheck disable=SC2155
3
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
+
4
9
  # Cleanup local branches that are no longer needed
5
10
  cleanup() {
6
11
  # -----------------------------
@@ -85,7 +90,7 @@ EOF
85
90
  if [[ "$json_mode" == false ]]; then
86
91
  if ! command -v fzf >/dev/null 2>&1; then
87
92
  echo "fzf is not installed."
88
- read -rp "Install fzf with Homebrew? (y/N): " ans
93
+ prompt_read "Install fzf with Homebrew? (y/N): " ans
89
94
  case "$ans" in
90
95
  [yY][eE][sS]|[yY])
91
96
  echo "Installing fzf with brew..."
@@ -459,7 +464,7 @@ Found $total_count branches ($preselect_count pre-selected for deletion)" \
459
464
  # Default to Y if only merged branches, otherwise N
460
465
  local confirm
461
466
  if [[ "$only_merged" == true ]]; then
462
- read -rp "Delete these ${#branches_to_delete[@]} local branch(es)? (Y/n): " confirm
467
+ prompt_read "Delete these ${#branches_to_delete[@]} local branch(es)? (Y/n): " confirm
463
468
  case "$confirm" in
464
469
  [nN][oO]|[nN])
465
470
  echo "Deletion cancelled."
@@ -467,7 +472,7 @@ Found $total_count branches ($preselect_count pre-selected for deletion)" \
467
472
  ;;
468
473
  esac
469
474
  else
470
- read -rp "Delete these ${#branches_to_delete[@]} local branch(es)? (y/N): " confirm
475
+ prompt_read "Delete these ${#branches_to_delete[@]} local branch(es)? (y/N): " confirm
471
476
  case "$confirm" in
472
477
  [yY][eE][sS]|[yY])
473
478
  ;;
@@ -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
  # Stage all changes and commit with a message.
2
10
  # If no commit message argument is given, prompt the user for one.
3
11
  commit() {
@@ -84,7 +92,7 @@ EOF
84
92
  # If no commit message was provided...
85
93
  if [ -z "$msg" ]; then
86
94
  # Prompt the user for a commit message (no newline, no extra spaces)
87
- read -rp "Commit message: " msg
95
+ prompt_read "Commit message: " msg
88
96
  fi
89
97
 
90
98
  # Check if there are staged changes
@@ -107,7 +115,7 @@ EOF
107
115
  echo
108
116
  echo "You have both staged and unstaged changes."
109
117
  echo
110
- read -rp "Commit [s]taged only, or [a]ll changes? (s/a): " commit_choice
118
+ prompt_read "Commit [s]taged only, or [a]ll changes? (s/a): " commit_choice
111
119
 
112
120
  case "$commit_choice" in
113
121
  [sS])
@@ -1,6 +1,11 @@
1
1
  #!/usr/bin/env bash
2
2
  # shellcheck disable=SC2155
3
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
+
4
9
  # List recent commits and optionally revert selected ones
5
10
  commits() {
6
11
  # -----------------------------
@@ -57,7 +62,7 @@ EOF
57
62
 
58
63
  if ! command -v fzf >/dev/null 2>&1; then
59
64
  echo "fzf is not installed."
60
- read -rp "Install fzf with Homebrew? (y/N): " ans
65
+ prompt_read "Install fzf with Homebrew? (y/N): " ans
61
66
  case "$ans" in
62
67
  [yY][eE][sS]|[yY])
63
68
  echo "Installing fzf with brew..."
@@ -185,7 +190,7 @@ Showing last $count commits" \
185
190
  echo ""
186
191
 
187
192
  local confirm
188
- read -rp "Revert these ${#commits_to_revert[@]} commit(s)? (y/N): " confirm
193
+ prompt_read "Revert these ${#commits_to_revert[@]} commit(s)? (y/N): " confirm
189
194
  case "$confirm" in
190
195
  [yY][eE][sS]|[yY])
191
196
  echo "Reverting commits..."
@@ -1,6 +1,11 @@
1
1
  #!/usr/bin/env bash
2
2
  # shellcheck disable=SC2155
3
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
+
4
9
  create() {
5
10
  # -----------------------------
6
11
  # 0. Check for help/version flag
@@ -71,7 +76,7 @@ EOF
71
76
  else
72
77
  # Interactive mode
73
78
  echo "Enter Jira link (e.g., https://jira.company.com/browse/PROJ-123):"
74
- read -rp " > " jira_link
79
+ prompt_read " > " jira_link
75
80
  fi
76
81
 
77
82
  if [[ -z "$jira_link" ]]; then
@@ -112,7 +117,7 @@ EOF
112
117
  # -----------------------------
113
118
  if [[ -z "$branch_title" ]]; then
114
119
  echo "Enter branch title (will be converted to lowercase with dashes):"
115
- read -rp " > " branch_title
120
+ prompt_read " > " branch_title
116
121
  fi
117
122
 
118
123
  if [[ -z "$branch_title" ]]; then
@@ -138,7 +143,7 @@ EOF
138
143
  # -----------------------------
139
144
  if git show-ref --verify --quiet "refs/heads/$branch_name"; then
140
145
  echo "⚠ Branch '$branch_name' already exists locally."
141
- read -rp "Switch to this branch instead? (Y/n): " ans
146
+ prompt_read "Switch to this branch instead? (Y/n): " ans
142
147
  case "$ans" in
143
148
  [nN][oO]|[nN])
144
149
  echo "Aborted."
package/commands/stale.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
  stale() {
2
10
  # -----------------------------
3
11
  # 0. Check for help/version flag and parse options
@@ -103,7 +111,7 @@ EOF
103
111
  if ! command -v fzf >/dev/null 2>&1; then
104
112
  echo "fzf is not installed."
105
113
 
106
- read -rp "Install fzf with Homebrew? (y/N): " ans
114
+ prompt_read "Install fzf with Homebrew? (y/N): " ans
107
115
  case "$ans" in
108
116
  [yY][eE][sS]|[yY])
109
117
  echo "Installing fzf with brew..."
@@ -392,7 +400,7 @@ Showing $stale_count stale branches (older than 3 months)" \
392
400
  done
393
401
  echo ""
394
402
 
395
- read -rp "Delete these ${#branches_to_delete[@]} branch(es) from remote? (y/N): " confirm
403
+ prompt_read "Delete these ${#branches_to_delete[@]} branch(es) from remote? (y/N): " confirm
396
404
  case "$confirm" in
397
405
  [yY][eE][sS]|[yY])
398
406
  echo "Deleting branches..."
@@ -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
  stashes() {
2
10
  # -----------------------------
3
11
  # 0. Check for help/version flag
@@ -102,7 +110,7 @@ EOF
102
110
  echo "fzf is not installed."
103
111
 
104
112
  # Ask whether to install with Homebrew
105
- read -r -p "Install fzf with Homebrew? (y/N): " ans
113
+ prompt_read "Install fzf with Homebrew? (y/N): " ans
106
114
  case "$ans" in
107
115
  [yY][eE][sS]|[yY])
108
116
  echo "Installing fzf with brew..."
@@ -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
  # Show git status with fzf file selector and diff preview
2
10
  status() {
3
11
  # -----------------------------
@@ -75,7 +83,7 @@ EOF
75
83
  echo "fzf is not installed."
76
84
 
77
85
  # Ask whether to install with Homebrew
78
- read -rp "Install fzf with Homebrew? (y/N): " ans
86
+ prompt_read "Install fzf with Homebrew? (y/N): " ans
79
87
  case "$ans" in
80
88
  [yY][eE][sS]|[yY])
81
89
  echo "Installing fzf with brew..."
@@ -212,7 +220,7 @@ EOF
212
220
  for f in "${untracked_to_delete[@]}"; do
213
221
  echo " - $f"
214
222
  done
215
- read -rp "Delete these ${#untracked_to_delete[@]} untracked file(s)? (y/N): " confirm
223
+ prompt_read "Delete these ${#untracked_to_delete[@]} untracked file(s)? (y/N): " confirm
216
224
  case "$confirm" in
217
225
  [yY][eE][sS]|[yY])
218
226
  for f in "${untracked_to_delete[@]}"; do
@@ -232,7 +240,7 @@ EOF
232
240
  for f in "${files_to_revert[@]}"; do
233
241
  echo " - $f"
234
242
  done
235
- read -rp "Revert changes in these ${#files_to_revert[@]} file(s)? This cannot be undone. (y/N): " confirm
243
+ prompt_read "Revert changes in these ${#files_to_revert[@]} file(s)? This cannot be undone. (y/N): " confirm
236
244
  case "$confirm" in
237
245
  [yY][eE][sS]|[yY])
238
246
  for f in "${files_to_revert[@]}"; do
@@ -312,7 +320,7 @@ EOF
312
320
  done
313
321
 
314
322
  echo
315
- read -rp "Would you like to commit and push these changes? (Y/n): " ans
323
+ prompt_read "Would you like to commit and push these changes? (Y/n): " ans
316
324
  case "$ans" in
317
325
  [nN][oO]|[nN])
318
326
  echo "Continuing..."
@@ -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
  # Select and switch to a branch using fzf
2
10
  switch() {
3
11
  # -----------------------------
@@ -60,7 +68,7 @@ EOF
60
68
  echo "fzf is not installed."
61
69
 
62
70
  # Ask whether to install with Homebrew
63
- read -rp "Install fzf with Homebrew? (y/N): " ans
71
+ prompt_read "Install fzf with Homebrew? (y/N): " ans
64
72
  case "$ans" in
65
73
  [yY][eE][sS]|[yY])
66
74
  echo "Installing fzf with brew..."
@@ -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
  unstash() {
2
10
  # -----------------------------
3
11
  # 0. Check for help/version flag
@@ -72,7 +80,7 @@ EOF
72
80
  echo "fzf is not installed."
73
81
 
74
82
  # Ask whether to install with Homebrew
75
- read -rp "Install fzf with Homebrew? (y/N): " ans
83
+ prompt_read "Install fzf with Homebrew? (y/N): " ans
76
84
  case "$ans" in
77
85
  [yY][eE][sS]|[yY])
78
86
  echo "Installing fzf with brew..."
@@ -165,7 +173,7 @@ EOF
165
173
  # 6. Confirm before dropping
166
174
  # -----------------------------
167
175
  echo
168
- read -rp "Drop $stash_id now? (y/N): " drop_ans
176
+ prompt_read "Drop $stash_id now? (y/N): " drop_ans
169
177
  case "$drop_ans" in
170
178
  [yY][eE][sS]|[yY])
171
179
  echo "Dropping $stash_id ..."
@@ -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
  # Update the current branch with the latest version of master/main
2
10
  update() {
3
11
  local merge_tool="${GITBASH_FEATURE_BRANCH_PREFIX:-}"
@@ -122,7 +130,7 @@ EOF
122
130
  echo "You have uncommitted changes:"
123
131
  git status --short
124
132
  echo ""
125
- read -rp "Commit changes before updating? (Y/n): " reply
133
+ prompt_read "Commit changes before updating? (Y/n): " reply
126
134
  if [[ "$reply" =~ ^[Nn]$ ]]; then
127
135
  echo "⚠ Cannot merge with uncommitted changes. Commit or stash them first."
128
136
  return 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitbash",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Opinionated git utilities for bash with fzf-powered menus",
5
5
  "author": "jaggli",
6
6
  "license": "MIT",