Keep new window open after execution of a command with Shift-Enter Topic is solved
Keep new window open after execution of a command with Shift-Enter
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!
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.
- HaRT
- Moderator
- Posts: 10866
- 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
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
-
- Posts: 6840
- Joined: Thu 23 Mar, 2006 21:36
- Location: Israel
- Has thanked: 41 times
- Been thanked: 530 times
Keep new window open after execution of a command with Shift-Enter
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;
}
Keep new window open after execution of a command with Shift-Enter
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
So far I have tried the following with Far v1.75:
but it has no effect!
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"
Keep new window open after execution of a command with Shift-Enter
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.
-
- Posts: 6840
- Joined: Thu 23 Mar, 2006 21:36
- Location: Israel
- Has thanked: 41 times
- Been thanked: 530 times
Keep new window open after execution of a command with Shift-Enter
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
My macro is for Far 3.0.
The case when command line is empty is handled by
flags="NotEmptyCommandLine"
- reread the macro.Keep new window open after execution of a command with Shift-Enter
After Shmuel's Far3 example I have tried also the following:
but, again, no effect (the command executes and the the window gets closed).
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"
Keep new window open after execution of a command with Shift-Enter
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.
-
- Posts: 6840
- Joined: Thu 23 Mar, 2006 21:36
- Location: Israel
- Has thanked: 41 times
- Been thanked: 530 times
Keep new window open after execution of a command with Shift-Enter
Right. I wrote the macro taking into account exactly your requirements in the original message.
- HaRT
- Moderator
- Posts: 10866
- 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
Last edited by HaRT on Mon 28 Jan, 2019 13:34, edited 1 time in total.
Фар есть инструмент, а не нянька. © 2009 DrKnS
Keep new window open after execution of a command with Shift-Enter
Great! It works. The only drawback is that
%COMSPEC% /k
appears in the command history but it is acceptable.Keep new window open after execution of a command with Shift-Enter
Minor improvement of HaRT's solution:
In this way if I recall a "ShiftEnter-ed" command from history and hit ShiftEnter again I don't get two
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"
%COMSPEC% /k
occurrences.
Last edited by jo.navy on Mon 28 Jan, 2019 15:07, edited 1 time in total.
Keep new window open after execution of a command with Shift-Enter
Further improvement: replaced
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.
%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"
- HaRT
- Moderator
- Posts: 10866
- 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
I'd recommend adding empty double quotes as
start
's first argument — it fixes at least starting .lnk
shortcut files for me.Фар есть инструмент, а не нянька. © 2009 DrKnS
Keep new window open after execution of a command with Shift-Enter
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"
If there was a way to hide the "start" in command history it would be really perfect.