Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

Tuesday, 15 February 2011

Dropbox config change from the CLI

I use Dropbox on my MacBook. It's neat. However for some reason it's not really autodetecting my proxy, which completely set up via a master proxy.pac file.

I have already a shell script that takes care of adjusting my SSH configuration and my custom proxy.pac depending on where I am. So I just extended it to change Dropbox's configuration and restart it. Here's the gist of it:

Tuesday, 27 May 2008

Process substitution in bash

I like the process substitution syntax in bash. Since I don't expect everyone to already use it at lengths, a small note on it might be welcomed.

Process substitution connects the input or the output of a process list to a pipe whose other end is connected to the rest of your command line. For example, this will list your files in reverse order:

sort --reverse <(ls)

You'd said, I could have used a good old pipe, as in ls | sort --reverse. Fair enough, but sometimes you want more than one input, or output. That's where process substitution comes to the rescue.

I find this particularly useful with diff(1). I like diff. Don't you like diff? (GNU diff, I mean, the one with -u for unified diffs. It don't mean a thing if it ain't got that switch.) I read unified diffs every morning at breakfast. (I swear it's true.)

So let's see, I want to compare the output of two commands. Let's say I want to compare two perl optrees. (A perl optree is the intermediate form in which perl compiles your program before executing them.) To get a good, but concise, overview of a perl optree, dumped on the standard error stream, my favourite command is:
perl -MO=Concise foo.pl

(I think I'll make myself an alias for that one day.)

Let's say my almost similar programs are in files foo.pl and bar.pl. To get a diff of their optrees, the command will then be:
diff -u <(perl -MO=Concise foo.pl 2>&1) <(perl -MO=Concise bar.pl 2>&1)

(Note that I redirected stderr to stdout.) Et voilà.

And if that's too much typing, there's always history substitution:
perl -MO=Concise foo.pl 2>&1
diff -u <(!!) <(!!:s/foo/bar/)