Instant Aereal Terminal

You can talk about anything here, not necessarily game-related. You may also advertise here.
Post Reply
User avatar
The Beatles
Fear me for I am root
Posts: 6285
Joined: Tue May 24, 2005 8:12 pm

Post by The Beatles »

.wterm.sh

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
fi
I've hooked this up to my F9 key on my XFCE desktop, and I must say, in the few hours I've used it, it's already become my "panic-button". Having an "instant terminal" all ready is quite nice. To use, just copy it to .wterm.sh in your home directory, make it executable, and hook it up to some keyboard shortcut. Note the TODO! Don't Alt-Tab away from it, always use the keyboard shortcut to toggle its state. It backgrounds itself for greater speed, and is graceful in recovering from errors. When you close all windows, it is visible at the bottom -- this is partly a limitation and partly a feature.

This 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 #####################################
For this to be quite handy, it's useful to set up /etc/sudoers to contain a line:

code: Select all

<username>        ALL=(ALL) NOPASSWD: ALL
(make sure no subsequent lines override it, e.g. wheel group, etc.)
Then 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.
:wq
User avatar
Fresh Water Fighters
Legendary River Dog
Posts: 838
Joined: Sat Mar 20, 2004 1:07 pm
Location: Thialand (But I come form New Zealand)

Post by Fresh Water Fighters »

whats it for?
User avatar
Nohc
Beware of Former Fangirls
Posts: 941
Joined: Mon Mar 08, 2004 8:36 pm

Post by Nohc »

It'd just do what I do and completely ignore all of this Linux stuff. I'm not even sure if anyone here understands what Beatles says sometimes. XD
User avatar
Devari
Mr. -1
Posts: 3194
Joined: Wed Mar 10, 2004 5:02 am
Location: British Columbia, Canada

Post by Devari »

On KDE, it opens and then swiftly closes.
If you go down to the woods today, you better not go alone
It's a lovely day in the woods today, but safer to stay at home
BECAUSE EVIL FREEN IS KILLING ALL THE TEDDY BEARS AT THEIR PICNIC
User avatar
bjornredtail
Warbands Admin
Posts: 821
Joined: Tue Apr 20, 2004 12:07 am
Contact:

Post by bjornredtail »

I do understand it... Just don't have a useable Linux rig to use it on (yet).
0===)=B=j=o=r=n==R=e=d=t=a=i=l==>
Warbands Admin

"Program testing can be used to show the presence of bugs, but never to show their absence!"-Edsger W. Dijkstra
User avatar
The Beatles
Fear me for I am root
Posts: 6285
Joined: Tue May 24, 2005 8:12 pm

Post by The Beatles »

1. Probably the shell isn't being launched properly.
2. Maybe your environment is different.
3. Maybe KDE kills it after backgrounding.
:wq
User avatar
Devari
Mr. -1
Posts: 3194
Joined: Wed Mar 10, 2004 5:02 am
Location: British Columbia, Canada

Post by Devari »

Ah, it opens properly, but then dies. Perhaps it is a KDE issue... I'll try on GNOME.

(For some reason, XFCE on my computer is completely messed up.)
If you go down to the woods today, you better not go alone
It's a lovely day in the woods today, but safer to stay at home
BECAUSE EVIL FREEN IS KILLING ALL THE TEDDY BEARS AT THEIR PICNIC
User avatar
The Beatles
Fear me for I am root
Posts: 6285
Joined: Tue May 24, 2005 8:12 pm

Post by The Beatles »

Never mind, it was a really stupid copy and paste issue. It's fixed now, in fact, it's slightly updated, since it uses ksh, which is faster. But it also avoids making external calls. I.e. overall faster.
:wq
User avatar
Devari
Mr. -1
Posts: 3194
Joined: Wed Mar 10, 2004 5:02 am
Location: British Columbia, Canada

Post by Devari »

Ah! Very nice, everything spiffy now. :D

Heh, I messed something up in the file or wmctrl, and it kept crashing X whenever I tried to open it.

I'm actually rather surprised X doesn't do more to protect itself against such crashes...
If you go down to the woods today, you better not go alone
It's a lovely day in the woods today, but safer to stay at home
BECAUSE EVIL FREEN IS KILLING ALL THE TEDDY BEARS AT THEIR PICNIC
User avatar
Devari
Mr. -1
Posts: 3194
Joined: Wed Mar 10, 2004 5:02 am
Location: British Columbia, Canada

Post by Devari »

And now it's back to crashing again...

Oh well, at least I have xterm on the F11 key.
If you go down to the woods today, you better not go alone
It's a lovely day in the woods today, but safer to stay at home
BECAUSE EVIL FREEN IS KILLING ALL THE TEDDY BEARS AT THEIR PICNIC
User avatar
The Beatles
Fear me for I am root
Posts: 6285
Joined: Tue May 24, 2005 8:12 pm

Post by The Beatles »

Wow... it crashed X?!

In any case, the command "./.wterm.sh cl" will clear all /tmp entries and kill all the Wonderterm processes. So you can use that if stuff messes up.
:wq
User avatar
Devari
Mr. -1
Posts: 3194
Joined: Wed Mar 10, 2004 5:02 am
Location: British Columbia, Canada

Post by Devari »

That dies too... :P
If you go down to the woods today, you better not go alone
It's a lovely day in the woods today, but safer to stay at home
BECAUSE EVIL FREEN IS KILLING ALL THE TEDDY BEARS AT THEIR PICNIC
Post Reply
  • Members connected in real time

    🔒 Close the panel of connected members