Smart cd in directory hotlist

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
good_alias
Junior Member
Junior Member
Posts: 20
Joined: 2006-03-01, 21:33 UTC
Contact:

Smart cd in directory hotlist

Post by *good_alias »

I'm trying to implement a smart relative shortcut in directory hotlist.

I work on a big code base with a lot of structure. And I have different branches checked out on my disk.

So first I used an environment variable like: %branch1% and %branch2%

then i can do: "cd %branch1%/server/plugin"

but what I would like to do is:

"smartcd server/plugin"

and smartcd is a script that finds the top of the branch I'm in and does a relative cd from there.

I already have the script, but can't in any way transfer that information to Total Commander. One rather simple solution would be if I could run two commands on the Directory Hotlist command line. Then the script could set an environment variable and the second command could be cd including that variable.

I almost found a solution using commandline arguments to TC. But then I had to choose which side of TC I should open the path in.
seb-
Senior Member
Senior Member
Posts: 276
Joined: 2011-11-15, 06:14 UTC
Location: DE\BN - only part time TC user after switching to Linux ;)

Post by *seb- »

i did something similar (i had a "cd to newest sub directory") via script and

%commander_exe%" /O /S /L="targetdirectory"

always openened the directories in the active panel...


by the way: i dont understand from your posting whether you know that since last TC Release you can run multiple em_commands from one button. That could solve your "two commands" usage problem. I think it is also working for directory hotlist.



hope that helps a little.
good_alias
Junior Member
Junior Member
Posts: 20
Joined: 2006-03-01, 21:33 UTC
Contact:

Post by *good_alias »

Thanks
I did not now about a new "two commands" feature, I will take look at that.

But I don't understand what /L="targetdirectory" should do, /L always sets the left pane to that directory, but I want my Directory Hotlist item to work for both the right and left side unfortunately.

But perhaps I have to decide to always do this in either the right or the left pane or have one set of Directory Hotlist items for left panel and one set for the right...
good_alias
Junior Member
Junior Member
Posts: 20
Joined: 2006-03-01, 21:33 UTC
Contact:

Post by *good_alias »

No two commands doesn't seem to work in Directory Hotlist.
Or cd does not work in combination with another command, not in the button bar either.
So I can not execute

find_root.bat, cd %test%
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

2good_alias

(I don't have read and understood the whole thread, but..)

With "commands", TC commands are meant, like CM_xyz or EM_abc

To use your two commands in button,
first make a user command out of them, like

usercmd.ini
[em_rootBat]
cmd=cmd /c D:\rive\path\find_root.bat
[em_cdTest]
cmd=cd %test%

Then try in button:
em_rootBat, em_cdTest

But I guess the CD command could be in the bat as well?


Such commands will not work in Directory Hotlist at all.
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1052
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

Stefan2 wrote: Then try in button:
em_rootBat, em_cdTest
Won't work with a space after the comma. The corrected version will also work in the Directory Hotlist.
seb-
Senior Member
Senior Member
Posts: 276
Joined: 2011-11-15, 06:14 UTC
Location: DE\BN - only part time TC user after switching to Linux ;)

Post by *seb- »

good_alias wrote:Thanks
I did not now about a new "two commands" feature, I will take look at that.

But I don't understand what /L="targetdirectory" should do, /L always sets the left pane to that directory, but I want my Directory Hotlist item to work for both the right and left side unfortunately.

But perhaps I have to decide to always do this in either the right or the left pane or have one set of Directory Hotlist items for left panel and one set for the right...
No. Just try the command :-)
At least for me it always addresses the currently actibe panel. No matter if it is left or right.

I dont know from top of my head but one of the orher two switches cha ges the behavuor accordingly. Check the help. The commandline options are quite complex...


Regarding the Double command i was quite sure i have used it myself within hotlist.
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

ZoSTeR wrote:Won't work with a space after the comma.
Again! Still not? :oops: :)
The corrected version will also work in the Directory Hotlist.
Fine, thx :D
good_alias
Junior Member
Junior Member
Posts: 20
Joined: 2006-03-01, 21:33 UTC
Contact:

Post by *good_alias »

Well, I got it to work, kind of

the first, em_rootBat sets an environment variable, and since TC listens to environment changes, I can use that in the second command which does:
cd %test%

but this only works if I sleep 2 or 3 seconds in em_rootBat, after setting the environment variable.

And I can't do the cd command in the first command since, that will not change the current directory of TC (right?)

so any other bright ideas on how to do this?
seb-
Senior Member
Senior Member
Posts: 276
Joined: 2011-11-15, 06:14 UTC
Location: DE\BN - only part time TC user after switching to Linux ;)

Post by *seb- »

Why are you calling a batch file ( i assume because you name it
rootbat) and set an environment variable?

Why dont you set a local variable in the batch and the call totalcommander from the batch with the command i posted above? The you dont need to workaround with sleeps etc...

Hth
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

PowerShell: change server

Post by *Stefan2 »

2good_alias
Are that %branch1% ones mapped drives? Or do we talk about UNC paths?



EDIT: not relevant question if we use PowerShell

Here is an example. Needs more thinking and to develop a nicer prompt.



Example:

TC Button or em_command: you will be prompted to modify wantedshare

cmd=PowerShell -NoExit -NoProfile -ExecutionPolicy Bypass
param=?D:\rive\path\to\root.ps1 '%P' wantedshare

root.ps1
 

Code: Select all

#REM Get whole current path from TCs %P variable (first argument)
$oPath=$args[0]

#REM Get wanted branch from TCs second argument (type wanted text your own, overwrite 'wantedshare')
$wBranch=$args[1]
Write-Host Profided: $wBranch -AND- $oPath

#REM compute wanted path
$oBranch= split-path $oPath -qualifier
$wPath= ($oPath -replace($oBranch,$wBranch))
Write-Host New branch full path: $wPath
Write-Host "Press any key to continue ..."

#REM command to open $wPath in TC:
# todo...
#
#
#



Just a idea, POC.
 
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Calling batch and then using envvar in TC is wrong because batch only changes envvars in its own environment. Setting global envvars in batch AFAIK requires third-party tools.

Most correct way was mentioned above: you should simply start a script (e.g. batch file) that will retrieve correct envvar and call TOTALCMD /O /S /L="path", it will pass a CD command to running TC instance.
good_alias
Junior Member
Junior Member
Posts: 20
Joined: 2006-03-01, 21:33 UTC
Contact:

Post by *good_alias »

Oh great, the secret was the /S parameter, I didn't know about that one, and the explanation in the help file is not obvious.

/S /L=c:\mydir

will cd to mydir in the active panel, weather it is left or right. Great, what a fantastic forum.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Great!

BTW,
TOTALCMD.chm, section 4.a wrote:/S Interprets the passed dirs as source/target instead of left/right (for usage with /O). For example, a dir passed with /R= will be interpreted as the target dir.
Sounds quite logical for me, even with example. Maybe you have better explanation? :)
Post Reply