aboutsummaryrefslogtreecommitdiff
path: root/tmuxrdr/scripts/install
diff options
context:
space:
mode:
Diffstat (limited to 'tmuxrdr/scripts/install')
-rwxr-xr-xtmuxrdr/scripts/install84
1 files changed, 84 insertions, 0 deletions
diff --git a/tmuxrdr/scripts/install b/tmuxrdr/scripts/install
new file mode 100755
index 00000000..f4c0f1ea
--- /dev/null
+++ b/tmuxrdr/scripts/install
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+# Put this machine on tmuxrdr's config and plugin. Dry run by default; pass
+# `yes` to apply -- the same interface as dot's link.sh.
+#
+# ~/.local/share/tmuxrdr/plugin -> <repo>/tmuxrdr/plugin
+# the stable path config.toml's popups run from, whatever the checkout
+# is called; registered with `herdr plugin link`
+# ~/.config/herdr/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. Uses whichever herdr is first on
+# PATH, or $HERDR.
+
+set -euo pipefail
+
+repo="$(cd "$(dirname "$0")/../.." && pwd -P)"
+herdr="${HERDR:-herdr}"
+apply="${1:-}"
+plugin_id="tmuxrdr.tmux-mode"
+plugin_link="${XDG_DATA_HOME:-$HOME/.local/share}/tmuxrdr/plugin"
+config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/herdr"
+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 on PATH"; 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 "Running herdr picks this up on prefix+r."
+else
+ echo "Execute with: $0 yes"
+fi