Working With History in Bash

Working With History in Bash: “

Yesterday we talked about favorite bash features (on the ##textmate IRC channel). I figured it was worth posting mine to this blog, they mostly revolve around history, hence the title.

Setup

My shell history collects a lot of complex command invocations which take time to figure out. To ensure that I have access to them at a later time, I have the following 3 lines in my bash init:

export HISTCONTROL=erasedups
export HISTSIZE=10000
shopt -s histappend

The first one will remove duplicates from the history (when a new item is added). For example if you switch between running make and ./a.out in a shell, you may later find that the last 100 or so history items is a mix of these two commands. Not very useful.

The second one increase the history size. With duplicates erased, the history already holds a lot more actual information, but I still like to increase the default size of only 1,000 items.

The third line ensures that when you exit a shell, the history from that session is appended to ~/.bash_history. Without this, you might very well lose the history of entire sessions (rather weird that this is not enabled by default).

History Searching

Now that I have my history preserved nicely in ~/.bash_history there are a few ways to search it.

Using Grep

The most crude is grep. You can do:

history|grep iptables

For me (on this particular Linux server) I get:

4599  iptables -N http-block
4600  iptables -A http-block -s 58.60.43.196 -j DROP
4601  iptables -A INPUT -p tcp --dport 80 -j http-block
4602  iptables -L http-block
4603  iptables-save -c
4604  history|grep iptables

I do this often enough to have an alias for history (which is just h).

From the output I can either copy/paste the stuff I want, or repeat a given history event. You’ll notice that each history event has a number, you can repeat e.g. event number 4603 simply by running:

!4603

I will write a bit more about referencing history events in History Expansion.

Prefix Searching

Similar to how you can press arrow up for the previous history event, there is a function you can invoke for the previous history event with the same prefix as what is to the left of the insertion point.

This function is called history-search-backward and by default does not have a key equivalent. So to actually reach this function, I have the following in ~/.inputrc (or /etc/inputrc when I control the full system):

'\ep': history-search-backward

This places the function on P (escape P). So if I want to repeat the iptables-save -c history event we found in previous section, all I do is type ipt and hit P. If it finds a later event with the same prefix, hit P again to go further back.

This functionality is offered by the readline library, so if you setup this key, you have access to prefix searching in all commands which use this library.

Incremental Search

It is possible to press ⌃R to do an incremental (interactive) search of the history.

Personally I am not a big fan of this feature, so I will leave it at that :)

Update: The reason I dislike ⌃R is both because the interactive stuff just seems to get in the way (when P is what I need 99% of the time) and because it fails in cases where I ‘switch shell’, for example I may do: ssh mm press return, then instantly type: fP and again hit return (to execute free -m on the server called mm). I enter this before the connection to the server has been fully established, and here ⌃R would have been taken by the local shell, but it is the shell history at the server I want to search.

History Expansion

History Expansion was what we did above when we ran !4603. It is a DSL for referencing history events and optionally run transformations on these.

Anyone interested in this should run man bash and search for History Expansion, but just to give you a feel for what it is, I will reference a subset of the manual and provide a few examples.

Event Designators

First, an event designator starts with ! and then the event we want to reference. This can be:

«n»      Reference event number «n».
-«n»     Go «n» events back.
!        Last line (this is the default).
#        Current line.
«text»   Last event starting with «text».
?«text»  Last event containing «text».

So if we want to re-run our iptables-save -c we can do: !ipt.

What’s more useful though is to use history references as part of larger commands.

For example take this example:

% which ruby
/usr/bin/ruby
% ls -l $(!!)
lrwxr-xr-x  1 root  wheel  76 30 Oct  2007 /usr/bin/ruby -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby

Or something like:

% make some_target
(no errors)
% path/to/target some arguments
(no errors)
% !-2 && !-1

Word Designators

In the previous section we referenced entire history events. It is possible to reference just a subset of a history event by appending a : to the event designator and then the word of interest, the two most useful are:

«n»      Reference the «n»’th word.
$        Reference the last word.

So for example we can do:

% mkdir -p /path/to/our/www-files
(no errors)
% chown www:www !$
(no errors)

Here we reference last word of last line. We can also reference stuff on the same line, e.g.:

% cp /path/to/important/file !#:1_backup

To reference the last word of last line one can also press _ which will immediately insert that word.

Modifiers

To make history substitution even more useful (and harder to remember), one can also add a modifier to the event designator.

The most useful modifiers are in my experience :h and :t, these are head and tail respectively or better know as dirname and basename.

