Run Total commander from bash on windows

Posted on

QUESTION :

I am trying to setup alias/function to call Total Commander from bash (MINGW) on windows. So far all my attempts failed, the closes

function tc() {
  dir="$1"
  if [ "$dir" == "" ]; then
    dir="."
  fi
  /c/TotalCmd/totalcmd.exe /O /L="`cygpath -wa $dir`" /R="`cygpath -wa .`" &

}

This solution has one drawback: TC is opened with given directories, but paths have additional / in them. This makes TC to go to root when I am trying to go one directory up.

enter image description here

Do you know how to setup this alias to work correctly? Thank you!

ANSWER :

You have to quote the $dir parameter, otherwise you may be giving more than two strings as arguments to cygpath (1st -wa, 2nd /path/). This will be a problem only when the $dir parameter holds a directory whose path contains spaces.

I.E.

cygpath -wa “~/x/hello world”

is not the same as

cygpath -wa ~/x/hello world

This should work for you (as it did for me):

jaroslav@wraptor ~
$ function winPath { cygpath.exe  -wa -- "$1"; }
$ FreeCommander.exe C: "$(winPath /cygdrive/m/muzica/_christian_liturgy/
    Athonite Fathers of St. Anthony's Greek Orthodox Monastery - 
    Vigil of St. Anthony/)"

So solution that works, thanks Jaroslav!

function tc() {
  dir="$1"
  if [ "$dir" == "" ]; then
    dir="."
  fi
  /c/totalcmd/totalcmd.exe /O L="`winPath $dir`"
}

function winPath { cygpath.exe  -wa -- "$1"; }

Leave a Reply

Your email address will not be published.