File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -52,3 +52,9 @@ switch_to_session() {
5252 local session_name=" $1 "
5353 tmux switch-client -t " $session_name "
5454}
55+
56+ number_of_session_collisions () {
57+ tmux -S " $( tmux_socket) " list-sessions | grep -c " $1 "
58+ # this is a temporary implementation, a session might have a similar name or have a name with a higher value than the number of collision
59+ # I need help fixing those potential issues
60+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ source "$CURRENT_DIR/helpers.sh"
77# global vars passed to the script as arguments
88CURRENT_SESSION_ID=" $1 "
99CURRENT_PANE_ID=" $2 "
10+ PANE_CURRENT_COMMAND=" $3 "
1011PANE_CURRENT_PATH=" $4 "
1112
1213number_of_panes () {
@@ -24,13 +25,24 @@ new_session_pane_id() {
2425 tmux list-panes -t " $session_id " -F " #{pane_id}"
2526}
2627
28+ rename_session_to_pane () {
29+ local new_session_name=" $PANE_CURRENT_COMMAND "
30+ [ " $new_session_name " == " tmux" ] &&
31+ new_session_name=" $( echo " $PANE_CURRENT_PATH " | sed ' s/.*\/\([^/]*\)$/\1/' ) "
32+ [ -z " $new_session_name " ] &&
33+ new_session_name=" /"
34+ name_collisions=" $( number_of_session_collisions " $new_session_name " ) "
35+ [ " $name_collisions " -gt 0 ] &&
36+ new_session_name=" $new_session_name -$(( name_collisions+ 1 )) "
37+ tmux rename-session -t " $1 " " $new_session_name "
2738}
2839
2940promote_pane () {
3041 local session_id=" $( create_new_session) "
3142 local new_session_pane_id=" $( new_session_pane_id " $session_id " ) "
3243 tmux swap-pane -s " $CURRENT_PANE_ID " -t " $new_session_pane_id "
3344 tmux kill-pane -t " $new_session_pane_id "
45+ rename_session_to_pane " $session_id "
3446 switch_to_session " $session_id "
3547}
3648
Original file line number Diff line number Diff line change @@ -25,13 +25,20 @@ new_session_window_id() {
2525 tmux list-windows -t " $session_id " -F " #{window_id}"
2626}
2727
28+ rename_session_to_window () {
29+ local new_session_name=" $CURRENT_WINDOW_NAME "
30+ name_collisions=" $( number_of_session_collisions " $new_session_name " ) "
31+ [ " $name_collisions " -gt 0 ] &&
32+ new_session_name=" $new_session_name -$(( name_collisions+ 1 )) "
33+ tmux rename-session -t " $1 " " $new_session_name "
2834}
2935
3036promote_window () {
3137 local session_id=" $( create_new_session) "
3238 local new_session_window_id=" $( new_session_window_id " $session_id " ) "
3339 tmux swap-window -s " $CURRENT_WINDOW_ID " -t " $new_session_window_id "
3440 tmux kill-window -t " $new_session_window_id "
41+ rename_session_to_window " $session_id "
3542 switch_to_session " $session_id "
3643}
3744
You can’t perform that action at this time.
0 commit comments