Juanjo
Post de prueba

Some years ago (on November 10th, 2006) I wrote one of my favourite console hacks.

At that time I was digging in Bash and discovered the PROMPT_COMMAND variable. It defines a command line that will be run before the prompt is showed. I thought this might be useful to see the files in a directory when enters in it, so the cd → ls sequence will not be so repeated. There are some constraints:

  • It has to be fast. I use the console a lot and don’t like waiting to the prompt to be ready.
  • The content should be limited. If a directory has hundreds or thousands of files it should not list them.
  • I would like to have a little header with a summary of the content (total size, number of directories, etc).

After some minutes I had coded a dirty C program which makes everything, with a little Bash support. Something like this: