3 ms·
This is a set of alias/functions that I use to setup tmux and my ssh connections, I'm always in tmux be it locally or in ssh, it survive session disconnections.
by tupolef 4y ago
This is a set of alias/functions that I use to setup tmux and my ssh connections, I'm always in tmux be it locally or in ssh, it survive session disconnections.
# full terminal page of \n
pgdown () {
printf '\n%.0s' $(eval echo {1..$(( $(tput lines) - 1 ))})
}
# clear teminal and TMUX history and get to the bottom line
c () {
echo -en "\ec"; pgdown
if [[ -n $TMUX_PANE ]]; then
tmux clear-history -t $TMUX_PANE
fi
}
# force MOTD display in a new ssh session
alias sshmotd='ssh -o SetEnv=SSH_MOTD=1'
if command -v tmux 1> /dev/null; then
# open a new tmux session named default or attach to it
tmuxa () {
systemd-run -q --scope --user tmux new-session -A -s default "$@"
exit
}
# open a new tmux session named ssh_tmux or attach to it
alias tmuxs='tmux new-session -A -s ssh_tmux && exit'
# run tmux if TMUX variable is null locally or in an ssh session
if [[ "${TERM-}" != tmux* ]] && [[ -z "${TMUX}" ]] && [[ -z "${SSH_CONNECTION}" ]]; then
tmuxa
elif [[ -z "${TMUX}" ]] && [[ -n "${SSH_CONNECTION}" ]]; then
tmuxs
fi
fi
# run MOTD at login only in an ssh session
if [[ -n "${TMUX}" ]] && [[ -n "${SSH_CONNECTION}" ]] && [[ "${SSH_MOTD-}" == 1 ]] && [[ -f "/etc/update-motd.d/00-motdfetch" ]]; then
motd
else
pgdown
fi