On Fri, 20 May 2011, Andrew Hills wrote:

On Fri, May 20, 2011 at 12:16 PM, Suraj N. Kurapati wrote:
history | xmessage -file - &

I keep this ugly mess around in for convenience:

h()
{
   `history | perl -e 'while(<STDIN>){s/\s+\d+\s+//;push
@o,$_;}for($i=$#o-1;$i>=0;$i--){print $o[$i];}' | dmenu -b`
}


Yikes. Ugly indeed. Unsolicited (sort of... "something wrong on the internet" 'n all), but:

'for($i=$#o-1;$i>=0;$i--){print $o[$i];}'

is better written:

'pop @o; print for reverse @o'
or
'print for reverse @o[0..$#o-1]'

Plus it's easier to reverse the whole thing outside of Perl (via tac), and you can use '-n' to avoid the 'while(<STDIN>){}', so the whole thing becomes:

h()
{
    `history | perl -nwe 's/\s+\d+\s+//; print unless eof' | tac | dmenu -b`
}

Don't have `tac` installed? (I think it's in linux-utils or core-utils, but maybe it's linux- and/or GNU-centric.)

tac () { perl -nwe 'unshift @o, $_; END { print for @o }' }

--
Best,
Ben

Reply via email to