Last active
December 8, 2015 18:15
-
-
Save pol/2ac9f27ad6c5b0c5a592 to your computer and use it in GitHub Desktop.
sudo into root with a tmux session, default to a new session named with the date. Otherwise, do sensible things (ls will list root tmux sessions).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this will open up a root prompt inside a tmux session | |
# if nothing is given, open up a new tmux session with current datetime | |
# if a string is given, attach or new depending on if the session already exists | |
# Note: this will probably cause trouble if multiple people are using it. Recommend | |
# namespacing the sessions with your username. | |
function root () { | |
name=$1 | |
session="new -s" | |
if [ -z "$name" ]; then | |
name=$(date +%Y-%m-%d-%H%M) | |
elif [ "$name" = "ls" ]; then | |
unset name | |
elif [ -n "$(sudo -i tmux ls -F "#S" | grep "^$name")" ]; then | |
session="attach -t" | |
fi | |
if [ -n "$name" ]; then | |
cmd="tmux $session $name" | |
else | |
cmd="tmux ls" | |
fi | |
echo $cmd | |
sudo -i $cmd | |
unset name session | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment