Page 2 of 2

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

Posted: Mon 28 Jan, 2019 17:29
by HaRT

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.

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

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

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

Posted: Mon 28 Jan, 2019 18:14
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:

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

Posted: Mon 28 Jan, 2019 19:42
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.

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

Posted: Mon 28 Jan, 2019 19:59
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.

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

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