Show an fzf menu on interactive SSH login, then start a normal shell, create a new tmux session, or attach to an existing tmux session.
This is useful for small remote machines where SSH should land directly in the right long-running workspace.
tmuxfzf- A POSIX-compatible shell
The script is written for /bin/sh. The login hook examples below cover zsh and bash.
mkdir -p ~/.local/bin
curl -fsSL https://gist.githubusercontent.com/golbin/2842fab87515ce56b3bb1a216f8c433e/raw/ssh-start-menu.sh -o ~/.local/bin/ssh-start-menu
chmod +x ~/.local/bin/ssh-start-menuFor zsh, add this to ~/.zprofile:
if [ -n "${SSH_TTY:-}" ] && [ -z "${TMUX:-}" ] && [ -x "$HOME/.local/bin/ssh-start-menu" ]; then
"$HOME/.local/bin/ssh-start-menu"
fiFor bash, add this to ~/.bash_profile:
if [ -n "${SSH_TTY:-}" ] && [ -z "${TMUX:-}" ] && [ -x "$HOME/.local/bin/ssh-start-menu" ]; then
"$HOME/.local/bin/ssh-start-menu"
fiIf Korean or other multibyte text works in a plain SSH shell but breaks inside tmux, make tmux start sessions with an explicit UTF-8 locale.
The script uses tmux -u for session listing, session creation, and attach. This forces tmux to treat the client terminal as UTF-8 capable.
Add this to ~/.tmux.conf:
set -g update-environment "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
set-environment -g LANG ko_KR.UTF-8
set-environment -g LC_CTYPE ko_KR.UTF-8
set-environment -g LC_ALL ko_KR.UTF-8
set -g default-terminal "tmux-256color"Then restart existing tmux sessions, or reload the config and open a new pane:
tmux source-file ~/.tmux.confExisting tmux clients keep their old UTF-8 flag. Detach and attach again through this menu after changing the script or config.
You can check the current client flag with:
tmux list-clients -F '#{client_name} #{client_termname} #{client_utf8}'The last value should be 1.
The menu appears only for an interactive SSH login with a terminal attached.
It does not run:
- outside SSH
- inside an existing
tmuxsession - for non-interactive commands such as
ssh host command,scp, orrsync
Menu choices:
New shell: continue into the normal login shellNew tmux session: create or attach to a named sessionAttach: <session>: attach to an existing session
If fzf is missing, the script falls back to:
tmux new-session -A -s mainThe script uses full-screen fzf mode and --no-unicode to avoid layout glitches in mobile SSH clients when the software keyboard changes the terminal height.
It also sets LANG and LC_CTYPE to an available UTF-8 locale when the SSH login environment is not already UTF-8. This keeps Korean and other multibyte text readable in fzf.
If the menu still renders incorrectly, check:
echo "$TERM"
echo "$LANG"
echo "$LC_ALL"
stty size
infocmp "$TERM" >/dev/null && echo ok || echo missingMIT