Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Saturday, 12 March 2011

zsh tips

Invoke 'less' smartly

One of the nice little things about Git is that if the output of a command is long, then it is displayed in less. If output of a command is short, it is just displayed (there is no interactive Git involved). One can make Mercurial suck less by emulating this behavoiur with Pager extension.

Would be it nice to have this automatic less for everything, not just hg and git? Add this one line to your .zshrc:

AL() { $* 2>&1 | less -FSRX }

Now you can call commands like AL ls /tmp/mydir and enjoy having pager only when you need it. -R option makes less not mess up colour escapes.

Have easy access to newest download

I set chrome to automatically download everything to ~/downloads folder. I often want to do something with newest downloaded file (like open it or move somewhere else).

alias -g @@NDL='~/downloads/*(.om[1])'

You can use anything that is unlikely to collide with anything else instead of @@NDL (which stands for Newest DownLoad). Now you can use it like:

acroread @@NDL
mv @@NDL .

Parenthesis after glob is qualifier. Dot stands for file, om Ordered by Modification. One is there because om[0] always matches current directory.

Wednesday, 20 May 2009

Controlling roommate's music with ssh and dcop

This is rather old one, but I didn't publish it here before.

Both my roommates use Amarok as their music player. I'm OK with music they listen to for 90% of time, but their big, fat playlists hide some real monsters. And they both have a bad habit of leaving the room with Amaroks playing in shuffle mode.

This is why I created two little scripts to pause/change the song without leaving the comfort of my chair.

Here is one, for Paweł (username pavlo) and his widescreen laptop kuandatun (kuandatun it's supposed to mean "wide ass" in Chineese).


#!/bin/zsh
ssh kuandatun "/opt/kde3/bin/dcop --all-sessions --user pavlo amarok player $*"


I have kuandatun in /etc/hosts, my .ssh/config knows that it should log in as pavlo to his machine and I have my public key listed in his .ssh/authorized_keys. Now, changing shitty song on his computer is as easy as AmarokPawla next.

The less evil use of this script is getting title, lyrics or artist of currently playing song.

EDIT: this is going to be obsolete soon, when they switch to amarok2, which uses D-Bus instead of DCOP, but it's basically the same trick