#!/bin/sh #!/bin/sh # shellcheck disable=2016,2089 if [ "$#" -eq 0 ]; then ATTACHED=$(tmux display -p '#{session_path}') lines=$(tmux display -p "#{pane_height}") columns=$(tmux display -p "#{pane_width}") WIDTH=$([ "$columns" -gt "20" ] && printf %s "20" || printf %s "90%") HEIGHT=$([ "$lines" -gt "15" ] && printf %s "15" || printf %s "90%") # 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 -p "$WIDTH,$HEIGHT" -- --multi --print-query -d/ --with-nth -1 | tr -s '\n' ' ' ) && [ $# -gt 1 ] && shift fi exit 0 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