WIP: Running custom commands#388
Conversation
| wg.Add(1) | ||
|
|
||
| go func() { | ||
| io.Copy(stdout, stdoutIn) |
There was a problem hiding this comment.
Error return value of io.Copy is not checked (from errcheck)
| wg.Done() | ||
| }() | ||
|
|
||
| io.Copy(stderr, stderrIn) |
There was a problem hiding this comment.
Error return value of io.Copy is not checked (from errcheck)
| io.Copy(stderr, stderrIn) | ||
| wg.Wait() | ||
|
|
||
| cmd.Wait() |
There was a problem hiding this comment.
Error return value of cmd.Wait is not checked (from errcheck)
|
|
||
| func (gui *Gui) listenForSubprocesses() { | ||
| // every time there is a subprocess, we're going to halt the execution of the UI via an update block, and wait for the command to finish | ||
| gui.subProcessChan = make(chan *exec.Cmd, 0) |
There was a problem hiding this comment.
S1019: should use make(chan *exec.Cmd) instead (from gosimple)
| wg.Wait() | ||
|
|
||
| cmd.Wait() | ||
| outStr := string(stdoutBuf.Bytes()) |
There was a problem hiding this comment.
S1030: should use stdoutBuf.String() instead of string(stdoutBuf.Bytes()) (from gosimple)
Codecov Report
@@ Coverage Diff @@
## master #388 +/- ##
==========================================
+ Coverage 84.84% 84.87% +0.02%
==========================================
Files 21 21
Lines 3464 3484 +20
==========================================
+ Hits 2939 2957 +18
- Misses 486 488 +2
Partials 39 39
Continue to review full report at Codecov.
|
a7e2c3b to
c081118
Compare
c081118 to
9f9885e
Compare
fixes #389
This feature is not for storing custom commands in a config to then access in lazygit via a hotkey (although I still do want to do that)
This is for directly typing a command in lazygit to run in a shell.
The keybinding is 'X' on the files panel, and I might make it global.
Currently in order to switch to a subprocess we need to close and re-open the gui which in itself doesn't take too long but it does cause a flash which is a bit jarring for commands that run instantly.
I also want to refresh the side panels after you run the command given how likely it will be that your command changes something in those panels. This brings to the foreground the need to speed up the various refresh-panel functions, given that right now a lot of it could be parallelised and taken out of the UI thread.
I've tested with the following commands:
read -p "Name: " name; echo $name; read -p "Number: " number; echo $numbervimlsEach is a different use case: in 1, we need to give input so I think it makes sense to be swapping out to a full subprocess so that you can enter stuff. In 2 we definitely need to switch to that subprocess, and in 3 we don't, so it's the one that currently seems the most off.
In each case when we get back to lazygit I show the command's output (both stdout and stderr) in a popup panel, unless for example we've just come back from vim and the output is huge because it was rendering a whole screen's worth of characters.
Let me know what you think of this first-cut approach :)