✨ feat(fish): git_open & open functions
This commit is contained in:
parent
85446f029c
commit
581e4fe391
3 changed files with 37 additions and 1 deletions
25
.config/fish/functions/git_open.fish
Normal file
25
.config/fish/functions/git_open.fish
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/env fish
|
||||||
|
|
||||||
|
function git_open
|
||||||
|
set -f origin "$(git remote get-url origin)"
|
||||||
|
|
||||||
|
switch "$origin"
|
||||||
|
case "*github*"
|
||||||
|
if command -v gh &>/dev/null
|
||||||
|
gh repo view --web &>/dev/null
|
||||||
|
else if command -v hub &>/dev/null
|
||||||
|
hub browse &>/dev/null
|
||||||
|
else
|
||||||
|
set_color red
|
||||||
|
echo "[ERROR] Install gh-cli or hub to open Github repos." >&2
|
||||||
|
set_color normal
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
case "https://*"
|
||||||
|
open '$origin' >/dev/null &
|
||||||
|
case "*"
|
||||||
|
set_color red
|
||||||
|
printf "[ERROR] Unrecognized origin %s" "$origin" >&2
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
11
.config/fish/functions/open.fish
Normal file
11
.config/fish/functions/open.fish
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env fish
|
||||||
|
|
||||||
|
if test "$OS" = Darwin
|
||||||
|
function open --wraps open
|
||||||
|
open "$argv"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
function open --wraps xdg-open
|
||||||
|
xdg-open "$argv" >/dev/null
|
||||||
|
end
|
||||||
|
end
|
|
@ -124,7 +124,7 @@
|
||||||
|
|
||||||
nevermind = "!git reset --hard HEAD && git clean -df"
|
nevermind = "!git reset --hard HEAD && git clean -df"
|
||||||
|
|
||||||
open = "!f() { URL=$(git config remote.${1:-origin}.url); xdg-open \"${URL%%.git}\"; }; f"
|
open = "!fish -c git_open"
|
||||||
|
|
||||||
chash = "!git log --oneline | gum filter --height 10 | cut -d' ' -f1 | copyq copy - &>/dev/null"
|
chash = "!git log --oneline | gum filter --height 10 | cut -d' ' -f1 | copyq copy - &>/dev/null"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue