Nov 23

This is a three-part solution to something I’ve always wanted to do but never applied myself to. Doubtless there will be a dozen better ways to do it that have remained hidden until I solved it myself.

The aim is to start a new bash session in a directory of your choice, but keeping all your nice personal settings.

My environment: I have cygwin and console2, though you can use any terminal you like.

The key to the whole shebang is clip.tgz. A simple command-line clipboard reader and writer for cygwin. clip -p to write the clipboard to stdout, clip -c to get stdin onto the clipboard.

Next up: pastedir.sh

#!/usr/bin/bash
candidate="`clip -p`"
if [ -d "$candidate" ]
then
pushd “$candidate”
fi

I put this in ~/bin

Finally, I add the following line to .bash_profile:

. bin/pastedir.sh

The result: whenever a bash session starts, if there’s a directory on the clipboard, the bash prompt starts in that directory.

To start in a directory, I swipe its name and hit ^T in console. Console starts a new window, and bash spots the directory and changes to it.

Todo:

  • Accept forward and backward slashes
  • Right now the dir must be absolute, or relative to home. Would be nice to somehow take the current directory into account.

2 comments so far...

  • sweavo Said on November 23rd, 2007 at 14:18:

    addendum:

    alias cpd to the following:

    pwd -P | clip -c

    and you can then go cpd (enter) (^T) and you get a new session in the current directory.

  • ianb1469 Said on November 23rd, 2007 at 20:26:

    You need acme or wily … remember?

leave a reply

You must be logged in to post a comment.

 

November 2007
S M T W T F S
« Oct   Dec »
 123
45678910
11121314151617
18192021222324
252627282930  

Archives

Meta