blob: 886f24c9e0875b0cb41cb52254b9a9503f1b37aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
{ pkgs, ... }:
let
# 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 = ''
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##*/}"
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 = ''
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
parent=''${dir%/*}
label="''${parent##*/}/''${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 <input>`, 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%"
'';
}
|