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.
User avatar
HaRT
Moderator
Posts: 8721
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 81 times
Been thanked: 147 times

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

Post by HaRT » Mon 28 Jan, 2019 17:29

Latest post of the previous page:

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 » Mon 28 Jan, 2019 17:47

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: 8721
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 81 times
Been thanked: 147 times

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

Post by HaRT » Mon 28 Jan, 2019 18:14

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: 409
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 5 times
Been thanked: 21 times

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

Post by pepak » Mon 28 Jan, 2019 19:42

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: 8721
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 81 times
Been thanked: 147 times

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

Post by HaRT » Mon 28 Jan, 2019 19:59

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 » Wed 30 Jan, 2019 17:18

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”