1
0
Fork 0
mirror of synced 2024-12-04 14:45:38 -05:00

Compare commits

...

5 commits

Author SHA1 Message Date
Adrian Calinescu
be4bc937b3
Merge f5b086c89c into 2e419db5d9 2024-11-15 20:24:45 +08:00
Gregory Pakosz
2e419db5d9 refactored TPM plugins discovery, resolves #671
lift the limitation that allows plugins to only be declared from the main
`.local` customization file

from now on, spawn an ephemeral tmux server/client pair to discover plugins with
a mix of source-file -nvq and a recursive shell function

the upside of the new approach is that it respects tmux conditionals and we only
consider set -g @plugin that are really evaluated by tmux, e.g. within %if,
%elif, %else blocks

---
currently, source-file -v doesn't apply the -v flag to subsequent source-file
commands being evaluated, so we use -n and recurse ourselves

trying to (ab)use the after-set-option hook to accumulate all the evaluations of
set -g @plugin into a variable was promising, but is not immune to configuration
files that use set-(hook|option) -gu after-set-option to clear the hook, which
makes plugin discovery fail partially or even entirely
2024-11-13 19:55:01 +01:00
Gregory Pakosz
6e22cc2965 updated _pane_info() to stop walking down the process tree at the first ssh command found, fixes #748
which helps when the ssh configuration uses ProxyCommand to connect to the remote host
2024-10-31 12:51:47 +01:00
Gregory Pakosz
5fcc377128 updated README.me to reference @bphogan's tmux3 book 2024-10-16 10:30:53 +02:00
Adrian Calinescu
f5b086c89c
Works with the new Windows Terminal (plus screenshot) 2019-10-15 09:06:42 +03:00
2 changed files with 76 additions and 18 deletions

View file