An example could be:

% ls -l /path/to/some/file
(listing of file)
% cd !$:h
(change directory to that of file)

Brace Expansion

Somewhat related to the backup example where we reference the first argument as !#:1 and append _backup to this, another approach is bracket expansion.

Anywhere on a command line, one can write {a,b,c} which will expand to the 3 words a, b, and c. If we include a prefix/suffix, that will be part of each of the expanded words. We can also leave the word in the braces empty, and have it expand to just the prefix/suffix, so for example we can do:

% cp /path/to/important/file{,_backup}

This is functionally equivalent to:

% cp /path/to/important/file !#:1_backup

But lack of hardcoded word number is IMO an improvement.

(Via TextMate Blog.)

Neues GmbH-Recht: Gefahr für Designer

Der BDG :Bund Deutscher Grafik-Designer e.V. weist in einer heutigen Stellungnahme darauf hin, dass »die Einführung der so genannten ›1-Euro-GmbH‹ ist eine Gefahr für die soziale Absicherung zahlreicher Freiberufler« darstellte. Der Berufsverband der Kommunikationsdesigner fordert daher flankierende soziale Maßnahmen.

Am gestrigen Donnerstag hat der Bundestag beschlossen, GmbHs auch ohne das bislang nötige Garantiekapital zuzulassen. Der BDG befürchtet nun, dass die Zahl an scheinselbstständigen Designern, die schon jetzt in Unternehmen ohne entsprechende arbeitsvertragliche Absicherung durch sozialversicherungspflichtige Beschäftigungsverhältnisse tätig sind, in rasantem Maße ansteigen werden – und zwar jetzt völlig legal als Ein-Personen-GmbH.

Der Vorteil für den Auftraggeber läge auf der Hand: Werde eine GmbH beauftragt, so fallen keinerlei Sozialversicherungsbeiträge an. Und nicht nur das: Zusätzlich entfallen auch bei Auftragsvergabe an eine GmbH die Abgaben an die Künstlersozialkasse.

Seit der Einführung vermehrter Kontrollen der Künstlersozialabgaben würden schon jetzt freiberufliche Designer durch potentielle Auftraggeber vermehrt zur Gründung einer GmbH gedrängt, so die Beobachtung des BDG. Mit dem Wegfall des Mindestkapitals werde es zu einem größeren Druck kommen.

Der BDG schlägt daher vor, Sozialversicherungsprüfungen auch bei Betreibern von GmbHs vorzunehmen. Weiterhin sollten Zahlungen an GmbHs zukünftig ebenfalls mit der Künstlersozialabgabe belegt werden.

(Via Fontblog.)

Großes ß ist nun internationale Norm

Das ß als Großbuchstabe ist nun von der Internationalen Organisation für Normung (ISO) als internationale Norm veröffentlicht worden. Ende Mai fand bei der ISO die finale Abstimmung statt, die Norm wurde ohne Gegenstimme angenommen, bestätigte Roman Grahle vom Deutschen Institut für Normung (DIN) gegenüber heise online. Das DIN hatte sich im vergangenen Jahr für die Aufnahme als Standard eingesetzt. Am 23. Juni hat die betreffende Ergänzung der Norm ISO/IEC 10646 den Status 60.60 (“International Standard published”) erreicht und ist damit gültig.

Bereits am 4. April trat die Unicode-Version 5.1 in Kraft, die das versale ß als Zeichen U+1E9E enthält. Das zuständige Unicode Consortium steht den ISO-Gremien beratend zur Seite. Die Rechtschreibregeln sind von der neuen Norm nicht betroffen, das ß wird danach weiterhin in Großschreibweise als “SS” umgesetzt. Laut Grahle wurden nun aber die maschinellen Voraussetzungen dafür geschaffen, dass das große ß im Schriftdeutschen Einzug halten kann. Deutsche Typographen diskutieren seit 2005 erneut über mögliche Formen des großen ß, 2006 widmete die Zeitschrift Signa eine Ausgabe dem neuen Buchstaben. Der Typograph Andreas Stötzner weist auf seiner Website auf Tastatur-Treiber mit Versal-ß für Windows und Mac OS X hin.

