feat(fish): git_open & open functions

This commit is contained in:
punkfairie 2024-03-10 12:03:11 -07:00
parent 85446f029c
commit 581e4fe391
Signed by: punkfairie
GPG key ID: A86AF57F837E320F
3 changed files with 37 additions and 1 deletions

View 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

View 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

View file

@ -124,7 +124,7 @@
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"