start Cygwin from Total Commander

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
darylz
Junior Member
Junior Member
Posts: 6
Joined: 2008-11-21, 09:57 UTC

start Cygwin from Total Commander

Post by *darylz »

Hi guys,

Currently I start Cygwin from TC by right click, Cygwin can be started and "cd" the current directory.
Right click integration is done by add this key to Windows registry:

c:\cygwin\bin\bash.exe --login -i -c 'cd "`cygpath "$*"`";bash' bash %L

Can I set a hot-key in TC for to do this?

Thanks in advance!

Darylz
fredvej
Junior Member
Junior Member
Posts: 26
Joined: 2003-03-13, 11:14 UTC
Location: Denmark

Post by *fredvej »

You can add the command to the user menu and define a hotkey to activate that menu point :

[User]
Menu1=Cygwin shell
Cmd1=c:\cygwin\bin\bash.exe --login -i -c 'cd "`cygpath "$*"`";bash' bash %L


[Shortcuts]
F2=cm_usermenu1
Best regards
Freddy Vejen
darylz
Junior Member
Junior Member
Posts: 6
Joined: 2008-11-21, 09:57 UTC

Post by *darylz »

Thanks fredvej,

There still is a problem:
For Explorer right click integration, "%L" is used to represent the current directory, but in TC, how to get this info transfer as an argument?

Darylz
stud
Junior Member
Junior Member
Posts: 9
Joined: 2004-06-04, 12:48 UTC

Post by *stud »

darylz wrote: For Explorer right click integration, "%L" is used to represent the current directory, but in TC, how to get this info transfer as an argument?
Hi, I used %P instead of %L, and it works, even with paths containing spaces.

BTW you can also change the user menu in Total Commander itself.
darylz
Junior Member
Junior Member
Posts: 6
Joined: 2008-11-21, 09:57 UTC

Post by *darylz »

but I got an error:

Code: Select all


bash: cd: %P: No such file or directory

fredvej
Junior Member
Junior Member
Posts: 26
Joined: 2003-03-13, 11:14 UTC
Location: Denmark

Post by *fredvej »

When you start Cygwin bash, it starts in your Cygwin home directory. Puth this in ~/.profile :
cd "$OLDPWD"
to make it jump back to the starting directory.

Now you must start Cygwin from the current directory in Windows :

[User]
Menu1=Cygwin shell
Cmd1=c:\cygwin\bin\bash.exe
Param1=--login -i
Path1=%P
Best regards
Freddy Vejen
stud
Junior Member
Junior Member
Posts: 9
Joined: 2004-06-04, 12:48 UTC

Post by *stud »

darylz wrote:but I got an error:

Code: Select all


bash: cd: %P: No such file or directory

Strange, my start menu entry looks like this, and is working fine.

Image: http://img151.imageshack.us/img151/4386/sshot2ou2.png
darylz
Junior Member
Junior Member
Posts: 6
Joined: 2008-11-21, 09:57 UTC

Post by *darylz »

Hi Vejen,

It's working well now with your solution except I have to remove this line "Path1=%P". Otherwise, Cygwin always start from cygdrive/c. It's very strange...

Thanks a lot anyway.

Stud,

I'll try more your way later, maybe I made some mistake. Thanks!

Darylz
User avatar
Naruki
Junior Member
Junior Member
Posts: 18
Joined: 2009-02-21, 02:28 UTC
Location: Tokyo, Japan

Thanks!

Post by *Naruki »

This post helped a lot. For any noobs like myself, here is what I have working.

The text file that holds custom commands should be located somewhere like this:
c:\Documents and Settings\%username%\Application Data\GHISLER\usercmd.ini

It might also be in your c:\totalcmd folder, depending on how it is installed. If you don't have one, just create it.

