Keep new window open after execution of a command with Shift-Enter Topic is solved

You have encountered a problem using Far Manager? Here you can get help.
jo.navy
Posts: 11
Joined: Mon 28 Jan, 2019 10:31
Has thanked: 1 time

Keep new window open after execution of a command with Shift-Enter

Post by jo.navy »

Latest post of the previous page:

HaRT wrote:
Mon 28 Jan, 2019 16:39
I'd recommend adding empty double quotes as start's first argument — it fixes at least starting .lnk shortcut files for me.
Yes, more precisely it fixes any ShiftEnter over a file or directory containing spaces. I've found a vague reference to this fact here. Since start's first argument is the title of the new window, I prefer using "%COMSPEC%" instead of an empty string. The macro, with regedit escapes, becomes:

Code: Select all

"Sequence"="%e = CmdLine.Empty; %s=\"start \\\"%COMSPEC%\\\" \"; %i=index(CmdLine.Value, %s); $If(%i != 0) CtrlHome $Text %s $End $If(%e) CtrlEnter $End ShiftEnter"
I think that the Far3 equivalent of this macro should be added to the Macro folder of future releases.
If there was a way to hide the "start" in command history it would be really perfect.

User avatar
HaRT
Moderator
Posts: 9485
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 109 times
Been thanked: 225 times

Keep new window open after execution of a command with Shift-Enter

Post by HaRT »

jo.navy wrote:
Mon 28 Jan, 2019 17:17
it fixes any ShiftEnter over a file or directory containing spaces. I've found a vague reference to this fact here.
That page is imprecise. As per start /?, the Title argument is optional. Now I see why I needed it in my use cases. I think it is a good idea to quote the file path/name instead of providing a fake window title.

P.S.
Hmm, the start "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Far Manager 3\Far Manager 3.lnk" command doesn't start FAR (I get a cmd window instead), whereas start "" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Far Manager 3\Far Manager 3.lnk" does.
Фар есть инструмент, а не нянька. © 2009 DrKnS

jo.navy
Posts: 11
Joined: Mon 28 Jan, 2019 10:31
Has thanked: 1 time

Keep new window open after execution of a command with Shift-Enter

Post by jo.navy »

HaRT wrote:
Mon 28 Jan, 2019 17:29
the start "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Far Manager 3\Far Manager 3.lnk" command doesn't start FAR
Yes, it doesn't start Far because the file name contains spaces so Far Manager must add quotes to it and quotes are used by the start command for the window title too. Using start "" "Far Manager 3.lnk" or start "%COMSPEC%" "Far Manager 3.lnk" works.

User avatar
HaRT
Moderator
Posts: 9485
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 109 times
Been thanked: 225 times

Keep new window open after execution of a command with Shift-Enter

Post by HaRT »

jo.navy wrote:
Mon 28 Jan, 2019 17:47
because the file name contains spaces so Far Manager must add quotes to it
All spaces in the file name are quoted already, so it should not be the problem. Moreover, it does not work even if I try it in CMD, no Far involved. It must be some perverted parsing by start itself which treats the first quote as beginning of Title. Normal parsing would count parameters instead and, if more than 1, treat the first one as the Title. But it's not the CMD way of doing things. :crazy:
Фар есть инструмент, а не нянька. © 2009 DrKnS

pepak
Posts: 474
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 12 times
Been thanked: 34 times

Keep new window open after execution of a command with Shift-Enter

Post by pepak »

Well, sure. Because when Start encounters the quote, it says, "Oh, a title for the window! But where the heck is the command line?" That's why you need to use start "whatever" "path" - so that the first quoted string is considered the title and the second is considered the path.

User avatar
HaRT
Moderator
Posts: 9485
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 109 times
Been thanked: 225 times

Keep new window open after execution of a command with Shift-Enter

Post by HaRT »

pepak wrote:
Mon 28 Jan, 2019 19:42
when Start encounters the quote, it says, "Oh, a title for the window! But where the heck is the command line?"
That's what I call “perverted parsing”. See above for what I call the normal one. ;-)
start pause and start "pause" giving different results — it is crazy.
Фар есть инструмент, а не нянька. © 2009 DrKnS

jo.navy
Posts: 11
Joined: Mon 28 Jan, 2019 10:31
Has thanked: 1 time

Keep new window open after execution of a command with Shift-Enter

Post by jo.navy »

I handled two other corner cases: disabled the macro in plugin panels and when ShiftEnter is pressed on a folder; I also avoided "hitting" ShiftEnter instead of Enter to execute the "start" command. The final logic with indentation is:

Code: Select all

%s="start \"%COMSPEC%\" ";
$If(CmdLine.Empty)
	$If (APanel.Folder)
		ShiftEnter
	$Else
		$Text %s CtrlEnter Enter
	$End
$Else
	%i=index(CmdLine.Value, %s);
	$If(%i != 0)
		CtrlHome $Text %s
	$End
	Enter
$End
Final result in regedit syntax is:

Code: Select all

REGEDIT4

[-HKEY_CURRENT_USER\Software\Far\KeyMacros\Shell\ShiftEnter]
[HKEY_CURRENT_USER\Software\Far\KeyMacros\Shell\ShiftEnter]
"Description"="Keep new window open after execution of a command with Shift-Enter"
"NoPluginPanels"=dword:00000001
"Sequence"="%s=\"start \\\"%COMSPEC%\\\" \"; $If(CmdLine.Empty) $If (APanel.Folder) ShiftEnter $Else $Text %s CtrlEnter Enter $End $Else %i=index(CmdLine.Value, %s); $If(%i != 0) CtrlHome $Text %s $End Enter $End"
Tested with Far v1.75.
Last edited by jo.navy on Thu 31 Jan, 2019 11:43, edited 1 time in total.

Post Reply

Return to “Support and Troubleshooting”