#!/bin/sh #!/bin/sh # shellcheck disable=2016,2089 if [ "$#" -eq 0 ]; then ATTACHED=$(tmux display -p '#{session_path}') # shellcheck disable=2046 set -- $( grep -P '^[Hh]ost ([^*]+)$' "$HOME/.ssh/config" | grep -Po ' \K(\w+)' | sed "\|^$HOST\$|d" | sed "\|^${ATTACHED#SSH_}\$|d" | sort -u | timestamp.sh --type="ssh" --format="{}:{1}" | sort -r | cut -d':' -f2 | fzf-tmux "$FZF_TMUX_OPTS" -- --multi --print-query -d/ --with-nth -1 | tr -s '\n' ' ' ) && [ $# -gt 1 ] && shift fi while [ $# -gt 0 ]; do ssh_host="$1" shift name="SSH_$ssh_host" if ! tmux has-session -t "$name" 2>/dev/null; then tmux new-session -ds "$name" ssh -t "$ssh_host" # 'tmux new -As $USER' fi done if [ -z "$TMUX" ] && [ -z "$name" ]; then tmux attach-session -t "$name" elif tmux has-session -t="$name" 2>/dev/null; then tmux switch-client -t "$name" fi