Seit etwa 130 Jahren war immer wieder darüber diskutiert worden, dem ß wie allen anderen Buchstaben eine große Variante zu verschaffen. Der Große Duden der DDR enthielt in den 1950er-Jahren ein großes ß, doch dann verschwand es wieder. Eine neue Rechtschreibreform für das große ß schließt der Rat für deutsche Rechtschreibung zwar aus, aber: “Die Menschen werden entscheiden, ob sie es verwenden”, sagt Geschäftsführerin Kerstin Güthert laut dpa. Eine Voraussetzung wäre beispielsweise eine Änderung des Tastatur-Layouts, doch diese bezeichnete eine Sprecherin des Tastatur-Herstellers Cherry als “erheblichen Eingriff in das Standard-Tastatur-Layout”. Dort teilt sich das ß den Platz mit dem Fragezeichen. Ohne eigene Taste ließe sich die Tastatur zwar relativ leicht anpassen, das hätte aber eine Folge für die beruflichen Schnellschreiber: “Das Maschineschreiben müsste dann teilweise neu gelernt werden.”

Via heise.de

Leben und Arbeiten mit Social Software und Web 2.0

Anlässlich der tiefgreifenden Veränderungen, die Social Software und Web 2.0 mit sich bringen, hat die MFG Innovationsagentur für IT und Medien des Landes Baden Württemberg die Publikation “a digital lifestyle – leben und arbeiten mit social software” herausgebracht, die wesentliche Aspekte dieses Wandels beleuchtet.

Auf über 80 Seiten gehen namhafte Autoren aus Wissenschaft und Praxis der Frage nach, wie sich unser Lebensstil und unsere Arbeitswelt in Punkto Kooperation, Interaktion und Partizipation in der digitalen Zukunft entwickeln werden.

Die informative und zugleich interessant gestaltete Publikation wird kostenlos zum Download angeboten und ist zudem als Printversion für eine Schutzgebühr von 15 Euro erwerbbar. Sie eignet sich als Einstieg in das Thema für interessierte Privatpersonen und Unternehmen als Überblick über Möglichkeiten, die das Web 2.0 bietet.

http://www.digital-lifestyle.mfg-innovation.de/?page_id=34

Web Form Factory: Open Source Formular-Generator

Formulare ermöglichen einen direkten Kontakt zu den Besuchern einer Seite und erfragen zum Beispiel Daten für Newsletter, Kommentare und Adressen. Das Design ist schnell erledigt, doch ohne PHP-Kenntnisse wird daraus kein nützliches Formular. Wer gerade keinen PHP-Entwickler zur Hand hat, der kann auf die Web Form Factory zurückgreifen.
Web Form Factory: Open Source Generator für Formulare

Die Erstellung von Formularen für eine Webseite bleibt in aller Regel entsprechend geschulten Entwicklern vorbehalten. Die optische Gestaltung stellt für viele Publisher keine große Hürde dar, bei der Programmierung der Formulare sieht das schon anders aus. Hier sind spezielle Kenntnisse gefragt, um die Formulareingaben in einer Datenbank speichern oder per E-Mail versenden zu können.

Mit der Web Form Factory (WFF) gibt es jetzt eine Open-Source-Lösung zur Erstellung von Formularen für das Web. Die einfach zu bedienende Web-Applikation untersucht eine selbst erstellte HTML-Datei auf verwendete Eingabetypen wie Textfelder, Drop-Down-Listen, Checkboxen sowie Radio-Buttons und generiert daraus automatisch ein an PHP-gebundenes HTML-Formular. Das Ergebnis lässt sich dann in Form einer Zip-Datei herunterladen, auspacken und in die eigene Webseite integrieren.

WFF befindet sich derzeit im Beta-Stadium. Momentan wird nur die Anbindung von HTML-Dateien an PHP (wahlweise 4, 5 oder 5.1) unterstützt, was sich aber in naher Zukunft ändern soll. Außerdem ist die Erstellung eines E-Mail-Formulars möglich, bei dem die erhobenen Daten nicht in eine Datenbank fließen, sondern an eine E-Mail-Adresse geschickt werden.

Eine Hilfestellung für die Arbeit mit WFF inklusive der Erstellung der HTML-Datei bietet ein Einführungsvideo im Tutorial-Bereich.

via t3n

How To Run Firefox 2 and 3 Simultaneously

How To Run Firefox 2 and 3 Simultaneously: “

Firefox 3 was released just yesterday, bringing a wealth of new features to be excited about. From faster launch time and better memory management to interface polish and glitz, and over 8 million downloads already, Firefox 3.0 is truly a gem among modern web browsers.

