Is there a shortcut for /cygdrive/

3

1

Is there a shortcut for typing /cygdrive/ for every path? Is it possible to alias /cygdrive/ to /cd/ for example?

Altoid Muncher

Posted 2011-10-13T12:19:37.403

Reputation: 151

Does ln -s cygdrive /cd not work? – user1686 – 2011-10-13T13:48:01.357

Answers

5

$ man alias
NAME
     alias, unalias - create or remove a pseudonym  or  shorthand
     for a command or series of commands

They are used for commands only.

if you want to create a shortcut to /cygdrive i recommend using environment variables:
export PROJECT_DIR=/cygdrive/c/path/to/project
export c_dir=/cygdrive/c
export d_dir=/cygdrive/d

Put these into the .profile file under your home directory.
Usage:

cd $c_dir
cd $d_dir
cd $PROJECT_DIR

aayoubi

Posted 2011-10-13T12:19:37.403

Reputation: 151

Although you can alias c:='/cydrive/c' too, it might have some unwanted side effects. – ocodo – 2011-10-13T15:33:12.010

5

You could use : mount --change-cygdrive-prefix

For example : mount --change-cygdrive-prefix / and cd /c/ will change the working directory to /cygdrive/c/.

For permanent change (not session's change), you need to change the Windows registry.

Franck Lefort

Posted 2011-10-13T12:19:37.403

Reputation: 75

I just added this to my .bashrc and it works great, thanks! – Mark Ransom – 2015-12-03T17:24:04.607

If I put this solution in my .bashrc or the .bash_profile either one file $HOME ends up being incorrect and everything referencing it or ~ fail. – None – 2017-12-14T18:08:00.093

2

There's no need to edit the registry. In Cygwin versions before 1.7, changing the prefix with the mount command automatically became permanent, by updating the relevant registry entry. In Cygwin 1.7, mount points are no longer stored in the registry but read from /etc/fstab. See the user manual for the format of this.

– ak2 – 2011-10-13T15:27:45.327

This is the correct solution, supported by Cygwin, as the manual for the Cygwin mount command shows.

– Andrew Schulman – 2011-11-01T06:53:26.580

2

What I do is create symbolic links in the Cygwin home for those directories that I go to regularly, for example:

$ cd ~
$ ln -s /cygdrive/c/code

Then $ cd code takes me where I want to go.

Eric Wilson

Posted 2011-10-13T12:19:37.403

Reputation: 6 388

1

I found a more correct answerlink after I used the accepted one here and felt it was way to hacky to be correct given all the stuff it broke.

edit /etc/fstab the current version as of this time is

none /cygdrive cygdrive binary,posix=0,user 0 0

make it look like

none / cygdrive binary,posix=0,user 0 0

and you are good to go, no hacks to replace stuff in $PATH or $HOME or anything else!

user22908

Posted 2011-10-13T12:19:37.403

Reputation:

1

Could you use tab completion? eg type cd /cy and then press TAB and it should hopefully complete to /cygdrive/

Matthew Steeples

Posted 2011-10-13T12:19:37.403

Reputation: 2 130

FYI zsh completion will expand cd /cy/c to cd /cygdrive/c, I think bash won't. Of course, zsh completion will do the whole path as abbreviations, e.g. cd /cy/c/prog/mi/ [TAB] reliant on unique abbreviations of course. – ocodo – 2011-10-13T15:35:26.437

1

the following is a cygwin mount solution:

mount --change-cygdrive-prefix /

then instead of cd /cygdrive/c

cd /c

the earlier posts aliases are still useful for shortening "cd long-path" commands

MatthewP

Posted 2011-10-13T12:19:37.403

Reputation: 11