Julius Plenz – Blog

sed and jekyll tags

Did you know the -s switch to sed? I had the strange effect that operating on several files produced different results between when I called sed repeatedly in a for loop and passing all the files as arguments just once. – -s tells sed not to consider all files to be one big stream, but to separate them from each other.

Anyway, here's a script that searches all the posts now and gives me numbers on the tags I already used.


sed -s -n '
    /---/,/---/ {
        /tags:/ {
            s/^tags: \[//;
            s/, */\n/g;
    }' ~/blog/_posts/*.markdown | sort | uniq -c | sort -n

posted 2011-12-27 tagged sh and sed

URL shortener

The bit.ly service requires some sort of registration or an API key for some time now. I used to use it in shell scripts to automate shortening of links.

Similar to the sprunge pastebin service, there's come up a new, easy-to-understand URL shortening service called gnzkrz (short for German "ganz kurz", "very short"). And with it's latest commit, it acquired a simple API. I use it as such:

URL=`xclip -o`
SHORT=`wget -qO- "http://krzz.de/_api/save?url=$URL"`
(echo -n $SHORT | xclip -i -display :0 -loops 0 ) &
/home/feh/bin/notify-wrapper "krzz.de: switched URL in clipboard" "$SHORT"

Now I simply bind a hotkey to call this program, and it will exchange the URL from my X clipboard with a shortened version.

posted 2011-08-07 tagged sh and oneliner

Sprunge, the fine pastebin service

I have never understood why automatically pasting to a pastebin service should be so hard as in "I need a huge script to do the job!".

Luckily, once in a while there are smart people that build good and simple applications. Enter sprunge, the first truly sane pastebin service. Need to know how it works? You'll find the man page on their website (no, really). – No listing of pastes. No annotation, comments, amendments. No foobar. Paste away!

$ sprunge < ~/bin/sprunge 

$ wget -qO- http://sprunge.us/OcPR
exec curl -F 'sprunge=<-' http://sprunge.us

posted 2011-07-20 tagged sh

vi mode in GNU readline

I am stuck in a course about computer algebra systems. We are using Singular. I searched for some minutes how to switch on the vi mode on the Singular command line, but apparently, there is none.

However, since Singular uses the GNU readline libs, you can simply switch to vi mode with Ctrl-Meta-j. – How convenient is that. I wonder if there's a possibility to configure readline to switch to vi mode by default.

Update 2015-03-25: Markus informs me that to enable Vi mode by default, write the line set editing-mode vi into your ~/.inputrc (or the global /etc/inputrc).

posted 2011-02-28 tagged sh and vi

Google: Fast search result retrieval

This whole Google jQuery autosuggestion bothers the hell out of me. I mean, why would you use several keystrokes and possibly the mouse to find a page, continuously requesting suggestions in the background?

Often I use Google to find a page I can pretty safely identify with some simple keywords. For example, in an IRC conversation I want to give someone a link to Al Jazeera's page about current events in Egypt.

Stupid way: 1. fire up browser, 2. enter search terms in address bar (:tabopen in Vimperator), 3. wait for the kilobytes to trickle through the line, 4. find your way around the page, 5. select link, 6. copy it somehow, 7. switch back to IRC window, 8. paste URL. Estimated time amount: ranging from anywhere between 10 seconds to 30 seconds.

Clever way: write a shell script to extract "I am feeling lucky" result.


test -z "$1" && exit 1

URL="`curl -s -i -e 'http://www.google.com' -A 'Firefox 23' \
    -G -d hl=en -d btnI=lucky --data-urlencode q=\"$1\" \
    http://www.google.com/search | grep '^Location:' | \
    head -n 1 | cut -d' ' -f2 | tr -d '\r\n'`"

echo -n "$URL" | (xclip -i -display :0 -loops 0 ) &
/home/feh/bin/notify-wrapper "Google 1st result" "$URL"

(Footnote: You need a more or less sensible User-Agent string (-A) as well as a request on www.google.com, otherwise you won't be served a result.)

Then, bind a key to open a prompt in which you'll enter your search term. For awesome, this is:

awful.key({ modkey }, "g",
  function ()
    awful.prompt.run({ prompt = "Google: " },
      function (s)
        awful.util.spawn("/home/feh/bin/glucky '" .. s .. "'")
      nil, nil)

The notify-wrapper script uses DBus's notify-send to make a little notification box appear as soon as the URL is retrieved (which is, like, instantaneous).

Clever way works like this now: 1. Press Mod1-g, 2. enter search term, 3. paste URL. Time you need to find a popular link: Time to type search string + 1 second. Huge time saver.

posted 2011-01-31 tagged google, sh, curl and awesome