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 { func waitKey() error {
// TODO: this should be done with termbox somehow // 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.Stdin = os.Stdin
cmd.Stdout = os.Stdout 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...) args = append([]string{"-c", s, "--"}, args...)
cmd := exec.Command(envShell, args...) cmd := exec.Command(gOpts.shell, args...)
if !async { if !async {
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin

12
comp.go
View File

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

View File

@ -23,12 +23,14 @@
## Options ## Options
preview bool (default on)
hidden bool (default off) hidden bool (default off)
tabstop int (default 8) preview bool (default on)
scrolloff int (default 0) 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) showinfo string (default none)
sortby string (default name)
ratios string (default 1:2:3) ratios string (default 1:2:3)
## Variables ## Variables

View File

@ -5,6 +5,13 @@
#set nopreview #set nopreview
#set showinfo size #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 # leave some space at the top and the bottom of the screen
set scrolloff 10 set scrolloff 10

View File

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

View File

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