A UNIX shell tip

UNIX: I’ve just made the first change to my core bash configuration in years, to add -b to the set command-line. It triggered some thinking about when the last one was.

It turns out, that apart from writing scripts and aliases frequently, I haven’t changed my commandline UI in any respect, since about 2 years ago. By contrast, I’ve been hacking about with GUI settings continually, new desktop backgrounds, themes, colours, etc. Odd!

Anyway, here’s the tip — it’s very handy, I find.

I changed to using a 2-line prompt, with the first line containing the time and the full working directory, in a ‘magic’ cut-and-pasteable format:

        : exit=0 Thu Jun 24 17:55:29 PDT 2004; cd /home/jm/DL
        : jm 1203...; 

Note that the prompt starts with “:”, which means that bash/sh will ignore the line until it hits “;”. The end result is that the entire line evaluates to “cd /home/jm/DL” when pasted. Hey presto, cd’ing several terminals to the same dir just involves triple-clicking in one, and middle-button-pasting into the others. nifty! Similarly, the second line has a little bit of prompt, but that snippet will be ignored when cut and pasted.

Having the exit status of the last command (bash var: $?) is useful too. The code:

  do_prompt () {
    echo ": exit=$? `date`; cd $PWD"
  }
  PROMPT_COMMAND='do_prompt $?'   # executed before every prompt
  do_prompt 0                     # set up first prompt
  PS1=": `whoami` \!"
  PS2="... >>; "            # continuation prompt
  PS1="$PS1...; "

Tags: , , , , , , , , , ,

Comments (2)

I Hate Windows

So I had to edit a Word doc. Left it for a few minutes, the network connection died, so I tried to save it somewhere else.

Foolishly, I did this by hitting File->Exit, knowing (ha!) that I could save it on the way out. All well and good — until something in Word decided it required the old copy of the doc to save the new one — even though that was in memory, since I could scroll around it etc. (it wasn’t a very long doc).

So it refused to let me save until I restored the network connection. I couldn’t be bothered doing that, so I hit Cancel on that ‘please restore the net connection’ dialog, assuming it’d let me just cut and paste the text, which is all I wanted. Guess what it did? That’s right, it just exited, taking the unsaved doc with it. Argh.

I’ve learned my lesson. Next time, I’ll stick with trusty (and sane) Vim. At least it knows how to do an Edit File UI, even if it’s not quite as pretty (or featureful).

Tags: , , , , , , , , ,

Comments