{ pkgs, ... }: let # ghq lays repos out as ~/ghq///. Spaces are labelled # "/", 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 = spaceLabel + '' sel=$(ghq list -p | fzf --prompt 'repo ❯ ' --reverse) || exit 0 [ -n "''${sel:-}" ] || exit 0 label=$(space_label "$sel") existing=$(herdr workspace list \ | jq -r --arg l "$label" '.result.workspaces[] | select(.label == $l) | .workspace_id' \ | head -n1) if [ -n "$existing" ]; then herdr workspace focus "$existing" >/dev/null else herdr workspace create --cwd "$sel" --label "$label" --focus >/dev/null fi ''; }; # Prompt for a `ghq get` target, clone it, then open the clone as a workspace. repoGet = pkgs.writeShellApplication { name = "herdr-repo-get"; runtimeInputs = [ pkgs.ghq pkgs.herdr ]; text = spaceLabel + '' read -r -p 'ghq get ❯ ' q || exit 0 [ -n "''${q:-}" ] || exit 0 before=$(ghq list -p | sort) ghq get "$q" # Prefer the repo that appeared; fall back to matching the query. dir=$(comm -13 <(printf '%s\n' "$before") <(ghq list -p | sort) | head -n1) [ -n "$dir" ] || dir=$(ghq list -p "$q" | head -n1) [ -n "$dir" ] || exit 0 label=$(space_label "$dir") herdr workspace create --cwd "$dir" --label "$label" --focus >/dev/null ''; }; in { home.packages = [ repoPicker repoGet ]; home.file.".config/herdr/config.toml".text = '' [keys] # Match the tmux prefix (see modules/home/tmux.nix). prefix = "ctrl+s" # prefix+j opens the searchable workspace picker: j/k move, `/` searches by # name, b/w/i/d/a filter by agent state, enter switches. Stays open until you pick. workspace_picker = "prefix+j" # Disable the spatial navigate mode so it doesn't reclaim prefix+g (lazygit). goto = "" # prefix+f: fuzzy-pick a ~/ghq repo and open it as a workspace (replaces `twm`). [[keys.command]] key = "prefix+f" type = "popup" command = "${repoPicker}/bin/herdr-repo-picker" width = "70%" height = "60%" # prefix+shift+f: prompt for `ghq get `, clone it, and open it. [[keys.command]] key = "prefix+shift+f" type = "popup" command = "${repoGet}/bin/herdr-repo-get" width = "70%" height = "40%" # prefix+g: lazygit in the current pane's repo (replaces tmux `bind g`). [[keys.command]] key = "prefix+g" type = "popup" command = "${pkgs.lazygit}/bin/lazygit -p \"$HERDR_ACTIVE_PANE_CWD\"" width = "90%" height = "90%" ''; }