I have the following two entries in my file.
[em_cygwin_shell]
button=
cmd=c:\cygwin\bin\bash.exe --login -i -c 'cd "`cygpath "$*"`";bash' bash
param=%P
[em_cygwin_tail]
button=
cmd=c:\cygwin\bin\bash.exe --login -i -c 'tail -f "`cygpath "$*"`";bash' bash
param=%P%N
The first one opens a BASH shell at the directory that has focus. The second one starts tailing the file you have selected.

To use them,
  • right click on the button bar and select Change.
    (You can also select it from the Configuration menu.)
  • add a new button
  • click the magnifying glass button to the right of the Command text
  • select usercmd.ini at the bottom of the category list
  • and choose the command you want to use.
Technically, you can just enter the name of the command in the Command text field, but this way you know how to find other commands if you want.

Good luck!
User avatar
frenky
Senior Member
Senior Member
Posts: 250
Joined: 2005-07-30, 19:36 UTC

Post by *frenky »

I would recommend PuTTYcyg.

in "cygwin\etc\profile" comment out 'cd "$HOME"':

Code: Select all

# Make sure we start in home
#cd "$HOME" 
and create a button in TC to launch patched version of putty.

Code: Select all

Command: PuttyCygwin\puttycyg-20101029\putty.exe
Params    : -cygterm -
It will always open working dir.
CMD shell is a poor replacement for PuTTYCyg... That is the set-up I use :-)
Ambiguity succeeds where honesty dares not venture.
User avatar
Naruki
Junior Member
Junior Member
Posts: 18
Joined: 2009-02-21, 02:28 UTC
Location: Tokyo, Japan

Post by *Naruki »

Interesting! I wish I could use that, but I don't want to edit the profile (else it won't get updated).

Another problem I have is that Cygwin now defaults to put my home directory under Docs&Settings\... instead of the Cygwin\home\... folder. I hate that, so I set a Windows environment variable HOME to be c:\cygwin\home\%username%.

But PuTTYcyg does not expand the %username% variable and creates an ugly folder.

I wish I knew how to make Cygwin use the old style home path without having to hack it like that, but I don't.
User avatar
frenky
Senior Member
Senior Member
Posts: 250
Joined: 2005-07-30, 19:36 UTC

Post by *frenky »

I just looked at the new Cygwin installation, one does no longer need to delete "cd $HOME" or do 'cd "$OLDPWD"' as fredvej suggested (nice trick though), you can do:

Code: Select all

