-
Notifications
You must be signed in to change notification settings - Fork 5k
feat(shell): add fish support to common
#1360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,169 @@ | ||||||||||||
| #!/usr/bin/env fish | ||||||||||||
| # Common functions and variables for all Fish shell scripts | ||||||||||||
|
|
||||||||||||
| # Get repository root, with fallback for non-git repositories | ||||||||||||
| function get_repo_root | ||||||||||||
| if git rev-parse --show-toplevel 2>/dev/null | ||||||||||||
| return 0 | ||||||||||||
| else | ||||||||||||
| # Fall back to script location for non-git repos | ||||||||||||
| set script_dir (dirname (status --current-filename)) | ||||||||||||
| cd $script_dir/../../.. && pwd | ||||||||||||
| end | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| # Get current branch, with fallback for non-git repositories | ||||||||||||
| function get_current_branch | ||||||||||||
| # First check if SPECIFY_FEATURE environment variable is set | ||||||||||||
| if set -q SPECIFY_FEATURE; and test -n "$SPECIFY_FEATURE" | ||||||||||||
| echo $SPECIFY_FEATURE | ||||||||||||
| return | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| # Then check git if available | ||||||||||||
| if git rev-parse --abbrev-ref HEAD 2>/dev/null | ||||||||||||
| return | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| # For non-git repos, try to find the latest feature directory | ||||||||||||
| set repo_root (get_repo_root) | ||||||||||||
| set specs_dir "$repo_root/specs" | ||||||||||||
|
|
||||||||||||
| if test -d "$specs_dir" | ||||||||||||
| set latest_feature "" | ||||||||||||
| set highest 0 | ||||||||||||
|
|
||||||||||||
| for dir in $specs_dir/* | ||||||||||||
| if test -d "$dir" | ||||||||||||
| set dirname (basename $dir) | ||||||||||||
| if string match -qr '^([0-9]{3})-' $dirname | ||||||||||||
| set number (string sub -l 3 $dirname) | ||||||||||||
| # Remove leading zeros | ||||||||||||
| set number (math $number + 0) | ||||||||||||
| if test $number -gt $highest | ||||||||||||
| set highest $number | ||||||||||||
| set latest_feature $dirname | ||||||||||||
| end | ||||||||||||
| end | ||||||||||||
| end | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| if test -n "$latest_feature" | ||||||||||||
| echo $latest_feature | ||||||||||||
| return | ||||||||||||
| end | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| echo "main" # Final fallback | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| # Check if we have git available | ||||||||||||
| function has_git | ||||||||||||
| git rev-parse --show-toplevel 2>/dev/null >/dev/null | ||||||||||||
| return $status | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| function check_feature_branch | ||||||||||||
| set branch $argv[1] | ||||||||||||
| set has_git_repo $argv[2] | ||||||||||||
|
|
||||||||||||
| # For non-git repos, we can't enforce branch naming but still provide output | ||||||||||||
| if test "$has_git_repo" != "true" | ||||||||||||
| echo "[specify] Warning: Git repository not detected; skipped branch validation" >&2 | ||||||||||||
| return 0 | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| if not string match -qr '^[0-9]{3}-' $branch | ||||||||||||
| echo "ERROR: Not on a feature branch. Current branch: $branch" >&2 | ||||||||||||
| echo "Feature branches should be named like: 001-feature-name" >&2 | ||||||||||||
| return 1 | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| return 0 | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| function get_feature_dir | ||||||||||||
| echo "$argv[1]/specs/$argv[2]" | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| # Find feature directory by numeric prefix instead of exact branch match | ||||||||||||
|
||||||||||||
| # Find feature directory by numeric prefix instead of exact branch match | |
| # Find feature directory by numeric prefix instead of exact branch match. This allows | |
| # multiple branches to work on the same spec (e.g., 004-fix-bug, 004-add-feature). |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says "Extract numeric prefix from branch" but is missing the more detailed explanation that the bash version has: "Extract numeric prefix from branch (e.g., '004' from '004-whatever')". The bash version provides a helpful example that clarifies the expected format.
| # Extract numeric prefix from branch | |
| # Extract numeric prefix from branch (e.g., '004' from '004-whatever') |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says "No match found" but the bash version includes more context: "No match found - return the branch name path (will fail later with clear error)". This additional context explains the expected behavior when no match is found, which helps with understanding the error handling strategy.
| # No match found | |
| # No match found - return the branch name path (will fail later with clear error) |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says "Multiple matches - this shouldn't happen" but the bash version is more complete: "Multiple matches - this shouldn't happen with proper naming convention". Including the reason (proper naming convention) provides better context for why this scenario is unexpected.
| # Multiple matches - this shouldn't happen | |
| # Multiple matches - this shouldn't happen with proper naming convention |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is missing context. The bash version says "Return something to avoid breaking the script" which explains why a fallback value is returned in this error case. This helps readers understand the defensive programming approach.
| # Multiple matches - this shouldn't happen | |
| # Multiple matches - this shouldn't happen, but return a fallback path | |
| # so that callers still receive a usable directory and scripts don't break. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
cdcommand in the fallback path permanently changes the current directory, which differs from the bash implementation that uses a subshell. This will cause the working directory to remain changed afterget_repo_rootreturns, potentially affecting subsequent operations. Consider using a subshell or command substitution to avoid side effects.