1

I work in a windows environment but prefer to use bash in cygwin as my shell. To cd to a lengthy path I am given in windows form I type:

cd $(cygpath -u 'Z:\Some\long\windows\path')

..pasting the windows path in from the clipboard. Since I'm lazy I tried to make a shortcut thus:

#!/usr/bin/env bash
if [ -z "$1" ]; then
    exit 0
else 
    TGT=$(cygpath -u $1)    
    cd $TGT
fi
exit 0

..then realised that the cd takes place in the shell my script runs in rather than the one I called it from so does not have the desired effect. How do I make this work?

2 Answers2

1

You could just set it as an alias:

alias cd='cd $(cygpath -u "$1")'

Stick that in your .bashrc file or wherever else you have your aliases set, and you should be golden.

Otherwise you'd need to put the directory with the path to your custom script earlier in your path than the directory with the actual cd command (I think cygwin sets path in .bash_profile); which probably won't work since cd is a shell builtin.

Jed Daniels
  • 7,282
  • 2
  • 34
  • 42
1

Plain cd 'Z:\Some\long\windows\path' should just work actually. You might want to enable the nodosfilewarning option though.

ak2
  • 562
  • 3
  • 4