From 5643ec6b124cfad307dd1fd5d7fe67924fa1aefb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20La=C3=ADn?= Date: Wed, 11 Jun 2025 00:06:50 +0200 Subject: [PATCH] feat(tmux): script to change from notes to last session --- .config/tmux/conf/binds.conf | 4 ++-- .local/bin/dev | 8 +++++--- .local/bin/tmux-notes-switch | 13 +++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100755 .local/bin/tmux-notes-switch diff --git a/.config/tmux/conf/binds.conf b/.config/tmux/conf/binds.conf index d94302b0..919700d8 100644 --- a/.config/tmux/conf/binds.conf +++ b/.config/tmux/conf/binds.conf @@ -61,5 +61,5 @@ bind -r ">" swap-window -d -t +1 # Projects bind-key Enter popup -E -h 80% -w 80% "dev" -# Notes Session -bind-key n run "tmux switch-client -t 'notes-tasks'" +# Switch from Notes/Tasks Session with last session +bind-key n run "tmux-notes-switch" diff --git a/.local/bin/dev b/.local/bin/dev index d8f36f04..91b3e612 100755 --- a/.local/bin/dev +++ b/.local/bin/dev @@ -19,14 +19,14 @@ yaml_config() { tmuxp_load() { launch_docs if [[ -n "$TMUX" ]]; then - tmuxp load -d "$selected_dir" + tmuxp load -y "$selected_dir" zoxide_score else tmuxp load "$selected_dir" zoxide_score fi - tmux switch-client -t "$tab_title" + # tmux switch-client -t "$tab_title" } handle_tmuxp() { @@ -65,7 +65,9 @@ zoxide_score() { } launch_docs() { - tmuxp load -d notes-tasks # Doesn't load if it exists already + if ! tmux has-session -t "$SESSION_NOTES" 2>/dev/null; then + tmuxp load -d notes-tasks + fi } selected_dir=$($projects_command | $fzf_command --prompt='Select a directory: ' \ diff --git a/.local/bin/tmux-notes-switch b/.local/bin/tmux-notes-switch new file mode 100755 index 00000000..671f1fa4 --- /dev/null +++ b/.local/bin/tmux-notes-switch @@ -0,0 +1,13 @@ +#!/bin/bash + +SESSION_NOTES="notes-tasks" + +if [ "$(tmux display-message -p '#S')" == "$SESSION_NOTES" ]; then + tmux switch-client -l +else + if tmux has-session -t "$SESSION_NOTES" 2>/dev/null; then + tmux switch-client -t "$SESSION_NOTES" + else + tmuxp load -y "$SESSION_NOTES" + fi +fi