diff --git a/complete.go b/complete.go index 5b770ee8..c3b965ea 100644 --- a/complete.go +++ b/complete.go @@ -192,6 +192,7 @@ var ( "cleaner", "promptfmt", "ratios", + "selmode", "shell", "shellflag", "shellopts", diff --git a/doc.go b/doc.go index bdfe8340..50868ada 100644 --- a/doc.go +++ b/doc.go @@ -146,6 +146,7 @@ The following options can be used to customize the behavior of lf: relativenumber bool (default off) reverse bool (default off) scrolloff int (default 0) + selmode string (default 'all') shell string (default 'sh' for Unix and 'cmd' for Windows) shellflag string (default '-c' for Unix and '/c' for Windows) shellopts []string (default '') @@ -742,6 +743,12 @@ When 'number' is enabled, current line shows the absolute position, otherwise no Reverse the direction of sort. + selmode string (default 'all') + +Selection mode for commands. +When set to 'all' it will use the selected files from all directories. +When set to 'dir' it will only use the selected files in the current directory. + scrolloff int (default 0) Minimum number of offset lines shown at all times in the top and the bottom of the screen when scrolling. diff --git a/docstring.go b/docstring.go index 3efe281f..e108cad8 100644 --- a/docstring.go +++ b/docstring.go @@ -149,6 +149,7 @@ The following options can be used to customize the behavior of lf: relativenumber bool (default off) reverse bool (default off) scrolloff int (default 0) + selmode string (default 'all') shell string (default 'sh' for Unix and 'cmd' for Windows) shellflag string (default '-c' for Unix and '/c' for Windows) shellopts []string (default '') @@ -787,6 +788,12 @@ shown. Reverse the direction of sort. + selmode string (default 'all') + +Selection mode for commands. When set to 'all' it will use the selected +files from all directories. When set to 'dir' it will only use the selected +files in the current directory. + scrolloff int (default 0) Minimum number of offset lines shown at all times in the top and the bottom diff --git a/eval.go b/eval.go index 29d60250..71bccbc4 100644 --- a/eval.go +++ b/eval.go @@ -386,6 +386,8 @@ func (e *setExpr) eval(app *app, args []string) { gOpts.ratios = rats app.ui.wins = getWins(app.ui.screen) app.ui.loadFile(app.nav, true) + case "selmode": + gOpts.selmode = e.val case "shell": gOpts.shell = e.val case "shellflag": diff --git a/lf.1 b/lf.1 index 1ac3c42f..9e288ae8 100644 --- a/lf.1 +++ b/lf.1 @@ -164,6 +164,7 @@ The following options can be used to customize the behavior of lf: relativenumber bool (default off) reverse bool (default off) scrolloff int (default 0) + selmode string (default 'all') shell string (default 'sh' for Unix and 'cmd' for Windows) shellflag string (default '-c' for Unix and '/c' for Windows) shellopts []string (default '') @@ -894,6 +895,12 @@ Show the position number relative to the current line. When 'number' is enabled, .PP Reverse the direction of sort. .PP +.EX + selmode string (default 'all') +.EE +.PP +Selection mode for commands. When set to 'all' it will use the selected files from all directories. When set to 'dir' it will only use the selected files in the current directory. +.PP .EX scrolloff int (default 0) .EE diff --git a/nav.go b/nav.go index 28ffb3d8..2d7f0b18 100644 --- a/nav.go +++ b/nav.go @@ -1838,27 +1838,37 @@ func (m indexedSelections) Swap(i, j int) { func (m indexedSelections) Less(i, j int) bool { return m.indices[i] < m.indices[j] } func (nav *nav) currSelections() []string { + + currDirOnly := gOpts.selmode == "dir" + currDirPath := "" + if currDirOnly { + // select only from this directory + currDirPath = nav.currDir().path + } + paths := make([]string, 0, len(nav.selections)) indices := make([]int, 0, len(nav.selections)) for path, index := range nav.selections { - paths = append(paths, path) - indices = append(indices, index) + if !currDirOnly || filepath.Dir(path) == currDirPath { + paths = append(paths, path) + indices = append(indices, index) + } } sort.Sort(indexedSelections{paths: paths, indices: indices}) return paths } func (nav *nav) currFileOrSelections() (list []string, err error) { - if len(nav.selections) == 0 { + sel := nav.currSelections() + + if len(sel) == 0 { curr, err := nav.currFile() if err != nil { return nil, errors.New("no file selected") } - return []string{curr.path}, nil } - - return nav.currSelections(), nil + return sel, nil } func (nav *nav) calcDirSize() error { diff --git a/opts.go b/opts.go index 20f97088..cd2f890b 100644 --- a/opts.go +++ b/opts.go @@ -60,6 +60,7 @@ var gOpts struct { previewer string cleaner string promptfmt string + selmode string shell string shellflag string timefmt string @@ -112,6 +113,7 @@ func init() { gOpts.previewer = "" gOpts.cleaner = "" gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m" + gOpts.selmode = "all" gOpts.shell = gDefaultShell gOpts.shellflag = gDefaultShellFlag gOpts.timefmt = time.ANSIC diff --git a/ui.go b/ui.go index 53586b33..5faccc60 100644 --- a/ui.go +++ b/ui.go @@ -789,8 +789,9 @@ func (ui *ui) drawStatLine(nav *nav) { } } - if len(nav.selections) > 0 { - selection += fmt.Sprintf(" \033[35;7m %d \033[0m", len(nav.selections)) + currSelections := nav.currSelections() + if len(currSelections) > 0 { + selection += fmt.Sprintf(" \033[35;7m %d \033[0m", len(currSelections)) } if len(dir.filter) != 0 {