From a5c7443464a31f141db7ed1dcf32e01f2cedbe75 Mon Sep 17 00:00:00 2001 From: punkfairie Date: Sat, 16 Nov 2024 23:42:55 -0800 Subject: [PATCH] fix(home): Don't define top-level options under programs.git --- modules/home/programs/git/default.nix | 143 +++++++++++++------------- 1 file changed, 71 insertions(+), 72 deletions(-) diff --git a/modules/home/programs/git/default.nix b/modules/home/programs/git/default.nix index e7ed664..84e92a8 100644 --- a/modules/home/programs/git/default.nix +++ b/modules/home/programs/git/default.nix @@ -17,7 +17,6 @@ in ]; config = mkIf cfg.enable { - home.packages = with pkgs; [ gum clipboard-jh @@ -180,88 +179,88 @@ in credential.helper = "store"; }; + }; - # ███╗ ███╗██╗███████╗ ██████╗ - # ████╗ ████║██║██╔════╝██╔════╝ - # ██╔████╔██║██║███████╗██║ - # ██║╚██╔╝██║██║╚════██║██║ - # ██║ ╚═╝ ██║██║███████║╚██████╗ - # ╚═╝ ╚═╝╚═╝╚══════╝ ╚═════╝ + # ███╗ ███╗██╗███████╗ ██████╗ + # ████╗ ████║██║██╔════╝██╔════╝ + # ██╔████╔██║██║███████╗██║ + # ██║╚██╔╝██║██║╚════██║██║ + # ██║ ╚═╝ ██║██║███████║╚██████╗ + # ╚═╝ ╚═╝╚═╝╚══════╝ ╚═════╝ - home.shellAbbrs = { - g = "git"; - }; + home.shellAbbrs = { + g = "git"; + }; - programs.fish.functions = lib.mkIf config.programs.fish.enable { - git_develop_branch = # fish - '' - command git rev-parse --git-dir &>/dev/null || return - set -l branch + programs.fish.functions = lib.mkIf config.programs.fish.enable { + git_develop_branch = # fish + '' + command git rev-parse --git-dir &>/dev/null || return + set -l branch - for branch in dev devel develop development - if command git show-ref -q --verify refs/heads/$branch - echo $branch - return 0 + for branch in dev devel develop development + if command git show-ref -q --verify refs/heads/$branch + echo $branch + return 0 + end + end + + echo develop + return 1 + ''; + + git_main_branch = # fish + '' + command git rev-parse --git-dir &>/dev/null || return + set -l ref + + for ref in + refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,master} + if command git show-ref -q --verify $ref + echo (basename $ref) + return 0 end - end + end - echo develop - return 1 - ''; + echo main + return 1 + ''; - git_main_branch = # fish - '' - command git rev-parse --git-dir &>/dev/null || return - set -l ref + git_current_branch = # fish + '' + set -l ref (git symbolic-ref --quiet HEAD 2>/dev/null) + set -l ret $status - for ref in - refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,master} - if command git show-ref -q --verify $ref - echo (basename $ref) - return 0 - end - end + if [ $ret -ne 0 ] + [ $ret -eq 128 ] && return # no git repo + set ref (git rev-parse --short HEAD 2>/dev/null) || return + end - echo main - return 1 - ''; + echo (string replace "refs/heads/" "" $ref) + ''; - git_current_branch = # fish - '' - set -l ref (git symbolic-ref --quiet HEAD 2>/dev/null) - set -l ret $status + git_open = # fish + '' + set -f origin "$(git remote get-url origin)" - if [ $ret -ne 0 ] - [ $ret -eq 128 ] && return # no git repo - set ref (git rev-parse --short HEAD 2>/dev/null) || return - end - - echo (string replace "refs/heads/" "" $ref) - ''; - - git_open = # fish - '' - 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 - set_color red - echo "[ERROR] Install gh-cli 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 - ''; - }; + switch "$origin" + case "*github*" + if command -v gh &>/dev/null + gh repo view --web &>/dev/null + else + set_color red + echo "[ERROR] Install gh-cli 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 + ''; }; }; }