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: 13
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 »

When I execute a command from the command line with Shift-Enter I would like to keep the new console window open after the command terminates its execution. I use Shift-Enter, for example, when i run a build from the command line so I need to examine the output to check for build errors.
Keeping the window open was default behaviour in Far 1.65 but not in v1.75 nor in v3 (tested with build 4949). I really need this feature, is there any way to enable it? I would like to get it in v1.75. Please, help!
Last edited by jo.navy on Mon 28 Jan, 2019 15:15, edited 1 time in total.
User avatar
HaRT
Moderator
Posts: 10823
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

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

Post by HaRT »

jo.navy wrote: Mon 28 Jan, 2019 10:43 is there any way to enable it
You can easily assign a script (“macro” — see docs) to the ShiftEnter shortcut, which will prepend the command with “cmd.exe /k ” and only then “hit” ShiftEnter — this will give the effect you ask for.
Фар есть инструмент, а не нянька. © 2009 DrKnS
Shmuel
Posts: 6820
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

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

Post by Shmuel »

HaRT wrote: Mon 28 Jan, 2019 11:23 You can easily assign a script

Code: Select all

Macro {
  description="Keep the external console window open";
  area="Shell QView Info"; key="ShiftEnter";
  flags="NotEmptyCommandLine";
  action=function()
    Far.DisableHistory(0xF)
    panel.SetCmdLine(nil, "cmd.exe /k "..panel.GetCmdLine())
    Keys("ShiftEnter")
  end;
}
jo.navy
Posts: 13
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 »

Yes, I was already examining the docs about macros and available examples. I also created a simple macro recently.
I know that I can get the content of the command line with CmdLine.Value and I how to hit "hit" Enter, but I'm not sure about the syntax to prepend CmdLine.Value with cmd.exe /k ; furthermore I'm not sure how to handle the case that the command line is empty: in this case Shift-Enter operates on the selected file in panel (if any).

So far I have tried the following with Far v1.75:

Code: Select all

REGEDIT4

[-HKEY_CURRENT_USER\Software\Far\KeyMacros\Shell\ShiftEnter]
[HKEY_CURRENT_USER\Software\Far\KeyMacros\Shell\ShiftEnter]
"Sequence"="$If (!CmdLine.Empty) \"%COMSPEC% /k \" + CmdLine.Value $Else ShiftEnter $End"
"DisableOutput"=dword:00000000
"Description"="Keep new window open after execution of a command with Shift-Enter"
but it has no effect!
jo.navy
Posts: 13
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 »

Shmuel wrote: Mon 28 Jan, 2019 12:03 panel.SetCmdLine(nil, "cmd.exe /k "..panel.GetCmdLine())
Thank you, Shmuel. Is panel.SetCmdLine available in v1.75 too? I don't see it in "Far Manager Encyclopedia" provided with v1.75.
And what about the case the command line is empty? It's not considered by your script.
Shmuel
Posts: 6820
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

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

Post by Shmuel »

In the era of Far 1.x I did not use macros so it'd be better you ask somebody else.
My macro is for Far 3.0.
The case when command line is empty is handled by flags="NotEmptyCommandLine" - reread the macro.
jo.navy
Posts: 13
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 »

After Shmuel's Far3 example I have tried also the following:

Code: Select all

REGEDIT4

[-HKEY_CURRENT_USER\Software\Far\KeyMacros\Shell\ShiftEnter]
[HKEY_CURRENT_USER\Software\Far\KeyMacros\Shell\ShiftEnter]
"Sequence"="$If (!CmdLine.Empty) CmdLine.Value =\"%COMSPEC% /k \" + CmdLine.Value; $End ShiftEnter"
"DisableOutput"=dword:00000000
"Description"="Keep new window open after execution of a command with Shift-Enter"
but, again, no effect (the command executes and the the window gets closed).
jo.navy
Posts: 13
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 »

Shmuel wrote: Mon 28 Jan, 2019 13:00 The case when command line is empty is handled by flags="NotEmptyCommandLine" - reread the macro.
But it means that your macro has no effect when the command line is empty (right?), on the contrary the file selected in active panel should be runned with cmd.exe /k so that the window remains open in this case too.
Last edited by jo.navy on Mon 28 Jan, 2019 13:07, edited 1 time in total.
Shmuel
Posts: 6820
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

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

Post by Shmuel »

jo.navy wrote: Mon 28 Jan, 2019 13:06 But it means that your macro has no effect when the command line is empty (right?)
Right. I wrote the macro taking into account exactly your requirements in the original message.
User avatar
HaRT
Moderator
Posts: 10823
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

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

Post by HaRT »

jo.navy wrote: Mon 28 Jan, 2019 12:46 it has no effect
Try .
Yet I prefer the & Fast Prefix.
Last edited by HaRT on Mon 28 Jan, 2019 13:34, edited 1 time in total.
Фар есть инструмент, а не нянька. © 2009 DrKnS
jo.navy
Posts: 13
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 13:22 "Sequence"="%e = CmdLine.Empty; CtrlHome $Text \"%COMSPEC% /k \" $If(%e) CtrlEnter $End ShiftEnter"
Great! It works. The only drawback is that %COMSPEC% /k appears in the command history but it is acceptable.
jo.navy
Posts: 13
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 »

Minor improvement of HaRT's solution:

Code: Select all

"Sequence"="%e = CmdLine.Empty; %cs=\"%COMSPEC% /k \"; %i=index(CmdLine.Value, %cs); $If(%i != 0) CtrlHome $Text %cs $End $If(%e) CtrlEnter $End ShiftEnter"
In this way if I recall a "ShiftEnter-ed" command from history and hit ShiftEnter again I don't get two %COMSPEC% /k occurrences.
Last edited by jo.navy on Mon 28 Jan, 2019 15:07, edited 1 time in total.
jo.navy
Posts: 13
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 »

Further improvement: replaced %COMSPEC% /k with start . Result is:

Code: Select all

"Sequence"="%e = CmdLine.Empty; %s=\"start \"; %i=index(CmdLine.Value, %s); $If(%i != 0) CtrlHome $Text %s $End $If(%e) CtrlEnter $End ShiftEnter"
In this way if I shift-enter over a RAR file (for example) I get the WinRAR window only, without the console window; all other use-cases work as with previous solution.
User avatar
HaRT
Moderator
Posts: 10823
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

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

Post by HaRT »

jo.navy wrote: Mon 28 Jan, 2019 15:51 Further improvement: replaced %COMSPEC% /k with start .
I'd recommend adding empty double quotes as start's first argument — it fixes at least starting .lnk shortcut files for me.
Фар есть инструмент, а не нянька. © 2009 DrKnS
jo.navy
Posts: 13
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 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.
Post Reply

Return to “Support and Troubleshooting”