diff --git a/.config/fish/functions/git_open.fish b/.config/fish/functions/git_open.fish new file mode 100644 index 0000000..d8e67eb --- /dev/null +++ b/.config/fish/functions/git_open.fish @@ -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 diff --git a/.config/fish/functions/open.fish b/.config/fish/functions/open.fish new file mode 100644 index 0000000..a0c2fef --- /dev/null +++ b/.config/fish/functions/open.fish @@ -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 diff --git a/.config/git/config.aliases b/.config/git/config.aliases index a1c52ef..68cc556 100644 --- a/.config/git/config.aliases +++ b/.config/git/config.aliases @@ -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"