Code Sample |
#!/bin/bash # If user is not in screen session AND file $HOME/.noscreen does not exist... if [ -z `echo "$TERM" | grep screen` ] && [ ! -f "$HOME/.noscreen" ] then # Ask user if he/she wants to start/continue a screen session. if source /usr/local/lib/dialoghelper && D_BACKTITLE="Starting a root session..." D_TITLE="Question" yesnoDialog "Start/Continue a screen session?" then # Retach screen or start new screen session. # Also run 'clear' after screen exit for security. # Yes. It's a long line. It could be more neat, but I'm lazy. screen -dr && clear && exit \ || ps -U `whoami` -u `whoami` | grep screen > /dev/null \ && echo -e "\nProblems starting screen. Now running offscreen. :(" \ || screen && clear && exit \ || echo -e "\nCould not start screen. Do you have screen installed and is screen in your $PATH?" fi # No else here. Do nothing if user chose not to start or continue screen session. else # Otherwise tell user that $HOME/.noscreen is present or he/she just opened a new screen window. # Yes. A long line again. test -f "$HOME/.noscreen" && test -z `echo "$TERM" | grep screen` \ && echo -e "File $HOME/.noscreen exist, no screen startup.\n run 'screen' to start new screen session, or 'screen -dr' to continue previous session." fi clear # Show user the $TERM and tell that it's a new window. # (I myself wanted to see this in every new screen window.) echo $TERM | grep "screen" > /dev/null \ && echo -e "New screen window opened.\nTerminal: $TERM" && sleep 1s \ || echo -e "Root session opened offscreen.\nTerminal: $TERM" # I added a one sec pause there to show user that the new window # was _just_ opened. Useless... Maybe. # Next line is just to load aliases # I have same aliases for my root account.;) test -f "/home/zucca/.aliases" && source /home/zucca/.aliases echo -e "Ready.\n" # I hope you can read how this script works.;) |