For those that do web development, though, the 3.0 release means another round of website compatibility testing in both the earlier release and now the current one. For the most part, this isn’t a new challenge, but Firefox can be a bit peculiar: Upon launching Firefox, it checks to see if another instance is already running, and if found, brings up a new browser window of the currently running version. So, launching Firefox 2.0 while 3.0 is running results in two 2.0 windows, and vice versa for 3.0. This effectively stops the casual user from simultaneously running both Firefox 2.0 and 3.0 side by side. As an added side effect, when you completely shut down Firefox and launch a different major version, your profile information can get skewed, resulting in sometimes strange bookmark appearance and lots of checking for updates to installed add-ons. With a little tweaking, though, Firefox 2.0 and 3.0 can be convinced to run independently, each with their own bookmarks and add-ons.

Mac OS X Instructions
Running two versions of Firefox under Mac OS X couldn’t be simpler. The freeware application MultiFirefox takes all the guesswork out of the process by automatically detecting Firefox versions in your main Applications folder and presenting you with a list from which to choose the Firefox versions you’d like to launch. Complete with self-updating (thanks to the ubiquitous Sparkle framework), MultiFirefox is the easiest way to pull off this multi-browser stunt.

Windows Instructions
If you already have Firefox (2.0 or 3.0) installed, it’s important to back up your crucial information before getting started. Navigate to C:\Documents and Settings\YourName\Application Data\Mozilla\Firefox and copy your ‘Profiles’ folder somewhere safe.

Once backed up, download Firefox 2 and/or Firefox 3, depending on what you already have installed. Launch each installer and begin setting up Firefox, but make sure to choose Custom settings. When asked for a place to install Firefox, change the path(s) to C:\Program Files\Mozilla Firefox 3\ (or …\Mozilla Firefox 2), instead of just ‘Mozilla Firefox’. In doing so, you’ll place Firefox 2 at C:\Program Files\Mozilla Firefox 2\, and Firefox 3 at C:\Program Files\Mozilla Firefox 3\. Both versions of Firefox should now be in separate folders. (If you already have one version of Firefox installed at C:\Program Files\Mozilla Firefox\, you may choose to leave that where it is and just install the other version in a separate folder, however you’ll have to make a note of which is where, and modify the following instructions accordingly.)

Create a new shortcut to Firefox 2.0 by right-mouse-button-dragging C:\Program Files\Mozilla Firefox 2\firefox.exe to your Desktop (for now), and choosing ‘Create Shortcuts Here’. Name the shortcut ‘Firefox 2″. Repeat for Firefox 3, changing ‘2″ to ‘3″ where appropriate.

You’re almost there, but now we have to tell Firefox to keep the two instances separate. Open the Properties window for the Firefox 3 shortcut, and add ‘ -ProfileManager’ (space key, minus sign, ProfileManager) to the end of the string of text in the Target field. Click OK, then run that same shortcut to bring up Firefox’s Profile Manager. Rename the existing ‘default’ profile to ‘firefox3″, and also create a new ‘firefox2″ profile:

Once profiles are set, exit Firefox completely. With two profiles in place, each version of Firefox can have its own bookmarks, extensions, and other settings, without interfering with each other. Open up the properties windows for both the Firefox 2 and Firefox 3 shortcuts you made. Remove the -ProfileManager addition from the Firefox 3 shortcut Target, replacing it with -no-remote -p firefox3 (space key, minus sign, no-remote, space key, minus sign, space key, firefox3). Add the same to the Firefox 2 shortcut, again changing the 3 to a 2. Both shortcuts should now have the -no-remote option set, as well as -p followed by the designated profile that matches that Firefox’s version. In short, Firefox 3 gets the firefox3 profile, and Firefox 2 gets the firefox2 profile, seen below:

Click OK on both shortcuts to confirm the changes, and finally double-click each to run Firefox 2 and 3 at the same time!

Also, don’t miss LifeHacker’s Power User’s Guide to Firefox 3 for some excellent 3.0 tips and tricks, as well as ArsTechnica’s briefing of what’s to come in Firefox 3.1.

(Via Command-Tab.)

Optimizing TYPO3 backend responsiveness

During the last months I attended two excellent meetings. One was the TYPO3DD08 and the other was the “Dirty Handson Session” (Forelle ist geil!). During the last session we worked on HCI issues in Arnhem @ the Netcreators office together with Ben van ‘t Ende, Benjamin Mack, Jens Hoffmann, Patrick Broens, Steffen Kamper and me. We had a lot of fun and made a good start improving the backend step by step….

http://typofree.org/articles/optimizing-typo3-backend-responsiveness/