Tag Archive for 'cli'

Quick directory switching

At work, I do a lot of directory traversal: going from one location to another within the whole (global) filesystem structure. So, to conveniently go back to a previous directory, I use pushd and popd, aside from the usual cd:

$ pwd
/home/iandexter
$ pushd /etc/sysconfig
$ pwd
/etc/sysconfig
$ popd
$ pwd
/home/iandexter

You can even echo $DIRSTACK to list the current directories in the stack, and push multiple directories.

Twitter updates, via CLI

TwitterI’ve just started using Twitter, an up-and-coming web service that posts user status on the web, in IM and in SMS. The service also exposes its API, so it’s possible to build apps using it.

I found a nifty way of updating my Twitter status through the command line:

curl -u username:password -d status='status_goes_here' -s http://twitter.com/statuses/update.xml > /dev/null 2>&1

FizzBuzz

Hmmm

In Bash, I would have done:

$ for i in `seq 100` ; do if [ `expr $i % 15` -eq 0 ] ; then echo FizzBuzz; elif [ `expr $i % 3` -eq 0 ]; then echo Fizz; elif [ `expr $i % 5` -eq 0 ]; then echo Buzz; else echo $i; fi; done

Then again, it took me about 10 minutes to do that. (I couldn’t get the ternary operator to work, somehow.) In C: about five minutes (rusty — I last used C way back in college {ages ago!}).

In a recent phone interview, I was asked to programmatically (in shell) rename a set of files. I blundered for about two minutes, and gave up in the end, saying I could probably do that by experimentation. I could fairly say I passed that interview. The point? Answering “FizzBuzz” questions does not reflect real-world situations — it’s how you approached the problem, even if you didn’t get the answer, that matters.

If I were an interviewer, I’d concentrate on the steps rather than the solution.

Trivial desktop customization

I’m currently playing with Devil’s Pie, a utility that matches windows and window events to a set of rules similar to Emacs’ (yikes! :P) S-expressions.

I installed Devil’s Pie on my work desktop (running FC6), thus:

$ sudo yum install devilspie

(I have previously organized my desktop with four workspaces: for browsing, remote SSH sessions, remote desktop sessions, and other tasks.) I then created a configuration file:

$ mkdir .devilspie && vi ~/.devilspie/workspaces.ds
   (debug)
   (if (is (application_name) "Firefox") (begin maximize (undecorate (set_workspace 1))))
   (if (is (application_name) "Terminal") (begin maximize (undecorate (set_workspace 2))))
   (if (matches (application_name) "^rdesktop.+") (begin center (maximize (set_workspace 3))))

and invoked Devil’s Pie: devilspie -d ~/.devilspie/workspaces.ds &. The (debug) line in the configuration is, heh, for debugging purposes so Devil’s Pie will print out events and other information, which I can then later use.

Seems pretty straightforward, though there isn’t much functionality that I can use. (Then again, my requirement is minimal: I just want to group apps to different workspaces to avoid clutter.) I can then drop Devil’s Pie in my X startup script, along with the other startup apps.

CLI shortcuts, 7

(This is part of an ongoing series on Linux CLI shortcuts and hacks.)

After editing .bashrc and .bash_profile, you can reload the values by running

$ source ~/.bash_profile