tmux session ssh add hosts from history

This commit is contained in:
thek4n 2024-10-17 15:27:30 +03:00
parent 2a4f583d33
commit a85249e473

View File

@ -3,8 +3,10 @@
set -eu
SSH_SERVERS="$(grep 'Host ' "${HOME}/.ssh/config" | sed 's/^Host //')"
HOSTS=$(grep -v '^#' /etc/hosts)
ALL_HOSTS="$(echo "$SSH_SERVERS" "$HOSTS" | grep -v '\*'| sed 's/ /\n/g' | sed '/^$/d' | sort | uniq)"
HOSTS="$(grep -v '^#' /etc/hosts)"
HISTORY_HOSTS="$(grep ssh "${HOME}/.zsh_history" | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')"
ALL_HOSTS="$(echo "$SSH_SERVERS" "$HOSTS" "$HISTORY_HOSTS" | grep -v '\*'| sed 's/ /\n/g' | sed '/^$/d' | sort | uniq | tac)"
SSH_SERVER="$(echo -n "$ALL_HOSTS" | fzf +m --print-query --bind 'tab:replace-query' | tail -n 1)"