add an option to configure shell used by commands

This commit is contained in:
Gokcehan 2016-08-27 14:12:03 +03:00
parent 4dc8eccf9e
commit ce25fc55ca
6 changed files with 25 additions and 10 deletions

4
app.go
View File

@ -16,7 +16,7 @@ type App struct {
func waitKey() error {
// TODO: this should be done with termbox somehow
cmd := exec.Command(envShell, "-c", "echo; echo -n 'Press any key to continue'; stty -echo; read -n 1; stty echo; echo")
cmd := exec.Command(gOpts.shell, "-c", "echo; echo -n 'Press any key to continue'; stty -echo; read -n 1; stty echo; echo")
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
@ -98,7 +98,7 @@ func (app *App) runShell(s string, args []string, wait bool, async bool) {
}
args = append([]string{"-c", s, "--"}, args...)
cmd := exec.Command(envShell, args...)
cmd := exec.Command(gOpts.shell, args...)
if !async {
cmd.Stdin = os.Stdin

12
comp.go
View File

@ -11,16 +11,18 @@ import (
var (
gCmdWords = []string{"set", "map", "cmd"}
gOptWords = []string{
"preview",
"nopreview",
"preview!",
"hidden",
"nohidden",
"hidden!",
"tabstop",
"preview",
"nopreview",
"preview!",
"scrolloff",
"sortby",
"tabstop",
"ifs",
"shell",
"showinfo",
"sortby",
"ratios",
}
)

View File

@ -23,12 +23,14 @@
## Options
preview bool (default on)
hidden bool (default off)
tabstop int (default 8)
preview bool (default on)
scrolloff int (default 0)
sortby string (default name)
tabstop int (default 8)
ifs string (default not set)
shell string (default $SHELL)
showinfo string (default none)
sortby string (default name)
ratios string (default 1:2:3)
## Variables

View File

@ -5,6 +5,13 @@
#set nopreview
#set showinfo size
# Some systems use more efficient shell implementations for non-interactive use
# (e.g. `dash`) mapped to `/bin/sh`. By setting this option here we can tell
# `lf` to use this implementation for shell commands. This can decrease the
# startup times of commands but may also change the syntax that you are used to
# (e.g. non-POSIX features provided by your regular shell).
set shell /bin/sh
# leave some space at the top and the bottom of the screen
set scrolloff 10

View File

@ -62,6 +62,8 @@ func (e *SetExpr) eval(app *App, args []string) {
gOpts.tabstop = n
case "ifs":
gOpts.ifs = e.val
case "shell":
gOpts.shell = e.val
case "showinfo":
if e.val != "none" && e.val != "size" && e.val != "time" {
msg := "showinfo should either be 'none', 'size' or 'time'"

View File

@ -6,6 +6,7 @@ type Opts struct {
scrolloff int
tabstop int
ifs string
shell string
showinfo string
sortby string
ratios []int
@ -21,6 +22,7 @@ func init() {
gOpts.scrolloff = 0
gOpts.tabstop = 8
gOpts.ifs = ""
gOpts.shell = envShell
gOpts.showinfo = "none"
gOpts.sortby = "name"
gOpts.ratios = []int{1, 2, 3}