@ -164,6 +164,8 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration'
# # exit the script if any statement returns a non-true return value
# set -e
#
# unset SHELL
#
# unset GREP_OPTIONS
# export LC_NUMERIC=C
# # shellcheck disable=SC3041
@ -189,7 +191,7 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration'
# if [ -z "$TMUX_PROGRAM" ]; then
# TMUX_PID=$(printf '%s' "$TMUX" | cut -d, -f2)
# TMUX_PROGRAM=$(lsof -b -w -a -d txt -p "$TMUX_PID" -Fn 2>/dev/null | perl -n -e "if (s/^n((?:.(?!dylib$|so$))+)$/\1/g) { print; exit } } exit 1; {" 2>/dev/null || readlink "/proc/$TMUX_PID/exe" 2>/dev/null)
# [ x"$("$TMUX_PROGRAM" -S "$TMUX_SOCKET" display -p '#{pid}' 2>/dev/null)" = x"$TMUX_PID" ] || TMUX_PROGRAM=$(command -v tmux || printf tmux)
# [ "$("$TMUX_PROGRAM" -S "$TMUX_SOCKET" display -p '#{pid}' 2>/dev/null)" = "$TMUX_PID" ] || TMUX_PROGRAM=$(command -v tmux || printf tmux)
# fi
# if [ "$TMUX_PROGRAM" = "tmux" ]; then
# tmux() {
@ -603,7 +605,7 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration'
# battery_status="$battery_status_charging"
# fi
#
# tmux set -g '@battery_status' "$battery_status"
# tmux set -g '@battery_status' "$battery_status" >/dev/null 2>/dev/null
# }
#
# _pane_info() {
@ -611,14 +613,18 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration'
# pane_tty="${2##/dev/}"
# case "$_uname_s" in
# *CYGWIN*)
# ps -al | tail -n +2 | awk -v pane_pid="$pane_pid" -v tty="$pane_tty" '
# ps -al | tail -n +2 | awk -v pane_pid="$pane_pid" -v tty="$pane_tty" -v ssh="$(command -v ssh)" '
# ((/ssh/ && !/-W/ && !/tsh proxy ssh/ &!/sss_ssh_knownhostsproxy/) || !/ssh/) && !/tee/ && $5 == tty {
# user[$1] = $6; if (!child[$2]) child[$2] = $1
# }
# END {
# pid = pane_pid
# while (child[pid])
# while (child[pid]) {
# if (match(command[pid], "^" ssh " |^ssh ")) {
# break
# }
# pid = child[pid]
# }
#
# file = "/proc/" pid "/cmdline"; getline command < file; close(file)
# gsub(/\0/, " ", command)
@ -628,28 +634,36 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration'
# '
# ;;
# *Linux*)
# ps -t "$pane_tty" --sort=lstart -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command= | awk -v pane_pid="$pane_pid" '
# ps -t "$pane_tty" --sort=lstart -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command= | awk -v pane_pid="$pane_pid" -v ssh="$(command -v ssh)" '
# ((/ssh/ && !/-W/ && !/tsh proxy ssh/ && !/sss_ssh_knownhostsproxy/) || !/ssh/) && !/tee/ {
# user[$2] = $1; if (!child[$3]) child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4)
# }
# END {
# pid = pane_pid
# while (child[pid])
# while (child[pid]) {
# if (match(command[pid], "^" ssh " |^ssh ")) {
# break
# }
# pid = child[pid]
# }
#
# print pid":"user[pid]":"command[pid]
# }
# '
# ;;
# *)
# ps -t "/dev/$pane_tty" -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command= | awk -v pane_pid="$pane_pid" '
# ps -t "/dev/$pane_tty" -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command= | awk -v pane_pid="$pane_pid" -v ssh="$(command -v ssh)" '
# ((/ssh/ && !/-W/ && !/tsh proxy ssh/ && !/sss_ssh_knownhostsproxy/) || !/ssh/) && !/tee/ {
# user[$2] = $1; if (!child[$3]) child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4)
# }
# END {
# pid = pane_pid
# while (child[pid])
# while (child[pid]) {
# if (match(command[pid], "^" ssh " |^ssh ")) {
# break
# }
# pid = child[pid]
# }
#
# print pid":"user[pid]":"command[pid]
# }
@ -904,7 +918,7 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration'
# if _is_true "$tmux_conf_preserve_stock_bindings"; then
# probe_socket="$(dirname "$TMUX_SOCKET")/tmux-stock-bindings-$$"
# TMUX_SOCKET="$probe_socket" tmux -f /dev/null list-keys >> "$cfg"
# rm -f "%probe_socket"
# rm -f "$probe_socket"
# fi
#
# # tmux 3.0 doesn't include 02254d1e5c881be95fd2fc37b4c4209640b6b266 and the
@ -1607,8 +1621,48 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration'
# fi
# mkdir -p "$TMUX_PLUGIN_MANAGER_PATH"
#
# __discover_plugins() (
# probe_socket="$(dirname "$TMUX_SOCKET")/tmux-discover-plugins-$$"
# TMUX_SOCKET="$probe_socket" tmux -f /dev/null start-server \; set-option exit-empty off
# ___discover_plugins() {
# depth=$((${depth:-0} + 1))
# IFS=${_IFS:-$IFS}
# [ "$depth" -le 100 ] || return
# for current_file in "$@"; do
# current_file="$(cd "${current_file%/*}" 2>/dev/null && pwd)/${current_file##*/}" || continue
# while IFS= read -r line; do
# if plugin=$(printf '%s\n' "$line" | perl -s -n -E 'print if s/^set-option\s+-g\s+\@plugin\s+//g or die' 2>/dev/null); then
# discovered_plugins="${discovered_plugins}${discovered_plugins:+ }${plugin}"
# elif next_files=$(printf '%s\n' "$line" | perl -s -n -E 's/(?<!\@)current_file/\@current_file/g ; print if s/^source(?:-file)?(?:\s+-[qF]+)*\s*(.+?)$/\1/g or die' 2>/dev/null); then
# next_files=$(TMUX_SOCKET="$probe_socket" tmux -f /dev/null \
# set -g @current_file "$current_file" \; \
# display -pF "$next_files")
#
# _IFS="$IFS"
# IFS=$(printf '\n\nx')
# IFS=${IFS%?}
# # we don't want quoting here as we want wildcard expansion
# # shellcheck disable=SC2046
# ___discover_plugins $(printf '%s\n' "$next_files" | xargs printf '%s\n\n')
# fi
# done << EOF
# $(TMUX_SOCKET="$probe_socket" tmux -f /dev/null source -nvq "$current_file" | perl -s -n -E 'print if s/^$current_file:\d+:\s*(set-option\s+-g\s+\@plugin\s+|source-file)/\1/g' -- -current_file="$current_file")
# EOF
# done
# }
# ___discover_plugins "$@"
# TMUX_SOCKET="$probe_socket" tmux -f /dev/null kill-server
# rm -rf "$probe_socket"
# printf '%s\n' "$discovered_plugins"
# )
#
# tpm_plugins=$(tmux show -gvq '@tpm_plugins' 2>/dev/null)
# if [ -z "$(tmux show -gv '@plugin' 2>/dev/null)" ] && [ -z "$tpm_plugins" ]; then
# tpm_plugins=$(cat << EOF | tr ' ' '\n' | awk '/^\s*$/ {next;}; !seen[$0]++ { gsub(/^[ \t]+/,"",$0); gsub(/[ \t]+$/,"",$0); print $0 }'
# $tpm_plugins
# $(__discover_plugins "$TMUX_CONF_LOCAL")
# EOF
# )
# if [ -z "$tpm_plugins" ]; then
# if _is_true "$tmux_conf_uninstall_plugins_on_reload" && [ -d "$TMUX_PLUGIN_MANAGER_PATH/tpm" ]; then
# tmux display 'Uninstalling tpm and plugins...'
# tmux set-environment -gu TMUX_PLUGIN_MANAGER_PATH
@ -1617,11 +1671,6 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration'
# fi
# else
# if [ "$(command tmux display -p '#{pid} #{version} #{socket_path}')" = "$("$TMUX_PROGRAM" display -p '#{pid} #{version} #{socket_path}')" ]; then
# tpm_plugins=$(cat << EOF | tr ' ' '\n' | awk '/^\s*$/ {next;}; !seen[$0]++ { gsub(/^[ \t]+/,"",$0); gsub(/[ \t]+$/,"",$0); print $0 }'
# $tpm_plugins
# $(awk '/^[ \t]*set(-option)?.*[ \t]@plugin[ \t]/ { gsub(/'\''/, ""); gsub(/'\"'/, ""); print $NF }' "$TMUX_CONF_LOCAL" 2>/dev/null)
# EOF
# )
# tmux set-environment -g TMUX_PLUGIN_MANAGER_PATH "$TMUX_PLUGIN_MANAGER_PATH"
# tmux set -g '@tpm_plugins' "$tpm_plugins"
#

View file

@ -54,12 +54,12 @@ you're on your own. Instead, every customization should happen in your
If you're a Vim user, setting the `$EDITOR` environment variable to `vim` will
enable and further customize the vi-style key bindings (see tmux manual).
If you're new to tmux, I recommend you to read [tmux 2: Productive Mouse-Free
Development][bhtmux2] by [@bphogan].
If you're new to tmux, I recommend you to read [tmux 3: Productive Mouse-Free
Development][bhtmux3] by [@bphogan].
Now proceed to [adjust] your `.local` customization file copy.
[bhtmux2]: https://pragprog.com/titles/bhtmux2/tmux-2
[bhtmux3]: https://pragprog.com/titles/bhtmux3/tmux-3/
[@bphogan]: https://twitter.com/bphogan
[adjust]: #configuration
@ -108,6 +108,13 @@ Troubleshooting
one, Powerline symbols will be broken.
The alternative is to use the [Mintty terminal for WSL][wsltty].
- **Will this work with the new [Windows Terminal]?**
Yes, yes it will. Here's a screenshot:
![image](https://user-images.githubusercontent.com/6472374/66804257-a8225d00-ef2a-11e9-901a-318a3a22151f.png)
[1681]: https://github.com/Microsoft/BashOnWindows/issues/1681
[wsltty]: https://github.com/mintty/wsltty
@ -364,3 +371,5 @@ font.
![regedit](https://cloud.githubusercontent.com/assets/553208/19741304/71a2f3ae-9bc0-11e6-96aa-4c09a812c313.png)
[font linking]: https://msdn.microsoft.com/en-us/goglobal/bb688134.aspx
[Windows Terminal]: https://github.com/microsoft/terminal