-
Notifications
You must be signed in to change notification settings - Fork 0
Port zsh shell helpers to Fish #6
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,3 @@ | ||
| function cdgr | ||
| cd (git root) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| function fpr | ||
| if not git rev-parse --git-dir >/dev/null 2>&1 | ||
| echo 'error: fpr must be executed from within a git repository' >&2 | ||
| return 1 | ||
| end | ||
|
|
||
| cdgr; or return | ||
|
|
||
| set -l repo user branch | ||
| switch (count $argv) | ||
| case 2 | ||
| set repo (basename $PWD) | ||
| set user $argv[1] | ||
| set branch $argv[2] | ||
| case 3 | ||
| set repo $argv[1] | ||
| set user $argv[2] | ||
| set branch $argv[3] | ||
| case '*' | ||
| echo 'Usage: fpr [repo] username branch' >&2 | ||
| return 1 | ||
| end | ||
|
|
||
| git fetch git@github.com:$user/$repo $branch:$user/$branch | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| function jump | ||
| cd (dirname $argv[1]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If We should validate that an argument is provided and that the target directory exists before attempting to change directories. |
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| function nonascii | ||
| env LC_ALL=C grep -n '[^[:print:][:space:]]' $argv[1] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| function serve | ||
| set -l port 8080 | ||
| test (count $argv) -ge 1; and set port $argv[1] | ||
| ruby -run -e httpd . -p $port | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| function syspip | ||
| env PIP_REQUIRE_VIRTUALENV= pip $argv | ||
| end | ||
|
|
||
| function syspip3 | ||
| env PIP_REQUIRE_VIRTUALENV= pip3 $argv | ||
| end | ||
|
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Fish, autoloaded functions are loaded by filename. Because To fix this, |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| function xin | ||
| cd $argv[1]; or return | ||
| set -e argv[1] | ||
| command $argv | ||
|
Comment on lines
+2
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Fish, functions run in the current shell context. Calling We should use |
||
| end | ||
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.
Using
git rootis not a standard Git command and relies on a custom alias that may not be configured on all systems. Additionally, if the command fails or is run outside of a Git repository, it outputs nothing to stdout, causingcdto be executed with no arguments, which unexpectedly changes the directory to$HOME.Using
git rev-parse --show-toplevelis the standard, portable way to find the repository root, and we should verify that a path was returned before attempting to change directories.