Skip to content

Instantly share code, notes, and snippets.

@ClassicOldSong
Last active Jul 5, 2021
Embed
What would you like to do?
Use tmux as your login shell
#!/bin/bash
# Usage:
# Download this file
# Put it in /bin or wherever you want, eg: `/bin/tmuxlogin`
# Give it excutable permission, eg: `sudo chmod +x /bin/tmuxlogin`
# Modify your `/etc/shells` and add `/bin/tmuxlogin` to it
# Modify your `~/.tmux.conf` and add `set-option -g default-shell /bin/bash(or whatever shell you want)` to it
# `chsh -s /bin/tmuxlogin`
# Done!
# Define colors
YELLOW="\033[0;93m"
GREEN="\033[0;32m"
CYAN="\033[0;36m"
RED="\033[0;31m"
NC="\033[0m"
# Do not attach when using a local terminal emulator or tty
if [ "$SSH_CLIENT" == "" ]; then
/usr/bin/tmux new
exit $?
fi
# Switch to bash when there's arguments exist
# such as `scp' or `sftp' or `ssh -t'
if [ "$1" != "" ]; then
exec -l /bin/bash "$@"
fi
# Add a pause for displaying motd
echo -e "\n$GREEN[ Press any key to continue ]\n$YELLOW"
read -n 1 -s -r
/usr/bin/tmux attach || /usr/bin/tmux new
EXITSTATUS=$?
echo -e $NC
exit $EXITSTATUS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment