summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-09-16 12:19:12 -0500
committerToby Vincent <tobyv13@gmail.com>2022-09-16 12:19:12 -0500
commit7c5a4742466c2d3e7358a93224b2bd918b14eae8 (patch)
treee9fac1ce82c4d9f4d6a75b44befdf333472d3234
parent37c2542e5da96b87f010009771d235e23305fdc2 (diff)
feat(tmux): start work on ssh-based sessionizer
-rw-r--r--tmux/.config/tmux/tmux.conf15
-rwxr-xr-xtmux/.local/bin/tmux-ssh18
2 files changed, 24 insertions, 9 deletions
diff --git a/tmux/.config/tmux/tmux.conf b/tmux/.config/tmux/tmux.conf
index b244289..3d30a5e 100644
--- a/tmux/.config/tmux/tmux.conf
+++ b/tmux/.config/tmux/tmux.conf
@@ -17,16 +17,13 @@ set -g detach-on-destroy off
bind-key -N "Open new window" t new-window
bind-key -N "Show a clock" T clock-mode
-bind-key -N "Open project in new session" f run-shell ~/.local/bin/tmux-sessionizer
-bind-key -N "Switch between sessions" F run-shell ~/.local/bin/tmux-sessions
+bind-key -N "New ssh host" s run-shell ~/.local/bin/tmux-ssh
+# bind-key -N "Switch ssh host" S run-shell ~/.local/bin/tmux-ssh
+bind-key -N "New session" f run-shell ~/.local/bin/tmux-sessionizer
+bind-key -N "Switch session" F run-shell ~/.local/bin/tmux-sessions
bind-key -N "Open neovim" e new-window -Sn nvim nvim
-bind-key -N "Open spotify in popup" s display-popup -w 90% -h 90% -E spt
-bind-key -N "Open spotify in new window" S new-window -S spt
-# TODO: fix issue with tmux popups using the tmux-server's parent env (in this case, wsl spawn env?)
-# https://www.reddit.com/r/tmux/comments/r3hfy0/tmux_popup_does_not_load_zshrc/
-# bind-key -N "Open lazygit in popup" g display-popup -w 90% -h 90% -E lazygit
-bind-key -N "Open lazygit" g send-keys "lazygit" Enter
-bind-key -N "Open lazygit in new window" G new-window -S lazygit
+bind-key -N "Open spotify" m display-popup -w 90% -h 90% -E spt
+bind-key -N "Open lazygit" g display-popup -w 90% -h 90% -E lazygit
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
diff --git a/tmux/.local/bin/tmux-ssh b/tmux/.local/bin/tmux-ssh
new file mode 100755
index 0000000..2dedc53
--- /dev/null
+++ b/tmux/.local/bin/tmux-ssh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+setopt localoptions nonomatch
+tmp="$(mktemp)"
+
+tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2>/dev/null | grep -i '^\s*host ' |
+ awk '{for (i = 2; i <= NF; i++) print "ssh_config " $i}' | grep -v '[*?%]' >"$tmp"
+
+grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | tr -d '[' | awk '{ print "known_hosts " $1 }' >"$tmp"
+grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0' >"$tmp"
+cat "$tmp"
+exit 0
+while IFS= read -r host; do
+ hosts="$hosts $host"
+done <"$tmp"
+rm "$tmp"
+
+printf %s\\n "$hosts" | xargs -I{} -d ' ' printf %s\\n {}