From 8b2099aa407eeb10d579e0fed262a70b48150fb8 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Mon, 12 Dec 2022 11:52:32 +0100 Subject: [PATCH] Improve splitting session for workstation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Attach to session if it already exists Don't attach to new window/pane by default Improve usage of TARGET_PANE Kill default session … --- splitWORKSTATION | 69 +++++++++++++++++++++++++++++++----------------- tmux.conf | 2 +- 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/splitWORKSTATION b/splitWORKSTATION index 176bfb2..9618224 100644 --- a/splitWORKSTATION +++ b/splitWORKSTATION @@ -1,30 +1,51 @@ -#### Session -------------------------------------------------------------- -# -sX : numéro de la session -# -nNOM_TERMINAL : nom du terminal -# -d : indique à tmux de ne pas attacher la session et de ne pas prendre les -# nouvelles fenêtres comme une fenêtre courante -# -tX:Y : modifier les paramètres de la fenêtre Y de la session X. !Attention -# la fenêtre doit exister avant de pouvoir modifier ses paramètres! +### Session -------------------------------------------------------------- +# -sXX : XX session ID or name +# -nWINDOW_NAME : Name of the window… +# -d : Don't attache to the new session/window/pane/… +# -tXX:YY.ZZ : +# XX : session ID or name +# YY : (optional) Window ID +# ZZ : (optional) Pane ID +# YY and ZZ should exists to be able to change the parameters,… # monitor-activity : permet de mettre en avant une fenêtre quand son contenu reçoit un événement # 'exec ${SHELL}' : Allow to keep the pane running after the program exists -# New session for working station +# Manage session named **jd** for working station -# New session with a first window with 2 panes in 42 debops project -new -A -sjd -n42 -splitw -h -t1 -c '/home/jegardai/repos/101010.debops' -select-pane -t 1 -# Second window with 2 panes in IPR debops project -neww -d -nIPR -c '/home/jegardai/repos/ipr.debops' -select-window -t 2 -splitw -h -c '/home/jegardai/repos/ipr.debops' -select-pane -t 1 -# Third window in home -#neww -d -c '/home/jegardai/' +# If a session already exists {{{ +if-shell -b 'tmux has-session -t jd' { + display-message "Attach to **jd** existing session" + ## Attach to the first pane of the first window + attach-session -t jd:1.1 +} +# }}} +# If no session already exists +if-shell '! tmux has-session -t jd' { + display-message "Create a new session for Workstation" + # A first window named **42** + new-session -A -sjd -n42 + ## Split the first window and move to 42 debops project + split-window -d -h -tjd:1.1 -c '/home/jegardai/repos/101010.debops' + ## Split again the first window and move to 42 debops project + split-window -v -tjd:1.1 -c '/home/jegardai/repos/101010.debops' + # Kill first pane of the first window + # Little trick to avoid to set this directory as default for any new pane… + kill-pane -tjd:1.1 -# Default window: jd:0 -select-window -t 1 -select-pane -t 1 + # Second window named **IPR** + new-window -d -nIPR -c '/home/jegardai/repos/ipr.debops' + # with 2 panes in IPR debops project + split-window -d -h -tjd:2.1 -c '/home/jegardai/repos/ipr.debops' + # Third window in home + #new-window -d -# Kill default created session -kill-session -t 0 + # Default window should be jd:1 + #select-window -t 1 + # Default pane should be jd:1.1 +} +# If a default session still exists {{{ +if-shell -b 'tmux has-session -t 0' { + # Kill it + kill-session -t 0 +} +# }}} diff --git a/tmux.conf b/tmux.conf index ef288e9..80ce299 100644 --- a/tmux.conf +++ b/tmux.conf @@ -243,7 +243,7 @@ set -g lock-after-time 1800 if 'command -v cmatrix' 'set -g lock-command "cmatrix -s && physlock"' 'set -g lock-command physlock' # Initialize sessions -bind I source-file ~/.tmux/splitWORKSTATION\; display-message "tmux split for Work" +bind I source-file ~/.tmux/splitWORKSTATION bind V source-file ~/.tmux/split101010\; display-message "tmux split for 101010" bind H source-file ~/.tmux/splitHP\; display-message "tmux split for HP"