Archive for the ‘Windows Shell’ Category

Jump points to file system location in windows shell

January 28, 2009

I spend a ton of my time in the windows shell going back and forth between source trees, tons of notes, todo lists, etc. I got tired of typing in these same paths to CD to all the time so I created a simple pair of scripts to manage this for me.
A usage example is like this:
I CD to a directory I frequently want to use, such as d:\src\db_prj\branch7\tbl\constraint\pk. While in that directory, I run my script with something like “sd.cmd pk7”. This associates my arbitrary token “pk7” with this location by creating a batch file called pk7.cmd.
When I later want to jump that directory I run “gd.cmd pk7”, which invokes the pk7.cmd and puts me in this location. I don’t always remember my defined tokens so I run “ld.cmd” to get a listing of all tokens I have defined. Here are the contents of the scripts:
_begin sd.cmd_
@echo off
rem token is %1
rem path is %~p1

@if not exist "%~dp0\cd_store" md "%~dp0\cd_store"

echo @cd /d "%~dp1" > %~dp0\cd_store\%1.cmd

echo Stored "%~dp1" as token %1, CD to path with: gd %1

_end sd.cmd_

_begin gd.cmd_

@if exist "%~dp0\cd_store\%1.cmd" (@call %~dp0\cd_store\%1.cmd) else (@echo No location defined for token %1)

_end gd.cmd_

_begin ld.cmd_

@echo off

dir "%~dp0cd_store\*%1*cmd" /b

_end ld.cmd_

To use the scripts, just create a location like c:\cmd and place the files there. Then add c:\cmd to your path.

I think there is room for improvement in the token listing at some point. I was thinking of stuffing some metadata in each token.cmd file that could then be parsed out to generate the listing. The current solution is highly effective so I haven’t been motivated to tweak it further. 🙂