mirror of
https://github.com/theniceboy/.config.git
synced 2025-12-26 14:44:57 +08:00
tmux: prefix+number to move window to session#
This commit is contained in:
parent
2f240f9ab6
commit
62fd493769
3 changed files with 45 additions and 10 deletions
20
.tmux.conf
20
.tmux.conf
|
|
@ -167,16 +167,16 @@ bind -T copy-mode-vi M-V send-keys -X cancel \; run -b "~/.config/tmux/scripts/p
|
|||
bind -T copy-mode M-V send-keys -X cancel \; run -b "~/.config/tmux/scripts/paste_from_clipboard.sh"
|
||||
|
||||
# pane navigation
|
||||
bind 1 select-pane -t:.1
|
||||
bind 2 select-pane -t:.2
|
||||
bind 3 select-pane -t:.3
|
||||
bind 4 select-pane -t:.4
|
||||
bind 5 select-pane -t:.5
|
||||
bind 6 select-pane -t:.6
|
||||
bind 7 select-pane -t:.7
|
||||
bind 8 select-pane -t:.8
|
||||
bind 9 select-pane -t:.9
|
||||
bind 0 select-pane -t:.10
|
||||
bind 1 run-shell "~/.config/tmux/scripts/move_window_to_session.sh 1"
|
||||
bind 2 run-shell "~/.config/tmux/scripts/move_window_to_session.sh 2"
|
||||
bind 3 run-shell "~/.config/tmux/scripts/move_window_to_session.sh 3"
|
||||
bind 4 run-shell "~/.config/tmux/scripts/move_window_to_session.sh 4"
|
||||
bind 5 run-shell "~/.config/tmux/scripts/move_window_to_session.sh 5"
|
||||
bind 6 run-shell "~/.config/tmux/scripts/move_window_to_session.sh 6"
|
||||
bind 7 run-shell "~/.config/tmux/scripts/move_window_to_session.sh 7"
|
||||
bind 8 run-shell "~/.config/tmux/scripts/move_window_to_session.sh 8"
|
||||
bind 9 run-shell "~/.config/tmux/scripts/move_window_to_session.sh 9"
|
||||
bind 0 run-shell "~/.config/tmux/scripts/move_window_to_session.sh 10"
|
||||
bind -n M-n select-pane -L
|
||||
bind -n M-e select-pane -D
|
||||
bind -n M-u select-pane -U
|
||||
|
|
|
|||
9
tmux/scripts/move_window_to_session.sh
Executable file
9
tmux/scripts/move_window_to_session.sh
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
index="$1"
|
||||
|
||||
if [[ -z "$index" || ! "$index" =~ ^[0-9]+$ ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
python3 "$HOME/.config/tmux/scripts/session_manager.py" move-window-to "$index"
|
||||
|
|
@ -71,6 +71,10 @@ def current_session_id() -> str:
|
|||
return run_tmux(["display-message", "-p", "#{session_id}"], capture=True)
|
||||
|
||||
|
||||
def current_window_id() -> str:
|
||||
return run_tmux(["display-message", "-p", "#{window_id}"], capture=True)
|
||||
|
||||
|
||||
def command_switch(index_str: str) -> None:
|
||||
try:
|
||||
index = int(index_str)
|
||||
|
|
@ -126,6 +130,26 @@ def command_created() -> None:
|
|||
command_ensure()
|
||||
|
||||
|
||||
def command_move_window_to_session(index_str: str) -> None:
|
||||
try:
|
||||
index = int(index_str)
|
||||
except ValueError:
|
||||
return
|
||||
if index < 1:
|
||||
return
|
||||
sessions = list_sessions()
|
||||
if index > len(sessions):
|
||||
return
|
||||
target_session_id = sessions[index - 1]["id"]
|
||||
source_window_id = current_window_id()
|
||||
if not source_window_id:
|
||||
return
|
||||
current_id = current_session_id()
|
||||
if target_session_id != current_id:
|
||||
run_tmux(["move-window", "-s", source_window_id, "-t", f"{target_session_id}:"], check=False)
|
||||
run_tmux(["switch-client", "-t", target_session_id], check=False)
|
||||
|
||||
|
||||
def main(argv: List[str]) -> None:
|
||||
if len(argv) < 2:
|
||||
return
|
||||
|
|
@ -140,6 +164,8 @@ def main(argv: List[str]) -> None:
|
|||
command_ensure()
|
||||
elif command == "created":
|
||||
command_created()
|
||||
elif command == "move-window-to" and len(argv) >= 3:
|
||||
command_move_window_to_session(argv[2])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue