Archive for January, 2009

Extending GNU Screen - Adding a taskbar

Posted in Howto, Tipps on January 17th, 2009 by Benjamin Milde – 3 Comments

One of the biggest drawbacks of GNU Screen is that you don’t see an overview of your virtual terminals in most standard configurations. But that can be easily changed. My screen now looks like this:

Bild / Screenshot eines gepimpten und aufgemotzten screen-Terminals

Screenshot of extented screen with taskbar

You can clearly see which programs are running and you have a good overview. The other goodies like cpu load display and the clock is also very practical.

The global configuration file /etc/screenrc already has some minor tweaks (Depending on your distribution). If you only want the taskbar for a particular user, than the local .screenrc in your home directory is the file to edit.

The heart of my screen configuration is:


backtick 1 0 0 /usr/bin/cpuusage
hardstatus alwayslastline
hardstatus string '%{= kG} %{G}%H %{g}[%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}] %1`%% CPU %{W}%c %{g}’

With “backtick” a command-directive (1 here - must be a number) is noted. The “0 0″ then means that whenever a new output from the program is produced, screen stores the last line of output. “Hardstatus” is for the taskbar and each % directive is for special purposes. With `% 1 for example the last line of the backtick command is printed. For all the other directives better read the GNU screen-manpage

The cpuusage-script looks like this:

  1. #!/bin/bash
  2. awk ‘BEGIN {file = "/proc/stat";while (a==a) {getline < file;u=$2-up;s=$3-sp;n=$4-np;i=$5-ip;printf ("%2.1f\n"),(u+s)/(u+s+n+i)*100;up=$2;sp=$3;np=$4;ip=$5;close(file);system("sleep 1")}}’

This awk-oneliner uses the information from /proc/stat to calculate the cpuload for one second. That is supported on all unixes with proc support (Mac OS X has no proc).

What’s missing now, is dynamic window titles. In the previous configuration, all titles are set to “n * bash”, we had to change the titles manually.

With a special escape-sequence, the title can be set from the console. The screen manpage explains the procedure:


The default name for all shell windows can be set with the "shelltitle"
command in the .screenrc file, while all other windows are created with
a "screen" command and thus can have their name set with the -t option.
Interactively, there is the title-string escape-sequence
(kname\) and the “title” command (C-a A). The former can be
output from an application to control the window’s name under software
control, and the latter will prompt for a name when typed. You can
also bind pre-defined names to keys with the “title” command to set
things quickly without prompting.

Finally, screen has a shell-specific heuristic that is enabled by set-
ting the window’s name to “search|name” and arranging to have a null
title escape-sequence output as a part of your prompt. The search por-
tion specifies an end-of-prompt search string, while the name portion
specifies the default shell name for the window. If the name ends in a
‘:’ screen will add what it believes to be the current command running
in the window to the end of the window’s shell name (e.g. “name:cmd”).
Otherwise the current command name supersedes the shell name while it
is running.

Here’s how it works: you must modify your shell prompt to output a
null title-escape-sequence (k\) as a part of your prompt.
The last part of your prompt must be the same as the string you speci-
fied for the search portion of the title. Once this is set up, screen
will use the title-escape-sequence to clear the previous command name
and get ready for the next command. Then, when a newline is received
from the shell, a search is made for the end of the prompt. If found,
it will grab the first word after the matched string and use it as the
command name. If the command name begins with either ‘!’, ‘%’, or ‘^’
screen will use the first word on the following line (if found) in
preference to the just-found name. This helps csh users get better
command names when using job control or history recall commands.

My shellprompt looks like this:


server1 pastacode #

That means, all my commands are typed in after the #. So, I have to add this to my .shellrc :


#dynamic title
shelltitle '# |bash'

Screen now looks for a # when it gets the escape-sequence. “| Bash” means that the default title is “Bash”. We now only need the escape sequence in our promt; that can be customized (in Bash) with the PS1 variable. To do this we will either edit the /etc/bashrc (for any user) or the local .bashrc in our home directory. My .bashrc looks like this:

  1. export EDITOR=/usr/bin/vi
  2.  
  3. # Set the screen title
  4. case $TERM in
  5. screen*)
  6. # This is the escape sequence ESC k \w ESC \
  7. #Use path as titel
  8. #SCREENTITLE=’\[\ek\w\e\\\]‘
  9. #Use program name as titel
  10. SCREENTITLE=‘\[\ek\e\\\]‘
  11. ;;
  12. *)
  13. SCREENTITLE=
  14. ;;
  15. esac
  16.  
  17.  
  18. PS1="${SCREENTITLE}${PS1}"

The PS1 is altered to add the screen escape-sequence, but only when we are in screen. In my file, you can actually choose between two versions: either the current path is the dynamic title, or the program name, although I prefer the latter. Unfortunately viewing both seems to be not a trivial thing.

So I hope the whole thing works for you - for suggestions, better ideas - write a comment!

Last but not least my complete .screenrc:

  1. #no bells and startup messages
  2. startup_message off
  3. vbell off
  4.  
  5. #10000 lines scrollback buffer
  6. defscrollback 10000
  7. #no login
  8. deflogin off
  9.  
  10. # Default shell
  11. shell bash
  12.  
  13. #Timeout for displaying messages
  14. msgwait 1
  15. activity "         Activity has appeared in window      %n - %t"
  16.  
  17. #taskbar
  18. backtick 1 0 0 /usr/bin/cpuusage
  19. hardstatus alwayslastline
  20. hardstatus string ‘%{= kG} %{G}%H %{g}[%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}] %1`%% CPU %{W}%c %{g}’
  21.  
  22. #dynamic title
  23. shelltitle ‘# |bash’
  24.  
  25. #When your ssh connection dies, screen is autodetached
  26. autodetach on
  27.  
  28. #Nice 256 term colors
  29. attrcolor b ".I"
  30. termcapinfo xterm ‘Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm’

And the cpuusage script:

  1. #!/bin/bash
  2. awk ‘BEGIN {file = "/proc/stat";while (a==a) {getline < file;u=$2-up;s=$3-sp;n=$4-np;i=$5-ip;printf ("%2.1f\n"),(u+s)/(u+s+n+i)*100;up=$2;sp=$3;np=$4;ip=$5;close(file);system("sleep 1")}}’

Sources:

The pages below helped me alot:

http://listserv.ccjclearline.com/pipermail/kwlug-disc/2006-November/002132.html
http://b79.net/code/screenrc
http://www.mediacollege.com/cgi-bin/man/page.cgi?topic=screen

Songbird … The Firefox of audioplayers

Posted in Musik, Tipps on January 17th, 2009 by Benjamin Milde – Be the first to comment

Songbird screenshot under Mac OS X

Songbird screenshot under Mac OS X

From a certain size on one’s own music collection is not simply sortable in a file structure. The index approach is something I started to like, I gained control over my collection again. This approach is used by almost all the major players - be it Amarok (Linux), Windows Media Player or Itunes.

Songbird is coming to conquer the crown of this sort of audioplayers. The big download button on getsongbird.com, the domain, the site …. all that is familiar and is reminiscent of Firefox and Co. read more »

Cdogs Mac OS X port

Posted in Games, Mac on January 14th, 2009 by Benjamin Milde – 1 Comment

I’ve made another Mac Bundle, this time it is the SDL version of the legacy DOS-Game Cdogs.

It’s not the first mac version, but there exists only an older ppc build.

Download: cdogs.dmg.

* Cdogs 0.4
* UniversalBinary
* needs OS X >= 10.4
* tested under Mac OS X 10.5, Intel.

“Numpty Physics” intel mac port

Posted in Games, Mac on January 12th, 2009 by Benjamin Milde – 21 Comments

“Harness gravity with your crayon and set about creating blocks, ramps, levers, pulleys and whatever else you fancy to get the little red thing to the little yellow thing.”

I ported this nice little 2D-physics game to Mac OS X: http://numptyphysics.garage.maemo.org/

The SDL-Linux source was used to port and I only needed minor changes. Mail me if you want the project files. The port is native (Cocoa-SDL!), so no xorg server is needed

Download: here. (Latest version: 0.2 svn-11jan)

Requirements:

* Intel Mac. Sorry, no UB. Couldn’t make the library Box2D for ppc. If you tell me how much you would love it to have a ppc version, I may try it again.
* Mac Os X >= 10.4

Please comment for questions and tell me if it works for you. HAVE FUN! :)

Numpty Physics 0.2 mac port screenshot

Screenshot

Suffixarrays – Eine Datenstruktur um lange Texte zu indizieren

Posted in Algorithmen, Datenstrukturen on January 10th, 2009 by Benjamin Milde – Be the first to comment

Einleitung

Das Suffixarray ist eine einfach Datenstruktur, die zusätzliche Informationen zum Auffinden aller Vorkommenisse eines Teilstrings eines Textes bereithält. Dieser Artikel befasst sich intensiv mit der Theorie aber auch mit der Umsetzung und den dazu passenden Algorithmen in der Praxis.

Um einen Text zu durchsuchen und eine bestimmte Zeichenkette zu finden, muss ohne Vorarbeit min. jedes Zeichen des Textes einmal verglichen werden. Dieser Vorgang ist bestenfalls in O(n).

Bei naiver Implementierung, liegt die Suche mit einem Suffix-Array in O(mlog(n)). m ist dabei die länge des Suchwortes. Dieser Geschwindigkeitsvorteil hat seinen Preis, je nach Größe des Textes wird ca. das 4-Fache der Textlänge an zusätzlichem Speicherplatz benötigt. Auf Kosten weiteren Speicherplatzes kann die Suche noch weiter verbessert werden.

read more »

Screen, der “Windowmanager” für die Konsole

Posted in Howto, Linux on January 9th, 2009 by Benjamin Milde – 1 Comment

Dieser Artikel ist für alle, die Screen noch nicht kennen. Auf manchen Distributionen ist es bereits vorinstalliert auf anderen muss es nachinstalliert werden. Das Paket heißt eigentlich immer ’screen’.

Screen ist im Prinzip ein Windowmanager Ersatz für die Konsole. Man kann so auf mehreren Shells arbeiten und zwischen Ihnen hin und her springen. Auch bietet sich screen an, um Standart-Programme im Hintergrund laufen zu lassen.

read more »

10 interessante Bash-Tipps für Linux und Unix Admins

Posted in Linux, Tipps on January 8th, 2009 by Benjamin Milde – 1 Comment

Tipp 1:

DVD/CD auswerfen? Manchmal keine so einfache Aufgabe unter Linux. Greift ein Programm auf das Laufwerk zu, sei es nur eine Shell die sich gerade im DVD-Verzeichnis befindet, blockt Linux das auswerfen.

Das sieht wohlmöglich so aus:

$ umount: /media/dvd: device is busy

Keine unnötigen Neustarts mehr oder wahlloses Programm schließen:

$ fuser /media/dvd

Damit findet man heraus, welcher Prozess das Laufwerk in beschlag nimmt.
Mit root oder sudo kann man nun ein wenig mit den Muskeln spielen:

$ fuser -k /media/dvd

Yuhu. Freiheit! Der Prozess, der das DVD-Laufwerk blockierte wurde gekillt. (Je nach System muss der Pfad /media/dvd ggf. angepasst werden) read more »

Firefox performance Tipp - Datenbank entmüllen

Posted in Browser, Tipps on January 7th, 2009 by Benjamin Milde – 2 Comments

Firefox speichert einen Teil seines Caches, seiner Bookmarks und Cookies etc. in einer Sqlite-Datenbank ab. Doch wird diese nie entmüllt, wann immer etwas gelöscht wird, wird es nicht wirklich gelöscht, sonden nur zum löschen gekennzeichnet.
read more »

Itunes: Bald DRM frei

Posted in Apple, Musik, News on January 6th, 2009 by Benjamin Milde – Be the first to comment

So wies aussieht scheint Apple die Kritik an den DRM-Musik-Downloads wahrgenommen zu haben und möchte zum April dieses Jahres die meisten Songs DRM-frei anbieten. Da ich nie Geld für DRM-Musik ausgeben würde, kann ich diesen Schritt nur begrüßen und hoffe das wir im Musikbereich bald den Wandel erleben, der von vielen Prophezeit wird.

Alles weitere ist auf der offiziellnen Apple-Verkündung nachzulesen: http://www.apple.com/pr/library/2009/01/06itunes.html

Web-Development in C++

Posted in Howto, Programming on January 6th, 2009 by Benjamin Milde – 1 Comment

Php ist inzwischen überall… und hat sich zur Programmiersprache des dynamischen Webs etabliert. Aber was, wenn es zu langsam wird?

Sicher: es gibt den eaccelerator und noch andere Möglichkeiten PHP schneller zu machen. Im großen und ganzen mag ich PHP aber gar nicht so sehr, also begab ich mich auf die Suche nach Alternativen. Warum nicht C++? Es war etwas schwer an die richtigen Informatinen zu kommen und es existieren auch noch alte Informationen die C(++) in Zusammenhang mit dem in die Jahre gekommenen CGI verwenden.
read more »