diff options
| author | Simen A. W. Olsen <hello@simenandre.no> | 2026-09-26 23:22:31 +0200 |
|---|---|---|
| committer | Simen A. W. Olsen <hello@simenandre.no> | 2026-09-26 23:22:31 +0200 |
| commit | 15fc85204fe7426e69225e9c3fd56bb900d854e4 (patch) | |
| tree | f15f5d985a31f2ac138d0740bbf20d95ab3929fe /modules/home | |
| parent | 692d97e43d200b218c3eb2eb97752c94070ecb29 (diff) | |
| download | dotfiles-15fc85204fe7426e69225e9c3fd56bb900d854e4.tar.gz dotfiles-15fc85204fe7426e69225e9c3fd56bb900d854e4.zip | |
fix(home): elide long org and repo names in herdr labels
Diffstat (limited to 'modules/home')
| -rw-r--r-- | modules/home/herdr.nix | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/modules/home/herdr.nix b/modules/home/herdr.nix index 886f24c..55e6b7a 100644 --- a/modules/home/herdr.nix +++ b/modules/home/herdr.nix @@ -1,18 +1,33 @@ { pkgs, ... }: let + # ghq lays repos out as ~/ghq/<host>/<org>/<repo>. Spaces are labelled + # "<org>/<repo>", elided to fit herdr's narrow sidebar: an org over 4 chars + # keeps its first 4 ("simenandre.no" -> "sime.."), a repo over 12 keeps its + # first and last 5 ("frontend-panel" -> "front..panel"). + spaceLabel = '' + space_label() { + local path org repo parent + path=''${1%/} + repo=''${path##*/} + parent=''${path%/*} + org=''${parent##*/} + if [ ''${#org} -gt 4 ]; then org="''${org:0:4}.."; fi + if [ ''${#repo} -gt 12 ]; then repo="''${repo:0:5}..''${repo: -5}"; fi + printf '%s/%s\n' "$org" "$repo" + } + ''; + # twm replacement: fuzzy-pick a repo under ~/ghq and open it as a herdr # workspace, reusing an already-open workspace with the same name. repoPicker = pkgs.writeShellApplication { name = "herdr-repo-picker"; runtimeInputs = [ pkgs.ghq pkgs.fzf pkgs.jq pkgs.herdr ]; - text = '' + text = spaceLabel + '' sel=$(ghq list -p | fzf --prompt 'repo ❯ ' --reverse) || exit 0 [ -n "''${sel:-}" ] || exit 0 - # ghq lays repos out as ~/ghq/<host>/<org>/<repo>; label the space <org>/<repo>. - parent=''${sel%/*} - label="''${parent##*/}/''${sel##*/}" + label=$(space_label "$sel") existing=$(herdr workspace list \ | jq -r --arg l "$label" '.result.workspaces[] | select(.label == $l) | .workspace_id' \ | head -n1) @@ -29,7 +44,7 @@ let repoGet = pkgs.writeShellApplication { name = "herdr-repo-get"; runtimeInputs = [ pkgs.ghq pkgs.herdr ]; - text = '' + text = spaceLabel + '' read -r -p 'ghq get ❯ ' q || exit 0 [ -n "''${q:-}" ] || exit 0 @@ -41,8 +56,7 @@ let [ -n "$dir" ] || dir=$(ghq list -p "$q" | head -n1) [ -n "$dir" ] || exit 0 - parent=''${dir%/*} - label="''${parent##*/}/''${dir##*/}" + label=$(space_label "$dir") herdr workspace create --cwd "$dir" --label "$label" --focus >/dev/null ''; }; |
