fix(home): Don't define top-level options under programs.git

This commit is contained in:
punkfairie 2024-11-16 23:42:55 -08:00
parent 465a717669
commit a5c7443464
Signed by: punkfairie
GPG key ID: A509E8F77FB9D696

View file

@ -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
'';
};
};
}