From fc639f1fe4d5d0c6b01c78da6d57cb4ba4d2a9f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Jane=C5=BEi=C4=8D?= Date: Thu, 1 Feb 2024 14:48:34 +0100 Subject: [PATCH] feat(tmux): tmux-ssher wip --- .gitignore | 1 + tmux/tmux-ssher | 25 +++++++++++++++++++++++++ tmux/tmux.conf | 5 +---- 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100755 tmux/tmux-ssher diff --git a/.gitignore b/.gitignore index 8c05a0d..25bc181 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ tmux/* !tmux/tmux.conf !tmux/tmux-sessionizer !tmux/tmux-ggclone +!tmux/tmux-ssher # git !git diff --git a/tmux/tmux-ssher b/tmux/tmux-ssher new file mode 100755 index 0000000..7893ca5 --- /dev/null +++ b/tmux/tmux-ssher @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +if [[ $# -eq 1 ]]; then + selected=$1 +else + selected=$(grep "Host .*" ~/.ssh/config | grep -v "*" | sed "s/Host \(.*\)/\1/" | fzf --cycle --bind 'tab:toggle-up,btab:toggle-down') +fi + +if [[ -z $selected ]]; then + exit 0 +fi + +selected_name="ssh_$selected" +tmux_running=$(pgrep tmux) + +if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then + tmux new-session -s $selected_name -c $selected ssh "$selected" + exit 0 +fi + +if ! tmux has-session -t=$selected_name 2> /dev/null; then + tmux new-session -ds $selected_name -c $selected ssh "$selected" +fi + +tmux switch-client -t $selected_name diff --git a/tmux/tmux.conf b/tmux/tmux.conf index 058a7c6..8eabe85 100644 --- a/tmux/tmux.conf +++ b/tmux/tmux.conf @@ -34,11 +34,8 @@ bind -r j select-pane -D bind -r h select-pane -L bind -r l select-pane -R -bind -r D neww -c "#{pane_current_path}" "nvim TODO.md" -bind -r t neww -c "~" "nvim ~/.TODO.md" - bind-key -r f run-shell "tmux neww ~/.config/tmux/tmux-sessionizer" -bind-key -r g run-shell "tmux neww ~/.config/tmux/tmux-sessionizer $XDG_CONFIG_HOME" +bind-key -r F run-shell "tmux neww ~/.config/tmux/tmux-ssher" bind-key -r T run-shell "tmux neww ~/.config/tmux/tmux-sessionizer ~/temp" bind-key -r R run-shell "tmux neww ~/.config/tmux/tmux-sessionizer ~" bind-key -r G run-shell "tmux neww ~/.config/tmux/tmux-ggclone"