Skip to content

Commit 7fdcadf

Browse files
committed
refactor: update shebang and improve pattern matching in scripts
- Changed the shebang in `gtr.bash` and `generate-completions.sh` to use `/usr/bin/env bash` for better portability. - Refactored pattern matching logic in `copy.sh` to utilize a case statement, enhancing readability and maintainability. - Added a local variable declaration in `create.sh` for improved clarity in the command execution flow. - Updated conditional checks in `go.sh` and `run.sh` to use quotes around array length checks, preventing potential errors.
1 parent e512a10 commit 7fdcadf

File tree

7 files changed

+7
-6
lines changed

7 files changed

+7
-6
lines changed

completions/gtr.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# AUTO-GENERATED by scripts/generate-completions.sh — DO NOT EDIT MANUALLY
33
# Re-generate with: ./scripts/generate-completions.sh
44
#

lib/commands/create.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ cmd_create() {
169169
echo "Branch: $branch_name"
170170

171171
# Create the worktree
172+
local worktree_path
172173
if ! worktree_path=$(create_worktree "$base_dir" "$prefix" "$branch_name" "$from_ref" "$track_mode" "$skip_fetch" "$force" "$custom_name" "$folder_override"); then
173174
exit 1
174175
fi

lib/commands/go.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
cmd_go() {
66
parse_args "" "$@"
77

8-
if [ ${#_pa_positional[@]} -ne 1 ]; then
8+
if [ "${#_pa_positional[@]}" -ne 1 ]; then
99
log_error "Usage: git gtr go <id|branch>"
1010
exit 1
1111
fi

lib/commands/rename.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ cmd_rename() {
7676
move_args+=(--force)
7777
fi
7878

79-
if ! git -C "$repo_root" worktree move "$old_path" "$new_path" "${move_args[@]}"; then
79+
if ! git -C "$repo_root" worktree move "${move_args[@]}" "$old_path" "$new_path"; then
8080
# Rollback: rename branch back
8181
log_warn "Worktree move failed, rolling back branch rename..."
8282
git -C "$repo_root" branch -m "$new_name" "$old_branch" 2>/dev/null || true

lib/commands/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ cmd_run() {
4747
exit 1
4848
fi
4949

50-
if [ ${#run_args[@]} -eq 0 ]; then
50+
if [ "${#run_args[@]}" -eq 0 ]; then
5151
log_error "Usage: git gtr run <id|branch> <command...>"
5252
log_error "No command specified"
5353
exit 1

lib/copy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ copy_directories() {
320320
log_warn "Failed to copy directory $dir_path"
321321
fi
322322
done <<EOF
323-
$(if [[ "$pattern" == */* ]]; then find . -type d -path "./$pattern" 2>/dev/null; else find . -type d -name "$pattern" 2>/dev/null; fi || true)
323+
$(case "$pattern" in */*) find . -type d -path "./$pattern" 2>/dev/null ;; *) find . -type d -name "$pattern" 2>/dev/null ;; esac)
324324
EOF
325325
done <<EOF
326326
$dir_patterns

scripts/generate-completions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ CONFIG_KEYS=$(get_config_keys)
8888

8989
generate_bash() {
9090
cat <<'HEADER'
91-
#!/bin/bash
91+
#!/usr/bin/env bash
9292
# AUTO-GENERATED by scripts/generate-completions.sh — DO NOT EDIT MANUALLY
9393
# Re-generate with: ./scripts/generate-completions.sh
9494
#

0 commit comments

Comments
 (0)