From 581e4fe391421eb0c2dd37fbfbfb1760ec918564 Mon Sep 17 00:00:00 2001 From: punkfairie <23287005+punkfairie@users.noreply.github.com> Date: Sun, 10 Mar 2024 12:03:11 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(fish):=20git=5Fopen=20&=20open?= =?UTF-8?q?=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/fish/functions/git_open.fish | 25 +++++++++++++++++++++++++ .config/fish/functions/open.fish | 11 +++++++++++ .config/git/config.aliases | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .config/fish/functions/git_open.fish create mode 100644 .config/fish/functions/open.fish 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"