add 'shellflag' option to customize shell flag

cc #597
This commit is contained in:
Gokcehan 2021-04-04 18:23:14 +03:00
parent aebff483a7
commit ca0068514a
8 changed files with 29 additions and 7 deletions

View File

@ -138,6 +138,7 @@ var (
"promptfmt", "promptfmt",
"ratios", "ratios",
"shell", "shell",
"shellflag",
"shellopts", "shellopts",
"sortby", "sortby",
"timefmt", "timefmt",

8
doc.go
View File

@ -126,6 +126,7 @@ The following options can be used to customize the behavior of lf:
reverse bool (default off) reverse bool (default off)
scrolloff int (default 0) scrolloff int (default 0)
shell string (default 'sh' for unix and 'cmd' for windows) shell string (default 'sh' for unix and 'cmd' for windows)
shellflag string (default '-c' for unix and '/c' for windows)
shellopts []string (default '') shellopts []string (default '')
smartcase bool (default on) smartcase bool (default on)
smartdia bool (default off) smartdia bool (default off)
@ -641,8 +642,11 @@ A smaller offset can be used when the current file is close to the beginning or
shell string (default 'sh' for unix and 'cmd' for windows) shell string (default 'sh' for unix and 'cmd' for windows)
Shell executable to use for shell commands. Shell executable to use for shell commands.
Shell commands are executed as 'shell shellopts -c command -- arguments'. Shell commands are executed as 'shell shellopts shellflag command -- arguments'.
On windows, '/c' is used instead of '-c' which should work in 'cmd' and 'powershell'.
shellflag string (default '-c' for unix and '/c' for windows)
Command line flag used to pass shell commands.
shellopts []string (default '') shellopts []string (default '')

View File

@ -129,6 +129,7 @@ The following options can be used to customize the behavior of lf:
reverse bool (default off) reverse bool (default off)
scrolloff int (default 0) scrolloff int (default 0)
shell string (default 'sh' for unix and 'cmd' for windows) shell string (default 'sh' for unix and 'cmd' for windows)
shellflag string (default '-c' for unix and '/c' for windows)
shellopts []string (default '') shellopts []string (default '')
smartcase bool (default on) smartcase bool (default on)
smartdia bool (default off) smartdia bool (default off)
@ -685,8 +686,11 @@ beginning or end of the list to show the maximum number of items.
shell string (default 'sh' for unix and 'cmd' for windows) shell string (default 'sh' for unix and 'cmd' for windows)
Shell executable to use for shell commands. Shell commands are executed as Shell executable to use for shell commands. Shell commands are executed as
'shell shellopts -c command -- arguments'. On windows, '/c' is used instead 'shell shellopts shellflag command -- arguments'.
of '-c' which should work in 'cmd' and 'powershell'.
shellflag string (default '-c' for unix and '/c' for windows)
Command line flag used to pass shell commands.
shellopts []string (default '') shellopts []string (default '')

View File

@ -309,6 +309,8 @@ func (e *setExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
case "shell": case "shell":
gOpts.shell = e.val gOpts.shell = e.val
case "shellflag":
gOpts.shellflag = e.val
case "shellopts": case "shellopts":
if e.val == "" { if e.val == "" {
gOpts.shellopts = nil gOpts.shellopts = nil

9
lf.1
View File

@ -141,6 +141,7 @@ The following options can be used to customize the behavior of lf:
reverse bool (default off) reverse bool (default off)
scrolloff int (default 0) scrolloff int (default 0)
shell string (default 'sh' for unix and 'cmd' for windows) shell string (default 'sh' for unix and 'cmd' for windows)
shellflag string (default '-c' for unix and '/c' for windows)
shellopts []string (default '') shellopts []string (default '')
smartcase bool (default on) smartcase bool (default on)
smartdia bool (default off) smartdia bool (default off)
@ -764,7 +765,13 @@ Minimum number of offset lines shown at all times in the top and the bottom of t
shell string (default 'sh' for unix and 'cmd' for windows) shell string (default 'sh' for unix and 'cmd' for windows)
.EE .EE
.PP .PP
Shell executable to use for shell commands. Shell commands are executed as 'shell shellopts -c command -- arguments'. On windows, '/c' is used instead of '-c' which should work in 'cmd' and 'powershell'. Shell executable to use for shell commands. Shell commands are executed as 'shell shellopts shellflag command -- arguments'.
.PP
.EX
shellflag string (default '-c' for unix and '/c' for windows)
.EE
.PP
Command line flag used to pass shell commands.
.PP .PP
.EX .EX
shellopts []string (default '') shellopts []string (default '')

View File

@ -55,6 +55,7 @@ var gOpts struct {
cleaner string cleaner string
promptfmt string promptfmt string
shell string shell string
shellflag string
timefmt string timefmt string
truncatechar string truncatechar string
ratios []int ratios []int
@ -95,6 +96,7 @@ func init() {
gOpts.cleaner = "" gOpts.cleaner = ""
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m" gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"
gOpts.shell = gDefaultShell gOpts.shell = gDefaultShell
gOpts.shellflag = gDefaultShellFlag
gOpts.timefmt = time.ANSIC gOpts.timefmt = time.ANSIC
gOpts.truncatechar = "~" gOpts.truncatechar = "~"
gOpts.ratios = []int{1, 2, 3} gOpts.ratios = []int{1, 2, 3}

3
os.go
View File

@ -23,6 +23,7 @@ var (
var ( var (
gDefaultShell = "sh" gDefaultShell = "sh"
gDefaultShellFlag = "-c"
gDefaultSocketProt = "unix" gDefaultSocketProt = "unix"
gDefaultSocketPath string gDefaultSocketPath string
) )
@ -99,7 +100,7 @@ func shellCommand(s string, args []string) *exec.Cmd {
s = fmt.Sprintf("IFS='%s'; %s", gOpts.ifs, s) s = fmt.Sprintf("IFS='%s'; %s", gOpts.ifs, s)
} }
args = append([]string{"-c", s, "--"}, args...) args = append([]string{gOpts.shellflag, s, "--"}, args...)
args = append(gOpts.shellopts, args...) args = append(gOpts.shellopts, args...)

View File

@ -22,6 +22,7 @@ var envPathExt = os.Getenv("PATHEXT")
var ( var (
gDefaultShell = "cmd" gDefaultShell = "cmd"
gDefaultShellFlag = "/c"
gDefaultSocketProt = "tcp" gDefaultSocketProt = "tcp"
gDefaultSocketPath = "127.0.0.1:12345" gDefaultSocketPath = "127.0.0.1:12345"
) )
@ -77,7 +78,7 @@ func detachedCommand(name string, arg ...string) *exec.Cmd {
} }
func shellCommand(s string, args []string) *exec.Cmd { func shellCommand(s string, args []string) *exec.Cmd {
args = append([]string{"/c", s}, args...) args = append([]string{gOpts.shellflag, s}, args...)
args = append(gOpts.shellopts, args...) args = append(gOpts.shellopts, args...)