Skip to content

Instantly share code, notes, and snippets.

@samsalisbury
Last active January 19, 2016 12:00
Show Gist options
  • Save samsalisbury/f4e60048074889e78a04 to your computer and use it in GitHub Desktop.
Save samsalisbury/f4e60048074889e78a04 to your computer and use it in GitHub Desktop.
connect: My SSH interactive session connection script
#!/bin/sh
# I keep scripts like this in $HOME/bin and add that dir to my
# path, so I can call e.g. `connect some.host.com` from anywhere.
[ -z "$1" ] && {
echo "usage: $0 <hostname>"; exit 3
}
REMOTE_TMUX_SESSION_NAME=Sam
exec ssh -t "$1" '
# Emulate standard logon procedure
load() { [ -f "$1" ] && { . "$1"; echo "Loaded $1"; } || echo "Not loaded: $1"; }
load /etc/profile
load ~/.profile
load ~/.bash_profile
load ~/.bashrc
export EDITOR=vim
export TERM=xterm-256color
# If we do not have tmux installed, just start bash in vi mode
command -v tmux 2>&1>/dev/null || { /bin/bash -o vi; exit $?; }
# Truncate and then write ~/.tmux.conf
: > ~/.tmux.conf
tmux_conf () { echo "$@" >> ~/.tmux.conf; }
tmux_conf set -g base-index 1
tmux_conf set -g pane-base-index 1
tmux_conf setw -g aggressive-resize on
tmux_conf set -g history-limit 50000
tmux_conf set -g display-time 4000
tmux_conf setw -g utf8 on
tmux_conf set -g status-utf8 on
tmux_conf setw -g mode-keys vi
# Start a new session named '$REMOTE_TMUX_SESSION_NAME' or attach to it if it exists (-A)
tmux new-session -ADs '$REMOTE_TMUX_SESSION_NAME' "/bin/bash -o vi"
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment