From d870bfb3e921e89fbd682563376dff500e820a29 Mon Sep 17 00:00:00 2001 From: Sam Estep Date: Mon, 25 May 2026 22:28:47 -0400 Subject: [PATCH] Add `ghcd` shell function alternative to `ghcode` --- docker-arm/home-manager/home.nix | 5 ++++- docker-x86/home-manager/home.nix | 5 ++++- macos/home-manager/home.nix | 5 ++++- nixos/home-manager/home.nix | 5 ++++- tart/home-manager/home.nix | 5 ++++- util.nix | 17 +++++++++++++++++ 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/docker-arm/home-manager/home.nix b/docker-arm/home-manager/home.nix index c472688..a243c34 100644 --- a/docker-arm/home-manager/home.nix +++ b/docker-arm/home-manager/home.nix @@ -26,7 +26,10 @@ in }; programs = util.programs // { - bash.enable = true; # Necessary for aliases and Starship to work. + bash = { + enable = true; # Necessary for aliases and Starship to work. + initExtra = util.shellInit; + }; }; assertions = util.assertions; diff --git a/docker-x86/home-manager/home.nix b/docker-x86/home-manager/home.nix index f46603f..8e1357e 100644 --- a/docker-x86/home-manager/home.nix +++ b/docker-x86/home-manager/home.nix @@ -26,7 +26,10 @@ in }; programs = util.programs // { - bash.enable = true; # Necessary for aliases and Starship to work. + bash = { + enable = true; # Necessary for aliases and Starship to work. + initExtra = util.shellInit; + }; }; assertions = util.assertions; diff --git a/macos/home-manager/home.nix b/macos/home-manager/home.nix index ba19194..3b5271e 100644 --- a/macos/home-manager/home.nix +++ b/macos/home-manager/home.nix @@ -69,7 +69,10 @@ in }; programs = util.programs // { - zsh.enable = true; # Necessary for aliases and Starship to work. + zsh = { + enable = true; # Necessary for aliases and Starship to work. + initContent = util.shellInit; + }; }; assertions = util.assertions; diff --git a/nixos/home-manager/home.nix b/nixos/home-manager/home.nix index e95bf86..01bf3c3 100644 --- a/nixos/home-manager/home.nix +++ b/nixos/home-manager/home.nix @@ -49,7 +49,10 @@ in }; programs = util.programs // { - bash.enable = true; # Necessary for aliases and Starship to work. + bash = { + enable = true; # Necessary for aliases and Starship to work. + initExtra = util.shellInit; + }; firefox = { enable = true; diff --git a/tart/home-manager/home.nix b/tart/home-manager/home.nix index 75f4765..ca884a9 100644 --- a/tart/home-manager/home.nix +++ b/tart/home-manager/home.nix @@ -26,7 +26,10 @@ in }; programs = util.programs // { - zsh.enable = true; # Necessary for aliases and Starship to work. + zsh = { + enable = true; # Necessary for aliases and Starship to work. + initContent = util.shellInit; + }; }; assertions = util.assertions; diff --git a/util.nix b/util.nix index 96c86a8..47ffe83 100644 --- a/util.nix +++ b/util.nix @@ -53,6 +53,23 @@ rec { ".gitconfig" = symlink ".gitconfig"; }; + shellInit = '' + ghcd() { + local regex='^((https://)?github\.com/)?([A-Za-z0-9._-]+/[A-Za-z0-9._-]+)' + local repo + repo=$(printf '%s' "''${1-}" | sed -nE "s|''${regex}.*|\3|p") + if [ -z "$repo" ]; then + printf 'must match this regex: %s\n' "$regex" >&2 + return 1 + fi + local dir="$HOME/github/$repo" + if [ ! -e "$dir" ]; then + git clone --recurse-submodules "https://github.com/$repo.git" "$dir" || return $? + fi + cd "$dir" + } + ''; + programs = { eza.enable = true;