blob: e125a29eae94314dfe698920e880e1d2d32dc074 (
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
90
91
92
|
#!/bin/bash
# Put this machine's tmuxrdr on the checkout's config and plugin. Dry run by
# default; pass `yes` to apply -- the same interface as dot's link.sh. Only
# tmuxrdr is touched: stock herdr keeps its own config and plugins in
# ~/.config/herdr.
#
# ~/.local/share/tmuxrdr/plugin -> <repo>/tmuxrdr/plugin
# the stable path config.toml's popups run from, whatever the checkout
# is called; registered with `tmuxrdr plugin link`
# ~/.config/tmuxrdr/config.toml -> <repo>/tmuxrdr/config/config.toml
# herdr saves its settings with an in-place write (src/config/write.rs),
# so the link survives and every change lands here, under git. A real
# file already there is kept beside it as config.toml.pre-tmuxrdr.
#
# Run it again after moving the checkout. Needs the tmuxrdr binary
# (scripts/build), or $HERDR pointing at another tmuxrdr build; it refuses a
# binary that reads its config from anywhere else, such as stock herdr.
set -euo pipefail
repo="$(cd "$(dirname "$0")/../.." && pwd -P)"
herdr="${HERDR:-tmuxrdr}"
apply="${1:-}"
plugin_id="tmuxrdr.tmux-mode"
plugin_link="${XDG_DATA_HOME:-$HOME/.local/share}/tmuxrdr/plugin"
config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/tmuxrdr"
config_link="$config_dir/config.toml"
run() {
if [[ "$apply" == "yes" ]]; then
"$@"
else
echo "would run: $*"
fi
}
# link TARGET LINK: make LINK a symlink to TARGET, keeping a real file that is
# in the way as LINK.pre-tmuxrdr. A real directory is left alone: too much to
# guess about.
link() {
local target="$1" link="$2"
if [[ -L "$link" && "$(readlink "$link")" == "$target" ]]; then
echo "ok: $link"
return
fi
if [[ -d "$link" && ! -L "$link" ]]; then
>&2 echo "ERROR: $link is a directory; move it away and run again"
exit 1
fi
if [[ -f "$link" && ! -L "$link" ]]; then
run mv "$link" "$link.pre-tmuxrdr"
fi
run mkdir -p "$(dirname "$link")"
run ln -sfn "$target" "$link"
[[ "$apply" == "yes" ]] && echo "linked: $link -> $target"
return 0
}
command -v "$herdr" >/dev/null || { >&2 echo "ERROR: no $herdr; build it: tmuxrdr/scripts/build"; exit 1; }
reads="$("$herdr" --help 2>/dev/null | sed -n 's/^Config: *//p')"
[[ "$reads" == "$config_link" ]] || {
>&2 echo "ERROR: $herdr reads its config from ${reads:-?}, not $config_link: not a tmuxrdr build"
exit 1
}
command -v jq >/dev/null || { >&2 echo "ERROR: the plugin needs jq"; exit 1; }
link "$repo/tmuxrdr/plugin" "$plugin_link"
link "$repo/tmuxrdr/config/config.toml" "$config_link"
# herdr records the link resolved, so compare against the checkout itself;
# registered under another path -- an older checkout -- means link again.
registered="$("$herdr" plugin list --json 2>/dev/null \
| jq -r --arg id "$plugin_id" '.. | objects | select(.plugin_id? == $id) | .plugin_root' \
| head -n 1)"
if [[ -n "$registered" && "$registered" != "$repo/tmuxrdr/plugin" ]]; then
run "$herdr" plugin unlink "$plugin_id"
registered=""
fi
if [[ -z "$registered" ]]; then
run "$herdr" plugin link "$plugin_link" >/dev/null
[[ "$apply" == "yes" ]] && echo "registered: plugin $plugin_id"
else
echo "ok: plugin $plugin_id"
fi
if [[ "$apply" == "yes" ]]; then
"$herdr" config check
echo "A running tmuxrdr picks this up on prefix+r."
else
echo "Execute with: $0 yes"
fi
|