code: Select all
#!/usr/bin/ksh
##################################### User Editable Section #####################################
WTERM_TMP="/tmp" # Directory for temporary files (must be writable)
WTERM_TERMCMD="xterm -sb -geometry 131x50+200+150" # Terminal arguments (usually xterm)
WTERM_TERMTITLEARG="-title" # In case you aren't using xterm
WTERM_TERMEXECARG="-e" # In case you aren't using xterm
WTERM_NAME="Wonderterm" # Initial title of Wonderterm
WTERM_ROOT="0" # Whether to become root (1: yes, 0: no) -- requires sudo
##################################### End User Editable Section #####################################
USER=${LOGNAME:=`whoami`}
WTERM_BNAME=`basename "$WTERM_CMD"`
WTERM_LOCK="$WTERM_TMP/$USER-$WTERM_BNAME-lock"
WTERM_WM=`which wmctrl`
if [ "$WTERM_ROOT" == "1" ]; then
WTERM_ROOT="sudo "
else
WTERM_ROOT=" "
fi
WTERM_XCMD="$WTERM_ROOT$SHELL; rm -f $WTERM_LOCK"
# TODO:
# * Completely hide windows (not all WMs)
# * When window loses focus, bring it back on repeat action
function killcl {
pid=`ps -ef | grep "$WTERM_TCMD" | awk '{print $2}'`
kill $pid 2>/dev/null
kill -9 $pid 2>/dev/null
rm -f $WTERM_LOCK
}
if [ "$1" != "bkgd" ]; then
$0 bkgd $@ &
exit
fi
if [ "$2" == "cl" ]; then
killcl
exit
fi
if [ -e $WTERM_LOCK ]; then
# Toggle
id=`cat $WTERM_LOCK`
if [ "$id" == "" ]; then
sleep 0.5
id=`cat $WTERM_LOCK`
if [ "$id" == "" ]; then
killcl
fi
fi
$WTERM_WM -i -r $id -b toggle,below
$WTERM_WM -i -R $id
else
# Launch
$WTERM_TERMCMD $WTERM_TERMTITLEARG "$WTERM_NAME" $WTERM_TERMEXECARG "$WTERM_XCMD" 1>/dev/null 2>/dev/null &
id=`$WTERM_WM -l | grep "$WTERM_NAME" | awk '{print $1}'`
echo $id > $WTERM_LOCK
$WTERM_WM -i -r $id -b add,skip_taskbar
if [ "$?" != "0" ]; then
sleep 0.5
id=`$WTERM_WM -l | grep "$WTERM_NAME" | awk '{print $1}'`
echo $id > $WTERM_LOCK
$WTERM_WM -i -r $id -b add,skip_taskbar
if [ "$?" != "0" ]; then
killcl
fi
fi
fiThis script depends on wmctrl.
Configuration for a root-terminal version of the same thing:
.wsuterm.sh:
code: Select all
##################################### User Editable Section #####################################
WTERM_TMP="/tmp" # Directory for temporary files (must be writable)
WTERM_TERMCMD="xterm -sb -geometry 131x50+200+150" # Terminal arguments (usually xterm)
WTERM_TERMTITLEARG="-title" # In case you aren't using xterm
WTERM_TERMEXECARG="-e" # In case you aren't using xterm
WTERM_NAME="Wonder-su-term" # Initial title of Wonderterm
WTERM_ROOT="1" # Whether to become root (1: yes, 0: no) -- requires sudo
##################################### End User Editable Section #####################################code: Select all
<username> ALL=(ALL) NOPASSWD: ALLThen you can hook that up to another key such as F10.
[edit] If you use .wsuterm, MAKE SURE its title is not a substring of the other's title!
Its main limitation is that once you alt-tab away from it, when you switch back, it doesn't know it's not focused. I used xprop to try to rectify this, but it seems at this time there's no good workaround (unless one were to actually write an app, not a shell script, which wouldn't be such a good idea in this case).
Oh yes: please let me know if you have suggestions, etc. for further "releases". Is it useful to you in your day-to-day work?
~Beatles
[edit] Made slight change.