Compare commits

23 Commits
Author SHA1 Message Date
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
Gokcehan 55b9189713 build release only on tags 2021-06-20 01:43:45 +03:00
Gokcehan b763c30cc5 deprecate travis in favor of github actions 2021-06-20 01:38:53 +03:00
gokcehan 61489ad00b Create release.yml 2021-06-20 01:37:44 +03:00
gokcehan 1ff3910c70 Create go.yml 2021-06-20 01:12:57 +03:00
Gokcehan 1966a30deb bump go version 2021-06-20 01:01:06 +03:00
ratijas 50e3a6856e PowerShell: use native Camel-Case style for commands (#650)
In PowerShell land it is preferred to use Camel Case for command names,
options and parameters, so lets respect that.
2021-06-19 23:41:14 +03:00
Gokcehan 9885c4be7a trim command prefix when it is longer than width
cc #648
2021-06-13 01:09:19 +03:00
Gokcehan 29aa77aa27 update doc 2021-06-13 00:36:48 +03:00
István Donkó 6e9f53f4bb Fix minor typo (#647)
* Fix minor typo

lf.1 will need to be regenerated as well.

* Fix minor typo
2021-06-13 00:36:16 +03:00
Gokcehan 099cccdcb5 show remote error when client id does not exists
cc #495
2021-06-13 00:27:43 +03:00
Gokcehan 4220868cc7 create data directory first before selection file
cc #645
2021-06-12 23:29:54 +03:00
17 changed files with 565 additions and 138 deletions

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
name: Go
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
+28
View File
@@ -0,0 +1,28 @@
name: Release
on:
push:
tags:
- '*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Build
run: gen/xbuild.sh
- name: Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-19
View File
@@ -1,19 +0,0 @@
language: go
go:
- 1.15.x
before_deploy:
- gen/xbuild.sh
deploy:
provider: releases
api_key:
secure: RdZAOPWooYq73iFQIjqe9+Awr7oA8m0j0tn1tUUfLjP+PGYpuz2lf1SHW/UjPcxySFkkBxnNPC1xgqmxekmvZadBaQbApqko4e47zCF0Pe91QG9OcDFaiJUWb7wcg+UDLoS0lJq8mcKYoi6bV76syOk0gBunLUmuYYpz/hR4lbalfq5//fD6sOOJ9cJPjeuG7LwYqbyw/8VwQWpiWgK9Sb5gu7+ZBgXkLG+/5OSHW8yNHGmtkw5sjMr4jQnNt2ixXVe5OdQ14mvRx0n4vlnzjNjmY6cPjEeqAc9eniOJ5o99k1OnR3H5kmNgI749q+VAkdu/uJfHiLXL1zerReb4SSTU+tTw9c7JYTcjBHlCT11CHlksVu55hHAbFvPkIpLfoRvdqrcjUyEHiCI/HbWiHhsQ+Gve+tpIcgu/aAC2TEsQ+vmmaXbOFcUsG77XP8gn1y+Spkyzou7tUvypIXduDSKFIvI51HYK2F5t5ttG6zJw9lpmmuoUWvCvbGvdAW893O6ef+iZvBoZYRjdeWvIqh/no2gWi1CRa4ZPSZWkn9NoE/2koaCQkrx9RHmEeLIukZVAT6ZViwvhMAOrvXQdKTDwbQ3ovMdtDvGcvjGz9k5xwnWrIcF7MV7nf7sj/JlcX2tulevcSLsYeBvcuTUFzy90erMy70MS01wp0I/IgpY=
skip_cleanup: true
file_glob: true
file: dist/*
name: $TRAVIS_TAG
on:
tags: true
repo: gokcehan/lf
-1
View File
@@ -5,7 +5,6 @@
| [#lf](https://webchat.freenode.net/?channels=lf) (on Freenode) | [#lf](https://webchat.freenode.net/?channels=lf) (on Freenode)
| [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org) (with IRC bridge) | [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org) (with IRC bridge)
[![Build Status](https://travis-ci.org/gokcehan/lf.svg?branch=master)](https://travis-ci.org/gokcehan/lf)
[![Go Report Card](https://goreportcard.com/badge/github.com/gokcehan/lf)](https://goreportcard.com/report/github.com/gokcehan/lf) [![Go Report Card](https://goreportcard.com/badge/github.com/gokcehan/lf)](https://goreportcard.com/report/github.com/gokcehan/lf)
[![Go Reference](https://pkg.go.dev/badge/github.com/gokcehan/lf.svg)](https://pkg.go.dev/github.com/gokcehan/lf) [![Go Reference](https://pkg.go.dev/badge/github.com/gokcehan/lf.svg)](https://pkg.go.dev/github.com/gokcehan/lf)
+10
View File
@@ -137,6 +137,10 @@ func loadFiles() (list []string, cp bool, err error) {
} }
func saveFiles(list []string, cp bool) error { func saveFiles(list []string, cp bool) error {
if err := os.MkdirAll(filepath.Dir(gFilesPath), os.ModePerm); err != nil {
return fmt.Errorf("creating data directory: %s", err)
}
files, err := os.Create(gFilesPath) files, err := os.Create(gFilesPath)
if err != nil { if err != nil {
return fmt.Errorf("opening file selections file: %s", err) return fmt.Errorf("opening file selections file: %s", err)
@@ -368,6 +372,7 @@ func (app *app) loop() {
case d := <-app.nav.dirChan: case d := <-app.nav.dirChan:
app.nav.checkDir(d) app.nav.checkDir(d)
if gOpts.dircache {
prev, ok := app.nav.dirCache[d.path] prev, ok := app.nav.dirCache[d.path]
if ok { if ok {
d.ind = prev.ind d.ind = prev.ind
@@ -375,6 +380,7 @@ func (app *app) loop() {
} }
app.nav.dirCache[d.path] = d app.nav.dirCache[d.path] = d
}
for i := range app.nav.dirs { for i := range app.nav.dirs {
if app.nav.dirs[i].path == d.path { if app.nav.dirs[i].path == d.path {
@@ -489,6 +495,9 @@ func (app *app) runShell(s string, args []string, prefix string) {
err = cmd.Run() err = cmd.Run()
case "%": case "%":
if app.ui.cmdPrefix == ">" {
return
}
stdin, err := cmd.StdinPipe() stdin, err := cmd.StdinPipe()
if err != nil { if err != nil {
log.Printf("writing stdin: %s", err) log.Printf("writing stdin: %s", err)
@@ -518,6 +527,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
switch prefix { switch prefix {
case "%": case "%":
normal(app)
app.cmd = cmd app.cmd = cmd
app.cmdOutBuf = nil app.cmdOutBuf = nil
app.ui.msg = "" app.ui.msg = ""
+11
View File
@@ -48,6 +48,8 @@ var (
"search-back", "search-back",
"search-next", "search-next",
"search-prev", "search-prev",
"filter",
"setfilter",
"mark-save", "mark-save",
"mark-remove", "mark-remove",
"mark-load", "mark-load",
@@ -73,12 +75,18 @@ var (
"autoquit", "autoquit",
"noautoquit", "noautoquit",
"autoquit!", "autoquit!",
"dircache",
"nodircache",
"dircache!",
"dircounts", "dircounts",
"nodircounts", "nodircounts",
"dircounts!", "dircounts!",
"dirfirst", "dirfirst",
"nodirfirst", "nodirfirst",
"dirfirst!", "dirfirst!",
"dironly",
"nodironly",
"dironly!",
"drawbox", "drawbox",
"nodrawbox", "nodrawbox",
"drawbox!", "drawbox!",
@@ -100,6 +108,9 @@ var (
"incsearch", "incsearch",
"noincsearch", "noincsearch",
"incsearch!", "incsearch!",
"incfilter",
"noincfilter",
"incfilter!",
"mouse", "mouse",
"nomouse", "nomouse",
"mouse!", "mouse!",
+31 -2
View File
@@ -62,6 +62,8 @@ The following commands are provided by lf:
search-back (modal) (default '?') search-back (modal) (default '?')
search-next (default 'n') search-next (default 'n')
search-prev (default 'N') search-prev (default 'N')
filter (modal)
setfilter
mark-save (modal) (default 'm') mark-save (modal) (default 'm')
mark-load (modal) (default "'") mark-load (modal) (default "'")
mark-remove (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) anchorfind bool (default on)
autoquit bool (default off) autoquit bool (default off)
dircache bool (default on)
dircounts bool (default off) dircounts bool (default off)
dirfirst bool (default on) dirfirst bool (default on)
dironly bool (default off)
drawbox bool (default off) drawbox bool (default off)
errorfmt string (default "\033[7;31;47m%s\033[0m") errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n") filesep string (default "\n")
@@ -112,6 +116,7 @@ The following options can be used to customize the behavior of lf:
ifs string (default '') ifs string (default '')
ignorecase bool (default on) ignorecase bool (default on)
ignoredia bool (default on) ignoredia bool (default on)
incfilter bool (default off)
incsearch bool (default off) incsearch bool (default off)
info []string (default '') info []string (default '')
mouse bool (default off) mouse bool (default off)
@@ -368,7 +373,7 @@ Read a shell command to execute and wait for a key press in the end.
shell-async (modal) (default '&') shell-async (modal) (default '&')
Read a shell command to execute synchronously without standard I/O. Read a shell command to execute asynchronously without standard I/O.
find (modal) (default 'f') find (modal) (default 'f')
find-back (modal) (default 'F') find-back (modal) (default 'F')
@@ -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) (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') mark-save (modal) (default 'm')
Save the current directory as a bookmark assigned to the given key. 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. Automatically quit server when there are no clients left connected.
dircache bool (default on)
Cache directory contents.
dircounts bool (default off) dircounts bool (default off)
When this option is enabled, directory sizes show the number of items inside instead of the size of directory file. 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. Show directories first above regular files.
dironly bool (default off)
Show only directories.
drawbox bool (default off) drawbox bool (default off)
Draw boxes around panes with box drawing characters. 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. 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 '') info []string (default '')
List of information shown for directory items at the right side of pane. 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") 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. 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. 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 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. 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 Colors
lf tries to automatically adapt its colors to the environment. lf tries to automatically adapt its colors to the environment.
+38 -6
View File
@@ -66,6 +66,8 @@ The following commands are provided by lf:
search-back (modal) (default '?') search-back (modal) (default '?')
search-next (default 'n') search-next (default 'n')
search-prev (default 'N') search-prev (default 'N')
filter (modal)
setfilter
mark-save (modal) (default 'm') mark-save (modal) (default 'm')
mark-load (modal) (default "'") mark-load (modal) (default "'")
mark-remove (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) anchorfind bool (default on)
autoquit bool (default off) autoquit bool (default off)
dircache bool (default on)
dircounts bool (default off) dircounts bool (default off)
dirfirst bool (default on) dirfirst bool (default on)
dironly bool (default off)
drawbox bool (default off) drawbox bool (default off)
errorfmt string (default "\033[7;31;47m%s\033[0m") errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n") filesep string (default "\n")
@@ -116,6 +120,7 @@ The following options can be used to customize the behavior of lf:
ifs string (default '') ifs string (default '')
ignorecase bool (default on) ignorecase bool (default on)
ignoredia bool (default on) ignoredia bool (default on)
incfilter bool (default off)
incsearch bool (default off) incsearch bool (default off)
info []string (default '') info []string (default '')
mouse bool (default off) mouse bool (default off)
@@ -384,7 +389,7 @@ Read a shell command to execute and wait for a key press in the end.
shell-async (modal) (default '&') shell-async (modal) (default '&')
Read a shell command to execute synchronously without standard I/O. Read a shell command to execute asynchronously without standard I/O.
find (modal) (default 'f') find (modal) (default 'f')
find-back (modal) (default 'F') find-back (modal) (default 'F')
@@ -408,6 +413,17 @@ direction and jump to the next/previous match.
(See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase', (See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase',
'ignoredia', and 'smartdia' options and 'Searching Files' section) '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') mark-save (modal) (default 'm')
Save the current directory as a bookmark assigned to the given key. 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. Automatically quit server when there are no clients left connected.
dircache bool (default on)
Cache directory contents.
dircounts bool (default off) dircounts bool (default off)
When this option is enabled, directory sizes show the number of items inside 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. Show directories first above regular files.
dironly bool (default off)
Show only directories.
drawbox bool (default off) drawbox bool (default off)
Draw boxes around panes with box drawing characters. 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. 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 '') info []string (default '')
List of information shown for directory items at the right side of pane. 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 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 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 directory, '%d' as the working directory with a trailing path separator,
'%f' as the file name. Home folder is shown as '~' in the working directory '%f' as the file name, and '%F' as the current filter. Home folder is shown
expansion. Directory names are automatically shortened to a single character as '~' in the working directory expansion. Directory names are automatically
starting from the left most parent when the prompt does not fit to the shortened to a single character starting from the left most parent when the
screen. prompt does not fit to the screen.
ratios []int (default '1:2:3') 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 Note that all shell commands are possible but '%' and '&' are usually more
appropriate as '$' and '!' causes flickers and pauses respectively. 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 Colors
+4 -4
View File
@@ -15,10 +15,10 @@
$tmp = [System.IO.Path]::GetTempFileName() $tmp = [System.IO.Path]::GetTempFileName()
lf -last-dir-path="$tmp" $args lf -last-dir-path="$tmp" $args
if (test-path -pathtype leaf "$tmp") { if (Test-Path -PathType Leaf "$tmp") {
$dir = type "$tmp" $dir = Get-Content "$tmp"
remove-item -force "$tmp" Remove-Item -Force "$tmp"
if (test-path -pathtype container "$dir") { if (Test-Path -PathType Container "$dir") {
if ("$dir" -ne "$pwd") { if ("$dir" -ne "$pwd") {
cd "$dir" cd "$dir"
} }
+238 -70
View File
@@ -26,12 +26,36 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.autoquit = false gOpts.autoquit = false
case "autoquit!": case "autoquit!":
gOpts.autoquit = !gOpts.autoquit gOpts.autoquit = !gOpts.autoquit
case "dircache":
gOpts.dircache = true
case "nodircache":
gOpts.dircache = false
case "dircache!":
gOpts.dircache = !gOpts.dircache
case "dircounts": case "dircounts":
gOpts.dircounts = true gOpts.dircounts = true
case "nodircounts": case "nodircounts":
gOpts.dircounts = false gOpts.dircounts = false
case "dircounts!": case "dircounts!":
gOpts.dircounts = !gOpts.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": case "dirfirst":
gOpts.sortType.option |= dirfirstSort gOpts.sortType.option |= dirfirstSort
app.nav.sort() app.nav.sort()
@@ -70,10 +94,19 @@ func (e *setExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
case "globsearch": case "globsearch":
gOpts.globsearch = true gOpts.globsearch = true
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "noglobsearch": case "noglobsearch":
gOpts.globsearch = false gOpts.globsearch = false
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "globsearch!": case "globsearch!":
gOpts.globsearch = !gOpts.globsearch gOpts.globsearch = !gOpts.globsearch
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "hidden": case "hidden":
gOpts.sortType.option |= hiddenSort gOpts.sortType.option |= hiddenSort
app.nav.sort() app.nav.sort()
@@ -102,14 +135,17 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.ignorecase = true gOpts.ignorecase = true
app.nav.sort() app.nav.sort()
app.ui.sort() app.ui.sort()
app.ui.loadFile(app.nav, true)
case "noignorecase": case "noignorecase":
gOpts.ignorecase = false gOpts.ignorecase = false
app.nav.sort() app.nav.sort()
app.ui.sort() app.ui.sort()
app.ui.loadFile(app.nav, true)
case "ignorecase!": case "ignorecase!":
gOpts.ignorecase = !gOpts.ignorecase gOpts.ignorecase = !gOpts.ignorecase
app.nav.sort() app.nav.sort()
app.ui.sort() app.ui.sort()
app.ui.loadFile(app.nav, true)
case "ignoredia": case "ignoredia":
gOpts.ignoredia = true gOpts.ignoredia = true
app.nav.sort() app.nav.sort()
@@ -122,6 +158,12 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.ignoredia = !gOpts.ignoredia gOpts.ignoredia = !gOpts.ignoredia
app.nav.sort() app.nav.sort()
app.ui.sort() app.ui.sort()
case "incfilter":
gOpts.incfilter = true
case "noincfilter":
gOpts.incfilter = false
case "incfilter!":
gOpts.incfilter = !gOpts.incfilter
case "incsearch": case "incsearch":
gOpts.incsearch = true gOpts.incsearch = true
case "noincsearch": case "noincsearch":
@@ -186,10 +228,19 @@ func (e *setExpr) eval(app *app, args []string) {
app.ui.sort() app.ui.sort()
case "smartcase": case "smartcase":
gOpts.smartcase = true gOpts.smartcase = true
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "nosmartcase": case "nosmartcase":
gOpts.smartcase = false gOpts.smartcase = false
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "smartcase!": case "smartcase!":
gOpts.smartcase = !gOpts.smartcase gOpts.smartcase = !gOpts.smartcase
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "smartdia": case "smartdia":
gOpts.smartdia = true gOpts.smartdia = true
case "nosmartdia": case "nosmartdia":
@@ -385,10 +436,10 @@ func (e *mapExpr) eval(app *app, args []string) {
} }
func (e *cmapExpr) 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) delete(gOpts.cmdkeys, e.key)
} else { } else {
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1} gOpts.cmdkeys[e.key] = e.expr
} }
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
@@ -402,6 +453,12 @@ func (e *cmdExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) 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) { func onChdir(app *app) {
if cmd, ok := gOpts.cmds["on-cd"]; ok { if cmd, ok := gOpts.cmds["on-cd"]; ok {
cmd.eval(app, nil) cmd.eval(app, nil)
@@ -461,10 +518,56 @@ func update(app *app) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) 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) { func normal(app *app) {
resetIncCmd(app)
app.ui.menuBuf = nil app.ui.menuBuf = nil
app.ui.menuSelected = -2 app.ui.menuSelected = -2
@@ -479,6 +582,9 @@ func insert(app *app, arg string) {
case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"): case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"):
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
update(app) 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: ": case app.ui.cmdPrefix == "find: ":
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight) 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: ": case app.ui.cmdPrefix == "mark-save: ":
normal(app) normal(app)
wd, err := os.Getwd() app.nav.marks[arg] = app.nav.currDir().path
if err != nil {
log.Printf("getting current directory: %s", err)
return
}
app.nav.marks[arg] = wd
if err := app.nav.writeMarks(); err != nil { if err := app.nav.writeMarks(); err != nil {
app.ui.echoerrf("mark-save: %s", err) 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") app.ui.echoerr("mark-load: no such mark")
return return
} }
if wd != path {
resetIncCmd(app)
preChdir(app)
}
if err := app.nav.cd(path); err != nil { if err := app.nav.cd(path); err != nil {
app.ui.echoerrf("%s", err) app.ui.echoerrf("%s", err)
return return
@@ -645,6 +752,7 @@ func insert(app *app, arg string) {
if wd != path { if wd != path {
app.nav.marks["'"] = wd app.nav.marks["'"] = wd
restartIncCmd(app)
onChdir(app) onChdir(app)
} }
case app.ui.cmdPrefix == "mark-remove: ": case app.ui.cmdPrefix == "mark-remove: ":
@@ -674,57 +782,38 @@ func insert(app *app, arg string) {
func (e *callExpr) eval(app *app, args []string) { func (e *callExpr) eval(app *app, args []string) {
switch e.name { switch e.name {
case "up": case "up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.up(e.count) { if app.nav.up(e.count) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "half-up": case "half-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.up(e.count * app.nav.height / 2) { if app.nav.up(e.count * app.nav.height / 2) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "page-up": case "page-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.up(e.count * app.nav.height) { if app.nav.up(e.count * app.nav.height) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "down": case "down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.down(e.count) { if app.nav.down(e.count) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "half-down": case "half-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.down(e.count * app.nav.height / 2) { if app.nav.down(e.count * app.nav.height / 2) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "page-down": case "page-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.down(e.count * app.nav.height) { if app.nav.down(e.count * app.nav.height) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "updir": case "updir":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" { resetIncCmd(app)
normal(app) preChdir(app)
}
for i := 0; i < e.count; i++ { for i := 0; i < e.count; i++ {
if err := app.nav.updir(); err != nil { if err := app.nav.updir(); err != nil {
app.ui.echoerrf("%s", err) 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.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
restartIncCmd(app)
onChdir(app) onChdir(app)
case "open": case "open":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
curr, err := app.nav.currFile() curr, err := app.nav.currFile()
if err != nil { if err != nil {
app.ui.echoerrf("opening: %s", err) app.ui.echoerrf("opening: %s", err)
@@ -745,6 +832,8 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if curr.IsDir() { if curr.IsDir() {
resetIncCmd(app)
preChdir(app)
err := app.nav.open() err := app.nav.open()
if err != nil { if err != nil {
app.ui.echoerrf("opening directory: %s", err) 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.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
restartIncCmd(app)
onChdir(app) onChdir(app)
return return
} }
@@ -787,17 +877,11 @@ func (e *callExpr) eval(app *app, args []string) {
case "quit": case "quit":
app.quitChan <- struct{}{} app.quitChan <- struct{}{}
case "top": case "top":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.top() { if app.nav.top() {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "bottom": case "bottom":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.bottom() { if app.nav.bottom() {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@@ -808,6 +892,7 @@ func (e *callExpr) eval(app *app, args []string) {
} else { } else {
dir := app.nav.currDir() dir := app.nav.currDir()
for _, path := range e.args { for _, path := range e.args {
path = replaceTilde(path)
if !filepath.IsAbs(path) { if !filepath.IsAbs(path) {
path = filepath.Join(dir.path, path) path = filepath.Join(dir.path, path)
} }
@@ -887,6 +972,10 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
if len(list) == 1 { if len(list) == 1 {
app.ui.cmdPrefix = "delete '" + list[0] + "' ? [y/N] " app.ui.cmdPrefix = "delete '" + list[0] + "' ? [y/N] "
} else { } else {
@@ -931,25 +1020,53 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "read": case "read":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = ":" app.ui.cmdPrefix = ":"
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "shell": case "shell":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "$" app.ui.cmdPrefix = "$"
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "shell-pipe": case "shell-pipe":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "%" app.ui.cmdPrefix = "%"
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "shell-wait": case "shell-wait":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "!" app.ui.cmdPrefix = "!"
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "shell-async": case "shell-async":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "&" app.ui.cmdPrefix = "&"
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "find": case "find":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "find: " app.ui.cmdPrefix = "find: "
app.nav.findBack = false app.nav.findBack = false
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "find-back": case "find-back":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "find-back: " app.ui.cmdPrefix = "find-back: "
app.nav.findBack = true app.nav.findBack = true
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@@ -982,6 +1099,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "search": case "search":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "/" app.ui.cmdPrefix = "/"
dir := app.nav.currDir() dir := app.nav.currDir()
app.nav.searchInd = dir.ind app.nav.searchInd = dir.ind
@@ -989,6 +1110,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.searchBack = false app.nav.searchBack = false
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "search-back": case "search-back":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "?" app.ui.cmdPrefix = "?"
dir := app.nav.currDir() dir := app.nav.currDir()
app.nav.searchInd = dir.ind 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": case "mark-save":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "mark-save: " app.ui.cmdPrefix = "mark-save: "
case "mark-load": case "mark-load":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.menuBuf = listMarks(app.nav.marks) app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-load: " app.ui.cmdPrefix = "mark-load: "
case "mark-remove": case "mark-remove":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.menuBuf = listMarks(app.nav.marks) app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-remove: " app.ui.cmdPrefix = "mark-remove: "
case "rename": case "rename":
@@ -1057,6 +1215,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("rename: %s:", err) app.ui.echoerrf("rename: %s:", err)
return return
} }
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "rename: " app.ui.cmdPrefix = "rename: "
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...) 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) 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 { if err := app.nav.cd(path); err != nil {
app.ui.echoerrf("%s", err) app.ui.echoerrf("%s", err)
return return
@@ -1091,14 +1265,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
if !filepath.IsAbs(path) {
path = filepath.Join(wd, path)
} else {
path = filepath.Clean(path)
}
if wd != path { if wd != path {
app.nav.marks["'"] = wd app.nav.marks["'"] = wd
restartIncCmd(app)
onChdir(app) onChdir(app)
} }
case "select": case "select":
@@ -1112,6 +1281,18 @@ func (e *callExpr) eval(app *app, args []string) {
log.Printf("getting current directory: %s", err) 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 { if err := app.nav.sel(e.args[0]); err != nil {
app.ui.echoerrf("%s", err) app.ui.echoerrf("%s", err)
return return
@@ -1120,15 +1301,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) 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 { if wd != path {
app.nav.marks["'"] = wd app.nav.marks["'"] = wd
restartIncCmd(app)
onChdir(app) onChdir(app)
} }
case "glob-select": case "glob-select":
@@ -1182,15 +1357,6 @@ func (e *callExpr) eval(app *app, args []string) {
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
return 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) normal(app)
case "cmd-complete": case "cmd-complete":
var matches []string var matches []string
@@ -1307,7 +1473,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
case "cmd-enter": case "cmd-enter":
s := string(append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)) s := string(append(app.ui.cmdAccLeft, app.ui.cmdAccRight...))
if len(s) == 0 { if len(s) == 0 && app.ui.cmdPrefix != "filter: " {
return return
} }
@@ -1384,6 +1550,14 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) 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: ": case "find: ":
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
if moved, found := app.nav.findNext(); !found { 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()) oldPath := filepath.Join(wd, curr.Name())
newPath := filepath.Clean(s) newPath := filepath.Clean(replaceTilde(s))
if !filepath.IsAbs(newPath) { if !filepath.IsAbs(newPath) {
newPath = filepath.Join(wd, newPath) newPath = filepath.Join(wd, newPath)
} }
@@ -1480,12 +1654,9 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd] cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
normal(app)
app.ui.cmdPrefix = cmd.prefix app.ui.cmdPrefix = cmd.prefix
app.ui.cmdAccLeft = []rune(cmd.value) 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": case "cmd-history-prev":
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
return return
@@ -1498,12 +1669,9 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.cmdHistoryInd++ app.cmdHistoryInd++
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd] cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
normal(app)
app.ui.cmdPrefix = cmd.prefix app.ui.cmdPrefix = cmd.prefix
app.ui.cmdAccLeft = []rune(cmd.value) 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": case "cmd-delete":
if len(app.ui.cmdAccRight) == 0 { if len(app.ui.cmdAccRight) == 0 {
return return
+1 -1
View File
@@ -218,7 +218,7 @@ var gEvalTests = []struct {
{ {
"cmap <c-g> cmd-escape", "cmap <c-g> cmd-escape",
[]string{"cmap", "<c-g>", "cmd-escape", "\n"}, []string{"cmap", "<c-g>", "cmd-escape", "\n"},
[]expr{&cmapExpr{"<c-g>", "cmd-escape"}}, []expr{&cmapExpr{"<c-g>", &callExpr{"cmd-escape", nil, 1}}},
}, },
{ {
+36 -2
View File
@@ -77,6 +77,8 @@ The following commands are provided by lf:
search-back (modal) (default '?') search-back (modal) (default '?')
search-next (default 'n') search-next (default 'n')
search-prev (default 'N') search-prev (default 'N')
filter (modal)
setfilter
mark-save (modal) (default 'm') mark-save (modal) (default 'm')
mark-load (modal) (default "'") mark-load (modal) (default "'")
mark-remove (modal) (default `"`) mark-remove (modal) (default `"`)
@@ -118,8 +120,10 @@ The following options can be used to customize the behavior of lf:
.EX .EX
anchorfind bool (default on) anchorfind bool (default on)
autoquit bool (default off) autoquit bool (default off)
dircache bool (default on)
dircounts bool (default off) dircounts bool (default off)
dirfirst bool (default on) dirfirst bool (default on)
dironly bool (default off)
drawbox bool (default off) drawbox bool (default off)
errorfmt string (default "\e033[7;31;47m%s\e033[0m") errorfmt string (default "\e033[7;31;47m%s\e033[0m")
filesep string (default "\en") filesep string (default "\en")
@@ -131,6 +135,7 @@ The following options can be used to customize the behavior of lf:
ifs string (default '') ifs string (default '')
ignorecase bool (default on) ignorecase bool (default on)
ignoredia bool (default on) ignoredia bool (default on)
incfilter bool (default off)
incsearch bool (default off) incsearch bool (default off)
info []string (default '') info []string (default '')
mouse bool (default off) mouse bool (default off)
@@ -455,7 +460,7 @@ Read a shell command to execute and wait for a key press in the end.
shell-async (modal) (default '&') shell-async (modal) (default '&')
.EE .EE
.PP .PP
Read a shell command to execute synchronously without standard I/O. Read a shell command to execute asynchronously without standard I/O.
.PP .PP
.EX .EX
find (modal) (default 'f') find (modal) (default 'f')
@@ -479,6 +484,15 @@ Read a pattern to search for a file name match in the forward/backward direction
.PP .PP
(See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options and 'Searching Files' section) (See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options and 'Searching Files' section)
.PP .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 .EX
mark-save (modal) (default 'm') mark-save (modal) (default 'm')
.EE .EE
@@ -624,6 +638,12 @@ When this option is enabled, find command starts matching patterns from the begi
.PP .PP
Automatically quit server when there are no clients left connected. Automatically quit server when there are no clients left connected.
.PP .PP
.EX
dircache bool (default on)
.EE
.PP
Cache directory contents.
.PP
.EX .EX
dircounts bool (default off) dircounts bool (default off)
.EE .EE
@@ -636,6 +656,12 @@ When this option is enabled, directory sizes show the number of items inside ins
.PP .PP
Show directories first above regular files. Show directories first above regular files.
.PP .PP
.EX
dironly bool (default off)
.EE
.PP
Show only directories.
.PP
.EX .EX
drawbox bool (default off) drawbox bool (default off)
.EE .EE
@@ -708,6 +734,12 @@ Ignore diacritics in sorting and search patterns.
.PP .PP
Jump to the first match after each keystroke during searching. Jump to the first match after each keystroke during searching.
.PP .PP
.EX
incfilter bool (default off)
.EE
.PP
Apply filter pattern after each keystroke during filtering.
.PP
.EX .EX
info []string (default '') info []string (default '')
.EE .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") promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%d\e033[0m\e033[1m%f\e033[0m")
.EE .EE
.PP .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 .PP
.EX .EX
ratios []int (default '1:2:3') 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 .EE
.PP .PP
Note that all shell commands are possible but `%` and `&` are usually more appropriate as `$` and `!` causes flickers and pauses respectively. 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 .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: 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 .PP
+101 -8
View File
@@ -113,7 +113,9 @@ type dir struct {
files []*file // displayed files in directory including or excluding hidden ones files []*file // displayed files in directory including or excluding hidden ones
allFiles []*file // all files in directory including hidden ones (same array as files) allFiles []*file // all files in directory including hidden ones (same array as files)
sortType sortType // sort method and options from last sort sortType sortType // sort method and options from last sort
dironly bool // dironly value from last sort
hiddenfiles []string // hiddenfiles 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 ignorecase bool // ignorecase value from last sort
ignoredia bool // ignoredia value from last sort ignoredia bool // ignoredia value from last sort
noPerm bool // whether lf has no permission to open the directory 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() { func (dir *dir) sort() {
dir.sortType = gOpts.sortType dir.sortType = gOpts.sortType
dir.dironly = gOpts.dironly
dir.hiddenfiles = gOpts.hiddenfiles dir.hiddenfiles = gOpts.hiddenfiles
dir.ignorecase = gOpts.ignorecase dir.ignorecase = gOpts.ignorecase
dir.ignoredia = gOpts.ignoredia 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 // when hidden option is disabled, we move hidden files to the
// beginning of our file list and then set the beginning of displayed // beginning of our file list and then set the beginning of displayed
// files to the first non-hidden file in the list // files to the first non-hidden file in the list
@@ -232,21 +255,41 @@ func (dir *dir) sort() {
for i, f := range dir.files { for i, f := range dir.files {
if !isHidden(f, dir.path, dir.hiddenfiles) { if !isHidden(f, dir.path, dir.hiddenfiles) {
dir.files = dir.files[i:] dir.files = dir.files[i:]
return break
} }
} }
if len(dir.files) > 0 && isHidden(dir.files[len(dir.files)-1], dir.path, dir.hiddenfiles) {
dir.files = dir.files[len(dir.files):] 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 { func (dir *dir) name() string {
if len(dir.files) == 0 { if len(dir.files) == 0 {
return "" return ""
} }
dir.ind = max(dir.ind, 0)
dir.ind = min(dir.ind, len(dir.files)-1)
return dir.files[dir.ind].Name() return dir.files[dir.ind].Name()
} }
@@ -307,12 +350,11 @@ type nav struct {
searchBack bool searchBack bool
searchInd int searchInd int
searchPos int searchPos int
prevFilter []string
volatilePreview bool volatilePreview bool
} }
func (nav *nav) loadDir(path string) *dir { func (nav *nav) loadDirInternal(path string) *dir {
d, ok := nav.dirCache[path]
if !ok {
d := &dir{ d := &dir{
loading: true, loading: true,
loadTime: time.Now(), loadTime: time.Now(),
@@ -322,7 +364,6 @@ func (nav *nav) loadDir(path string) *dir {
ignorecase: gOpts.ignorecase, ignorecase: gOpts.ignorecase,
ignoredia: gOpts.ignoredia, ignoredia: gOpts.ignoredia,
} }
nav.dirCache[path] = d
go func() { go func() {
d := newDir(path) d := newDir(path)
d.sort() d.sort()
@@ -332,9 +373,21 @@ func (nav *nav) loadDir(path string) *dir {
return 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) nav.checkDir(d)
return d return d
} else {
return nav.loadDirInternal(path)
}
} }
func (nav *nav) checkDir(dir *dir) { func (nav *nav) checkDir(dir *dir) {
@@ -358,10 +411,12 @@ func (nav *nav) checkDir(dir *dir) {
dir.loadTime = now dir.loadTime = now
go func() { go func() {
nd := newDir(dir.path) nd := newDir(dir.path)
nd.filter = dir.filter
nd.sort() nd.sort()
nav.dirChan <- nd nav.dirChan <- nd
}() }()
case dir.sortType != gOpts.sortType || case dir.sortType != gOpts.sortType ||
dir.dironly != gOpts.dironly ||
!reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) || !reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) ||
dir.ignorecase != gOpts.ignorecase || dir.ignorecase != gOpts.ignorecase ||
dir.ignoredia != gOpts.ignoredia: 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 { func (nav *nav) up(dist int) bool {
dir := nav.currDir() dir := nav.currDir()
@@ -1251,6 +1327,22 @@ func (nav *nav) searchPrev() (bool, error) {
return false, nil 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 { func (nav *nav) removeMark(mark string) error {
if _, ok := nav.marks[mark]; ok { if _, ok := nav.marks[mark]; ok {
delete(nav.marks, mark) delete(nav.marks, mark)
@@ -1322,6 +1414,7 @@ func (nav *nav) currFile() (*file, error) {
if len(dir.files) == 0 { if len(dir.files) == 0 {
return nil, fmt.Errorf("empty directory") return nil, fmt.Errorf("empty directory")
} }
return dir.files[dir.ind], nil return dir.files[dir.ind], nil
} }
+6
View File
@@ -30,12 +30,15 @@ type sortType struct {
var gOpts struct { var gOpts struct {
anchorfind bool anchorfind bool
autoquit bool autoquit bool
dircache bool
dircounts bool dircounts bool
dironly bool
drawbox bool drawbox bool
globsearch bool globsearch bool
icons bool icons bool
ignorecase bool ignorecase bool
ignoredia bool ignoredia bool
incfilter bool
incsearch bool incsearch bool
mouse bool mouse bool
number bool number bool
@@ -73,12 +76,15 @@ var gOpts struct {
func init() { func init() {
gOpts.anchorfind = true gOpts.anchorfind = true
gOpts.autoquit = false gOpts.autoquit = false
gOpts.dircache = true
gOpts.dircounts = false gOpts.dircounts = false
gOpts.dironly = false
gOpts.drawbox = false gOpts.drawbox = false
gOpts.globsearch = false gOpts.globsearch = false
gOpts.icons = false gOpts.icons = false
gOpts.ignorecase = true gOpts.ignorecase = true
gOpts.ignoredia = true gOpts.ignoredia = true
gOpts.incfilter = false
gOpts.incsearch = false gOpts.incsearch = false
gOpts.mouse = false gOpts.mouse = false
gOpts.number = false gOpts.number = false
+7 -11
View File
@@ -14,7 +14,7 @@ package main
// //
// MapExpr = 'map' <keys> Expr // MapExpr = 'map' <keys> Expr
// //
// CMapExpr = 'cmap' <key> <cmd> ';' // CMapExpr = 'cmap' <key> Expr
// //
// CmdExpr = 'cmd' <name> Expr // CmdExpr = 'cmd' <name> Expr
// //
@@ -59,10 +59,10 @@ func (e *mapExpr) String() string { return fmt.Sprintf("map %s %s", e.keys, e.ex
type cmapExpr struct { type cmapExpr struct {
key string key string
cmd 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 { type cmdExpr struct {
name string name string
@@ -191,23 +191,19 @@ func (p *parser) parseExpr() expr {
result = &mapExpr{keys, expr} result = &mapExpr{keys, expr}
case "cmap": case "cmap":
var cmd string var expr expr
s.scan() s.scan()
key := s.tok key := s.tok
s.scan() s.scan()
if s.typ != tokenSemicolon { if s.typ != tokenSemicolon {
if s.typ != tokenIdent { expr = p.parseExpr()
p.err = fmt.Errorf("expected command: %s", s.tok) } else {
}
cmd = s.tok
s.scan() s.scan()
} }
s.scan() result = &cmapExpr{key, expr}
result = &cmapExpr{key, cmd}
case "cmd": case "cmd":
var expr expr var expr expr
+4 -2
View File
@@ -103,8 +103,10 @@ Loop:
fmt.Fprintln(c, rest) fmt.Fprintln(c, rest)
} }
} else { } else {
if c, ok := gConnList[id]; ok { if c2, ok := gConnList[id]; ok {
fmt.Fprintln(c, rest2) fmt.Fprintln(c2, rest2)
} else {
echoerr(c, "listen: send: no such client id is connected")
} }
} }
} }
+25 -12
View File
@@ -676,7 +676,8 @@ func (ui *ui) loadFileInfo(nav *nav) {
func (ui *ui) drawPromptLine(nav *nav) { func (ui *ui) drawPromptLine(nav *nav) {
st := tcell.StyleDefault st := tcell.StyleDefault
pwd := nav.currDir().path dir := nav.currDir()
pwd := dir.path
if strings.HasPrefix(pwd, gUser.HomeDir) { if strings.HasPrefix(pwd, gUser.HomeDir) {
pwd = filepath.Join("~", strings.TrimPrefix(pwd, gUser.HomeDir)) pwd = filepath.Join("~", strings.TrimPrefix(pwd, gUser.HomeDir))
@@ -717,6 +718,12 @@ func (ui *ui) drawPromptLine(nav *nav) {
} }
prompt = strings.Replace(prompt, "%d", pwd, -1) 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) ui.promptWin.print(ui.screen, 0, 0, st, prompt)
} }
@@ -755,6 +762,10 @@ func (ui *ui) drawStatLine(nav *nav) {
selection += fmt.Sprintf(" \033[35;7m %d \033[0m", len(nav.selections)) 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 var progress string
if nav.copyTotal > 0 { if nav.copyTotal > 0 {
@@ -836,22 +847,24 @@ func (ui *ui) draw(nav *nav) {
ui.drawStatLine(nav) ui.drawStatLine(nav)
ui.screen.HideCursor() ui.screen.HideCursor()
case ">": case ">":
pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(ui.cmdPrefix)-1) prefix := ui.cmdPrefix[:min(ui.msgWin.w-1, len(ui.cmdPrefix))]
pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(prefix)-1)
left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:] left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:]
right := ui.cmdAccRight right := ui.cmdAccRight
ui.msgWin.printLine(ui.screen, 0, 0, st, ui.cmdPrefix) ui.msgWin.printLine(ui.screen, 0, 0, st, prefix)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, ui.msg) ui.msgWin.print(ui.screen, len(prefix), 0, st, ui.msg)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+printLength(ui.msg), 0, st, string(left)) ui.msgWin.print(ui.screen, len(prefix)+printLength(ui.msg), 0, st, string(left))
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+printLength(ui.msg)+runeSliceWidth(left), 0, st, string(right)) ui.msgWin.print(ui.screen, len(prefix)+printLength(ui.msg)+runeSliceWidth(left), 0, st, string(right))
ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+printLength(ui.msg)+runeSliceWidth(left), ui.msgWin.y) ui.screen.ShowCursor(ui.msgWin.x+len(prefix)+printLength(ui.msg)+runeSliceWidth(left), ui.msgWin.y)
default: default:
pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(ui.cmdPrefix)-1) prefix := ui.cmdPrefix[:min(ui.msgWin.w-1, len(ui.cmdPrefix))]
pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(prefix)-1)
left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:] left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:]
right := ui.cmdAccRight right := ui.cmdAccRight
ui.msgWin.printLine(ui.screen, 0, 0, st, ui.cmdPrefix) ui.msgWin.printLine(ui.screen, 0, 0, st, prefix)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, string(left)) ui.msgWin.print(ui.screen, len(prefix), 0, st, string(left))
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+runeSliceWidth(left), 0, st, string(right)) ui.msgWin.print(ui.screen, len(prefix)+runeSliceWidth(left), 0, st, string(right))
ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+runeSliceWidth(left), ui.msgWin.y) ui.screen.ShowCursor(ui.msgWin.x+len(prefix)+runeSliceWidth(left), ui.msgWin.y)
} }
if gOpts.preview { if gOpts.preview {