Zucca
Group: Members
Posts: 524
Joined: Feb. 2006 |
|
Posted: Oct. 17 2007,09:29 |
|
Here's an example how I use this dialoghelper in my Gentoo system. This is a .bashrc file of my root account:
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.;)
|
Why I made this script is that I sometimes forget to start screen session. If I happen to start a long process in X terminal it will be killed if I close it or exit X (for those who are unfamiliar with screen:all processes started inside screen session will not be terminated even if you close your X terminal). This script really makes me to remember to start screen session. ;) It's one of the most useful scripts I have made for myself. At least I think it's really neat. ;P
Before there was no choice not to start screen when logged as root now, with help of dialoghelper, there is. Of course you could do that without dialog... ;) But this is just simple example of the use of dialoghelper. I'll be adding new features to it and compability with DSL's whiptail too.
-------------- Do you have it? - http://dy.fi/mak
|