cmd /C set CHERE_INVOKING=true && start <path>\putty.exe -cygterm -
As a sidenote, I miss setting ENV directly from TC button :(

2Naruki
I have never had the kind of set-up where Cygwin HOME is set to any other value than the one I wished :mrgreen: What pops to mind is that you may try calling "mkpasswd.exe -l" to check whether your /etc/passwd file OK and "mkgroup.exe -l" for /etc/group.
Ambiguity succeeds where honesty dares not venture.
User avatar
Naruki
Junior Member
Junior Member
Posts: 18
Joined: 2009-02-21, 02:28 UTC
Location: Tokyo, Japan

Post by *Naruki »

frenky wrote:

Code: Select all

cmd /C set CHERE_INVOKING=true && start <path>\putty.exe -cygterm -
2Naruki
I have never had the kind of set-up where Cygwin HOME is set to any other value than the one I wished :mrgreen: What pops to mind is that you may try calling "mkpasswd.exe -l" to check whether your /etc/passwd file OK and "mkgroup.exe -l" for /etc/group.
Fairly awesome!

I tried using those programs to fix my problem, but I'm still too noobish to understand what to do. I don't know how my home directory got mis-set to begin with, but nothing I tried could fix it.

So I blew away the c:\Cygwin folder and re-installed. That fixed it.

Now your command works quite nicely for me. Thanks!
User avatar
sieve
Junior Member
Junior Member
Posts: 2
Joined: 2009-12-24, 23:35 UTC

Cygwin shell and Cygwin emacs and etc

Post by *sieve »

Install the chere package in cygwin (for explorer integration install with "chere -i").

Add a button:

Code: Select all

   command: C:\Apps\Cyg\bin\mintty.exe
parameters: -t "Cygwin" -e /bin/xhere /bin/bash.exe '%P'
 icon file: C:\Apps\Cyg\bin\mintty.exe
For cygwin native emacs (no X server needed), it can't deal with backslashes, so run file name through a batch file converter. Set this up using:

Code: Select all

Configuration | Options | Edit/View | Editor for F4 | Editor: C:\Apps\bin\LaunchEmacs.bat
Where that batch file is (change RUN to where cygwin is installed):

Code: Select all

@echo off
set RUN=C:\apps\cyg\bin\run.exe
:: Convert C:\Apps\bin into /c/Apps/bin so Cygwin emacs can grok
set file=%1
set file=%file:\=/%
set file=%file:C:=/c%
%RUN% /bin/emacs "%file%"
This depends on editing /etc/fstab to include:

Code: Select all

C: /c ntfs binary,user 1 1
So that instead of /cygdrive/c you simply use /c

After fixing /etc/fstab, to use your C:\Users\YOU directory as home instead of /home/YOU, edit /etc/passwd and where your name is at the end use:

Code: Select all

YOU:...stuff...:/c/Users/YOU:/bin/bash
For emacs I think I needed Control Panel | System | env vars | then:

Code: Select all

HOME   C:\Users\YOU
HOMEDRIVE  C:\
HOMEPATH \Users\YOU
Cygwin native emacs icon:

Code: Select all

Program  C:\Apps\Cyg\bin\run.exe emacs
Icon C:\Apps\Cyg\bin\emacs-w32.exe
Cygwin emacs startup using above shortcut now needs path to cygwin. In ~/.emacs:

Code: Select all

(setenv "PATH" (concat "/bin:/usr/bin:/usr/local/bin:" (getenv "PATH")))
(nconc exec-path '("/bin" "/usr/bin" "/usr/local/bin"))
Launch TotalCommander from Cygwin emacs in dired by typing capital W. Edit ~/.emacs:

Code: Select all

(add-hook 'dired-mode-hook
  '(lambda ()
    (progn
      (local-set-key "W" 'dired-run-windows-commander))))

(defun dired-run-windows-commander ()
  "Run Windows Commander on marked file in dired mode."
  (interactive)
  (progn
    (message '"Executing...")
    (let ((file (dired-get-filename)))
      (setq file (replace-regexp-in-string "^/c\\(.*\\)$" "\"C:\\1\"" file))
      (setq file (replace-regexp-in-string "/" "\\\\" file))
      (w32-shell-execute nil "/c/Apps/totalcmd/TOTALCMD64.EXE" file)
    )
  )
)
loc1263
New Member
New Member
Posts: 1
Joined: 2020-05-01, 18:55 UTC

Re: Thanks!

Post by *loc1263 »

Work fine !! Thanks !!
Naruki wrote: 2011-02-23, 16:15 UTC This post helped a lot. For any noobs like myself, here is what I have working.

The text file that holds custom commands should be located somewhere like this:
c:\Documents and Settings\%username%\Application Data\GHISLER\usercmd.ini

It might also be in your c:\totalcmd folder, depending on how it is installed. If you don't have one, just create it.

I have the following two entries in my file.
[em_cygwin_shell]
button=
cmd=c:\cygwin\bin\bash.exe --login -i -c 'cd "`cygpath "$*"`";bash' bash
param=%P
[em_cygwin_tail]
button=
cmd=c:\cygwin\bin\bash.exe --login -i -c 'tail -f "`cygpath "$*"`";bash' bash
param=%P%N
The first one opens a BASH shell at the directory that has focus. The second one starts tailing the file you have selected.

To use them,
  • right click on the button bar and select Change.
    (You can also select it from the Configuration menu.)
  • add a new button
  • click the magnifying glass button to the right of the Command text
  • select usercmd.ini at the bottom of the category list
  • and choose the command you want to use.
Technically, you can just enter the name of the command in the Command text field, but this way you know how to find other commands if you want.

Good luck!
Post Reply