ref: 189e8705a40955381d77090612747ad268471626
parent: 68e50a53bbb8dd2e32e3c6d8cec175866ce406ca
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Jul 12 21:01:46 EDT 2023
plumber-vt: document a working bash+tmux config
--- a/plumber-vt.md
+++ b/plumber-vt.md
@@ -11,9 +11,29 @@
For the remote shell to start sending `OSC 7` messages, follow
[these instructions](https://codeberg.org/dnkl/foot/wiki#user-content-spawning-new-terminal-instances-in-the-current-working-directory). You might want to replace `${HOSTNAME}` with `${HOSTNAME%.lan}` to get rid of `.lan` suffix, depending on how your hosts are shown in `/n/...`.
-If you intend to use `tmux`, it's required to enable the extension explicitly since `tmux` does not know what vt(1) is capable of. Example:
+If you intend to use `tmux`, it's required to pass `OSC 7` message to `vt` explicitely, by adding the following at the end of `osc7_cwd()`:
- $ cat ~/.tmux.conf
- set-option -s terminal-features[2] xterm*:osc7
+ if [ -n "$TMUX" ]; then
+ printf '\e]7;file://%s%s\e\\' "${HOSTNAME%.lan}" "${encoded}" > `tmux display-message -p '#{client_tty}'`
+ fi
-This option forces `tmux` to believe that your terminal emulator supports `OSC 7` extension.
+The full (confirmed to be working) strip from `.bash_profile`:
+
+ osc7_cwd() {
+ local strlen=${#PWD}
+ local encoded=""
+ local pos c o
+ for (( pos=0; pos<strlen; pos++ )); do
+ c=${PWD:$pos:1}
+ case "$c" in
+ [-/:_.!\'\(\)~[:alnum:]] ) o="${c}" ;;
+ * ) printf -v o '%%%02X' "'${c}" ;;
+ esac
+ encoded+="${o}"
+ done
+ printf '\e]7;file://%s%s\e\\' "${HOSTNAME%.lan}" "${encoded}"
+ if [ -n "$TMUX" ]; then
+ printf '\e]7;file://%s%s\e\\' "${HOSTNAME%.lan}" "${encoded}" > `tmux display-message -p '#{client_tty}'`
+ fi
+ }
+ export PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }osc7_cwd