Compare commits

13 Commits
Author SHA1 Message Date
Gokcehan 7872455021 restart event polling after ui resume on windows
cc #677
2021-10-19 22:51:25 +03:00
Gokcehan 1b71c33afd update doc 2021-10-10 00:01:01 +03:00
Gokcehan f01fab6257 fix crash when hidden is changed
cc #615 #657
2021-10-09 22:49:12 +03:00
SPFab 85aa3b9dc6 Cmap fixes (#691)
* fixed bug when switching commands

* filter and searches are now reset, whenever prompt is reset

* don't interrupt %-shell commands

* filter and search are now correctly started and stoped on cd

* movement commands now don't stop prompts

* forgot shell-pipe check in delete command
2021-08-29 18:28:29 +03:00
SPFabGerman 5566f82596 fixed bug, where ~ is not a absolute directory (#690) 2021-08-25 19:36:14 +03:00
SPFab 0edf0823b7 cmap now accepts all expressions (#686) 2021-08-25 18:28:47 +03:00
SPFab 05a48ea315 added pre-cd command (#685)
* added special pre-cd command

* added documentation
2021-08-23 17:11:56 +03:00
SPFab ff0933ca03 Added filter command (#667)
* added first version of interactive filter

* small fix when loading new file

* don't reset filter when directory is reloaded automatically

* reapply filter when options for searching change

* current filter or arguments now prefilled in the prompt

* empty filter can now be supplied

* added new setfilter command for use in scripts

* added incfilter option

* added very basic documentation

* added filter indication in statusbar

* added option to display filter to prompt
2021-08-21 16:40:24 +03:00
Gokcehan 6c46b217af add completion for dircache option 2021-08-01 17:06:04 +03:00
Gokcehan bdd1747e43 update doc 2021-08-01 17:04:37 +03:00
Yegor Bychin ee5b3f4813 add an option to disable directory cache (#673)
* add an option to disable directory cache

* change option name to `dircache`

* change 4 whitespaces to tab
2021-08-01 17:00:10 +03:00
Matthew Tooheyandmtoohey31 75eba115d2 implement dironly option (#669)
Co-authored-by: mtoohey31 <mtoohey31@users.noreply.github.com>
2021-07-31 16:10:25 +03:00
SeerLite 8adbd2b9ef Don't use the absolute path when saving bookmarks (#659)
The absolute path of symlinks were getting saved, so bookmarking a symlink
directory would cause the absolute path to be saved and loaded instead.
What's saved now is the current path string as understood by lf instead, so
path to symlinks can be saved too and they won't get dereferenced when
loading.
2021-07-09 16:34:45 +03:00
11 changed files with 520 additions and 126 deletions

No files matched your search

+12 -6
View File
@@ -372,13 +372,15 @@ func (app *app) loop() {
case d := <-app.nav.dirChan:
app.nav.checkDir(d)
prev, ok := app.nav.dirCache[d.path]
if ok {
d.ind = prev.ind
d.sel(prev.name(), app.nav.height)
}
if gOpts.dircache {
prev, ok := app.nav.dirCache[d.path]
if ok {
d.ind = prev.ind
d.sel(prev.name(), app.nav.height)
}
app.nav.dirCache[d.path] = d
app.nav.dirCache[d.path] = d
}
for i := range app.nav.dirs {
if app.nav.dirs[i].path == d.path {
@@ -493,6 +495,9 @@ func (app *app) runShell(s string, args []string, prefix string) {
err = cmd.Run()
case "%":
if app.ui.cmdPrefix == ">" {
return
}
stdin, err := cmd.StdinPipe()
if err != nil {
log.Printf("writing stdin: %s", err)
@@ -522,6 +527,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
switch prefix {
case "%":
normal(app)
app.cmd = cmd
app.cmdOutBuf = nil
app.ui.msg = ""
+11
View File
@@ -48,6 +48,8 @@ var (
"search-back",
"search-next",
"search-prev",
"filter",
"setfilter",
"mark-save",
"mark-remove",
"mark-load",
@@ -73,12 +75,18 @@ var (
"autoquit",
"noautoquit",
"autoquit!",
"dircache",
"nodircache",
"dircache!",
"dircounts",
"nodircounts",
"dircounts!",
"dirfirst",
"nodirfirst",
"dirfirst!",
"dironly",
"nodironly",
"dironly!",
"drawbox",
"nodrawbox",
"drawbox!",
@@ -100,6 +108,9 @@ var (
"incsearch",
"noincsearch",
"incsearch!",
"incfilter",
"noincfilter",
"incfilter!",
"mouse",
"nomouse",
"mouse!",
+30 -1
View File
@@ -62,6 +62,8 @@ The following commands are provided by lf:
search-back (modal) (default '?')
search-next (default 'n')
search-prev (default 'N')
filter (modal)
setfilter
mark-save (modal) (default 'm')
mark-load (modal) (default "'")
mark-remove (modal) (default `"`)
@@ -99,8 +101,10 @@ The following options can be used to customize the behavior of lf:
anchorfind bool (default on)
autoquit bool (default off)
dircache bool (default on)
dircounts bool (default off)
dirfirst bool (default on)
dironly bool (default off)
drawbox bool (default off)
errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n")
@@ -112,6 +116,7 @@ The following options can be used to customize the behavior of lf:
ifs string (default '')
ignorecase bool (default on)
ignoredia bool (default on)
incfilter bool (default off)
incsearch bool (default off)
info []string (default '')
mouse bool (default off)
@@ -388,6 +393,15 @@ Read a pattern to search for a file name match in the forward/backward direction
(See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options and 'Searching Files' section)
filter (modal)
setfilter
Read a pattern to filter out and only view files matching the pattern.
setfilter does the same but uses an argument to set the filter immediatly.
You can supply an argument to filter, in order to use that as the starting prompt.
(See also 'globsearch', 'incfilter', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options)
mark-save (modal) (default 'm')
Save the current directory as a bookmark assigned to the given key.
@@ -499,6 +513,10 @@ When this option is enabled, find command starts matching patterns from the begi
Automatically quit server when there are no clients left connected.
dircache bool (default on)
Cache directory contents.
dircounts bool (default off)
When this option is enabled, directory sizes show the number of items inside instead of the size of directory file.
@@ -512,6 +530,10 @@ A thousand items are counted per directory at most, and bigger directories are s
Show directories first above regular files.
dironly bool (default off)
Show only directories.
drawbox bool (default off)
Draw boxes around panes with box drawing characters.
@@ -577,6 +599,10 @@ Ignore diacritics in sorting and search patterns.
Jump to the first match after each keystroke during searching.
incfilter bool (default off)
Apply filter pattern after each keystroke during filtering.
info []string (default '')
List of information shown for directory items at the right side of pane.
@@ -625,7 +651,7 @@ Preview clearing is disabled when the value of this option is left empty.
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m")
Format string of the prompt shown in the top line.
Special expansions are provided, '%u' as the user name, '%h' as the host name, '%w' as the working directory, '%d' as the working directory with a trailing path separator, and '%f' as the file name.
Special expansions are provided, '%u' as the user name, '%h' as the host name, '%w' as the working directory, '%d' as the working directory with a trailing path separator, '%f' as the file name, and '%F' as the current filter.
Home folder is shown as '~' in the working directory expansion.
Directory names are automatically shortened to a single character starting from the left most parent when the prompt does not fit to the screen.
@@ -1230,6 +1256,9 @@ You can add an extra call to make it run on startup as well:
Note that all shell commands are possible but `%` and `&` are usually more appropriate as `$` and `!` causes flickers and pauses respectively.
There is also a 'pre-cd' command, that works like 'on-cd', but is run before the directory is actually changed.
It is generally a bad idea, to put movement commands (like 'up' / 'top' etc.) here.
Colors
lf tries to automatically adapt its colors to the environment.
+37 -5
View File
@@ -66,6 +66,8 @@ The following commands are provided by lf:
search-back (modal) (default '?')
search-next (default 'n')
search-prev (default 'N')
filter (modal)
setfilter
mark-save (modal) (default 'm')
mark-load (modal) (default "'")
mark-remove (modal) (default '"')
@@ -103,8 +105,10 @@ The following options can be used to customize the behavior of lf:
anchorfind bool (default on)
autoquit bool (default off)
dircache bool (default on)
dircounts bool (default off)
dirfirst bool (default on)
dironly bool (default off)
drawbox bool (default off)
errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n")
@@ -116,6 +120,7 @@ The following options can be used to customize the behavior of lf:
ifs string (default '')
ignorecase bool (default on)
ignoredia bool (default on)
incfilter bool (default off)
incsearch bool (default off)
info []string (default '')
mouse bool (default off)
@@ -408,6 +413,17 @@ direction and jump to the next/previous match.
(See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase',
'ignoredia', and 'smartdia' options and 'Searching Files' section)
filter (modal)
setfilter
Read a pattern to filter out and only view files matching the pattern.
setfilter does the same but uses an argument to set the filter immediatly.
You can supply an argument to filter, in order to use that as the starting
prompt.
(See also 'globsearch', 'incfilter', 'ignorecase', 'smartcase', 'ignoredia',
and 'smartdia' options)
mark-save (modal) (default 'm')
Save the current directory as a bookmark assigned to the given key.
@@ -525,6 +541,10 @@ beginning of file names, otherwise, it can match at an arbitrary position.
Automatically quit server when there are no clients left connected.
dircache bool (default on)
Cache directory contents.
dircounts bool (default off)
When this option is enabled, directory sizes show the number of items inside
@@ -541,6 +561,10 @@ directories are shown as '999+'.
Show directories first above regular files.
dironly bool (default off)
Show only directories.
drawbox bool (default off)
Draw boxes around panes with box drawing characters.
@@ -608,6 +632,10 @@ Ignore diacritics in sorting and search patterns.
Jump to the first match after each keystroke during searching.
incfilter bool (default off)
Apply filter pattern after each keystroke during filtering.
info []string (default '')
List of information shown for directory items at the right side of pane.
@@ -665,11 +693,11 @@ Preview clearing is disabled when the value of this option is left empty.
Format string of the prompt shown in the top line. Special expansions are
provided, '%u' as the user name, '%h' as the host name, '%w' as the working
directory, '%d' as the working directory with a trailing path separator, and
'%f' as the file name. Home folder is shown as '~' in the working directory
expansion. Directory names are automatically shortened to a single character
starting from the left most parent when the prompt does not fit to the
screen.
directory, '%d' as the working directory with a trailing path separator,
'%f' as the file name, and '%F' as the current filter. Home folder is shown
as '~' in the working directory expansion. Directory names are automatically
shortened to a single character starting from the left most parent when the
prompt does not fit to the screen.
ratios []int (default '1:2:3')
@@ -1379,6 +1407,10 @@ add an extra call to make it run on startup as well:
Note that all shell commands are possible but '%' and '&' are usually more
appropriate as '$' and '!' causes flickers and pauses respectively.
There is also a 'pre-cd' command, that works like 'on-cd', but is run before
the directory is actually changed. It is generally a bad idea, to put
movement commands (like 'up' / 'top' etc.) here.
Colors
+238 -70
View File
@@ -26,12 +26,36 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.autoquit = false
case "autoquit!":
gOpts.autoquit = !gOpts.autoquit
case "dircache":
gOpts.dircache = true
case "nodircache":
gOpts.dircache = false
case "dircache!":
gOpts.dircache = !gOpts.dircache
case "dircounts":
gOpts.dircounts = true
case "nodircounts":
gOpts.dircounts = false
case "dircounts!":
gOpts.dircounts = !gOpts.dircounts
case "dironly":
gOpts.dironly = true
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "nodironly":
gOpts.dironly = false
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "dironly!":
gOpts.dironly = !gOpts.dironly
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "dirfirst":
gOpts.sortType.option |= dirfirstSort
app.nav.sort()
@@ -70,10 +94,19 @@ func (e *setExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true)
case "globsearch":
gOpts.globsearch = true
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "noglobsearch":
gOpts.globsearch = false
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "globsearch!":
gOpts.globsearch = !gOpts.globsearch
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "hidden":
gOpts.sortType.option |= hiddenSort
app.nav.sort()
@@ -102,14 +135,17 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.ignorecase = true
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "noignorecase":
gOpts.ignorecase = false
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "ignorecase!":
gOpts.ignorecase = !gOpts.ignorecase
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "ignoredia":
gOpts.ignoredia = true
app.nav.sort()
@@ -122,6 +158,12 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.ignoredia = !gOpts.ignoredia
app.nav.sort()
app.ui.sort()
case "incfilter":
gOpts.incfilter = true
case "noincfilter":
gOpts.incfilter = false
case "incfilter!":
gOpts.incfilter = !gOpts.incfilter
case "incsearch":
gOpts.incsearch = true
case "noincsearch":
@@ -186,10 +228,19 @@ func (e *setExpr) eval(app *app, args []string) {
app.ui.sort()
case "smartcase":
gOpts.smartcase = true
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "nosmartcase":
gOpts.smartcase = false
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "smartcase!":
gOpts.smartcase = !gOpts.smartcase
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "smartdia":
gOpts.smartdia = true
case "nosmartdia":
@@ -385,10 +436,10 @@ func (e *mapExpr) eval(app *app, args []string) {
}
func (e *cmapExpr) eval(app *app, args []string) {
if e.cmd == "" {
if e.expr == nil {
delete(gOpts.cmdkeys, e.key)
} else {
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1}
gOpts.cmdkeys[e.key] = e.expr
}
app.ui.loadFileInfo(app.nav)
}
@@ -402,6 +453,12 @@ func (e *cmdExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav)
}
func preChdir(app *app) {
if cmd, ok := gOpts.cmds["pre-cd"]; ok {
cmd.eval(app, nil)
}
}
func onChdir(app *app) {
if cmd, ok := gOpts.cmds["on-cd"]; ok {
cmd.eval(app, nil)
@@ -461,10 +518,56 @@ func update(app *app) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case gOpts.incfilter && app.ui.cmdPrefix == "filter: ":
filter := string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
dir := app.nav.currDir()
old := dir.ind
if err := app.nav.setFilter(strings.Split(filter, " ")); err != nil {
app.ui.echoerrf("filter: %s", err)
} else if old != dir.ind {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
}
func restartIncCmd(app *app) {
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
dir := app.nav.currDir()
app.nav.searchInd = dir.ind
app.nav.searchPos = dir.pos
update(app)
} else if gOpts.incfilter && app.ui.cmdPrefix == "filter: " {
dir := app.nav.currDir()
app.nav.prevFilter = dir.filter
update(app)
}
}
func resetIncCmd(app *app) {
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
dir := app.nav.currDir()
dir.pos = app.nav.searchPos
if dir.ind != app.nav.searchInd {
dir.ind = app.nav.searchInd
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
} else if gOpts.incfilter && app.ui.cmdPrefix == "filter: " {
dir := app.nav.currDir()
old := dir.ind
app.nav.setFilter(app.nav.prevFilter)
if old != dir.ind {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
}
func normal(app *app) {
resetIncCmd(app)
app.ui.menuBuf = nil
app.ui.menuSelected = -2
@@ -479,6 +582,9 @@ func insert(app *app, arg string) {
case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"):
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
update(app)
case gOpts.incfilter && app.ui.cmdPrefix == "filter: ":
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
update(app)
case app.ui.cmdPrefix == "find: ":
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
@@ -605,12 +711,7 @@ func insert(app *app, arg string) {
case app.ui.cmdPrefix == "mark-save: ":
normal(app)
wd, err := os.Getwd()
if err != nil {
log.Printf("getting current directory: %s", err)
return
}
app.nav.marks[arg] = wd
app.nav.marks[arg] = app.nav.currDir().path
if err := app.nav.writeMarks(); err != nil {
app.ui.echoerrf("mark-save: %s", err)
}
@@ -636,6 +737,12 @@ func insert(app *app, arg string) {
app.ui.echoerr("mark-load: no such mark")
return
}
if wd != path {
resetIncCmd(app)
preChdir(app)
}
if err := app.nav.cd(path); err != nil {
app.ui.echoerrf("%s", err)
return
@@ -645,6 +752,7 @@ func insert(app *app, arg string) {
if wd != path {
app.nav.marks["'"] = wd
restartIncCmd(app)
onChdir(app)
}
case app.ui.cmdPrefix == "mark-remove: ":
@@ -674,57 +782,38 @@ func insert(app *app, arg string) {
func (e *callExpr) eval(app *app, args []string) {
switch e.name {
case "up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.up(e.count) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "half-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.up(e.count * app.nav.height / 2) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "page-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.up(e.count * app.nav.height) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.down(e.count) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "half-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.down(e.count * app.nav.height / 2) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "page-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.down(e.count * app.nav.height) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "updir":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
resetIncCmd(app)
preChdir(app)
for i := 0; i < e.count; i++ {
if err := app.nav.updir(); err != nil {
app.ui.echoerrf("%s", err)
@@ -733,11 +822,9 @@ func (e *callExpr) eval(app *app, args []string) {
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
restartIncCmd(app)
onChdir(app)
case "open":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
curr, err := app.nav.currFile()
if err != nil {
app.ui.echoerrf("opening: %s", err)
@@ -745,6 +832,8 @@ func (e *callExpr) eval(app *app, args []string) {
}
if curr.IsDir() {
resetIncCmd(app)
preChdir(app)
err := app.nav.open()
if err != nil {
app.ui.echoerrf("opening directory: %s", err)
@@ -752,6 +841,7 @@ func (e *callExpr) eval(app *app, args []string) {
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
restartIncCmd(app)
onChdir(app)
return
}
@@ -787,17 +877,11 @@ func (e *callExpr) eval(app *app, args []string) {
case "quit":
app.quitChan <- struct{}{}
case "top":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.top() {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "bottom":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.bottom() {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
@@ -808,6 +892,7 @@ func (e *callExpr) eval(app *app, args []string) {
} else {
dir := app.nav.currDir()
for _, path := range e.args {
path = replaceTilde(path)
if !filepath.IsAbs(path) {
path = filepath.Join(dir.path, path)
}
@@ -887,6 +972,10 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
if len(list) == 1 {
app.ui.cmdPrefix = "delete '" + list[0] + "' ? [y/N] "
} else {
@@ -931,25 +1020,53 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
case "read":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = ":"
app.ui.loadFileInfo(app.nav)
case "shell":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "$"
app.ui.loadFileInfo(app.nav)
case "shell-pipe":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "%"
app.ui.loadFileInfo(app.nav)
case "shell-wait":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "!"
app.ui.loadFileInfo(app.nav)
case "shell-async":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "&"
app.ui.loadFileInfo(app.nav)
case "find":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "find: "
app.nav.findBack = false
app.ui.loadFileInfo(app.nav)
case "find-back":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "find-back: "
app.nav.findBack = true
app.ui.loadFileInfo(app.nav)
@@ -982,6 +1099,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav)
}
case "search":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "/"
dir := app.nav.currDir()
app.nav.searchInd = dir.ind
@@ -989,6 +1110,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.searchBack = false
app.ui.loadFileInfo(app.nav)
case "search-back":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "?"
dir := app.nav.currDir()
app.nav.searchInd = dir.ind
@@ -1031,12 +1156,45 @@ func (e *callExpr) eval(app *app, args []string) {
}
}
}
case "filter":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "filter: "
dir := app.nav.currDir()
app.nav.prevFilter = dir.filter
if len(e.args) == 0 {
app.ui.cmdAccLeft = []rune(strings.Join(dir.filter, " "))
} else {
app.ui.cmdAccLeft = []rune(strings.Join(e.args, " "))
}
app.ui.loadFileInfo(app.nav)
case "setfilter":
log.Printf("filter: %s", e.args)
if err := app.nav.setFilter(e.args); err != nil {
app.ui.echoerrf("filter: %s", err)
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
case "mark-save":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "mark-save: "
case "mark-load":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-load: "
case "mark-remove":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-remove: "
case "rename":
@@ -1057,6 +1215,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("rename: %s:", err)
return
}
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "rename: "
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...)
}
@@ -1083,6 +1245,18 @@ func (e *callExpr) eval(app *app, args []string) {
log.Printf("getting current directory: %s", err)
}
path = replaceTilde(path)
if !filepath.IsAbs(path) {
path = filepath.Join(wd, path)
} else {
path = filepath.Clean(path)
}
if wd != path {
resetIncCmd(app)
preChdir(app)
}
if err := app.nav.cd(path); err != nil {
app.ui.echoerrf("%s", err)
return
@@ -1091,14 +1265,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
if !filepath.IsAbs(path) {
path = filepath.Join(wd, path)
} else {
path = filepath.Clean(path)
}
if wd != path {
app.nav.marks["'"] = wd
restartIncCmd(app)
onChdir(app)
}
case "select":
@@ -1112,6 +1281,18 @@ func (e *callExpr) eval(app *app, args []string) {
log.Printf("getting current directory: %s", err)
}
path := filepath.Dir(replaceTilde(e.args[0]))
if !filepath.IsAbs(path) {
path = filepath.Join(wd, path)
} else {
path = filepath.Clean(path)
}
if wd != path {
resetIncCmd(app)
preChdir(app)
}
if err := app.nav.sel(e.args[0]); err != nil {
app.ui.echoerrf("%s", err)
return
@@ -1120,15 +1301,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
path := filepath.Dir(e.args[0])
if !filepath.IsAbs(path) {
path = filepath.Join(wd, path)
} else {
path = filepath.Clean(path)
}
if wd != path {
app.nav.marks["'"] = wd
restartIncCmd(app)
onChdir(app)
}
case "glob-select":
@@ -1182,15 +1357,6 @@ func (e *callExpr) eval(app *app, args []string) {
if app.ui.cmdPrefix == ">" {
return
}
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
dir := app.nav.currDir()
dir.pos = app.nav.searchPos
if dir.ind != app.nav.searchInd {
dir.ind = app.nav.searchInd
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
normal(app)
case "cmd-complete":
var matches []string
@@ -1307,7 +1473,7 @@ func (e *callExpr) eval(app *app, args []string) {
}
case "cmd-enter":
s := string(append(app.ui.cmdAccLeft, app.ui.cmdAccRight...))
if len(s) == 0 {
if len(s) == 0 && app.ui.cmdPrefix != "filter: " {
return
}
@@ -1384,6 +1550,14 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "filter: ":
log.Printf("filter: %s", s)
app.ui.cmdPrefix = ""
if err := app.nav.setFilter(strings.Split(s, " ")); err != nil {
app.ui.echoerrf("filter: %s", err)
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
case "find: ":
app.ui.cmdPrefix = ""
if moved, found := app.nav.findNext(); !found {
@@ -1413,7 +1587,7 @@ func (e *callExpr) eval(app *app, args []string) {
oldPath := filepath.Join(wd, curr.Name())
newPath := filepath.Clean(s)
newPath := filepath.Clean(replaceTilde(s))
if !filepath.IsAbs(newPath) {
newPath = filepath.Join(wd, newPath)
}
@@ -1480,12 +1654,9 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
normal(app)
app.ui.cmdPrefix = cmd.prefix
app.ui.cmdAccLeft = []rune(cmd.value)
app.ui.cmdAccRight = nil
app.ui.cmdTmp = nil
app.ui.menuBuf = nil
app.ui.menuSelected = -2
case "cmd-history-prev":
if app.ui.cmdPrefix == ">" {
return
@@ -1498,12 +1669,9 @@ func (e *callExpr) eval(app *app, args []string) {
}
app.cmdHistoryInd++
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
normal(app)
app.ui.cmdPrefix = cmd.prefix
app.ui.cmdAccLeft = []rune(cmd.value)
app.ui.cmdAccRight = nil
app.ui.cmdTmp = nil
app.ui.menuBuf = nil
app.ui.menuSelected = -2
case "cmd-delete":
if len(app.ui.cmdAccRight) == 0 {
return
+1 -1
View File
@@ -218,7 +218,7 @@ var gEvalTests = []struct {
{
"cmap <c-g> cmd-escape",
[]string{"cmap", "<c-g>", "cmd-escape", "\n"},
[]expr{&cmapExpr{"<c-g>", "cmd-escape"}},
[]expr{&cmapExpr{"<c-g>", &callExpr{"cmd-escape", nil, 1}}},
},
{
+35 -1
View File
@@ -77,6 +77,8 @@ The following commands are provided by lf:
search-back (modal) (default '?')
search-next (default 'n')
search-prev (default 'N')
filter (modal)
setfilter
mark-save (modal) (default 'm')
mark-load (modal) (default "'")
mark-remove (modal) (default `"`)
@@ -118,8 +120,10 @@ The following options can be used to customize the behavior of lf:
.EX
anchorfind bool (default on)
autoquit bool (default off)
dircache bool (default on)
dircounts bool (default off)
dirfirst bool (default on)
dironly bool (default off)
drawbox bool (default off)
errorfmt string (default "\e033[7;31;47m%s\e033[0m")
filesep string (default "\en")
@@ -131,6 +135,7 @@ The following options can be used to customize the behavior of lf:
ifs string (default '')
ignorecase bool (default on)
ignoredia bool (default on)
incfilter bool (default off)
incsearch bool (default off)
info []string (default '')
mouse bool (default off)
@@ -479,6 +484,15 @@ Read a pattern to search for a file name match in the forward/backward direction
.PP
(See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options and 'Searching Files' section)
.PP
.EX
filter (modal)
setfilter
.EE
.PP
Read a pattern to filter out and only view files matching the pattern. setfilter does the same but uses an argument to set the filter immediatly. You can supply an argument to filter, in order to use that as the starting prompt.
.PP
(See also 'globsearch', 'incfilter', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options)
.PP
.EX
mark-save (modal) (default 'm')
.EE
@@ -624,6 +638,12 @@ When this option is enabled, find command starts matching patterns from the begi
.PP
Automatically quit server when there are no clients left connected.
.PP
.EX
dircache bool (default on)
.EE
.PP
Cache directory contents.
.PP
.EX
dircounts bool (default off)
.EE
@@ -636,6 +656,12 @@ When this option is enabled, directory sizes show the number of items inside ins
.PP
Show directories first above regular files.
.PP
.EX
dironly bool (default off)
.EE
.PP
Show only directories.
.PP
.EX
drawbox bool (default off)
.EE
@@ -708,6 +734,12 @@ Ignore diacritics in sorting and search patterns.
.PP
Jump to the first match after each keystroke during searching.
.PP
.EX
incfilter bool (default off)
.EE
.PP
Apply filter pattern after each keystroke during filtering.
.PP
.EX
info []string (default '')
.EE
@@ -754,7 +786,7 @@ Set the path of a cleaner file. This file will be called if previewing is enable
promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%d\e033[0m\e033[1m%f\e033[0m")
.EE
.PP
Format string of the prompt shown in the top line. Special expansions are provided, '%u' as the user name, '%h' as the host name, '%w' as the working directory, '%d' as the working directory with a trailing path separator, and '%f' as the file name. Home folder is shown as '~' in the working directory expansion. Directory names are automatically shortened to a single character starting from the left most parent when the prompt does not fit to the screen.
Format string of the prompt shown in the top line. Special expansions are provided, '%u' as the user name, '%h' as the host name, '%w' as the working directory, '%d' as the working directory with a trailing path separator, '%f' as the file name, and '%F' as the current filter. Home folder is shown as '~' in the working directory expansion. Directory names are automatically shortened to a single character starting from the left most parent when the prompt does not fit to the screen.
.PP
.EX
ratios []int (default '1:2:3')
@@ -1367,6 +1399,8 @@ This command runs whenever you change directory but not on startup. You can add
.EE
.PP
Note that all shell commands are possible but `%` and `&` are usually more appropriate as `$` and `!` causes flickers and pauses respectively.
.PP
There is also a 'pre-cd' command, that works like 'on-cd', but is run before the directory is actually changed. It is generally a bad idea, to put movement commands (like 'up' / 'top' etc.) here.
.SH COLORS
lf tries to automatically adapt its colors to the environment. It starts with a default colorscheme and updates colors using values of existing environment variables possibly by overwriting its previous values. Colors are set in the following order:
.PP
+121 -28
View File
@@ -113,7 +113,9 @@ type dir struct {
files []*file // displayed files in directory including or excluding hidden ones
allFiles []*file // all files in directory including hidden ones (same array as files)
sortType sortType // sort method and options from last sort
dironly bool // dironly value from last sort
hiddenfiles []string // hiddenfiles value from last sort
filter []string // last filter for this directory
ignorecase bool // ignorecase value from last sort
ignoredia bool // ignoredia value from last sort
noPerm bool // whether lf has no permission to open the directory
@@ -150,6 +152,7 @@ func normalize(s1, s2 string, ignorecase, ignoredia bool) (string, string) {
func (dir *dir) sort() {
dir.sortType = gOpts.sortType
dir.dironly = gOpts.dironly
dir.hiddenfiles = gOpts.hiddenfiles
dir.ignorecase = gOpts.ignorecase
dir.ignoredia = gOpts.ignoredia
@@ -219,6 +222,26 @@ func (dir *dir) sort() {
})
}
// when dironly option is enabled, we move files to the beginning of our file
// list and then set the beginning of displayed files to the first directory
// in the list
if dir.dironly {
sort.SliceStable(dir.files, func(i, j int) bool {
if !dir.files[i].IsDir() && !dir.files[j].IsDir() {
return i < j
}
return !dir.files[i].IsDir()
})
dir.files = func() []*file {
for i, f := range dir.files {
if f.IsDir() {
return dir.files[i:]
}
}
return dir.files[len(dir.files):]
}()
}
// when hidden option is disabled, we move hidden files to the
// beginning of our file list and then set the beginning of displayed
// files to the first non-hidden file in the list
@@ -232,11 +255,34 @@ func (dir *dir) sort() {
for i, f := range dir.files {
if !isHidden(f, dir.path, dir.hiddenfiles) {
dir.files = dir.files[i:]
return
break
}
}
dir.files = dir.files[len(dir.files):]
if len(dir.files) > 0 && isHidden(dir.files[len(dir.files)-1], dir.path, dir.hiddenfiles) {
dir.files = dir.files[len(dir.files):]
}
}
if len(dir.filter) != 0 {
sort.SliceStable(dir.files, func(i, j int) bool {
if isFiltered(dir.files[i], dir.filter) && isFiltered(dir.files[j], dir.filter) {
return i < j
}
return isFiltered(dir.files[i], dir.filter)
})
for i, f := range dir.files {
if !isFiltered(f, dir.filter) {
dir.files = dir.files[i:]
break
}
}
if len(dir.files) > 0 && isFiltered(dir.files[len(dir.files)-1], dir.filter) {
dir.files = dir.files[len(dir.files):]
}
}
dir.ind = max(dir.ind, 0)
dir.ind = min(dir.ind, len(dir.files)-1)
}
func (dir *dir) name() string {
@@ -244,9 +290,6 @@ func (dir *dir) name() string {
return ""
}
dir.ind = max(dir.ind, 0)
dir.ind = min(dir.ind, len(dir.files)-1)
return dir.files[dir.ind].Name()
}
@@ -307,36 +350,46 @@ type nav struct {
searchBack bool
searchInd int
searchPos int
prevFilter []string
volatilePreview bool
}
func (nav *nav) loadDir(path string) *dir {
d, ok := nav.dirCache[path]
if !ok {
d := &dir{
loading: true,
loadTime: time.Now(),
path: path,
sortType: gOpts.sortType,
hiddenfiles: gOpts.hiddenfiles,
ignorecase: gOpts.ignorecase,
ignoredia: gOpts.ignoredia,
}
nav.dirCache[path] = d
go func() {
d := newDir(path)
d.sort()
d.ind, d.pos = 0, 0
nav.dirChan <- d
}()
return d
func (nav *nav) loadDirInternal(path string) *dir {
d := &dir{
loading: true,
loadTime: time.Now(),
path: path,
sortType: gOpts.sortType,
hiddenfiles: gOpts.hiddenfiles,
ignorecase: gOpts.ignorecase,
ignoredia: gOpts.ignoredia,
}
nav.checkDir(d)
go func() {
d := newDir(path)
d.sort()
d.ind, d.pos = 0, 0
nav.dirChan <- d
}()
return d
}
func (nav *nav) loadDir(path string) *dir {
if gOpts.dircache {
d, ok := nav.dirCache[path]
if !ok {
d = nav.loadDirInternal(path)
nav.dirCache[path] = d
return d
}
nav.checkDir(d)
return d
} else {
return nav.loadDirInternal(path)
}
}
func (nav *nav) checkDir(dir *dir) {
s, err := os.Stat(dir.path)
if err != nil {
@@ -358,10 +411,12 @@ func (nav *nav) checkDir(dir *dir) {
dir.loadTime = now
go func() {
nd := newDir(dir.path)
nd.filter = dir.filter
nd.sort()
nav.dirChan <- nd
}()
case dir.sortType != gOpts.sortType ||
dir.dironly != gOpts.dironly ||
!reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) ||
dir.ignorecase != gOpts.ignorecase ||
dir.ignoredia != gOpts.ignoredia:
@@ -601,6 +656,27 @@ func (nav *nav) sort() {
}
}
func (nav *nav) setFilter(filter []string) error {
newfilter := []string{}
for _, tok := range filter {
_, err := filepath.Match(tok, "a")
if err != nil {
return err
}
if tok != "" {
newfilter = append(newfilter, tok)
}
}
dir := nav.currDir()
dir.filter = newfilter
// Apply filter, by sorting current dir (see nav.sort())
name := dir.name()
dir.sort()
dir.sel(name, nav.height)
return nil
}
func (nav *nav) up(dist int) bool {
dir := nav.currDir()
@@ -1251,6 +1327,22 @@ func (nav *nav) searchPrev() (bool, error) {
return false, nil
}
func isFiltered(f os.FileInfo, filter []string) bool {
for _, pattern := range filter {
matched, err := searchMatch(f.Name(), strings.TrimPrefix(pattern, "!"))
if err != nil {
log.Printf("Filter Error: %s", err)
return false
}
if strings.HasPrefix(pattern, "!") && matched {
return true
} else if !strings.HasPrefix(pattern, "!") && !matched {
return true
}
}
return false
}
func (nav *nav) removeMark(mark string) error {
if _, ok := nav.marks[mark]; ok {
delete(nav.marks, mark)
@@ -1322,6 +1414,7 @@ func (nav *nav) currFile() (*file, error) {
if len(dir.files) == 0 {
return nil, fmt.Errorf("empty directory")
}
return dir.files[dir.ind], nil
}
+6
View File
@@ -30,12 +30,15 @@ type sortType struct {
var gOpts struct {
anchorfind bool
autoquit bool
dircache bool
dircounts bool
dironly bool
drawbox bool
globsearch bool
icons bool
ignorecase bool
ignoredia bool
incfilter bool
incsearch bool
mouse bool
number bool
@@ -73,12 +76,15 @@ var gOpts struct {
func init() {
gOpts.anchorfind = true
gOpts.autoquit = false
gOpts.dircache = true
gOpts.dircounts = false
gOpts.dironly = false
gOpts.drawbox = false
gOpts.globsearch = false
gOpts.icons = false
gOpts.ignorecase = true
gOpts.ignoredia = true
gOpts.incfilter = false
gOpts.incsearch = false
gOpts.mouse = false
gOpts.number = false
+8 -12
View File
@@ -14,7 +14,7 @@ package main
//
// MapExpr = 'map' <keys> Expr
//
// CMapExpr = 'cmap' <key> <cmd> ';'
// CMapExpr = 'cmap' <key> Expr
//
// CmdExpr = 'cmd' <name> Expr
//
@@ -58,11 +58,11 @@ type mapExpr struct {
func (e *mapExpr) String() string { return fmt.Sprintf("map %s %s", e.keys, e.expr) }
type cmapExpr struct {
key string
cmd string
key string
expr expr
}
func (e *cmapExpr) String() string { return fmt.Sprintf("cmap %s %s", e.key, e.cmd) }
func (e *cmapExpr) String() string { return fmt.Sprintf("cmap %s %s", e.key, e.expr) }
type cmdExpr struct {
name string
@@ -191,23 +191,19 @@ func (p *parser) parseExpr() expr {
result = &mapExpr{keys, expr}
case "cmap":
var cmd string
var expr expr
s.scan()
key := s.tok
s.scan()
if s.typ != tokenSemicolon {
if s.typ != tokenIdent {
p.err = fmt.Errorf("expected command: %s", s.tok)
}
cmd = s.tok
expr = p.parseExpr()
} else {
s.scan()
}
s.scan()
result = &cmapExpr{key, cmd}
result = &cmapExpr{key, expr}
case "cmd":
var expr expr
+21 -2
View File
@@ -465,6 +465,7 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]in
type ui struct {
screen tcell.Screen
polling bool
wins []*win
promptWin *win
msgWin *win
@@ -538,6 +539,7 @@ func newUI(screen tcell.Screen) *ui {
ui := &ui{
screen: screen,
polling: true,
wins: getWins(screen),
promptWin: newWin(wtot, 1, 0, 0),
msgWin: newWin(wtot, 1, 0, htot-1),
@@ -561,6 +563,7 @@ func (ui *ui) pollEvents() {
for {
ev = ui.screen.PollEvent()
if ev == nil {
ui.polling = false
return
}
ui.tevChan <- ev
@@ -676,7 +679,8 @@ func (ui *ui) loadFileInfo(nav *nav) {
func (ui *ui) drawPromptLine(nav *nav) {
st := tcell.StyleDefault
pwd := nav.currDir().path
dir := nav.currDir()
pwd := dir.path
if strings.HasPrefix(pwd, gUser.HomeDir) {
pwd = filepath.Join("~", strings.TrimPrefix(pwd, gUser.HomeDir))
@@ -717,6 +721,12 @@ func (ui *ui) drawPromptLine(nav *nav) {
}
prompt = strings.Replace(prompt, "%d", pwd, -1)
if len(dir.filter) != 0 {
prompt = strings.Replace(prompt, "%F", fmt.Sprint(dir.filter), -1)
} else {
prompt = strings.Replace(prompt, "%F", "", -1)
}
ui.promptWin.print(ui.screen, 0, 0, st, prompt)
}
@@ -755,6 +765,10 @@ func (ui *ui) drawStatLine(nav *nav) {
selection += fmt.Sprintf(" \033[35;7m %d \033[0m", len(nav.selections))
}
if len(dir.filter) != 0 {
selection += " \033[34;7m F \033[0m"
}
var progress string
if nav.copyTotal > 0 {
@@ -1158,7 +1172,12 @@ func (ui *ui) suspend() error {
}
func (ui *ui) resume() error {
return ui.screen.Resume()
err := ui.screen.Resume()
if !ui.polling {
go ui.pollEvents()
ui.polling = true
}
return err
}
func anyKey() {