Skip to content

WIP: Running custom commands#388

Merged
jesseduffield merged 2 commits into
masterfrom
feature/custom_commands
Apr 7, 2019
Merged

WIP: Running custom commands#388
jesseduffield merged 2 commits into
masterfrom
feature/custom_commands

Conversation

@jesseduffield

@jesseduffield jesseduffield commented Mar 12, 2019

Copy link
Copy Markdown
Owner

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)

image

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:

  1. read -p "Name: " name; echo $name; read -p "Number: " number; echo $number
  2. vim
  3. ls

Each 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 :)

Comment thread pkg/gui/gui.go Outdated
wg.Add(1)

go func() {
io.Copy(stdout, stdoutIn)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error return value of io.Copy is not checked (from errcheck)

Comment thread pkg/gui/gui.go Outdated
wg.Done()
}()

io.Copy(stderr, stderrIn)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error return value of io.Copy is not checked (from errcheck)

Comment thread pkg/gui/gui.go Outdated
io.Copy(stderr, stderrIn)
wg.Wait()

cmd.Wait()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error return value of cmd.Wait is not checked (from errcheck)

Comment thread pkg/gui/gui.go Outdated

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S1019: should use make(chan *exec.Cmd) instead (from gosimple)

Comment thread pkg/gui/gui.go Outdated
wg.Wait()

cmd.Wait()
outStr := string(stdoutBuf.Bytes())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S1030: should use stdoutBuf.String() instead of string(stdoutBuf.Bytes()) (from gosimple)

@codecov-io

codecov-io commented Mar 12, 2019

Copy link
Copy Markdown

Codecov Report

Merging #388 into master will increase coverage by 0.02%.
The diff coverage is 90%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
pkg/commands/os.go 72.02% <0%> (-1.03%) ⬇️
pkg/i18n/dutch.go 100% <100%> (ø) ⬆️
pkg/i18n/polish.go 100% <100%> (ø) ⬆️
pkg/i18n/english.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 878a15a...9f9885e. Read the comment docs.

@jesseduffield
jesseduffield force-pushed the feature/custom_commands branch 4 times, most recently from a7e2c3b to c081118 Compare April 7, 2019 07:07
@jesseduffield
jesseduffield force-pushed the feature/custom_commands branch from c081118 to 9f9885e Compare April 7, 2019 07:10
@jesseduffield
jesseduffield merged commit 0f1abcb into master Apr 7, 2019
@jesseduffield
jesseduffield deleted the feature/custom_commands branch March 20, 2023 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typing Custom Commands from within lazygit

3 participants