views:

292

answers:

10

Hi, Im searching a tool which allows me to specify some folders as "bookmarks" and than access them on the commandline (on Windows XP) via a keyword. Something like:

C:\> go home
D:\profiles\user\home\> go svn-project1
D:\projects\project1\svn\branch\src\>

I'm currently using a bunch of batch files, but editing them by hand is a daunting task. On Linux there is cdargs or shell bookmarks but I haven't found something on windows.

+2  A: 

With PowerShell you could add the folders as variables in your profile.ps1 file, like:

$vids="C:\Users\mabster\Videos"

Then, like Unix, you can just refer to the variables in your commands:

cd $vids

Having a list of variable assignments in the one ps1 file is probably easier than maintaining separate batch files.

Matt Hamilton
A: 

Without Powershell you can do it like this:

C:\>set DOOMED=c:\windows
C:\>cd %DOOMED%
C:\WINDOWS>
Espo
A: 

Thanks for the Powershell suggestion, but I'm not allowed to install it on my box at work, so it should be a "classic" cmd.exe solution.

crono
A: 

Environment variables?

set home=D:\profiles\user\home
set svn-project1=D:\projects\project1\svn\branch\src

cd %home%

On Unix I use this along with popd/pushd/cd - all the time.

Stephen Darlington
A: 

Are Environment variables defined via "set" not meant for the current session only? Can I persist them?

crono
+8  A: 

What you are looking for is called DOSKEY

You can use the doskey command to create macros in the command interpreter. For example:

doskey mcd=mkdir "$*"$Tpushd "$*"

creates a new command "mcd" that creates a new directory and then changes to that directory (I prefer "pushd" to "cd" in this case because it lets me use "popd" later to go back to where I was before)

The $* will be replaced with the remainder of the command line after the macro, and the $T is used to delimit the two different commands that I want to evaluate. If I typed:

mcd foo/bar

at the command line, it would be equivalent to:

mkdir "foo/bar"&pushd "foo/bar"

The next step is to create a file that contains a set of macros which you can then import by using the /macrofile switch. I have a file (c:\tools\doskey.macros) which defines the commands that I regularly use. Each macro should be specified on a line with the same syntax as above.

But you don't want to have to manually import your macros every time you launch a new command interpreter, to make it happen automatically, just open up the registry key

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun and set the value to be doskey /macrofile "c:\tools\doskey.macro". Doing this will make sure that your macros are automatically predefined every time you start a new interpreter.

Extra thoughts: - If you want to do other things in AutoRun (like set environment parameters), you can delimit the commands with the ampersand. Mine looks like: set root=c:\SomeDir&doskey /macrofile "c:\tools\doskey.macros" - If you prefer that your AutoRun settings be set per-user, you can use the HKCU node instead of HKLM. - You can also use doskey to control things like the size of the command history. - I like to end all of my navigation macros with \$* so that I can chain things together - Be careful to add quotes as appropriate in your macros if you want to be able to handle paths with spaces in them.

Andrew
A: 

I think Doskey will do it - thanks to all of you :)

crono
+1  A: 

With just a Batch file, try this... (save as filename "go.bat")

@echo off
set BookMarkFolder=c:\data\cline\bookmarks\
if exist %BookMarkFolder%%1.lnk start %BookMarkFolder%%1.lnk
if exist %BookMarkFolder%%1.bat start %BookMarkFolder%%1.bat
if exist %BookMarkFolder%%1.vbs start %BookMarkFolder%%1.vbs
if exist %BookMarkFolder%%1.URL start %BookMarkFolder%%1.URL

Any shortcuts, batch files, VBS Scripts or Internet shortcuts you put in your bookmark folder (in this case "c:\data\cline\bookmarks\" can then be opened / accessed by typing "go bookmarkname"

e.g. I have a bookmark called "stack.url". Typing go stack takes me straight to this page.

You may also want to investigate Launchy

seanyboy
+1  A: 

Another alternative approach you may want to consider could be to have a folder that contains symlinks to each of your projects or frequently-used directories. So you can do something like

cd \go\svn-project-1
cd \go\my-douments 

Symlinks can be made on a NTFS disk using the Junction tool

Cheekysoft
+1  A: 

Crono wrote:

Are Environment variables defined via "set" not meant for the current session only? Can I persist them?

They are set for the current process, and by default inherited by any process that it creates. They are not persisted to the registry. Their scope can be limited in cmd scripts with "setlocal" (and "endlocal").

Adam Mitz