From 99e0f0c36e6a421c0c2aabb9775a9f89b134d58c Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 11 Nov 2021 13:08:37 -0600 Subject: [PATCH] TPM --- common/bin/tmux-lyte-session | 8 +++++--- common/bin/tmux-session-dir | 9 +++++++++ common/bin/tmux-session-preview | 13 +++++++++++++ common/bin/tmuxswitcher | 11 ++++++++++- common/envs | 2 +- common/fish/key-bindings.fish | 2 ++ common/tmux/conf | 5 ++++- host/desktop/tmux.d.conf | 0 host/{ => layer}/personal/gitconfig | 0 host/layer/personal/tmux-tpm.conf | 13 +++++++++++++ host/layer/personal/tmux.d.conf | 3 +++ 11 files changed, 60 insertions(+), 6 deletions(-) create mode 100755 common/bin/tmux-session-dir create mode 100755 common/bin/tmux-session-preview create mode 100644 host/desktop/tmux.d.conf rename host/{ => layer}/personal/gitconfig (100%) create mode 100644 host/layer/personal/tmux-tpm.conf create mode 100644 host/layer/personal/tmux.d.conf diff --git a/common/bin/tmux-lyte-session b/common/bin/tmux-lyte-session index eb23a06..d823b37 100755 --- a/common/bin/tmux-lyte-session +++ b/common/bin/tmux-lyte-session @@ -1,6 +1,8 @@ #!/usr/bin/env fish set session_name $argv[1] -set dir (set -q $argv[2] && echo $argv2 || pwd) -tmux new-session -D -s $session_name -c $dir || \ - tmux attach-session -d -t $session_name + +set d (set -q $argv[2] && echo $argv2 || pwd) + +tmux new-session -D -s "$session_name" -c "$d" || \ + tmux attach-session -d -t "$session_name" -c "$d" diff --git a/common/bin/tmux-session-dir b/common/bin/tmux-session-dir new file mode 100755 index 0000000..105327b --- /dev/null +++ b/common/bin/tmux-session-dir @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# if inside a session, use the current session +# if not, a session must be specified after the dir +d="${1}" +[ -z "$d" ] && d="#{pane_current_path}" +target_session="${2}" +[ -n "$TMUX" ] && target_session="." +tmux attach-session -t "$target_session" -c "$d" diff --git a/common/bin/tmux-session-preview b/common/bin/tmux-session-preview new file mode 100755 index 0000000..0684b1c --- /dev/null +++ b/common/bin/tmux-session-preview @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +session_data="$1" +session_id="$(echo "$session_data" | cut -d':' -f1)" + +S="$(tmux ls -F'#{session_id} #{session_name}: #{T:tree_mode_format}' | grep ^"$session_id")" +session_info="${S##$s}" +session_name="$(echo "$session_info" | cut -d ':' -f1)" + +echo "RAW: $1" +echo "S: $S" +echo "INFO: $session_info" +echo "NAME: $session_name" diff --git a/common/bin/tmuxswitcher b/common/bin/tmuxswitcher index 73c9882..fd5d5fe 100755 --- a/common/bin/tmuxswitcher +++ b/common/bin/tmuxswitcher @@ -7,7 +7,16 @@ t="tmux switch-client -t" sess="$({ tmux display-message -p -F "$fmt" && tmux list-sessions -F "$fmt"; } \ | awk '!seen[$1]++' \ | column -t -s'|' \ - | fzf -q '$' --reverse --prompt 'switch session: ' -1 \ + | fzf -q '$' --reverse --prompt 'switch session: ' -1 --preview "tmux-session-preview {}" \ | cut -d':' -f1)" +[ -z "$sess" ] && exit 1 + $t $sess + + + +# | while read w; do + # set W (tmux lsw -t"{}" -F'#{window_id}#{T:tree_mode_format}' | grep ^"$w") + # echo " ﬌ ${W##$w}" + # end diff --git a/common/envs b/common/envs index 72e9c37..4b3a558 100644 --- a/common/envs +++ b/common/envs @@ -21,4 +21,4 @@ host/laptop/divvy-macbook host/laptop/postmates-macbook host/laptop/uber-macbook host/laptop/val-macbook -host/personal +host/layer/personal diff --git a/common/fish/key-bindings.fish b/common/fish/key-bindings.fish index 50bcdc9..c91988f 100644 --- a/common/fish/key-bindings.fish +++ b/common/fish/key-bindings.fish @@ -22,4 +22,6 @@ function fish_user_key_bindings bind -M insert \cv edit_command_buffer bind -M default \cv edit_command_buffer + + bind -M insert \cs tmuxswitcher end diff --git a/common/tmux/conf b/common/tmux/conf index 8414093..31e85aa 100644 --- a/common/tmux/conf +++ b/common/tmux/conf @@ -62,7 +62,8 @@ bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel 'wl bind-key K kill-pane bind-key C-S-k kill-window -# attempt at integrating nested tmux sessions nicely +# TODO: handle tmux nesting by being able to toggle the prefix (and indicate in status bar?) + # bind -T root F12 \ # set prefix None \;\ # set key-table off \;\ @@ -75,3 +76,5 @@ bind-key C-S-k kill-window # set -u key-table \;\ # set status on \;\ # refresh-client -S + +source-file "$ENV_PATH/*/tmux.d.conf" diff --git a/host/desktop/tmux.d.conf b/host/desktop/tmux.d.conf new file mode 100644 index 0000000..e69de29 diff --git a/host/personal/gitconfig b/host/layer/personal/gitconfig similarity index 100% rename from host/personal/gitconfig rename to host/layer/personal/gitconfig diff --git a/host/layer/personal/tmux-tpm.conf b/host/layer/personal/tmux-tpm.conf new file mode 100644 index 0000000..307b98f --- /dev/null +++ b/host/layer/personal/tmux-tpm.conf @@ -0,0 +1,13 @@ +bind-key Z "display-message yotpm" + +set -g @tpm_plugins ' \ + tmux-plugins/tpm \ + tmux-plugins/tmux-sensible \ + tmux-plugins/tmux-resurrect \ + tmux-plugins/tmux-continuum \ +' + +set -g @continuum-restore 'on' +set -g @continuum-boot 'on' + +run '~/.tmux/plugins/tpm/tpm' diff --git a/host/layer/personal/tmux.d.conf b/host/layer/personal/tmux.d.conf new file mode 100644 index 0000000..370571c --- /dev/null +++ b/host/layer/personal/tmux.d.conf @@ -0,0 +1,3 @@ +bind-key Z "display-message yo" + +if-shell -b "test -d $HOME/.tmux/plugins/tpm" "source-file $ENV_PATH/host-layer-personal/tmux-tpm.conf"