diff --git a/app.go b/app.go index 9047287..19f0ec6 100644 --- a/app.go +++ b/app.go @@ -6,6 +6,7 @@ import ( "io" "log" "os" + "os/exec" "strconv" "strings" ) @@ -19,6 +20,7 @@ type app struct { ui *ui nav *nav quitChan chan bool + cmd *exec.Cmd cmdIn io.WriteCloser cmdHist []cmdItem cmdHistInd int @@ -230,6 +232,7 @@ func (app *app) runShell(s string, args []string, prefix string) { switch prefix { case "%": go func() { + app.cmd = cmd app.ui.msg = "" app.ui.cmdPrefix = ">" @@ -252,6 +255,7 @@ func (app *app) runShell(s string, args []string, prefix string) { log.Printf("running shell: %s", err) } app.nav.renew(app.ui.wins[0].h) + app.cmd = nil app.ui.cmdPrefix = "" app.ui.draw(app.nav) }() diff --git a/doc.go b/doc.go index 5936d89..23cd14c 100644 --- a/doc.go +++ b/doc.go @@ -69,6 +69,7 @@ keybindings: cmd-delete-word (default '') cmd-put (default '') cmd-transpose (default '') + cmd-interrupt (default '') The following options can be used to customize the behavior of lf: diff --git a/docstring.go b/docstring.go index f36c118..dd767a9 100644 --- a/docstring.go +++ b/docstring.go @@ -73,6 +73,7 @@ keybindings: cmd-delete-word (default '') cmd-put (default '') cmd-transpose (default '') + cmd-interrupt (default '') The following options can be used to customize the behavior of lf: diff --git a/eval.go b/eval.go index 3cb6612..7360632 100644 --- a/eval.go +++ b/eval.go @@ -559,6 +559,14 @@ func (e *callExpr) eval(app *app, args []string) { if len(app.ui.cmdAccLeft) > 1 { app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2] = app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1] } + case "cmd-interrupt": + if app.cmd != nil { + app.cmd.Process.Kill() + } + app.ui.menuBuf = nil + app.ui.cmdAccLeft = nil + app.ui.cmdAccRight = nil + app.ui.cmdPrefix = "" default: cmd, ok := gOpts.cmds[e.name] if !ok { diff --git a/opts.go b/opts.go index 74a41b1..93788c3 100644 --- a/opts.go +++ b/opts.go @@ -124,6 +124,7 @@ func init() { gOpts.cmdkeys[""] = &callExpr{"cmd-delete-word", nil} gOpts.cmdkeys[""] = &callExpr{"cmd-put", nil} gOpts.cmdkeys[""] = &callExpr{"cmd-transpose", nil} + gOpts.cmdkeys[""] = &callExpr{"cmd-interrupt", nil} gOpts.cmds = make(map[string]expr)