Skip to content

Instantly share code, notes, and snippets.

@ClassicOldSong
Last active November 21, 2023 22:49
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClassicOldSong/c9d43e199a8929ad8d783e8a3bc3793b to your computer and use it in GitHub Desktop.
Save ClassicOldSong/c9d43e199a8929ad8d783e8a3bc3793b to your computer and use it in GitHub Desktop.
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