Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c13807a70 | ||
|
|
876e3067c6 | ||
|
|
17b576ead5 | ||
|
|
2880cc92ed | ||
|
|
c9b023f546 | ||
|
|
f716ce1b0f | ||
|
|
651264e4de | ||
|
|
3ac42fe1ad | ||
|
|
0d005171f3 | ||
|
|
56c28828f2 | ||
|
|
b38693f1c9 | ||
|
|
edc5d977cd | ||
|
|
5ad11bdc84 | ||
|
|
02156a3806 | ||
|
|
42b36fd52c | ||
|
|
88a599643d | ||
|
|
9183e81f7f | ||
|
|
47b3bc5617 | ||
|
|
44483d7872 | ||
|
|
0a05a7106d | ||
|
|
b0c3f8dbd7 | ||
|
|
d385c9bef8 | ||
|
|
f6738eeda5 | ||
|
|
a01e80b6ff | ||
|
|
46cc577d4a | ||
|
|
ab662e6f33 | ||
|
|
23b30ae1ee | ||
|
|
d60acef469 | ||
|
|
5e24fd93d2 | ||
|
|
5b2d5ad99d | ||
|
|
041dfcc073 | ||
|
|
c7b59d27ce | ||
|
|
f27d82b391 | ||
|
|
82a983d934 | ||
|
|
93400c11a0 | ||
|
|
c31b92491f | ||
|
|
f2d5d08952 | ||
|
|
2788bc9b7f | ||
|
|
87c994b9de | ||
|
|
4758ef621c |
No files matched your search
@@ -14,7 +14,7 @@ jobs:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
@@ -37,7 +37,7 @@ jobs:
|
||||
cross-compile:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
@@ -52,7 +52,7 @@ jobs:
|
||||
formatting:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
@@ -24,8 +24,6 @@ jobs:
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: dist/*
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
winget:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -8,6 +8,40 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
- `Added`
|
||||
- `Fixed`
|
||||
|
||||
## [r37](https://github.com/gokcehan/lf/releases/tag/r37)
|
||||
|
||||
### Changed
|
||||
|
||||
- The default paths of files read by `lf` is changed on Windows, to separate configuration files from data files (#2051).
|
||||
- Configuration files (`lfrc`/`colors`/`icons`) are now stored in `%APPDATA%`, which can be overridden by `%LF_CONFIG_HOME%`.
|
||||
- Data files (`files`/`marks`/`tags`/`history`) are now stored in `%LOCALAPPDATA%`, which can be overridden by `%LF_DATA_HOME%`.
|
||||
- The change for following symbolic links when tagging files from the previous release has been reverted (#2055). The previous change made it impossible to tag symbolic links separately from their targets, and also caused `lf` to run slowly in some cases.
|
||||
- The existing `globfilter` and `globsearch` options are now deprecated in favor of the new `filtermethod` and `searchmethod` options, which support regex patterns (#2058).
|
||||
- `set globfilter true` should be replaced by `set filtermethod glob`.
|
||||
- `set globsearch true` should be replaced by `set searchmethod glob`.
|
||||
- File sizes are now displayed using binary units (e.g. `1.0K` means 1024 bytes, not 1000 bytes) (#2062). The maximum width for displaying the file size has been increased from four to five characters.
|
||||
|
||||
### Added
|
||||
|
||||
- `dircounts` are now respected when sorting by size (#2025).
|
||||
- The `info` and `sortby` options now support `btime` (file creation time) (#2042). This depends on support for file creation times from the underlying system.
|
||||
- The selection in Visual mode now follows wrapping when `wrapscan`/`wrapscroll` is enabled (#2056).
|
||||
- Input pasted from the terminal is now ignored while in Normal mode (#2059). This prevents pasted content from being treated as keybindings, which can result in dangerous unintended behavior.
|
||||
- The Command-line mode completion now supports keywords for the `selmode` and `sortby` options (#2061), as well as the `info` and `preserve` options (#2071).
|
||||
- Command line flags are now exported as environment variables in the form `lf_flag_{flag}` (#2079).
|
||||
- Support is added for terminal escape sequences that disable text styles (#2101).
|
||||
|
||||
### Fixed
|
||||
|
||||
- `dircounts` are now automatically populated after enabling it (#2049).
|
||||
- A bug where directories are unsorted after reloading when `dircache` is disabled is now fixed (#2050).
|
||||
- Filenames are now escaped when completing shell commands (#2071).
|
||||
- A bug where completion menu entries are misaligned when containing fullwidth characters is now fixed (#2071).
|
||||
- The `on-load` command now passes all files in the directory as arguments, not just files visible to the user (#2077).
|
||||
- Failure to move files across different filesystems is now shown as an error instead of a success in the UI (#2085).
|
||||
- Errors are now logged correctly when there are multiple errors during move/copy operations (#2089).
|
||||
- The progress for copy operations is now displayed immediately in the UI, even if it takes time to calculate the total size of files to be copied (#2093).
|
||||
|
||||
## [r36](https://github.com/gokcehan/lf/releases/tag/r36)
|
||||
|
||||
### Changed
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ Adding a new option usually requires the following steps:
|
||||
- Add option evaluation logic to `setExpr.eval` in `eval.go`
|
||||
- Implement the option somewhere in the code
|
||||
- Add option name and its default value to `Quick Reference` and `Options` sections in `doc.md`
|
||||
- Run `gen/doc-with-docker.sh` to update the documentation
|
||||
- Run `gen/doc.sh` to update the documentation (requires podman/docker)
|
||||
- Commit your changes and send a pull request
|
||||
|
||||
## Adding a new builtin command
|
||||
@@ -40,7 +40,7 @@ Adding a new command usually requires the following steps:
|
||||
- Implement the command somewhere in the code
|
||||
- Add command name to `gCmdWords` in `complete.go` for tab completion
|
||||
- Add command name to `Quick Reference` and `Commands` sections in `doc.md`
|
||||
- Optionally, run `gen/doc-with-docker.sh` to update the documentation
|
||||
- Optionally, run `gen/doc.sh` to update the documentation (requires podman/docker)
|
||||
- Commit your changes and send a pull request
|
||||
|
||||
## Platform specific code
|
||||
|
||||
@@ -31,7 +31,8 @@ type app struct {
|
||||
cmdHistoryBeg int
|
||||
cmdHistoryInd int
|
||||
menuCompActive bool
|
||||
menuComps []string
|
||||
menuCompTmp []string
|
||||
menuComps []compMatch
|
||||
menuCompInd int
|
||||
selectionOut []string
|
||||
watch *watch
|
||||
@@ -115,7 +116,7 @@ func (app *app) readFile(path string) {
|
||||
}
|
||||
}
|
||||
|
||||
func loadFiles() (list []string, cp bool, err error) {
|
||||
func loadFiles() (clipboard clipboard, err error) {
|
||||
files, err := os.Open(gFilesPath)
|
||||
if os.IsNotExist(err) {
|
||||
err = nil
|
||||
@@ -133,16 +134,16 @@ func loadFiles() (list []string, cp bool, err error) {
|
||||
|
||||
switch s.Text() {
|
||||
case "copy":
|
||||
cp = true
|
||||
clipboard.mode = clipboardCopy
|
||||
case "move":
|
||||
cp = false
|
||||
clipboard.mode = clipboardCut
|
||||
default:
|
||||
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
|
||||
return
|
||||
}
|
||||
|
||||
for s.Scan() && s.Text() != "" {
|
||||
list = append(list, s.Text())
|
||||
clipboard.paths = append(clipboard.paths, s.Text())
|
||||
}
|
||||
|
||||
if s.Err() != nil {
|
||||
@@ -150,12 +151,12 @@ func loadFiles() (list []string, cp bool, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("loading files: %v", list)
|
||||
log.Printf("loading files: %v", clipboard.paths)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func saveFiles(list []string, cp bool) error {
|
||||
func saveFiles(clipboard clipboard) error {
|
||||
if err := os.MkdirAll(filepath.Dir(gFilesPath), os.ModePerm); err != nil {
|
||||
return fmt.Errorf("creating data directory: %s", err)
|
||||
}
|
||||
@@ -166,16 +167,16 @@ func saveFiles(list []string, cp bool) error {
|
||||
}
|
||||
defer files.Close()
|
||||
|
||||
log.Printf("saving files: %v", list)
|
||||
log.Printf("saving files: %v", clipboard.paths)
|
||||
|
||||
if cp {
|
||||
if clipboard.mode == clipboardCopy {
|
||||
fmt.Fprintln(files, "copy")
|
||||
} else {
|
||||
fmt.Fprintln(files, "move")
|
||||
}
|
||||
|
||||
for _, f := range list {
|
||||
fmt.Fprintln(files, f)
|
||||
for _, path := range clipboard.paths {
|
||||
fmt.Fprintln(files, path)
|
||||
}
|
||||
|
||||
files.Sync()
|
||||
@@ -317,7 +318,7 @@ func (app *app) loop() {
|
||||
for {
|
||||
select {
|
||||
case <-app.quitChan:
|
||||
if app.nav.copyTotal > 0 {
|
||||
if app.nav.copyJobs > 0 {
|
||||
app.ui.echoerr("quit: copy operation in progress")
|
||||
continue
|
||||
}
|
||||
@@ -339,6 +340,9 @@ func (app *app) loop() {
|
||||
log.Print("bye!")
|
||||
|
||||
return
|
||||
case <-app.nav.copyJobsChan:
|
||||
app.nav.copyJobs += 1
|
||||
app.ui.draw(app.nav)
|
||||
case n := <-app.nav.copyBytesChan:
|
||||
app.nav.copyBytes += n
|
||||
// n is usually 32*1024B (default io.Copy() buffer) so update roughly per 32KB x 128 = 4MB copied
|
||||
@@ -350,6 +354,7 @@ func (app *app) loop() {
|
||||
app.nav.copyTotal += n
|
||||
if n < 0 {
|
||||
app.nav.copyBytes += n
|
||||
app.nav.copyJobs -= 1
|
||||
}
|
||||
if app.nav.copyTotal == 0 {
|
||||
app.nav.copyUpdate = 0
|
||||
@@ -392,12 +397,15 @@ func (app *app) loop() {
|
||||
d.ind = prev.ind
|
||||
d.pos = prev.pos
|
||||
d.visualAnchor = min(prev.visualAnchor, len(d.files)-1)
|
||||
d.visualWrap = prev.visualWrap
|
||||
d.filter = prev.filter
|
||||
d.sort()
|
||||
d.sel(prev.name(), app.nav.height)
|
||||
}
|
||||
|
||||
app.nav.dirCache[d.path] = d
|
||||
} else {
|
||||
d.sort()
|
||||
}
|
||||
|
||||
var oldCurrPath string
|
||||
@@ -427,7 +435,13 @@ func (app *app) loop() {
|
||||
}
|
||||
|
||||
app.watchDir(d)
|
||||
onLoad(app, d.fileNames())
|
||||
|
||||
paths := []string{}
|
||||
for _, file := range d.allFiles {
|
||||
paths = append(paths, file.path)
|
||||
}
|
||||
onLoad(app, paths)
|
||||
|
||||
app.ui.draw(app.nav)
|
||||
case r := <-app.nav.regChan:
|
||||
app.nav.regCache[r.path] = r
|
||||
@@ -661,6 +675,45 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (app *app) doComplete() (matches []compMatch) {
|
||||
var result string
|
||||
|
||||
switch app.ui.cmdPrefix {
|
||||
case ":":
|
||||
matches, result = completeCmd(app.ui.cmdAccLeft)
|
||||
case "$", "%", "!", "&":
|
||||
matches, result = completeShell(app.ui.cmdAccLeft)
|
||||
case "/", "?":
|
||||
matches, result = completeSearch(app.ui.cmdAccLeft)
|
||||
}
|
||||
|
||||
app.ui.cmdAccLeft = []rune(result)
|
||||
app.ui.menu = listMatches(app.ui.screen, matches, -1)
|
||||
return
|
||||
}
|
||||
|
||||
func (app *app) menuComplete(direction int) {
|
||||
if !app.menuCompActive {
|
||||
app.menuCompTmp = tokenize(string(app.ui.cmdAccLeft))
|
||||
app.menuComps = app.doComplete()
|
||||
if len(app.menuComps) > 1 {
|
||||
app.menuCompInd = -1
|
||||
app.menuCompActive = true
|
||||
}
|
||||
} else {
|
||||
app.menuCompInd += direction
|
||||
if app.menuCompInd == len(app.menuComps) {
|
||||
app.menuCompInd = 0
|
||||
} else if app.menuCompInd < 0 {
|
||||
app.menuCompInd = len(app.menuComps) - 1
|
||||
}
|
||||
|
||||
app.menuCompTmp[len(app.menuCompTmp)-1] = app.menuComps[app.menuCompInd].result
|
||||
app.ui.cmdAccLeft = []rune(strings.Join(app.menuCompTmp, " "))
|
||||
}
|
||||
app.ui.menu = listMatches(app.ui.screen, app.menuComps, app.menuCompInd)
|
||||
}
|
||||
|
||||
func (app *app) watchDir(dir *dir) {
|
||||
if !gOpts.watch {
|
||||
return
|
||||
|
||||
@@ -49,6 +49,7 @@ func run() {
|
||||
if gOpts.mouse {
|
||||
screen.EnableMouse()
|
||||
}
|
||||
screen.EnablePaste()
|
||||
|
||||
ui := newUI(screen)
|
||||
nav := newNav(ui.wins[0].h)
|
||||
|
||||
@@ -136,8 +136,6 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
|
||||
toks := strings.Split(s, ";")
|
||||
|
||||
// ECMA-48 details the standard
|
||||
// TODO: should we support turning off attributes?
|
||||
// Probably because this is used for previewers too
|
||||
tokslen := len(toks)
|
||||
|
||||
loop:
|
||||
@@ -173,6 +171,18 @@ loop:
|
||||
st = st.Foreground(bg)
|
||||
case "9":
|
||||
st = st.StrikeThrough(true)
|
||||
case "22":
|
||||
st = st.Bold(false).Dim(false)
|
||||
case "23":
|
||||
st = st.Italic(false)
|
||||
case "24":
|
||||
st = st.Underline(false)
|
||||
case "25":
|
||||
st = st.Blink(false)
|
||||
case "27":
|
||||
st = st.Reverse(false)
|
||||
case "29":
|
||||
st = st.StrikeThrough(false)
|
||||
case "30", "31", "32", "33", "34", "35", "36", "37":
|
||||
n, _ := strconv.Atoi(toks[i])
|
||||
st = st.Foreground(tcell.PaletteColor(n - 30))
|
||||
|
||||
@@ -72,6 +72,13 @@ func TestApplyAnsiCodes(t *testing.T) {
|
||||
{"4:4", none, none.Underline(tcell.UnderlineStyleDotted)},
|
||||
{"4:5", none, none.Underline(tcell.UnderlineStyleDashed)},
|
||||
|
||||
{"22", none.Italic(true).Bold(true).Dim(true), none.Italic(true)},
|
||||
{"23", none.Bold(true).Italic(true), none.Bold(true)},
|
||||
{"24", none.Bold(true).Underline(true), none.Bold(true)},
|
||||
{"25", none.Bold(true).Blink(true), none.Bold(true)},
|
||||
{"27", none.Bold(true).Reverse(true), none.Bold(true)},
|
||||
{"29", none.Bold(true).StrikeThrough(true), none.Bold(true)},
|
||||
|
||||
{"31", none, none.Foreground(tcell.ColorMaroon)},
|
||||
{"31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon)},
|
||||
{"31", none.Foreground(tcell.ColorGreen).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||
|
||||
+316
-266
@@ -2,9 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"maps"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
@@ -18,104 +20,104 @@ var (
|
||||
"vmap",
|
||||
"cmap",
|
||||
"cmd",
|
||||
"quit",
|
||||
"up",
|
||||
"half-up",
|
||||
"page-up",
|
||||
"scroll-up",
|
||||
"down",
|
||||
"half-down",
|
||||
"page-down",
|
||||
"scroll-down",
|
||||
"updir",
|
||||
"open",
|
||||
"jump-next",
|
||||
"jump-prev",
|
||||
"top",
|
||||
"addcustominfo",
|
||||
"bottom",
|
||||
"high",
|
||||
"middle",
|
||||
"low",
|
||||
"toggle",
|
||||
"invert",
|
||||
"unselect",
|
||||
"glob-select",
|
||||
"glob-unselect",
|
||||
"calcdirsize",
|
||||
"cd",
|
||||
"clear",
|
||||
"clearmaps",
|
||||
"copy",
|
||||
"cut",
|
||||
"paste",
|
||||
"clear",
|
||||
"sync",
|
||||
"draw",
|
||||
"redraw",
|
||||
"load",
|
||||
"reload",
|
||||
"echo",
|
||||
"echomsg",
|
||||
"echoerr",
|
||||
"cd",
|
||||
"select",
|
||||
"down",
|
||||
"delete",
|
||||
"rename",
|
||||
"source",
|
||||
"push",
|
||||
"read",
|
||||
"shell",
|
||||
"shell-pipe",
|
||||
"shell-wait",
|
||||
"shell-async",
|
||||
"draw",
|
||||
"echo",
|
||||
"echoerr",
|
||||
"echomsg",
|
||||
"filter",
|
||||
"find",
|
||||
"find-back",
|
||||
"find-next",
|
||||
"find-prev",
|
||||
"glob-select",
|
||||
"glob-unselect",
|
||||
"half-down",
|
||||
"half-up",
|
||||
"high",
|
||||
"invert",
|
||||
"jump-next",
|
||||
"jump-prev",
|
||||
"load",
|
||||
"low",
|
||||
"mark-load",
|
||||
"mark-remove",
|
||||
"mark-save",
|
||||
"middle",
|
||||
"open",
|
||||
"page-down",
|
||||
"page-up",
|
||||
"paste",
|
||||
"push",
|
||||
"quit",
|
||||
"read",
|
||||
"redraw",
|
||||
"reload",
|
||||
"rename",
|
||||
"scroll-down",
|
||||
"scroll-up",
|
||||
"search",
|
||||
"search-back",
|
||||
"search-next",
|
||||
"search-prev",
|
||||
"filter",
|
||||
"select",
|
||||
"setfilter",
|
||||
"mark-save",
|
||||
"mark-load",
|
||||
"mark-remove",
|
||||
"shell",
|
||||
"shell-async",
|
||||
"shell-pipe",
|
||||
"shell-wait",
|
||||
"source",
|
||||
"sync",
|
||||
"tag",
|
||||
"tag-toggle",
|
||||
"addcustominfo",
|
||||
"toggle",
|
||||
"top",
|
||||
"tty-write",
|
||||
"cmd-escape",
|
||||
"cmd-complete",
|
||||
"cmd-menu-complete",
|
||||
"cmd-menu-complete-back",
|
||||
"cmd-menu-accept",
|
||||
"cmd-enter",
|
||||
"cmd-interrupt",
|
||||
"cmd-history-next",
|
||||
"cmd-history-prev",
|
||||
"cmd-left",
|
||||
"cmd-right",
|
||||
"cmd-home",
|
||||
"cmd-end",
|
||||
"cmd-delete",
|
||||
"cmd-delete-back",
|
||||
"cmd-delete-home",
|
||||
"cmd-delete-end",
|
||||
"cmd-delete-unix-word",
|
||||
"cmd-yank",
|
||||
"cmd-transpose",
|
||||
"cmd-transpose-word",
|
||||
"cmd-word",
|
||||
"cmd-word-back",
|
||||
"cmd-delete-word",
|
||||
"cmd-delete-word-back",
|
||||
"cmd-capitalize-word",
|
||||
"cmd-uppercase-word",
|
||||
"cmd-lowercase-word",
|
||||
"unselect",
|
||||
"up",
|
||||
"updir",
|
||||
"visual",
|
||||
"visual-accept",
|
||||
"visual-unselect",
|
||||
"visual-discard",
|
||||
"visual-change",
|
||||
"visual-discard",
|
||||
"visual-unselect",
|
||||
"cmd-capitalize-word",
|
||||
"cmd-complete",
|
||||
"cmd-delete",
|
||||
"cmd-delete-back",
|
||||
"cmd-delete-end",
|
||||
"cmd-delete-home",
|
||||
"cmd-delete-unix-word",
|
||||
"cmd-delete-word",
|
||||
"cmd-delete-word-back",
|
||||
"cmd-end",
|
||||
"cmd-enter",
|
||||
"cmd-escape",
|
||||
"cmd-history-next",
|
||||
"cmd-history-prev",
|
||||
"cmd-home",
|
||||
"cmd-interrupt",
|
||||
"cmd-left",
|
||||
"cmd-lowercase-word",
|
||||
"cmd-menu-accept",
|
||||
"cmd-menu-complete",
|
||||
"cmd-menu-complete-back",
|
||||
"cmd-right",
|
||||
"cmd-transpose",
|
||||
"cmd-transpose-word",
|
||||
"cmd-uppercase-word",
|
||||
"cmd-word",
|
||||
"cmd-word-back",
|
||||
"cmd-yank",
|
||||
}
|
||||
|
||||
gOptWords = getOptWords(gOpts)
|
||||
@@ -158,50 +160,164 @@ func getLocalOptWords(localOpts any) (localOptWords []string) {
|
||||
return
|
||||
}
|
||||
|
||||
func matchLongest(s1, s2 []rune) []rune {
|
||||
func commonPrefix(s1, s2 string) string {
|
||||
r1 := []rune(s1)
|
||||
r2 := []rune(s2)
|
||||
|
||||
i := 0
|
||||
for ; i < len(s1) && i < len(s2); i++ {
|
||||
if s1[i] != s2[i] {
|
||||
for ; i < len(r1) && i < len(r2); i++ {
|
||||
if r1[i] != r2[i] {
|
||||
break
|
||||
}
|
||||
}
|
||||
return s1[:i]
|
||||
|
||||
return string(r1[:i])
|
||||
}
|
||||
|
||||
func matchWord(s string, words []string) (matches []string, longest []rune) {
|
||||
type compMatch struct {
|
||||
name string // display name in completion menu
|
||||
result string // result when cycling through completion menu
|
||||
}
|
||||
|
||||
func matchWord(s string, words []string) (matches []compMatch, result string) {
|
||||
for _, w := range words {
|
||||
if !strings.HasPrefix(w, s) {
|
||||
continue
|
||||
}
|
||||
|
||||
matches = append(matches, w)
|
||||
if len(longest) != 0 {
|
||||
longest = matchLongest(longest, []rune(w))
|
||||
} else if s != "" {
|
||||
longest = []rune(w + " ")
|
||||
matches = append(matches, compMatch{w, w})
|
||||
if len(matches) == 1 {
|
||||
result = w
|
||||
} else {
|
||||
result = commonPrefix(result, w)
|
||||
}
|
||||
}
|
||||
|
||||
if len(longest) == 0 {
|
||||
longest = []rune(s)
|
||||
switch len(matches) {
|
||||
case 0:
|
||||
result = s
|
||||
case 1:
|
||||
result += " "
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func matchExec(s string) (matches []string, longest []rune) {
|
||||
var words []string
|
||||
func matchList(s string, words []string) (matches []compMatch, result string) {
|
||||
toks := strings.Split(s, ":")
|
||||
|
||||
paths := strings.Split(envPath, string(filepath.ListSeparator))
|
||||
|
||||
for _, p := range paths {
|
||||
if _, err := os.Stat(p); os.IsNotExist(err) {
|
||||
for _, w := range words {
|
||||
if slices.Contains(toks[:len(toks)-1], w) || !strings.HasPrefix(w, toks[len(toks)-1]) {
|
||||
continue
|
||||
}
|
||||
|
||||
matchResult := strings.Join(append(slices.Clone(toks[:len(toks)-1]), w), ":")
|
||||
matches = append(matches, compMatch{w, matchResult})
|
||||
|
||||
if len(matches) == 1 {
|
||||
result = matchResult
|
||||
} else {
|
||||
result = commonPrefix(result, matchResult)
|
||||
}
|
||||
}
|
||||
|
||||
switch len(matches) {
|
||||
case 0:
|
||||
result = s
|
||||
case 1:
|
||||
if result == s {
|
||||
result += " "
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func matchCmd(s string) (matches []compMatch, result string) {
|
||||
words := append(gCmdWords, slices.Collect(maps.Keys(gOpts.cmds))...)
|
||||
slices.Sort(words)
|
||||
matches, result = matchWord(s, slices.Compact(words))
|
||||
return
|
||||
}
|
||||
|
||||
func matchFile(s string, dirOnly bool, escape func(string) string, unescape func(string) string) (matches []compMatch, result string) {
|
||||
dir, file := filepath.Split(unescape(replaceTilde(s)))
|
||||
|
||||
d := dir
|
||||
if dir == "" {
|
||||
d = "."
|
||||
}
|
||||
files, err := os.ReadDir(d)
|
||||
if err != nil {
|
||||
log.Printf("reading directory: %s", err)
|
||||
result = s
|
||||
return
|
||||
}
|
||||
|
||||
var commonName string
|
||||
|
||||
for _, f := range files {
|
||||
isDir := false
|
||||
if f.IsDir() {
|
||||
isDir = true
|
||||
} else if f.Type()&os.ModeSymlink != 0 {
|
||||
if stat, err := os.Stat(filepath.Join(d, f.Name())); err == nil && stat.IsDir() {
|
||||
isDir = true
|
||||
}
|
||||
}
|
||||
|
||||
if !isDir && dirOnly {
|
||||
continue
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(strings.ToLower(f.Name()), strings.ToLower(file)) {
|
||||
continue
|
||||
}
|
||||
|
||||
name := f.Name()
|
||||
if isDir {
|
||||
name += string(filepath.Separator)
|
||||
}
|
||||
matches = append(matches, compMatch{name, escape(dir + name)})
|
||||
|
||||
if len(matches) == 1 {
|
||||
commonName = name
|
||||
} else {
|
||||
commonName = commonPrefix(strings.ToLower(commonName), strings.ToLower(name))
|
||||
}
|
||||
}
|
||||
|
||||
switch len(matches) {
|
||||
case 0:
|
||||
result = s
|
||||
case 1:
|
||||
result = escape(dir + commonName)
|
||||
if !strings.HasSuffix(commonName, string(filepath.Separator)) {
|
||||
result += " "
|
||||
}
|
||||
default:
|
||||
result = escape(dir + commonName)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func matchCmdFile(s string, dirOnly bool) (matches []compMatch, result string) {
|
||||
matches, result = matchFile(s, dirOnly, cmdEscape, cmdUnescape)
|
||||
return
|
||||
}
|
||||
|
||||
func matchShellFile(s string) (matches []compMatch, result string) {
|
||||
matches, result = matchFile(s, false, shellEscape, shellUnescape)
|
||||
return
|
||||
}
|
||||
|
||||
func matchExec(s string) (matches []compMatch, result string) {
|
||||
var words []string
|
||||
for _, p := range strings.Split(envPath, string(filepath.ListSeparator)) {
|
||||
files, err := os.ReadDir(p)
|
||||
if err != nil {
|
||||
log.Printf("reading path: %s", err)
|
||||
if !os.IsNotExist(err) {
|
||||
log.Printf("reading path: %s", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
@@ -215,170 +331,23 @@ func matchExec(s string) (matches []string, longest []rune) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !finfo.Mode().IsRegular() || !isExecutable(finfo) {
|
||||
continue
|
||||
if finfo.Mode().IsRegular() && isExecutable(finfo) {
|
||||
words = append(words, f.Name())
|
||||
}
|
||||
|
||||
words = append(words, finfo.Name())
|
||||
}
|
||||
}
|
||||
|
||||
if len(words) > 0 {
|
||||
sort.Strings(words)
|
||||
|
||||
uniq := words[:1]
|
||||
for i := 1; i < len(words); i++ {
|
||||
if words[i] != words[i-1] {
|
||||
uniq = append(uniq, words[i])
|
||||
}
|
||||
}
|
||||
words = uniq
|
||||
}
|
||||
|
||||
return matchWord(s, words)
|
||||
slices.Sort(words)
|
||||
matches, result = matchWord(s, slices.Compact(words))
|
||||
return
|
||||
}
|
||||
|
||||
func matchFile(s string) (matches []string, longest []rune) {
|
||||
dir := replaceTilde(s)
|
||||
|
||||
if !filepath.IsAbs(dir) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
} else {
|
||||
dir = wd + string(filepath.Separator) + dir
|
||||
}
|
||||
}
|
||||
|
||||
dir = filepath.Dir(unescape(dir))
|
||||
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
log.Printf("reading directory: %s", err)
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
name := filepath.Join(dir, f.Name())
|
||||
f, err := os.Lstat(name)
|
||||
if err != nil {
|
||||
log.Printf("getting file information: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
name = strings.ToLower(escape(f.Name()))
|
||||
_, last := filepath.Split(s)
|
||||
if !strings.HasPrefix(name, strings.ToLower(last)) {
|
||||
continue
|
||||
}
|
||||
|
||||
name = f.Name()
|
||||
if isRoot(s) || filepath.Base(s) != s {
|
||||
name = filepath.Join(filepath.Dir(unescape(s)), f.Name())
|
||||
}
|
||||
name = escape(replaceTilde(name))
|
||||
|
||||
item := f.Name()
|
||||
if f.Mode().IsDir() {
|
||||
item += escape(string(filepath.Separator))
|
||||
}
|
||||
matches = append(matches, item)
|
||||
|
||||
if longest == nil {
|
||||
if f.Mode().IsRegular() {
|
||||
longest = []rune(name + " ")
|
||||
} else {
|
||||
longest = []rune(name + escape(string(filepath.Separator)))
|
||||
}
|
||||
} else {
|
||||
longest = matchLongest(longest, []rune(name))
|
||||
}
|
||||
}
|
||||
|
||||
if len(longest) < len([]rune(s)) {
|
||||
longest = []rune(s)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func matchCmd(s string) (matches []string, longest []rune) {
|
||||
words := make([]string, 0, len(gCmdWords)+len(gOpts.cmds))
|
||||
words = append(words, gCmdWords...)
|
||||
for c := range gOpts.cmds {
|
||||
words = append(words, c)
|
||||
}
|
||||
sort.Strings(words)
|
||||
j := 0
|
||||
for i := 1; i < len(words); i++ {
|
||||
if words[j] == words[i] {
|
||||
continue
|
||||
}
|
||||
j++
|
||||
words[i], words[j] = words[j], words[i]
|
||||
}
|
||||
words = words[:j+1]
|
||||
matches, longest = matchWord(s, words)
|
||||
return
|
||||
}
|
||||
|
||||
func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||
s := string(acc)
|
||||
f := tokenize(s)
|
||||
|
||||
var longest []rune
|
||||
|
||||
switch len(f) {
|
||||
case 1:
|
||||
matches, longestAcc = matchCmd(s)
|
||||
case 2:
|
||||
switch f[0] {
|
||||
case "set":
|
||||
matches, longest = matchWord(f[1], gOptWords)
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
case "map", "nmap", "vmap", "cmap", "cmd":
|
||||
longestAcc = acc
|
||||
default:
|
||||
matches, longest = matchFile(f[len(f)-1])
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
}
|
||||
case 3:
|
||||
switch f[0] {
|
||||
case "setlocal":
|
||||
matches, longest = matchWord(f[2], gLocalOptWords)
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
case "map", "nmap", "vmap", "cmap":
|
||||
matches, longest = matchCmd(f[2])
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
case "addcustominfo":
|
||||
longestAcc = acc
|
||||
default:
|
||||
matches, longest = matchFile(f[len(f)-1])
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
}
|
||||
default:
|
||||
switch f[0] {
|
||||
case "set", "setlocal", "map", "nmap", "vmap", "cmap", "cmd":
|
||||
longestAcc = acc
|
||||
default:
|
||||
matches, longest = matchFile(f[len(f)-1])
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func completeFile(acc []rune) (matches []string, longestAcc []rune) {
|
||||
s := string(acc)
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
}
|
||||
|
||||
files, err := os.ReadDir(wd)
|
||||
func matchSearch(s string) (matches []compMatch, result string) {
|
||||
files, err := os.ReadDir(".")
|
||||
if err != nil {
|
||||
log.Printf("reading directory: %s", err)
|
||||
result = s
|
||||
return
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
@@ -386,35 +355,116 @@ func completeFile(acc []rune) (matches []string, longestAcc []rune) {
|
||||
continue
|
||||
}
|
||||
|
||||
matches = append(matches, f.Name())
|
||||
|
||||
if longestAcc == nil {
|
||||
longestAcc = []rune(f.Name())
|
||||
matches = append(matches, compMatch{f.Name(), f.Name()})
|
||||
if len(matches) == 1 {
|
||||
result = f.Name()
|
||||
} else {
|
||||
longestAcc = matchLongest(longestAcc, []rune(f.Name()))
|
||||
result = commonPrefix(strings.ToLower(result), strings.ToLower(f.Name()))
|
||||
}
|
||||
}
|
||||
|
||||
if len(longestAcc) < len(acc) {
|
||||
longestAcc = acc
|
||||
if len(matches) == 0 {
|
||||
result = s
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
||||
func completeCmd(acc []rune) (matches []compMatch, result string) {
|
||||
s := string(acc)
|
||||
f := tokenize(s)
|
||||
|
||||
var longest []rune
|
||||
if len(f) == 1 {
|
||||
matches, result = matchCmd(s)
|
||||
return
|
||||
}
|
||||
|
||||
result = f[len(f)-1]
|
||||
|
||||
switch f[0] {
|
||||
case "set":
|
||||
if len(f) == 2 {
|
||||
matches, result = matchWord(f[1], gOptWords)
|
||||
break
|
||||
}
|
||||
if len(f) != 3 {
|
||||
break
|
||||
}
|
||||
switch f[1] {
|
||||
case "filtermethod", "searchmethod":
|
||||
matches, result = matchWord(f[2], []string{"glob", "regex", "text"})
|
||||
case "info":
|
||||
matches, result = matchList(f[2], []string{"atime", "btime", "ctime", "custom", "group", "perm", "size", "time", "user"})
|
||||
case "preserve":
|
||||
matches, result = matchList(f[2], []string{"mode", "timestamps"})
|
||||
case "selmode":
|
||||
matches, result = matchWord(f[2], []string{"all", "dir"})
|
||||
case "sortby":
|
||||
matches, result = matchWord(f[2], []string{"atime", "btime", "ctime", "custom", "ext", "name", "natural", "size", "time"})
|
||||
default:
|
||||
if slices.Contains(gOptWords, f[1]+"!") {
|
||||
matches, result = matchWord(f[2], []string{"false", "true"})
|
||||
}
|
||||
}
|
||||
case "setlocal":
|
||||
if len(f) == 3 {
|
||||
matches, result = matchWord(f[2], gLocalOptWords)
|
||||
break
|
||||
}
|
||||
if len(f) != 4 {
|
||||
break
|
||||
}
|
||||
switch f[2] {
|
||||
case "info":
|
||||
matches, result = matchList(f[3], []string{"atime", "btime", "ctime", "custom", "group", "perm", "size", "time", "user"})
|
||||
case "sortby":
|
||||
matches, result = matchWord(f[3], []string{"atime", "btime", "ctime", "custom", "ext", "name", "natural", "size", "time"})
|
||||
default:
|
||||
if slices.Contains(gLocalOptWords, f[2]+"!") {
|
||||
matches, result = matchWord(f[3], []string{"false", "true"})
|
||||
}
|
||||
}
|
||||
case "map", "nmap", "vmap", "cmap":
|
||||
if len(f) == 3 {
|
||||
matches, result = matchCmd(f[2])
|
||||
}
|
||||
case "cmd":
|
||||
case "cd":
|
||||
if len(f) == 2 {
|
||||
matches, result = matchCmdFile(f[1], true)
|
||||
}
|
||||
case "select", "source":
|
||||
if len(f) == 2 {
|
||||
matches, result = matchCmdFile(f[1], false)
|
||||
}
|
||||
case "toggle":
|
||||
matches, result = matchCmdFile(f[len(f)-1], false)
|
||||
default:
|
||||
if !slices.Contains(gCmdWords, f[0]) {
|
||||
matches, result = matchCmdFile(f[len(f)-1], false)
|
||||
}
|
||||
}
|
||||
|
||||
f[len(f)-1] = result
|
||||
result = strings.Join(f, " ")
|
||||
return
|
||||
}
|
||||
|
||||
func completeShell(acc []rune) (matches []compMatch, result string) {
|
||||
f := tokenize(string(acc))
|
||||
|
||||
switch len(f) {
|
||||
case 1:
|
||||
matches, longestAcc = matchExec(s)
|
||||
matches, result = matchExec(f[0])
|
||||
default:
|
||||
matches, longest = matchFile(f[len(f)-1])
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
matches, result = matchShellFile(f[len(f)-1])
|
||||
}
|
||||
|
||||
f[len(f)-1] = result
|
||||
result = strings.Join(f, " ")
|
||||
return
|
||||
}
|
||||
|
||||
func completeSearch(acc []rune) (matches []compMatch, result string) {
|
||||
matches, result = matchSearch(string(acc))
|
||||
return
|
||||
}
|
||||
+86
-50
@@ -5,56 +5,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMatchLongest(t *testing.T) {
|
||||
tests := []struct {
|
||||
s1 string
|
||||
s2 string
|
||||
exp string
|
||||
}{
|
||||
{"", "", ""},
|
||||
{"", "foo", ""},
|
||||
{"foo", "", ""},
|
||||
{"foo", "bar", ""},
|
||||
{"foo", "foobar", "foo"},
|
||||
{"foo", "barfoo", ""},
|
||||
{"foobar", "foobaz", "fooba"},
|
||||
{"год", "гол", "го"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if got := string(matchLongest([]rune(test.s1), []rune(test.s2))); got != test.exp {
|
||||
t.Errorf("at input '%s' and '%s' expected '%s' but got '%s'", test.s1, test.s2, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatchWord(t *testing.T) {
|
||||
tests := []struct {
|
||||
s string
|
||||
words []string
|
||||
matches []string
|
||||
longest string
|
||||
}{
|
||||
{"", nil, nil, ""},
|
||||
{"", []string{"foo", "bar", "baz"}, []string{"foo", "bar", "baz"}, ""},
|
||||
{"fo", []string{"foo", "bar", "baz"}, []string{"foo"}, "foo "},
|
||||
{"ba", []string{"foo", "bar", "baz"}, []string{"bar", "baz"}, "ba"},
|
||||
{"fo", []string{"bar", "baz"}, nil, "fo"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
m, l := matchWord(test.s, test.words)
|
||||
|
||||
if !reflect.DeepEqual(m, test.matches) {
|
||||
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.matches, m)
|
||||
}
|
||||
|
||||
if ls := string(l); ls != test.longest {
|
||||
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.longest, ls)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOptWords(t *testing.T) {
|
||||
tests := []struct {
|
||||
opts any
|
||||
@@ -92,3 +42,89 @@ func TestGetLocalOptWords(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommonPrefix(t *testing.T) {
|
||||
tests := []struct {
|
||||
s1 string
|
||||
s2 string
|
||||
exp string
|
||||
}{
|
||||
{"", "", ""},
|
||||
{"", "foo", ""},
|
||||
{"foo", "", ""},
|
||||
{"foo", "bar", ""},
|
||||
{"foo", "foobar", "foo"},
|
||||
{"foo", "barfoo", ""},
|
||||
{"foobar", "foobaz", "fooba"},
|
||||
{"год", "гол", "го"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if got := commonPrefix(test.s1, test.s2); got != test.exp {
|
||||
t.Errorf("at input '%s' and '%s' expected '%s' but got '%s'", test.s1, test.s2, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatchWord(t *testing.T) {
|
||||
tests := []struct {
|
||||
s string
|
||||
words []string
|
||||
matches []compMatch
|
||||
result string
|
||||
}{
|
||||
{"", nil, nil, ""},
|
||||
{"", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "foo"}, {"bar", "bar"}, {"baz", "baz"}}, ""},
|
||||
{"fo", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "foo"}}, "foo "},
|
||||
{"ba", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "bar"}, {"baz", "baz"}}, "ba"},
|
||||
{"fo", []string{"bar", "baz"}, nil, "fo"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
matches, result := matchWord(test.s, test.words)
|
||||
|
||||
if !reflect.DeepEqual(matches, test.matches) {
|
||||
t.Errorf("at input '%s' with '%s' expected '%v' but got '%v'", test.s, test.words, test.matches, matches)
|
||||
}
|
||||
|
||||
if result != test.result {
|
||||
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.result, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatchList(t *testing.T) {
|
||||
tests := []struct {
|
||||
s string
|
||||
words []string
|
||||
matches []compMatch
|
||||
result string
|
||||
}{
|
||||
{"", nil, nil, ""},
|
||||
{"", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "foo"}, {"bar", "bar"}, {"baz", "baz"}}, ""},
|
||||
{"f", []string{"bar", "baz"}, nil, "f"},
|
||||
{"f", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "foo"}}, "foo"},
|
||||
{"b", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "bar"}, {"baz", "baz"}}, "ba"},
|
||||
{"ba", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "bar"}, {"baz", "baz"}}, "ba"},
|
||||
{"foo", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "foo"}}, "foo "},
|
||||
{"foo:", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "foo:bar"}, {"baz", "foo:baz"}}, "foo:ba"},
|
||||
{"foo:f", []string{"foo", "bar", "baz"}, nil, "foo:f"},
|
||||
{"foo:b", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "foo:bar"}, {"baz", "foo:baz"}}, "foo:ba"},
|
||||
{"foo:ba", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "foo:bar"}, {"baz", "foo:baz"}}, "foo:ba"},
|
||||
{"bar:b", []string{"foo", "bar", "baz"}, []compMatch{{"baz", "bar:baz"}}, "bar:baz"},
|
||||
{"bar:f", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "bar:foo"}}, "bar:foo"},
|
||||
{"bar:foo", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "bar:foo"}}, "bar:foo "},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
matches, result := matchList(test.s, test.words)
|
||||
|
||||
if !reflect.DeepEqual(matches, test.matches) {
|
||||
t.Errorf("at input '%s' with '%s' expected '%v' but got '%v'", test.s, test.words, test.matches, matches)
|
||||
}
|
||||
|
||||
if result != test.result {
|
||||
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.result, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64,
|
||||
newPath := filepath.Join(dst, rel)
|
||||
switch {
|
||||
case info.IsDir():
|
||||
var dst_mode os.FileMode = os.ModePerm
|
||||
var dst_mode = os.ModePerm
|
||||
if slices.Contains(preserve, "mode") {
|
||||
dst_mode = info.Mode()
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,5 +15,5 @@ func diskFree(wd string) string {
|
||||
}
|
||||
|
||||
// Available blocks * size per block = available space in bytes
|
||||
return "df: " + humanize(int64(uint64(stat.F_bavail)*uint64(stat.F_bsize)))
|
||||
return "df: " + humanize(uint64(stat.F_bavail)*uint64(stat.F_bsize))
|
||||
}
|
||||
+1
-1
@@ -17,5 +17,5 @@ func diskFree(wd string) string {
|
||||
}
|
||||
|
||||
// Available blocks * size per block = available space in bytes
|
||||
return "df: " + humanize(int64(uint64(stat.Bavail)*uint64(stat.Bsize)))
|
||||
return "df: " + humanize(uint64(stat.Bavail)*uint64(stat.Bsize))
|
||||
}
|
||||
+1
-1
@@ -17,5 +17,5 @@ func diskFree(wd string) string {
|
||||
}
|
||||
|
||||
// Available blocks * size per block = available space in bytes
|
||||
return "df: " + humanize(int64(uint64(stat.Bavail)*uint64(stat.Bsize)))
|
||||
return "df: " + humanize(uint64(stat.Bavail)*uint64(stat.Bsize))
|
||||
}
|
||||
+1
-1
@@ -19,5 +19,5 @@ func diskFree(wd string) string {
|
||||
log.Printf("diskfree: %s", err)
|
||||
return ""
|
||||
}
|
||||
return "df: " + humanize(int64(free))
|
||||
return "df: " + humanize(free)
|
||||
}
|
||||
+1
-1
@@ -60,7 +60,7 @@ func runSearch(t *testing.T, ignorecase, smartcase, ignorediacritics, smartdiacr
|
||||
gOpts.smartcase = smartcase
|
||||
gOpts.ignoredia = ignorediacritics
|
||||
gOpts.smartdia = smartdiacritics
|
||||
matched, _ := searchMatch(base, pattern, false)
|
||||
matched, _ := searchMatch(base, pattern, textSearch)
|
||||
if matched != expected {
|
||||
t.Errorf("False search for ignorecase = %t, smartcase = %t, ignoredia = %t, smartdia = %t",
|
||||
gOpts.ignorecase,
|
||||
|
||||
@@ -57,13 +57,10 @@ The following commands are provided by lf:
|
||||
middle (default 'M')
|
||||
low (default 'L')
|
||||
toggle
|
||||
visual (default 'V')
|
||||
invert (default 'v')
|
||||
unselect (default 'u')
|
||||
glob-select
|
||||
glob-unselect
|
||||
calcdirsize
|
||||
clearmaps
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
@@ -73,15 +70,8 @@ The following commands are provided by lf:
|
||||
redraw (default '<c-l>')
|
||||
load
|
||||
reload (default '<c-r>')
|
||||
echo
|
||||
echomsg
|
||||
echoerr
|
||||
cd
|
||||
select
|
||||
delete (modal)
|
||||
rename (modal) (default 'r')
|
||||
source
|
||||
push
|
||||
read (modal) (default ':')
|
||||
shell (modal) (default '$')
|
||||
shell-pipe (modal) (default '%')
|
||||
@@ -102,8 +92,18 @@ The following commands are provided by lf:
|
||||
mark-remove (modal) (default '"')
|
||||
tag
|
||||
tag-toggle (default 't')
|
||||
echo
|
||||
echomsg
|
||||
echoerr
|
||||
cd
|
||||
select
|
||||
source
|
||||
push
|
||||
addcustominfo
|
||||
calcdirsize
|
||||
clearmaps
|
||||
tty-write
|
||||
visual (default 'V')
|
||||
|
||||
The following Visual mode commands are provided by lf:
|
||||
|
||||
@@ -114,6 +114,7 @@ The following Visual mode commands are provided by lf:
|
||||
|
||||
The following Command-line mode commands are provided by lf:
|
||||
|
||||
cmd-insert
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-menu-complete
|
||||
@@ -163,9 +164,8 @@ The following options can be used to customize the behavior of lf:
|
||||
dupfilefmt string (default '%f.~%n~')
|
||||
errorfmt string (default "\033[7;31;47m")
|
||||
filesep string (default "\n")
|
||||
filtermethod string (default 'text')
|
||||
findlen int (default 1)
|
||||
globfilter bool (default false)
|
||||
globsearch bool (default false)
|
||||
hidden bool (default false)
|
||||
hiddenfiles []string (default '.*' for Unix and '' for Windows)
|
||||
history bool (default true)
|
||||
@@ -193,6 +193,7 @@ The following options can be used to customize the behavior of lf:
|
||||
roundbox bool (default false)
|
||||
rulerfmt string (default " %a| %p| \033[7;31m %m \033[0m| \033[7;33m %c \033[0m| \033[7;35m %s \033[0m| \033[7;34m %f \033[0m| %i/%t")
|
||||
scrolloff int (default 0)
|
||||
searchmethod string (default 'text')
|
||||
selectfmt string (default "\033[7;35m")
|
||||
selmode string (default 'all')
|
||||
shell string (default 'sh' for Unix and 'cmd' for Windows)
|
||||
@@ -235,6 +236,7 @@ The following environment variables are exported for shell commands:
|
||||
lf
|
||||
lf_{option}
|
||||
lf_user_{option}
|
||||
lf_flag_{flag}
|
||||
lf_width
|
||||
lf_height
|
||||
lf_count
|
||||
@@ -296,6 +298,7 @@ The following additional keybindings are provided by default:
|
||||
map ss :set sortby size; set info size
|
||||
map st :set sortby time; set info time
|
||||
map sa :set sortby atime; set info atime
|
||||
map sb :set sortby btime; set info btime
|
||||
map sc :set sortby ctime; set info ctime
|
||||
map se :set sortby ext; set info
|
||||
map gh cd ~
|
||||
@@ -318,19 +321,19 @@ Configuration files should be located at:
|
||||
|
||||
OS system-wide user-specific
|
||||
Unix /etc/lf/lfrc ~/.config/lf/lfrc
|
||||
Windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Local\lf\lfrc
|
||||
Windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Roaming\lf\lfrc
|
||||
|
||||
The colors file should be located at:
|
||||
|
||||
OS system-wide user-specific
|
||||
Unix /etc/lf/colors ~/.config/lf/colors
|
||||
Windows C:\ProgramData\lf\colors C:\Users\<user>\AppData\Local\lf\colors
|
||||
Windows C:\ProgramData\lf\colors C:\Users\<user>\AppData\Roaming\lf\colors
|
||||
|
||||
The icons file should be located at:
|
||||
|
||||
OS system-wide user-specific
|
||||
Unix /etc/lf/icons ~/.config/lf/icons
|
||||
Windows C:\ProgramData\lf\icons C:\Users\<user>\AppData\Local\lf\icons
|
||||
Windows C:\ProgramData\lf\icons C:\Users\<user>\AppData\Roaming\lf\icons
|
||||
|
||||
The selection file should be located at:
|
||||
|
||||
@@ -364,12 +367,11 @@ You can configure these locations with the following variables given with their
|
||||
~/.local/share
|
||||
|
||||
Windows
|
||||
%ProgramData%
|
||||
C:\ProgramData
|
||||
|
||||
%LF_CONFIG_HOME%
|
||||
%APPDATA%
|
||||
|
||||
%LF_DATA_HOME%
|
||||
%LOCALAPPDATA%
|
||||
C:\Users\<user>\AppData\Local
|
||||
|
||||
A sample configuration file can be found at
|
||||
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example
|
||||
@@ -414,27 +416,6 @@ Move the current file selection to the high/middle/low of the screen.
|
||||
|
||||
Toggle the selection of the current file or files given as arguments.
|
||||
|
||||
## visual (default `V`)
|
||||
|
||||
Switch to Visual mode.
|
||||
If already in Visual mode, discard the visual selection and stay in Visual mode.
|
||||
|
||||
## visual-accept (default `V`)
|
||||
|
||||
Add the visual selection to the selection list, quit Visual mode and return to Normal mode.
|
||||
|
||||
## visual-unselect
|
||||
|
||||
Remove the visual selection from the selection list, quit Visual mode and return to Normal mode.
|
||||
|
||||
## visual-discard (default `<esc>`)
|
||||
|
||||
Discard the visual selection, quit Visual mode and return to Normal mode.
|
||||
|
||||
## visual-change (default `o`)
|
||||
|
||||
Go to the other end of the current Visual mode selection.
|
||||
|
||||
## invert (default `v`)
|
||||
|
||||
Reverse the selection of all files in the current directory (i.e. `toggle` all files).
|
||||
@@ -449,34 +430,24 @@ Remove the selection of all files in all directories.
|
||||
|
||||
Select/unselect files that match the given glob.
|
||||
|
||||
## calcdirsize
|
||||
|
||||
Calculate the total size for each of the selected directories.
|
||||
Option `info` should include `size` and option `dircounts` should be disabled to show this size.
|
||||
If the total size of a directory is not calculated, it will be shown as `-`.
|
||||
|
||||
## clearmaps
|
||||
|
||||
Remove all keybindings associated with the `map`, `nmap` and `vmap` command.
|
||||
This command can be used in the config file to remove the default keybindings.
|
||||
For safety purposes, `:` is left mapped to the `read` command, and `cmap` keybindings are retained so that it is still possible to exit `lf` using `:quit`.
|
||||
|
||||
## copy (default `y`)
|
||||
|
||||
If there are no selections, save the path of the current file to the copy buffer, otherwise, copy the paths of selected files.
|
||||
Save the paths of selected files to the clipboard as files to be copied.
|
||||
If there are no selected files, the path of the current file is used instead.
|
||||
|
||||
## cut (default `d`)
|
||||
|
||||
If there are no selections, save the path of the current file to the cut buffer, otherwise, copy the paths of selected files.
|
||||
Save the paths of selected files to the clipboard as files to be moved.
|
||||
If there are no selected files, the path of the current file is used instead.
|
||||
|
||||
## paste (default `p`)
|
||||
|
||||
Copy/Move files in the copy/cut buffer to the current working directory.
|
||||
Copy/Move files in the clipboard to the current working directory.
|
||||
A custom `paste` command can be defined to override this default.
|
||||
|
||||
## clear (default `c`)
|
||||
|
||||
Clear file paths in copy/cut buffer.
|
||||
Clear file paths in the clipboard.
|
||||
|
||||
## sync
|
||||
|
||||
@@ -501,26 +472,6 @@ This command is automatically called when required.
|
||||
|
||||
Flush the cache and reload all files and directories.
|
||||
|
||||
## echo
|
||||
|
||||
Print the given arguments to the message line at the bottom.
|
||||
|
||||
## echomsg
|
||||
|
||||
Print the given arguments to the message line at the bottom and also to the log file.
|
||||
|
||||
## echoerr
|
||||
|
||||
Print given arguments to the message line at the bottom as `errorfmt` and also to the log file.
|
||||
|
||||
## cd
|
||||
|
||||
Change the working directory to the given argument.
|
||||
|
||||
## select
|
||||
|
||||
Change the current file selection to the given argument.
|
||||
|
||||
## delete (modal)
|
||||
|
||||
Remove the current file or selected file(s).
|
||||
@@ -531,14 +482,6 @@ A custom `delete` command can be defined to override this default.
|
||||
Rename the current file using the built-in method.
|
||||
A custom `rename` command can be defined to override this default.
|
||||
|
||||
## source
|
||||
|
||||
Read the configuration file given in the argument.
|
||||
|
||||
## push
|
||||
|
||||
Simulate key pushes given in the argument.
|
||||
|
||||
## read (modal) (default `:`)
|
||||
|
||||
Read a command to evaluate.
|
||||
@@ -595,19 +538,82 @@ You can define a new tag-clearing command by combining `tag` with `tag-toggle` (
|
||||
|
||||
Tag a file with `*` or a single width character given in the argument if the file is untagged, otherwise remove the tag.
|
||||
|
||||
## echo
|
||||
|
||||
Print the given arguments to the message line at the bottom.
|
||||
|
||||
## echomsg
|
||||
|
||||
Print the given arguments to the message line at the bottom and also to the log file.
|
||||
|
||||
## echoerr
|
||||
|
||||
Print given arguments to the message line at the bottom as `errorfmt` and also to the log file.
|
||||
|
||||
## cd
|
||||
|
||||
Change the working directory to the given argument.
|
||||
|
||||
## select
|
||||
|
||||
Change the current file selection to the given argument.
|
||||
|
||||
## source
|
||||
|
||||
Read the configuration file given in the argument.
|
||||
|
||||
## push
|
||||
|
||||
Simulate key pushes given in the argument.
|
||||
|
||||
## addcustominfo
|
||||
|
||||
Update the `custom` info field of the given file with the given string.
|
||||
The info string may contain ANSI escape codes to further customize its appearance.
|
||||
If no info is provided, clear the file's info instead.
|
||||
|
||||
## calcdirsize
|
||||
|
||||
Calculate the total size for each of the selected directories.
|
||||
Option `info` should include `size` and option `dircounts` should be disabled to show this size.
|
||||
If the total size of a directory is not calculated, it will be shown as `-`.
|
||||
|
||||
## clearmaps
|
||||
|
||||
Remove all keybindings associated with the `map`, `nmap` and `vmap` command.
|
||||
This command can be used in the config file to remove the default keybindings.
|
||||
For safety purposes, `:` is left mapped to the `read` command, and `cmap` keybindings are retained so that it is still possible to exit `lf` using `:quit`.
|
||||
|
||||
## tty-write
|
||||
|
||||
Write the given string to the tty.
|
||||
This is useful for sending escape sequences to the terminal to control its behavior (e.g. OSC 0 to set the window title).
|
||||
Using `tty-write` is preferred over directly writing to `/dev/tty` because the latter is not synchronized and can interfere with drawing the UI.
|
||||
|
||||
# COMMAND LINE COMMANDS
|
||||
## visual (default `V`)
|
||||
|
||||
Switch to Visual mode.
|
||||
If already in Visual mode, discard the visual selection and stay in Visual mode.
|
||||
|
||||
# VISUAL MODE COMMANDS
|
||||
|
||||
## visual-accept (default `V`)
|
||||
|
||||
Add the visual selection to the selection list, quit Visual mode and return to Normal mode.
|
||||
|
||||
## visual-unselect
|
||||
|
||||
Remove the visual selection from the selection list, quit Visual mode and return to Normal mode.
|
||||
|
||||
## visual-discard (default `<esc>`)
|
||||
|
||||
Discard the visual selection, quit Visual mode and return to Normal mode.
|
||||
|
||||
## visual-change (default `o`)
|
||||
|
||||
Go to the other end of the current Visual mode selection.
|
||||
|
||||
# COMMAND-LINE MODE COMMANDS
|
||||
|
||||
The prompt character specifies which of the several Command-line modes you are in.
|
||||
For example, the `read` command takes you to the `:` mode.
|
||||
@@ -618,6 +624,11 @@ You can go back with `cmd-delete-back` (`<backspace>` by default).
|
||||
The command line commands should be mostly compatible with readline keybindings.
|
||||
A character refers to a Unicode code point, a word consists of letters and digits, and a unix word consists of any non-blank characters.
|
||||
|
||||
## cmd-insert
|
||||
|
||||
Insert the character given in the argument.
|
||||
This command is automatically called when required.
|
||||
|
||||
## cmd-escape (default `<esc>`)
|
||||
|
||||
Quit Command-line mode and return to Normal mode.
|
||||
@@ -759,6 +770,7 @@ This option only has an effect when `info` has a `size` field and the pane is wi
|
||||
## dirfirst (bool) (default true)
|
||||
|
||||
Show directories first above regular files.
|
||||
With `dircounts` enabled, sorting by `size` always separates directories and files, regardless of `dirfirst`.
|
||||
|
||||
## dironly (bool) (default false)
|
||||
|
||||
@@ -788,21 +800,17 @@ For example, `\033[4m%s\033[0m` has the same effect as `\033[4m`.
|
||||
|
||||
File separator used in environment variables `fs`, `fv` and `fx`.
|
||||
|
||||
## filtermethod (string) (default `text`)
|
||||
|
||||
How filter command patterns are treated.
|
||||
Currently supported methods are `text` (i.e. string literals), `glob` (i.e shell globs) and `regex` (i.e. regular expressions).
|
||||
See `SEARCHING FILES` for more details.
|
||||
|
||||
## findlen (int) (default 1)
|
||||
|
||||
Number of characters prompted for the find command.
|
||||
When this value is set to 0, find command prompts until there is only a single match left.
|
||||
|
||||
## globfilter (bool) (default false)
|
||||
|
||||
Patterns are treated as globs for the filter command, see `globsearch` for more details.
|
||||
|
||||
## globsearch (bool) (default false)
|
||||
|
||||
When this option is enabled, search command patterns are considered as globs, otherwise, they are literals.
|
||||
With globbing, `*` matches any sequence, `?` matches any character, and `[...]` or `[^...]` matches character sets or ranges.
|
||||
Otherwise, these characters are interpreted as they are.
|
||||
|
||||
## hidden (bool) (default false)
|
||||
|
||||
Show hidden files.
|
||||
@@ -841,18 +849,18 @@ Ignore case in sorting and search patterns.
|
||||
|
||||
Ignore diacritics in sorting and search patterns.
|
||||
|
||||
## incsearch (bool) (default false)
|
||||
|
||||
Jump to the first match after each keystroke during searching.
|
||||
|
||||
## incfilter (bool) (default false)
|
||||
|
||||
Apply filter pattern after each keystroke during filtering.
|
||||
|
||||
## incsearch (bool) (default false)
|
||||
|
||||
Jump to the first match after each keystroke during searching.
|
||||
|
||||
## info ([]string) (default ``)
|
||||
|
||||
A list of information that is shown for directory items at the right side of the pane.
|
||||
Currently supported information types are `size`, `time`, `atime`, `ctime`, `perm`, `user`, `group` and `custom`.
|
||||
Currently supported information types are `size`, `time`, `atime`, `btime`, `ctime`, `perm`, `user`, `group` and `custom`.
|
||||
The `custom` type is empty by default and can be updated using the `addcustominfo` command.
|
||||
Information is only shown when the pane width is more than twice the width of information.
|
||||
|
||||
@@ -894,7 +902,7 @@ Periodic checks are disabled when the value of this option is set to zero.
|
||||
## preserve ([]string) (default `mode`)
|
||||
|
||||
List of attributes that are preserved when copying files.
|
||||
Currently supported attributes are `mode` (i.a. access mode) and `timestamps` (i.e. modification time and access time).
|
||||
Currently supported attributes are `mode` (i.e. access mode) and `timestamps` (i.e. modification time and access time).
|
||||
Note that preserving other attributes like ownership of change/birth timestamp is desirable, but not portably supported in Go.
|
||||
|
||||
## preview (bool) (default true)
|
||||
@@ -947,6 +955,18 @@ Additional expansions are provided for environment variables exported by lf, in
|
||||
Expansions are also provided for user-defined options, in the form `%{lf_user_<name>}` (e.g. `%{lf_user_foo}`).
|
||||
The `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown.
|
||||
|
||||
## scrolloff (int) (default 0)
|
||||
|
||||
Minimum number of offset lines shown at all times at the top and bottom of the screen when scrolling.
|
||||
The current line is kept in the middle when this option is set to a large value that is bigger than the half of number of lines.
|
||||
A smaller offset can be used when the current file is close to the beginning or end of the list to show the maximum number of items.
|
||||
|
||||
## searchmethod (string) default `text`)
|
||||
|
||||
How search command patterns are treated.
|
||||
Currently supported methods are `text` (i.e. string literals), `glob` (i.e shell globs) and `regex` (i.e. regular expressions).
|
||||
See `SEARCHING FILES` for more details.
|
||||
|
||||
## selectfmt (string) (default `\033[7;35m`)
|
||||
|
||||
Format string of the indicator for files that are selected.
|
||||
@@ -957,12 +977,6 @@ Selection mode for commands.
|
||||
When set to `all` it will use the selected files from all directories.
|
||||
When set to `dir` it will only use the selected files in the current directory.
|
||||
|
||||
## scrolloff (int) (default 0)
|
||||
|
||||
Minimum number of offset lines shown at all times at the top and bottom of the screen when scrolling.
|
||||
The current line is kept in the middle when this option is set to a large value that is bigger than the half of number of lines.
|
||||
A smaller offset can be used when the current file is close to the beginning or end of the list to show the maximum number of items.
|
||||
|
||||
## shell (string) (default `sh` for Unix and `cmd` for Windows)
|
||||
|
||||
Shell executable to use for shell commands.
|
||||
@@ -997,14 +1011,29 @@ This option has no effect when `ignoredia` is disabled.
|
||||
## sortby (string) (default `natural`)
|
||||
|
||||
Sort type for directories.
|
||||
Currently supported sort types are `natural`, `name`, `size`, `time`, `ctime`, `atime`, `ext` and `custom`.
|
||||
Currently supported sort types are `natural`, `name`, `size`, `time`, `atime`, `btime`, `ctime`, `ext` and `custom`.
|
||||
|
||||
Meaning of each sort type:
|
||||
|
||||
natural file name (track_2.flac comes before track_10.flac)
|
||||
name file name (track_10.flac comes before track_2.flac)
|
||||
size file size
|
||||
time time of last data modification
|
||||
atime time of last access
|
||||
btime time of file birth
|
||||
ctime time of last status (inode) change
|
||||
ext file extension
|
||||
custom property defined via `addcustominfo`
|
||||
|
||||
## statfmt (string) (default `\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l`)
|
||||
|
||||
Format string of the file info shown in the bottom left corner.
|
||||
Special expansions are provided, `%p` as the file permissions, `%c` as the link count, `%u` as the user, `%g` as the group, `%s` as the file size, `%S` as the file size but with a fixed width of four characters (left-padded with spaces), `%t` as the last modified time, `%l` as the link target, `%m` as the current mode and `%M` as the current mode but also shown in Normal mode (displaying `NORMAL` instead of a blank string).
|
||||
Special expansions are provided, `%p` as the file permissions, `%c` as the link count, `%u` as the user, `%g` as the group, `%s` as the file size, `%S` as the file size but with a fixed width of five characters (left-padded with spaces), `%t` as the last modified time, `%l` as the link target, `%m` as the current mode and `%M` as the current mode but also shown in Normal mode (displaying `NORMAL` instead of a blank string).
|
||||
|
||||
The `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown.
|
||||
|
||||
File size is formatted using first letter of IEC 80000-13:2025 prefixes for binary multiples (i.e. 1024 bytes is `1.0K`).
|
||||
|
||||
## tabstop (int) (default 8)
|
||||
|
||||
Number of space characters to show for horizontal tabulation (U+0009) character.
|
||||
@@ -1141,6 +1170,10 @@ Value of the {option}.
|
||||
|
||||
Value of the user_{option}.
|
||||
|
||||
## lf_flag_{flag}
|
||||
|
||||
Value of the command line {flag}.
|
||||
|
||||
## lf_width, lf_height
|
||||
|
||||
Width/Height of the terminal.
|
||||
@@ -1249,7 +1282,7 @@ Command `set` is used to set an option which can be a boolean, integer, or strin
|
||||
set sortby "time" # string value with double quotes (backslash escapes)
|
||||
|
||||
Command `setlocal` is used to set a local option for a directory which can be a boolean or string.
|
||||
Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `reverse`, `sortby` and `locale`.
|
||||
Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `locale`, `reverse` and `sortby`.
|
||||
Adding a trailing path separator (i.e. `/` for Unix and `\` for Windows) sets the option for the given directory along with its subdirectories:
|
||||
|
||||
setlocal /foo/bar hidden # boolean enable
|
||||
@@ -1288,9 +1321,9 @@ Command `cmap` is used to bind a key on the command line to a command line comma
|
||||
|
||||
You can delete an existing binding by leaving the expression empty:
|
||||
|
||||
map gh # deletes 'gh' mapping in normal and visual mode
|
||||
nmap v # deletes 'v' mapping in normal mode
|
||||
vmap o # deletes 'o' mapping in visual mode
|
||||
map gh # deletes 'gh' mapping in Normal and Visual mode
|
||||
nmap v # deletes 'v' mapping in Normal mode
|
||||
vmap o # deletes 'o' mapping in Visual mode
|
||||
cmap <c-g> # deletes '<c-g>' mapping
|
||||
|
||||
Command `cmd` is used to define a custom command:
|
||||
@@ -1616,8 +1649,10 @@ Searching is the traditional method to move the selection to a file matching a g
|
||||
Finding is an alternative way to search for a pattern possibly using fewer keystrokes.
|
||||
|
||||
The searching mechanism is implemented with commands `search` (default `/`), `search-back` (default `?`), `search-next` (default `n`), and `search-prev` (default `N`).
|
||||
You can enable `globsearch` option to match with a glob pattern.
|
||||
You can set `searchmethod` to `glob` to match using a glob pattern.
|
||||
Globbing supports `*` to match any sequence, `?` to match any character, and `[...]` or `[^...]` to match character sets or ranges.
|
||||
You can set `searchmethod` to `regex` to match using a regex pattern.
|
||||
For a full overview of Go's RE2 syntax, see https://pkg.go.dev/regexp/syntax.
|
||||
You can enable `incsearch` option to jump to the current match at each keystroke while typing.
|
||||
In this mode, you can either use `cmd-enter` to accept the search or use `cmd-escape` to cancel the search.
|
||||
You can also map some other commands with `cmap` to accept the search and execute the command immediately afterwards.
|
||||
|
||||
@@ -47,13 +47,10 @@ The following commands are provided by lf:
|
||||
middle (default 'M')
|
||||
low (default 'L')
|
||||
toggle
|
||||
visual (default 'V')
|
||||
invert (default 'v')
|
||||
unselect (default 'u')
|
||||
glob-select
|
||||
glob-unselect
|
||||
calcdirsize
|
||||
clearmaps
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
@@ -63,15 +60,8 @@ The following commands are provided by lf:
|
||||
redraw (default '<c-l>')
|
||||
load
|
||||
reload (default '<c-r>')
|
||||
echo
|
||||
echomsg
|
||||
echoerr
|
||||
cd
|
||||
select
|
||||
delete (modal)
|
||||
rename (modal) (default 'r')
|
||||
source
|
||||
push
|
||||
read (modal) (default ':')
|
||||
shell (modal) (default '$')
|
||||
shell-pipe (modal) (default '%')
|
||||
@@ -92,8 +82,18 @@ The following commands are provided by lf:
|
||||
mark-remove (modal) (default '"')
|
||||
tag
|
||||
tag-toggle (default 't')
|
||||
echo
|
||||
echomsg
|
||||
echoerr
|
||||
cd
|
||||
select
|
||||
source
|
||||
push
|
||||
addcustominfo
|
||||
calcdirsize
|
||||
clearmaps
|
||||
tty-write
|
||||
visual (default 'V')
|
||||
|
||||
The following Visual mode commands are provided by lf:
|
||||
|
||||
@@ -104,6 +104,7 @@ The following Visual mode commands are provided by lf:
|
||||
|
||||
The following Command-line mode commands are provided by lf:
|
||||
|
||||
cmd-insert
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-menu-complete
|
||||
@@ -153,9 +154,8 @@ The following options can be used to customize the behavior of lf:
|
||||
dupfilefmt string (default '%f.~%n~')
|
||||
errorfmt string (default "\033[7;31;47m")
|
||||
filesep string (default "\n")
|
||||
filtermethod string (default 'text')
|
||||
findlen int (default 1)
|
||||
globfilter bool (default false)
|
||||
globsearch bool (default false)
|
||||
hidden bool (default false)
|
||||
hiddenfiles []string (default '.*' for Unix and '' for Windows)
|
||||
history bool (default true)
|
||||
@@ -183,6 +183,7 @@ The following options can be used to customize the behavior of lf:
|
||||
roundbox bool (default false)
|
||||
rulerfmt string (default " %a| %p| \033[7;31m %m \033[0m| \033[7;33m %c \033[0m| \033[7;35m %s \033[0m| \033[7;34m %f \033[0m| %i/%t")
|
||||
scrolloff int (default 0)
|
||||
searchmethod string (default 'text')
|
||||
selectfmt string (default "\033[7;35m")
|
||||
selmode string (default 'all')
|
||||
shell string (default 'sh' for Unix and 'cmd' for Windows)
|
||||
@@ -225,6 +226,7 @@ The following environment variables are exported for shell commands:
|
||||
lf
|
||||
lf_{option}
|
||||
lf_user_{option}
|
||||
lf_flag_{flag}
|
||||
lf_width
|
||||
lf_height
|
||||
lf_count
|
||||
@@ -287,6 +289,7 @@ The following additional keybindings are provided by default:
|
||||
map ss :set sortby size; set info size
|
||||
map st :set sortby time; set info time
|
||||
map sa :set sortby atime; set info atime
|
||||
map sb :set sortby btime; set info btime
|
||||
map sc :set sortby ctime; set info ctime
|
||||
map se :set sortby ext; set info
|
||||
map gh cd ~
|
||||
@@ -310,19 +313,19 @@ Configuration files should be located at:
|
||||
|
||||
OS system-wide user-specific
|
||||
Unix /etc/lf/lfrc ~/.config/lf/lfrc
|
||||
Windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Local\lf\lfrc
|
||||
Windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Roaming\lf\lfrc
|
||||
|
||||
The colors file should be located at:
|
||||
|
||||
OS system-wide user-specific
|
||||
Unix /etc/lf/colors ~/.config/lf/colors
|
||||
Windows C:\ProgramData\lf\colors C:\Users\<user>\AppData\Local\lf\colors
|
||||
Windows C:\ProgramData\lf\colors C:\Users\<user>\AppData\Roaming\lf\colors
|
||||
|
||||
The icons file should be located at:
|
||||
|
||||
OS system-wide user-specific
|
||||
Unix /etc/lf/icons ~/.config/lf/icons
|
||||
Windows C:\ProgramData\lf\icons C:\Users\<user>\AppData\Local\lf\icons
|
||||
Windows C:\ProgramData\lf\icons C:\Users\<user>\AppData\Roaming\lf\icons
|
||||
|
||||
The selection file should be located at:
|
||||
|
||||
@@ -357,12 +360,11 @@ with their order of precedences and their default values:
|
||||
~/.local/share
|
||||
|
||||
Windows
|
||||
%ProgramData%
|
||||
C:\ProgramData
|
||||
|
||||
%LF_CONFIG_HOME%
|
||||
%APPDATA%
|
||||
|
||||
%LF_DATA_HOME%
|
||||
%LOCALAPPDATA%
|
||||
C:\Users\<user>\AppData\Local
|
||||
|
||||
A sample configuration file can be found at
|
||||
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example
|
||||
@@ -413,30 +415,6 @@ toggle
|
||||
|
||||
Toggle the selection of the current file or files given as arguments.
|
||||
|
||||
visual (default V)
|
||||
|
||||
Switch to Visual mode. If already in Visual mode, discard the visual
|
||||
selection and stay in Visual mode.
|
||||
|
||||
visual-accept (default V)
|
||||
|
||||
Add the visual selection to the selection list, quit Visual mode and
|
||||
return to Normal mode.
|
||||
|
||||
visual-unselect
|
||||
|
||||
Remove the visual selection from the selection list, quit Visual mode
|
||||
and return to Normal mode.
|
||||
|
||||
visual-discard (default <esc>)
|
||||
|
||||
Discard the visual selection, quit Visual mode and return to Normal
|
||||
mode.
|
||||
|
||||
visual-change (default o)
|
||||
|
||||
Go to the other end of the current Visual mode selection.
|
||||
|
||||
invert (default v)
|
||||
|
||||
Reverse the selection of all files in the current directory (i.e. toggle
|
||||
@@ -454,39 +432,26 @@ glob-select, glob-unselect
|
||||
|
||||
Select/unselect files that match the given glob.
|
||||
|
||||
calcdirsize
|
||||
|
||||
Calculate the total size for each of the selected directories. Option
|
||||
info should include size and option dircounts should be disabled to show
|
||||
this size. If the total size of a directory is not calculated, it will
|
||||
be shown as -.
|
||||
|
||||
clearmaps
|
||||
|
||||
Remove all keybindings associated with the map, nmap and vmap command.
|
||||
This command can be used in the config file to remove the default
|
||||
keybindings. For safety purposes, : is left mapped to the read command,
|
||||
and cmap keybindings are retained so that it is still possible to exit
|
||||
lf using :quit.
|
||||
|
||||
copy (default y)
|
||||
|
||||
If there are no selections, save the path of the current file to the
|
||||
copy buffer, otherwise, copy the paths of selected files.
|
||||
Save the paths of selected files to the clipboard as files to be copied.
|
||||
If there are no selected files, the path of the current file is used
|
||||
instead.
|
||||
|
||||
cut (default d)
|
||||
|
||||
If there are no selections, save the path of the current file to the cut
|
||||
buffer, otherwise, copy the paths of selected files.
|
||||
Save the paths of selected files to the clipboard as files to be moved.
|
||||
If there are no selected files, the path of the current file is used
|
||||
instead.
|
||||
|
||||
paste (default p)
|
||||
|
||||
Copy/Move files in the copy/cut buffer to the current working directory.
|
||||
A custom paste command can be defined to override this default.
|
||||
Copy/Move files in the clipboard to the current working directory. A
|
||||
custom paste command can be defined to override this default.
|
||||
|
||||
clear (default c)
|
||||
|
||||
Clear file paths in copy/cut buffer.
|
||||
Clear file paths in the clipboard.
|
||||
|
||||
sync
|
||||
|
||||
@@ -510,28 +475,6 @@ reload (default <c-r>)
|
||||
|
||||
Flush the cache and reload all files and directories.
|
||||
|
||||
echo
|
||||
|
||||
Print the given arguments to the message line at the bottom.
|
||||
|
||||
echomsg
|
||||
|
||||
Print the given arguments to the message line at the bottom and also to
|
||||
the log file.
|
||||
|
||||
echoerr
|
||||
|
||||
Print given arguments to the message line at the bottom as errorfmt and
|
||||
also to the log file.
|
||||
|
||||
cd
|
||||
|
||||
Change the working directory to the given argument.
|
||||
|
||||
select
|
||||
|
||||
Change the current file selection to the given argument.
|
||||
|
||||
delete (modal)
|
||||
|
||||
Remove the current file or selected file(s). A custom delete command can
|
||||
@@ -542,14 +485,6 @@ rename (modal) (default r)
|
||||
Rename the current file using the built-in method. A custom rename
|
||||
command can be defined to override this default.
|
||||
|
||||
source
|
||||
|
||||
Read the configuration file given in the argument.
|
||||
|
||||
push
|
||||
|
||||
Simulate key pushes given in the argument.
|
||||
|
||||
read (modal) (default :)
|
||||
|
||||
Read a command to evaluate.
|
||||
@@ -613,12 +548,57 @@ tag-toggle (default t)
|
||||
Tag a file with * or a single width character given in the argument if
|
||||
the file is untagged, otherwise remove the tag.
|
||||
|
||||
echo
|
||||
|
||||
Print the given arguments to the message line at the bottom.
|
||||
|
||||
echomsg
|
||||
|
||||
Print the given arguments to the message line at the bottom and also to
|
||||
the log file.
|
||||
|
||||
echoerr
|
||||
|
||||
Print given arguments to the message line at the bottom as errorfmt and
|
||||
also to the log file.
|
||||
|
||||
cd
|
||||
|
||||
Change the working directory to the given argument.
|
||||
|
||||
select
|
||||
|
||||
Change the current file selection to the given argument.
|
||||
|
||||
source
|
||||
|
||||
Read the configuration file given in the argument.
|
||||
|
||||
push
|
||||
|
||||
Simulate key pushes given in the argument.
|
||||
|
||||
addcustominfo
|
||||
|
||||
Update the custom info field of the given file with the given string.
|
||||
The info string may contain ANSI escape codes to further customize its
|
||||
appearance. If no info is provided, clear the file's info instead.
|
||||
|
||||
calcdirsize
|
||||
|
||||
Calculate the total size for each of the selected directories. Option
|
||||
info should include size and option dircounts should be disabled to show
|
||||
this size. If the total size of a directory is not calculated, it will
|
||||
be shown as -.
|
||||
|
||||
clearmaps
|
||||
|
||||
Remove all keybindings associated with the map, nmap and vmap command.
|
||||
This command can be used in the config file to remove the default
|
||||
keybindings. For safety purposes, : is left mapped to the read command,
|
||||
and cmap keybindings are retained so that it is still possible to exit
|
||||
lf using :quit.
|
||||
|
||||
tty-write
|
||||
|
||||
Write the given string to the tty. This is useful for sending escape
|
||||
@@ -627,7 +607,33 @@ window title). Using tty-write is preferred over directly writing to
|
||||
/dev/tty because the latter is not synchronized and can interfere with
|
||||
drawing the UI.
|
||||
|
||||
COMMAND LINE COMMANDS
|
||||
visual (default V)
|
||||
|
||||
Switch to Visual mode. If already in Visual mode, discard the visual
|
||||
selection and stay in Visual mode.
|
||||
|
||||
VISUAL MODE COMMANDS
|
||||
|
||||
visual-accept (default V)
|
||||
|
||||
Add the visual selection to the selection list, quit Visual mode and
|
||||
return to Normal mode.
|
||||
|
||||
visual-unselect
|
||||
|
||||
Remove the visual selection from the selection list, quit Visual mode
|
||||
and return to Normal mode.
|
||||
|
||||
visual-discard (default <esc>)
|
||||
|
||||
Discard the visual selection, quit Visual mode and return to Normal
|
||||
mode.
|
||||
|
||||
visual-change (default o)
|
||||
|
||||
Go to the other end of the current Visual mode selection.
|
||||
|
||||
COMMAND-LINE MODE COMMANDS
|
||||
|
||||
The prompt character specifies which of the several Command-line modes
|
||||
you are in. For example, the read command takes you to the : mode.
|
||||
@@ -641,6 +647,11 @@ keybindings. A character refers to a Unicode code point, a word consists
|
||||
of letters and digits, and a unix word consists of any non-blank
|
||||
characters.
|
||||
|
||||
cmd-insert
|
||||
|
||||
Insert the character given in the argument. This command is
|
||||
automatically called when required.
|
||||
|
||||
cmd-escape (default <esc>)
|
||||
|
||||
Quit Command-line mode and return to Normal mode.
|
||||
@@ -800,7 +811,9 @@ directory at most, and bigger directories are shown as 999+.
|
||||
|
||||
dirfirst (bool) (default true)
|
||||
|
||||
Show directories first above regular files.
|
||||
Show directories first above regular files. With dircounts enabled,
|
||||
sorting by size always separates directories and files, regardless of
|
||||
dirfirst.
|
||||
|
||||
dironly (bool) (default false)
|
||||
|
||||
@@ -837,23 +850,17 @@ filesep (string) (default \n)
|
||||
|
||||
File separator used in environment variables fs, fv and fx.
|
||||
|
||||
filtermethod (string) (default text)
|
||||
|
||||
How filter command patterns are treated. Currently supported methods are
|
||||
text (i.e. string literals), glob (i.e shell globs) and regex (i.e.
|
||||
regular expressions). See SEARCHING FILES for more details.
|
||||
|
||||
findlen (int) (default 1)
|
||||
|
||||
Number of characters prompted for the find command. When this value is
|
||||
set to 0, find command prompts until there is only a single match left.
|
||||
|
||||
globfilter (bool) (default false)
|
||||
|
||||
Patterns are treated as globs for the filter command, see globsearch for
|
||||
more details.
|
||||
|
||||
globsearch (bool) (default false)
|
||||
|
||||
When this option is enabled, search command patterns are considered as
|
||||
globs, otherwise, they are literals. With globbing, * matches any
|
||||
sequence, ? matches any character, and [...] or [^...] matches character
|
||||
sets or ranges. Otherwise, these characters are interpreted as they are.
|
||||
|
||||
hidden (bool) (default false)
|
||||
|
||||
Show hidden files. On Unix systems, hidden files are determined by the
|
||||
@@ -894,22 +901,22 @@ ignoredia (bool) (default true)
|
||||
|
||||
Ignore diacritics in sorting and search patterns.
|
||||
|
||||
incsearch (bool) (default false)
|
||||
|
||||
Jump to the first match after each keystroke during searching.
|
||||
|
||||
incfilter (bool) (default false)
|
||||
|
||||
Apply filter pattern after each keystroke during filtering.
|
||||
|
||||
incsearch (bool) (default false)
|
||||
|
||||
Jump to the first match after each keystroke during searching.
|
||||
|
||||
info ([]string) (default ``)
|
||||
|
||||
A list of information that is shown for directory items at the right
|
||||
side of the pane. Currently supported information types are size, time,
|
||||
atime, ctime, perm, user, group and custom. The custom type is empty by
|
||||
default and can be updated using the addcustominfo command. Information
|
||||
is only shown when the pane width is more than twice the width of
|
||||
information.
|
||||
atime, btime, ctime, perm, user, group and custom. The custom type is
|
||||
empty by default and can be updated using the addcustominfo command.
|
||||
Information is only shown when the pane width is more than twice the
|
||||
width of information.
|
||||
|
||||
infotimefmtnew (string) (default Jan _2 15:04)
|
||||
|
||||
@@ -956,7 +963,7 @@ disabled when the value of this option is set to zero.
|
||||
preserve ([]string) (default mode)
|
||||
|
||||
List of attributes that are preserved when copying files. Currently
|
||||
supported attributes are mode (i.a. access mode) and timestamps (i.e.
|
||||
supported attributes are mode (i.e. access mode) and timestamps (i.e.
|
||||
modification time and access time). Note that preserving other
|
||||
attributes like ownership of change/birth timestamp is desirable, but
|
||||
not portably supported in Go.
|
||||
@@ -1031,6 +1038,21 @@ for user-defined options, in the form %{lf_user_<name>} (e.g.
|
||||
Any section containing a failed expansion (result is a blank string) is
|
||||
discarded and not shown.
|
||||
|
||||
scrolloff (int) (default 0)
|
||||
|
||||
Minimum number of offset lines shown at all times at the top and bottom
|
||||
of the screen when scrolling. The current line is kept in the middle
|
||||
when this option is set to a large value that is bigger than the half of
|
||||
number of lines. A smaller offset can be used when the current file is
|
||||
close to the beginning or end of the list to show the maximum number of
|
||||
items.
|
||||
|
||||
searchmethod (string) default text)
|
||||
|
||||
How search command patterns are treated. Currently supported methods are
|
||||
text (i.e. string literals), glob (i.e shell globs) and regex (i.e.
|
||||
regular expressions). See SEARCHING FILES for more details.
|
||||
|
||||
selectfmt (string) (default \033[7;35m)
|
||||
|
||||
Format string of the indicator for files that are selected.
|
||||
@@ -1041,15 +1063,6 @@ Selection mode for commands. When set to all it will use the selected
|
||||
files from all directories. When set to dir it will only use the
|
||||
selected files in the current directory.
|
||||
|
||||
scrolloff (int) (default 0)
|
||||
|
||||
Minimum number of offset lines shown at all times at the top and bottom
|
||||
of the screen when scrolling. The current line is kept in the middle
|
||||
when this option is set to a large value that is bigger than the half of
|
||||
number of lines. A smaller offset can be used when the current file is
|
||||
close to the beginning or end of the list to show the maximum number of
|
||||
items.
|
||||
|
||||
shell (string) (default sh for Unix and cmd for Windows)
|
||||
|
||||
Shell executable to use for shell commands. Shell commands are executed
|
||||
@@ -1084,19 +1097,36 @@ diacritic. This option has no effect when ignoredia is disabled.
|
||||
sortby (string) (default natural)
|
||||
|
||||
Sort type for directories. Currently supported sort types are natural,
|
||||
name, size, time, ctime, atime, ext and custom.
|
||||
name, size, time, atime, btime, ctime, ext and custom.
|
||||
|
||||
Meaning of each sort type:
|
||||
|
||||
natural file name (track_2.flac comes before track_10.flac)
|
||||
name file name (track_10.flac comes before track_2.flac)
|
||||
size file size
|
||||
time time of last data modification
|
||||
atime time of last access
|
||||
btime time of file birth
|
||||
ctime time of last status (inode) change
|
||||
ext file extension
|
||||
custom property defined via `addcustominfo`
|
||||
|
||||
statfmt (string) (default \033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l)
|
||||
|
||||
Format string of the file info shown in the bottom left corner. Special
|
||||
expansions are provided, %p as the file permissions, %c as the link
|
||||
count, %u as the user, %g as the group, %s as the file size, %S as the
|
||||
file size but with a fixed width of four characters (left-padded with
|
||||
file size but with a fixed width of five characters (left-padded with
|
||||
spaces), %t as the last modified time, %l as the link target, %m as the
|
||||
current mode and %M as the current mode but also shown in Normal mode
|
||||
(displaying NORMAL instead of a blank string). The | character splits
|
||||
the format string into sections. Any section containing a failed
|
||||
expansion (result is a blank string) is discarded and not shown.
|
||||
(displaying NORMAL instead of a blank string).
|
||||
|
||||
The | character splits the format string into sections. Any section
|
||||
containing a failed expansion (result is a blank string) is discarded
|
||||
and not shown.
|
||||
|
||||
File size is formatted using first letter of IEC 80000-13:2025 prefixes
|
||||
for binary multiples (i.e. 1024 bytes is 1.0K).
|
||||
|
||||
tabstop (int) (default 8)
|
||||
|
||||
@@ -1256,6 +1286,10 @@ lf_user_{option}
|
||||
|
||||
Value of the user_{option}.
|
||||
|
||||
lf_flag_{flag}
|
||||
|
||||
Value of the command line {flag}.
|
||||
|
||||
lf_width, lf_height
|
||||
|
||||
Width/Height of the terminal.
|
||||
@@ -1379,7 +1413,7 @@ string:
|
||||
|
||||
Command setlocal is used to set a local option for a directory which can
|
||||
be a boolean or string. Currently supported local options are dircounts,
|
||||
dirfirst, dironly, hidden, info, reverse, sortby and locale. Adding a
|
||||
dirfirst, dironly, hidden, info, locale, reverse and sortby. Adding a
|
||||
trailing path separator (i.e. / for Unix and \ for Windows) sets the
|
||||
option for the given directory along with its subdirectories:
|
||||
|
||||
@@ -1421,9 +1455,9 @@ command or any other command:
|
||||
|
||||
You can delete an existing binding by leaving the expression empty:
|
||||
|
||||
map gh # deletes 'gh' mapping in normal and visual mode
|
||||
nmap v # deletes 'v' mapping in normal mode
|
||||
vmap o # deletes 'o' mapping in visual mode
|
||||
map gh # deletes 'gh' mapping in Normal and Visual mode
|
||||
nmap v # deletes 'v' mapping in Normal mode
|
||||
vmap o # deletes 'o' mapping in Visual mode
|
||||
cmap <c-g> # deletes '<c-g>' mapping
|
||||
|
||||
Command cmd is used to define a custom command:
|
||||
@@ -1801,9 +1835,11 @@ way to search for a pattern possibly using fewer keystrokes.
|
||||
|
||||
The searching mechanism is implemented with commands search (default /),
|
||||
search-back (default ?), search-next (default n), and search-prev
|
||||
(default N). You can enable globsearch option to match with a glob
|
||||
(default N). You can set searchmethod to glob to match using a glob
|
||||
pattern. Globbing supports * to match any sequence, ? to match any
|
||||
character, and [...] or [^...] to match character sets or ranges. You
|
||||
can set searchmethod to regex to match using a regex pattern. For a full
|
||||
overview of Go's RE2 syntax, see https://pkg.go.dev/regexp/syntax. You
|
||||
can enable incsearch option to jump to the current match at each
|
||||
keystroke while typing. In this mode, you can either use cmd-enter to
|
||||
accept the search or use cmd-escape to cancel the search. You can also
|
||||
|
||||
+5
-1
@@ -6,6 +6,10 @@
|
||||
# given to the go compiler to strip the binary. Current git tag is passed to
|
||||
# the compiler by default to be used as the version in the binary.
|
||||
|
||||
[ -z $version ] && version=$(git describe --tags)
|
||||
set -o errexit -o nounset
|
||||
|
||||
[ -z "${version:-}" ] && version=$(git describe --tags --abbrev=0)
|
||||
|
||||
CGO_ENABLED=0 go build -ldflags="-s -w -X main.gVersion=$version" "$@"
|
||||
|
||||
# vim: tabstop=4 shiftwidth=4 textwidth=80 colorcolumn=80
|
||||
@@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Generates `lf.1` and `doc.txt` from the `doc.md` file.
|
||||
#
|
||||
# This script is used to generate a man page and a plain text conversion of the
|
||||
# markdown documentation using pandoc (https://pandoc.org/). GitHub Flavored
|
||||
# Markdown (GFM) (https://github.github.com/gfm/) is used for the markdown
|
||||
# input format. The markdown file is automatically rendered in the GitHub
|
||||
# repository (https://github.com/gokcehan/lf/blob/master/doc.md). The man page
|
||||
# file `lf.1` is meant to be used for installations on Unix systems. The plain
|
||||
# text file `doc.txt` is embedded in the binary to be displayed on request with
|
||||
# the `-doc` command line flag. Thus the same documentation is used for online
|
||||
# and terminal display.
|
||||
|
||||
[ -z $version ] && version=$(git describe --tags)
|
||||
[ -z $date ] && date=$(date +%F)
|
||||
|
||||
PANDOC_IMAGE=pandoc/minimal:3.7
|
||||
|
||||
docker run --rm -v "$PWD:/data" --user "$(id -u):$(id -g)" $PANDOC_IMAGE \
|
||||
--standalone \
|
||||
--from gfm --to man \
|
||||
--metadata=title:"LF" \
|
||||
--metadata=section:"1" \
|
||||
--metadata=date:"$date" \
|
||||
--metadata=footer:"$version" \
|
||||
--metadata=header:"DOCUMENTATION" \
|
||||
doc.md -o lf.1
|
||||
|
||||
docker run --rm -v "$PWD:/data" --user "$(id -u):$(id -g)" $PANDOC_IMAGE \
|
||||
--standalone \
|
||||
--from gfm --to plain \
|
||||
doc.md -o doc.txt
|
||||
+65
-15
@@ -11,20 +11,70 @@
|
||||
# the `-doc` command line flag. Thus the same documentation is used for online
|
||||
# and terminal display.
|
||||
|
||||
[ -z $version ] && version=$(git describe --tags)
|
||||
[ -z $date ] && date=$(date +%F)
|
||||
set -o errexit -o nounset
|
||||
|
||||
pandoc \
|
||||
--standalone \
|
||||
--from gfm --to man \
|
||||
--metadata=title:"LF" \
|
||||
--metadata=section:"1" \
|
||||
--metadata=date:"$date" \
|
||||
--metadata=footer:"$version" \
|
||||
--metadata=header:"DOCUMENTATION" \
|
||||
doc.md -o lf.1
|
||||
get_version() {
|
||||
printf "r%s" $(($(git describe --tags --abbrev=0 | tr -d r) + 1))
|
||||
}
|
||||
|
||||
pandoc \
|
||||
--standalone \
|
||||
--from gfm --to plain \
|
||||
doc.md -o doc.txt
|
||||
[ -z "${version:-}" ] && version=$(get_version)
|
||||
[ -z "${date:-}" ] && date=$(date +%F)
|
||||
|
||||
PANDOC_IMAGE=pandoc/minimal:3.7
|
||||
|
||||
generate_man_page() {
|
||||
"${OCI_PROGRAM?}" run \
|
||||
--rm \
|
||||
--volume "$PWD:/data" \
|
||||
"$@" "$PANDOC_IMAGE" \
|
||||
--standalone \
|
||||
--from gfm --to man \
|
||||
--metadata=title:"LF" \
|
||||
--metadata=section:"1" \
|
||||
--metadata=date:"$date" \
|
||||
--metadata=footer:"$version" \
|
||||
--metadata=header:"DOCUMENTATION" \
|
||||
doc.md -o lf.1
|
||||
}
|
||||
|
||||
generate_plain_text() {
|
||||
"${OCI_PROGRAM?}" run \
|
||||
--rm \
|
||||
--volume "$PWD:/data" \
|
||||
"$@" "$PANDOC_IMAGE" \
|
||||
--standalone \
|
||||
--from gfm --to plain \
|
||||
doc.md -o doc.txt
|
||||
}
|
||||
|
||||
is_rootless() {
|
||||
case "$OCI_PROGRAM" in
|
||||
podman) podman info -f '{{.Host.Security.Rootless}}' | grep -q true ;;
|
||||
docker) docker info -f '{{.SecurityOptions}}' | grep -q rootless ;;
|
||||
*) echo >&2 \
|
||||
"Unknown OCI program \"$OCI_PROGRAM\", assuming rootless mode" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# You can set your own OCI_PROGRAM, which assumes it runs in rootless mode.
|
||||
if [ -z "${OCI_PROGRAM:-}" ]; then
|
||||
if command -v podman > /dev/null; then
|
||||
OCI_PROGRAM=podman
|
||||
elif command -v docker > /dev/null; then
|
||||
OCI_PROGRAM=docker
|
||||
fi
|
||||
fi
|
||||
|
||||
if is_rootless; then
|
||||
generate_man_page
|
||||
else
|
||||
generate_man_page --user "$(id -u):$(id -g)"
|
||||
fi
|
||||
|
||||
if is_rootless; then
|
||||
generate_plain_text
|
||||
else
|
||||
generate_plain_text --user "$(id -u):$(id -g)"
|
||||
fi
|
||||
|
||||
# vim: tabstop=4 shiftwidth=4 textwidth=80 colorcolumn=80
|
||||
+3
-1
@@ -8,7 +8,7 @@
|
||||
# compressed in an archive form (`.zip` for windows and `.tar.gz` for the rest)
|
||||
# within a folder named `dist`.
|
||||
|
||||
[ -z "$version" ] && version=$(git describe --tags)
|
||||
[ -z "${version:-}" ] && version=$(git describe --tags --abbrev=0)
|
||||
|
||||
test -d dist && {
|
||||
echo "gen/xbuild.sh: WARNING: removing preexisting subdir 'dist'"
|
||||
@@ -90,3 +90,5 @@ if test -n "$ERRORS"; then
|
||||
printf "\ngen/xbuild.sh: some targets failed to compile.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# vim: tabstop=4 shiftwidth=4 textwidth=80 colorcolumn=80
|
||||
@@ -8,9 +8,9 @@ require (
|
||||
github.com/fsnotify/fsnotify v1.9.0
|
||||
github.com/gdamore/tcell/v2 v2.8.1
|
||||
github.com/mattn/go-runewidth v0.0.16
|
||||
golang.org/x/sys v0.33.0
|
||||
golang.org/x/term v0.32.0
|
||||
golang.org/x/text v0.26.0
|
||||
golang.org/x/sys v0.35.0
|
||||
golang.org/x/term v0.34.0
|
||||
golang.org/x/text v0.28.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@@ -55,8 +55,8 @@ golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
@@ -66,8 +66,8 @@ golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
|
||||
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
|
||||
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
|
||||
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
|
||||
golang.org/x/term v0.34.0 h1:O/2T7POpk0ZZ7MAzMeWFSg6S5IpWd/RXDlM9hgM3DR4=
|
||||
golang.org/x/term v0.34.0/go.mod h1:5jC53AEywhIVebHgPVeg0mj8OD3VO9OzclacVrqpaAw=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
@@ -77,8 +77,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
|
||||
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.\" Automatically generated by Pandoc 3.7.0.2
|
||||
.\"
|
||||
.TH "LF" "1" "2025\-07\-18" "" "DOCUMENTATION"
|
||||
.TH "LF" "1" "2025\-08\-25" "r37" "DOCUMENTATION"
|
||||
.SH NAME
|
||||
lf \- terminal file manager
|
||||
.SH SYNOPSIS
|
||||
@@ -56,13 +56,10 @@ high (default \(aqH\(aq)
|
||||
middle (default \(aqM\(aq)
|
||||
low (default \(aqL\(aq)
|
||||
toggle
|
||||
visual (default \(aqV\(aq)
|
||||
invert (default \(aqv\(aq)
|
||||
unselect (default \(aqu\(aq)
|
||||
glob\-select
|
||||
glob\-unselect
|
||||
calcdirsize
|
||||
clearmaps
|
||||
copy (default \(aqy\(aq)
|
||||
cut (default \(aqd\(aq)
|
||||
paste (default \(aqp\(aq)
|
||||
@@ -72,15 +69,8 @@ draw
|
||||
redraw (default \(aq<c\-l>\(aq)
|
||||
load
|
||||
reload (default \(aq<c\-r>\(aq)
|
||||
echo
|
||||
echomsg
|
||||
echoerr
|
||||
cd
|
||||
select
|
||||
delete (modal)
|
||||
rename (modal) (default \(aqr\(aq)
|
||||
source
|
||||
push
|
||||
read (modal) (default \(aq:\(aq)
|
||||
shell (modal) (default \(aq$\(aq)
|
||||
shell\-pipe (modal) (default \(aq%\(aq)
|
||||
@@ -101,8 +91,18 @@ mark\-load (modal) (default \(dq\(aq\(dq)
|
||||
mark\-remove (modal) (default \(aq\(dq\(aq)
|
||||
tag
|
||||
tag\-toggle (default \(aqt\(aq)
|
||||
echo
|
||||
echomsg
|
||||
echoerr
|
||||
cd
|
||||
select
|
||||
source
|
||||
push
|
||||
addcustominfo
|
||||
calcdirsize
|
||||
clearmaps
|
||||
tty\-write
|
||||
visual (default \(aqV\(aq)
|
||||
.EE
|
||||
.PP
|
||||
The following Visual mode commands are provided by lf:
|
||||
@@ -117,6 +117,7 @@ visual\-change (default \(aqo\(aq)
|
||||
The following Command\-line mode commands are provided by lf:
|
||||
.IP
|
||||
.EX
|
||||
cmd\-insert
|
||||
cmd\-escape (default \(aq<esc>\(aq)
|
||||
cmd\-complete (default \(aq<tab>\(aq)
|
||||
cmd\-menu\-complete
|
||||
@@ -168,9 +169,8 @@ drawbox bool (default false)
|
||||
dupfilefmt string (default \(aq%f.\(ti%n\(ti\(aq)
|
||||
errorfmt string (default \(dq\(rs033[7;31;47m\(dq)
|
||||
filesep string (default \(dq\(rsn\(dq)
|
||||
filtermethod string (default \(aqtext\(aq)
|
||||
findlen int (default 1)
|
||||
globfilter bool (default false)
|
||||
globsearch bool (default false)
|
||||
hidden bool (default false)
|
||||
hiddenfiles []string (default \(aq.*\(aq for Unix and \(aq\(aq for Windows)
|
||||
history bool (default true)
|
||||
@@ -198,6 +198,7 @@ reverse bool (default false)
|
||||
roundbox bool (default false)
|
||||
rulerfmt string (default \(dq %a| %p| \(rs033[7;31m %m \(rs033[0m| \(rs033[7;33m %c \(rs033[0m| \(rs033[7;35m %s \(rs033[0m| \(rs033[7;34m %f \(rs033[0m| %i/%t\(dq)
|
||||
scrolloff int (default 0)
|
||||
searchmethod string (default \(aqtext\(aq)
|
||||
selectfmt string (default \(dq\(rs033[7;35m\(dq)
|
||||
selmode string (default \(aqall\(aq)
|
||||
shell string (default \(aqsh\(aq for Unix and \(aqcmd\(aq for Windows)
|
||||
@@ -242,6 +243,7 @@ SHELL
|
||||
lf
|
||||
lf_{option}
|
||||
lf_user_{option}
|
||||
lf_flag_{flag}
|
||||
lf_width
|
||||
lf_height
|
||||
lf_count
|
||||
@@ -310,6 +312,7 @@ map sn :set sortby natural; set info
|
||||
map ss :set sortby size; set info size
|
||||
map st :set sortby time; set info time
|
||||
map sa :set sortby atime; set info atime
|
||||
map sb :set sortby btime; set info btime
|
||||
map sc :set sortby ctime; set info ctime
|
||||
map se :set sortby ext; set info
|
||||
map gh cd \(ti
|
||||
@@ -335,7 +338,7 @@ Configuration files should be located at:
|
||||
.EX
|
||||
OS system\-wide user\-specific
|
||||
Unix /etc/lf/lfrc \(ti/.config/lf/lfrc
|
||||
Windows C:\(rsProgramData\(rslf\(rslfrc C:\(rsUsers\(rs<user>\(rsAppData\(rsLocal\(rslf\(rslfrc
|
||||
Windows C:\(rsProgramData\(rslf\(rslfrc C:\(rsUsers\(rs<user>\(rsAppData\(rsRoaming\(rslf\(rslfrc
|
||||
.EE
|
||||
.PP
|
||||
The colors file should be located at:
|
||||
@@ -343,7 +346,7 @@ The colors file should be located at:
|
||||
.EX
|
||||
OS system\-wide user\-specific
|
||||
Unix /etc/lf/colors \(ti/.config/lf/colors
|
||||
Windows C:\(rsProgramData\(rslf\(rscolors C:\(rsUsers\(rs<user>\(rsAppData\(rsLocal\(rslf\(rscolors
|
||||
Windows C:\(rsProgramData\(rslf\(rscolors C:\(rsUsers\(rs<user>\(rsAppData\(rsRoaming\(rslf\(rscolors
|
||||
.EE
|
||||
.PP
|
||||
The icons file should be located at:
|
||||
@@ -351,7 +354,7 @@ The icons file should be located at:
|
||||
.EX
|
||||
OS system\-wide user\-specific
|
||||
Unix /etc/lf/icons \(ti/.config/lf/icons
|
||||
Windows C:\(rsProgramData\(rslf\(rsicons C:\(rsUsers\(rs<user>\(rsAppData\(rsLocal\(rslf\(rsicons
|
||||
Windows C:\(rsProgramData\(rslf\(rsicons C:\(rsUsers\(rs<user>\(rsAppData\(rsRoaming\(rslf\(rsicons
|
||||
.EE
|
||||
.PP
|
||||
The selection file should be located at:
|
||||
@@ -396,12 +399,11 @@ Unix
|
||||
\(ti/.local/share
|
||||
|
||||
Windows
|
||||
%ProgramData%
|
||||
C:\(rsProgramData
|
||||
|
||||
%LF_CONFIG_HOME%
|
||||
%APPDATA%
|
||||
|
||||
%LF_DATA_HOME%
|
||||
%LOCALAPPDATA%
|
||||
C:\(rsUsers\(rs<user>\(rsAppData\(rsLocal
|
||||
.EE
|
||||
.PP
|
||||
A sample configuration file can be found at \c
|
||||
@@ -436,21 +438,6 @@ A count can be specified to move to a specific line, for example, use
|
||||
Move the current file selection to the high/middle/low of the screen.
|
||||
.SS toggle
|
||||
Toggle the selection of the current file or files given as arguments.
|
||||
.SS visual (default \f[CR]V\f[R])
|
||||
Switch to Visual mode.
|
||||
If already in Visual mode, discard the visual selection and stay in
|
||||
Visual mode.
|
||||
.SS visual\-accept (default \f[CR]V\f[R])
|
||||
Add the visual selection to the selection list, quit Visual mode and
|
||||
return to Normal mode.
|
||||
.SS visual\-unselect
|
||||
Remove the visual selection from the selection list, quit Visual mode
|
||||
and return to Normal mode.
|
||||
.SS visual\-discard (default \f[CR]<esc>\f[R])
|
||||
Discard the visual selection, quit Visual mode and return to Normal
|
||||
mode.
|
||||
.SS visual\-change (default \f[CR]o\f[R])
|
||||
Go to the other end of the current Visual mode selection.
|
||||
.SS invert (default \f[CR]v\f[R])
|
||||
Reverse the selection of all files in the current directory (i.e.
|
||||
\f[CR]toggle\f[R] all files).
|
||||
@@ -463,32 +450,20 @@ remove selections in other directories.
|
||||
Remove the selection of all files in all directories.
|
||||
.SS glob\-select, glob\-unselect
|
||||
Select/unselect files that match the given glob.
|
||||
.SS calcdirsize
|
||||
Calculate the total size for each of the selected directories.
|
||||
Option \f[CR]info\f[R] should include \f[CR]size\f[R] and option
|
||||
\f[CR]dircounts\f[R] should be disabled to show this size.
|
||||
If the total size of a directory is not calculated, it will be shown as
|
||||
\f[CR]\-\f[R].
|
||||
.SS clearmaps
|
||||
Remove all keybindings associated with the \f[CR]map\f[R],
|
||||
\f[CR]nmap\f[R] and \f[CR]vmap\f[R] command.
|
||||
This command can be used in the config file to remove the default
|
||||
keybindings.
|
||||
For safety purposes, \f[CR]:\f[R] is left mapped to the \f[CR]read\f[R]
|
||||
command, and \f[CR]cmap\f[R] keybindings are retained so that it is
|
||||
still possible to exit \f[CR]lf\f[R] using \f[CR]:quit\f[R].
|
||||
.SS copy (default \f[CR]y\f[R])
|
||||
If there are no selections, save the path of the current file to the
|
||||
copy buffer, otherwise, copy the paths of selected files.
|
||||
Save the paths of selected files to the clipboard as files to be copied.
|
||||
If there are no selected files, the path of the current file is used
|
||||
instead.
|
||||
.SS cut (default \f[CR]d\f[R])
|
||||
If there are no selections, save the path of the current file to the cut
|
||||
buffer, otherwise, copy the paths of selected files.
|
||||
Save the paths of selected files to the clipboard as files to be moved.
|
||||
If there are no selected files, the path of the current file is used
|
||||
instead.
|
||||
.SS paste (default \f[CR]p\f[R])
|
||||
Copy/Move files in the copy/cut buffer to the current working directory.
|
||||
Copy/Move files in the clipboard to the current working directory.
|
||||
A custom \f[CR]paste\f[R] command can be defined to override this
|
||||
default.
|
||||
.SS clear (default \f[CR]c\f[R])
|
||||
Clear file paths in copy/cut buffer.
|
||||
Clear file paths in the clipboard.
|
||||
.SS sync
|
||||
Synchronize copied/cut files with the server.
|
||||
This command is automatically called when required.
|
||||
@@ -502,18 +477,6 @@ Load modified files and directories.
|
||||
This command is automatically called when required.
|
||||
.SS reload (default \f[CR]<c\-r>\f[R])
|
||||
Flush the cache and reload all files and directories.
|
||||
.SS echo
|
||||
Print the given arguments to the message line at the bottom.
|
||||
.SS echomsg
|
||||
Print the given arguments to the message line at the bottom and also to
|
||||
the log file.
|
||||
.SS echoerr
|
||||
Print given arguments to the message line at the bottom as
|
||||
\f[CR]errorfmt\f[R] and also to the log file.
|
||||
.SS cd
|
||||
Change the working directory to the given argument.
|
||||
.SS select
|
||||
Change the current file selection to the given argument.
|
||||
.SS delete (modal)
|
||||
Remove the current file or selected file(s).
|
||||
A custom \f[CR]delete\f[R] command can be defined to override this
|
||||
@@ -522,10 +485,6 @@ default.
|
||||
Rename the current file using the built\-in method.
|
||||
A custom \f[CR]rename\f[R] command can be defined to override this
|
||||
default.
|
||||
.SS source
|
||||
Read the configuration file given in the argument.
|
||||
.SS push
|
||||
Simulate key pushes given in the argument.
|
||||
.SS read (modal) (default \f[CR]:\f[R])
|
||||
Read a command to evaluate.
|
||||
.SS shell (modal) (default \f[CR]$\f[R])
|
||||
@@ -567,12 +526,42 @@ with \f[CR]tag\-toggle\f[R] (i.e.
|
||||
.SS tag\-toggle (default \f[CR]t\f[R])
|
||||
Tag a file with \f[CR]*\f[R] or a single width character given in the
|
||||
argument if the file is untagged, otherwise remove the tag.
|
||||
.SS echo
|
||||
Print the given arguments to the message line at the bottom.
|
||||
.SS echomsg
|
||||
Print the given arguments to the message line at the bottom and also to
|
||||
the log file.
|
||||
.SS echoerr
|
||||
Print given arguments to the message line at the bottom as
|
||||
\f[CR]errorfmt\f[R] and also to the log file.
|
||||
.SS cd
|
||||
Change the working directory to the given argument.
|
||||
.SS select
|
||||
Change the current file selection to the given argument.
|
||||
.SS source
|
||||
Read the configuration file given in the argument.
|
||||
.SS push
|
||||
Simulate key pushes given in the argument.
|
||||
.SS addcustominfo
|
||||
Update the \f[CR]custom\f[R] info field of the given file with the given
|
||||
string.
|
||||
The info string may contain ANSI escape codes to further customize its
|
||||
appearance.
|
||||
If no info is provided, clear the file\(aqs info instead.
|
||||
.SS calcdirsize
|
||||
Calculate the total size for each of the selected directories.
|
||||
Option \f[CR]info\f[R] should include \f[CR]size\f[R] and option
|
||||
\f[CR]dircounts\f[R] should be disabled to show this size.
|
||||
If the total size of a directory is not calculated, it will be shown as
|
||||
\f[CR]\-\f[R].
|
||||
.SS clearmaps
|
||||
Remove all keybindings associated with the \f[CR]map\f[R],
|
||||
\f[CR]nmap\f[R] and \f[CR]vmap\f[R] command.
|
||||
This command can be used in the config file to remove the default
|
||||
keybindings.
|
||||
For safety purposes, \f[CR]:\f[R] is left mapped to the \f[CR]read\f[R]
|
||||
command, and \f[CR]cmap\f[R] keybindings are retained so that it is
|
||||
still possible to exit \f[CR]lf\f[R] using \f[CR]:quit\f[R].
|
||||
.SS tty\-write
|
||||
Write the given string to the tty.
|
||||
This is useful for sending escape sequences to the terminal to control
|
||||
@@ -581,7 +570,23 @@ OSC 0 to set the window title).
|
||||
Using \f[CR]tty\-write\f[R] is preferred over directly writing to
|
||||
\f[CR]/dev/tty\f[R] because the latter is not synchronized and can
|
||||
interfere with drawing the UI.
|
||||
.SH COMMAND LINE COMMANDS
|
||||
.SS visual (default \f[CR]V\f[R])
|
||||
Switch to Visual mode.
|
||||
If already in Visual mode, discard the visual selection and stay in
|
||||
Visual mode.
|
||||
.SH VISUAL MODE COMMANDS
|
||||
.SS visual\-accept (default \f[CR]V\f[R])
|
||||
Add the visual selection to the selection list, quit Visual mode and
|
||||
return to Normal mode.
|
||||
.SS visual\-unselect
|
||||
Remove the visual selection from the selection list, quit Visual mode
|
||||
and return to Normal mode.
|
||||
.SS visual\-discard (default \f[CR]<esc>\f[R])
|
||||
Discard the visual selection, quit Visual mode and return to Normal
|
||||
mode.
|
||||
.SS visual\-change (default \f[CR]o\f[R])
|
||||
Go to the other end of the current Visual mode selection.
|
||||
.SH COMMAND\-LINE MODE COMMANDS
|
||||
The prompt character specifies which of the several Command\-line modes
|
||||
you are in.
|
||||
For example, the \f[CR]read\f[R] command takes you to the \f[CR]:\f[R]
|
||||
@@ -597,6 +602,9 @@ The command line commands should be mostly compatible with readline
|
||||
keybindings.
|
||||
A character refers to a Unicode code point, a word consists of letters
|
||||
and digits, and a unix word consists of any non\-blank characters.
|
||||
.SS cmd\-insert
|
||||
Insert the character given in the argument.
|
||||
This command is automatically called when required.
|
||||
.SS cmd\-escape (default \f[CR]<esc>\f[R])
|
||||
Quit Command\-line mode and return to Normal mode.
|
||||
.SS cmd\-complete (default \f[CR]<tab>\f[R])
|
||||
@@ -707,6 +715,8 @@ information.
|
||||
shown as \f[CR]999+\f[R].
|
||||
.SS dirfirst (bool) (default true)
|
||||
Show directories first above regular files.
|
||||
With \f[CR]dircounts\f[R] enabled, sorting by \f[CR]size\f[R] always
|
||||
separates directories and files, regardless of \f[CR]dirfirst\f[R].
|
||||
.SS dironly (bool) (default false)
|
||||
Show only directories.
|
||||
.SS dirpreviews (bool) (default false)
|
||||
@@ -734,20 +744,17 @@ For example, \f[CR]\(rs033[4m%s\(rs033[0m\f[R] has the same effect as
|
||||
.SS filesep (string) (default \f[CR]\(rsn\f[R])
|
||||
File separator used in environment variables \f[CR]fs\f[R],
|
||||
\f[CR]fv\f[R] and \f[CR]fx\f[R].
|
||||
.SS filtermethod (string) (default \f[CR]text\f[R])
|
||||
How filter command patterns are treated.
|
||||
Currently supported methods are \f[CR]text\f[R] (i.e.
|
||||
string literals), \f[CR]glob\f[R] (i.e shell globs) and \f[CR]regex\f[R]
|
||||
(i.e.
|
||||
regular expressions).
|
||||
See \f[CR]SEARCHING FILES\f[R] for more details.
|
||||
.SS findlen (int) (default 1)
|
||||
Number of characters prompted for the find command.
|
||||
When this value is set to 0, find command prompts until there is only a
|
||||
single match left.
|
||||
.SS globfilter (bool) (default false)
|
||||
Patterns are treated as globs for the filter command, see
|
||||
\f[CR]globsearch\f[R] for more details.
|
||||
.SS globsearch (bool) (default false)
|
||||
When this option is enabled, search command patterns are considered as
|
||||
globs, otherwise, they are literals.
|
||||
With globbing, \f[CR]*\f[R] matches any sequence, \f[CR]?\f[R] matches
|
||||
any character, and \f[CR][...]\f[R] or \f[CR][\(ha...]\f[R] matches
|
||||
character sets or ranges.
|
||||
Otherwise, these characters are interpreted as they are.
|
||||
.SS hidden (bool) (default false)
|
||||
Show hidden files.
|
||||
On Unix systems, hidden files are determined by the value of
|
||||
@@ -782,16 +789,17 @@ This option does not have any effect on Windows.
|
||||
Ignore case in sorting and search patterns.
|
||||
.SS ignoredia (bool) (default true)
|
||||
Ignore diacritics in sorting and search patterns.
|
||||
.SS incsearch (bool) (default false)
|
||||
Jump to the first match after each keystroke during searching.
|
||||
.SS incfilter (bool) (default false)
|
||||
Apply filter pattern after each keystroke during filtering.
|
||||
.SS incsearch (bool) (default false)
|
||||
Jump to the first match after each keystroke during searching.
|
||||
.SS info ([]string) (default \(ga\(ga)
|
||||
A list of information that is shown for directory items at the right
|
||||
side of the pane.
|
||||
Currently supported information types are \f[CR]size\f[R],
|
||||
\f[CR]time\f[R], \f[CR]atime\f[R], \f[CR]ctime\f[R], \f[CR]perm\f[R],
|
||||
\f[CR]user\f[R], \f[CR]group\f[R] and \f[CR]custom\f[R].
|
||||
\f[CR]time\f[R], \f[CR]atime\f[R], \f[CR]btime\f[R], \f[CR]ctime\f[R],
|
||||
\f[CR]perm\f[R], \f[CR]user\f[R], \f[CR]group\f[R] and
|
||||
\f[CR]custom\f[R].
|
||||
The \f[CR]custom\f[R] type is empty by default and can be updated using
|
||||
the \f[CR]addcustominfo\f[R] command.
|
||||
Information is only shown when the pane width is more than twice the
|
||||
@@ -830,7 +838,7 @@ Periodic checks are disabled when the value of this option is set to
|
||||
zero.
|
||||
.SS preserve ([]string) (default \f[CR]mode\f[R])
|
||||
List of attributes that are preserved when copying files.
|
||||
Currently supported attributes are \f[CR]mode\f[R] (i.a.
|
||||
Currently supported attributes are \f[CR]mode\f[R] (i.e.
|
||||
access mode) and \f[CR]timestamps\f[R] (i.e.
|
||||
modification time and access time).
|
||||
Note that preserving other attributes like ownership of change/birth
|
||||
@@ -904,6 +912,20 @@ Expansions are also provided for user\-defined options, in the form
|
||||
The \f[CR]|\f[R] character splits the format string into sections.
|
||||
Any section containing a failed expansion (result is a blank string) is
|
||||
discarded and not shown.
|
||||
.SS scrolloff (int) (default 0)
|
||||
Minimum number of offset lines shown at all times at the top and bottom
|
||||
of the screen when scrolling.
|
||||
The current line is kept in the middle when this option is set to a
|
||||
large value that is bigger than the half of number of lines.
|
||||
A smaller offset can be used when the current file is close to the
|
||||
beginning or end of the list to show the maximum number of items.
|
||||
.SS searchmethod (string) default \f[CR]text\f[R])
|
||||
How search command patterns are treated.
|
||||
Currently supported methods are \f[CR]text\f[R] (i.e.
|
||||
string literals), \f[CR]glob\f[R] (i.e shell globs) and \f[CR]regex\f[R]
|
||||
(i.e.
|
||||
regular expressions).
|
||||
See \f[CR]SEARCHING FILES\f[R] for more details.
|
||||
.SS selectfmt (string) (default \f[CR]\(rs033[7;35m\f[R])
|
||||
Format string of the indicator for files that are selected.
|
||||
.SS selmode (string) (default \f[CR]all\f[R])
|
||||
@@ -912,13 +934,6 @@ When set to \f[CR]all\f[R] it will use the selected files from all
|
||||
directories.
|
||||
When set to \f[CR]dir\f[R] it will only use the selected files in the
|
||||
current directory.
|
||||
.SS scrolloff (int) (default 0)
|
||||
Minimum number of offset lines shown at all times at the top and bottom
|
||||
of the screen when scrolling.
|
||||
The current line is kept in the middle when this option is set to a
|
||||
large value that is bigger than the half of number of lines.
|
||||
A smaller offset can be used when the current file is close to the
|
||||
beginning or end of the list to show the maximum number of items.
|
||||
.SS shell (string) (default \f[CR]sh\f[R] for Unix and \f[CR]cmd\f[R] for Windows)
|
||||
Shell executable to use for shell commands.
|
||||
Shell commands are executed as
|
||||
@@ -942,21 +957,40 @@ This option has no effect when \f[CR]ignoredia\f[R] is disabled.
|
||||
.SS sortby (string) (default \f[CR]natural\f[R])
|
||||
Sort type for directories.
|
||||
Currently supported sort types are \f[CR]natural\f[R], \f[CR]name\f[R],
|
||||
\f[CR]size\f[R], \f[CR]time\f[R], \f[CR]ctime\f[R], \f[CR]atime\f[R],
|
||||
\f[CR]ext\f[R] and \f[CR]custom\f[R].
|
||||
\f[CR]size\f[R], \f[CR]time\f[R], \f[CR]atime\f[R], \f[CR]btime\f[R],
|
||||
\f[CR]ctime\f[R], \f[CR]ext\f[R] and \f[CR]custom\f[R].
|
||||
.PP
|
||||
Meaning of each sort type:
|
||||
.IP
|
||||
.EX
|
||||
natural file name (track_2.flac comes before track_10.flac)
|
||||
name file name (track_10.flac comes before track_2.flac)
|
||||
size file size
|
||||
time time of last data modification
|
||||
atime time of last access
|
||||
btime time of file birth
|
||||
ctime time of last status (inode) change
|
||||
ext file extension
|
||||
custom property defined via \(gaaddcustominfo\(ga
|
||||
.EE
|
||||
.SS statfmt (string) (default \f[CR]\(rs033[36m%p\(rs033[0m| %c| %u| %g| %S| %t| \-> %l\f[R])
|
||||
Format string of the file info shown in the bottom left corner.
|
||||
Special expansions are provided, \f[CR]%p\f[R] as the file permissions,
|
||||
\f[CR]%c\f[R] as the link count, \f[CR]%u\f[R] as the user,
|
||||
\f[CR]%g\f[R] as the group, \f[CR]%s\f[R] as the file size,
|
||||
\f[CR]%S\f[R] as the file size but with a fixed width of four characters
|
||||
\f[CR]%S\f[R] as the file size but with a fixed width of five characters
|
||||
(left\-padded with spaces), \f[CR]%t\f[R] as the last modified time,
|
||||
\f[CR]%l\f[R] as the link target, \f[CR]%m\f[R] as the current mode and
|
||||
\f[CR]%M\f[R] as the current mode but also shown in Normal mode
|
||||
(displaying \f[CR]NORMAL\f[R] instead of a blank string).
|
||||
.PP
|
||||
The \f[CR]|\f[R] character splits the format string into sections.
|
||||
Any section containing a failed expansion (result is a blank string) is
|
||||
discarded and not shown.
|
||||
.PP
|
||||
File size is formatted using first letter of IEC 80000\-13:2025 prefixes
|
||||
for binary multiples (i.e.
|
||||
1024 bytes is \f[CR]1.0K\f[R]).
|
||||
.SS tabstop (int) (default 8)
|
||||
Number of space characters to show for horizontal tabulation (U+0009)
|
||||
character.
|
||||
@@ -1077,6 +1111,8 @@ Otherwise, this is set to the string \f[CR]lf\f[R].
|
||||
Value of the {option}.
|
||||
.SS lf_user_{option}
|
||||
Value of the user_{option}.
|
||||
.SS lf_flag_{flag}
|
||||
Value of the command line {flag}.
|
||||
.SS lf_width, lf_height
|
||||
Width/Height of the terminal.
|
||||
.SS lf_count
|
||||
@@ -1179,8 +1215,8 @@ Command \f[CR]setlocal\f[R] is used to set a local option for a
|
||||
directory which can be a boolean or string.
|
||||
Currently supported local options are \f[CR]dircounts\f[R],
|
||||
\f[CR]dirfirst\f[R], \f[CR]dironly\f[R], \f[CR]hidden\f[R],
|
||||
\f[CR]info\f[R], \f[CR]reverse\f[R], \f[CR]sortby\f[R] and
|
||||
\f[CR]locale\f[R].
|
||||
\f[CR]info\f[R], \f[CR]locale\f[R], \f[CR]reverse\f[R] and
|
||||
\f[CR]sortby\f[R].
|
||||
Adding a trailing path separator (i.e.
|
||||
\f[CR]/\f[R] for Unix and \f[CR]\(rs\f[R] for Windows) sets the option
|
||||
for the given directory along with its subdirectories:
|
||||
@@ -1233,9 +1269,9 @@ cmap <a\-i> set incsearch!
|
||||
You can delete an existing binding by leaving the expression empty:
|
||||
.IP
|
||||
.EX
|
||||
map gh # deletes \(aqgh\(aq mapping in normal and visual mode
|
||||
nmap v # deletes \(aqv\(aq mapping in normal mode
|
||||
vmap o # deletes \(aqo\(aq mapping in visual mode
|
||||
map gh # deletes \(aqgh\(aq mapping in Normal and Visual mode
|
||||
nmap v # deletes \(aqv\(aq mapping in Normal mode
|
||||
vmap o # deletes \(aqo\(aq mapping in Visual mode
|
||||
cmap <c\-g> # deletes \(aq<c\-g>\(aq mapping
|
||||
.EE
|
||||
.PP
|
||||
@@ -1713,11 +1749,17 @@ The searching mechanism is implemented with commands \f[CR]search\f[R]
|
||||
(default \f[CR]/\f[R]), \f[CR]search\-back\f[R] (default \f[CR]?\f[R]),
|
||||
\f[CR]search\-next\f[R] (default \f[CR]n\f[R]), and
|
||||
\f[CR]search\-prev\f[R] (default \f[CR]N\f[R]).
|
||||
You can enable \f[CR]globsearch\f[R] option to match with a glob
|
||||
pattern.
|
||||
You can set \f[CR]searchmethod\f[R] to \f[CR]glob\f[R] to match using a
|
||||
glob pattern.
|
||||
Globbing supports \f[CR]*\f[R] to match any sequence, \f[CR]?\f[R] to
|
||||
match any character, and \f[CR][...]\f[R] or \f[CR][\(ha...]\f[R] to
|
||||
match character sets or ranges.
|
||||
You can set \f[CR]searchmethod\f[R] to \f[CR]regex\f[R] to match using a
|
||||
regex pattern.
|
||||
For a full overview of Go\(aqs RE2 syntax, see \c
|
||||
.UR https://pkg.go.dev/regexp/syntax
|
||||
.UE \c
|
||||
\&.
|
||||
You can enable \f[CR]incsearch\f[R] option to jump to the current match
|
||||
at each keystroke while typing.
|
||||
In this mode, you can either use \f[CR]cmd\-enter\f[R] to accept the
|
||||
|
||||
@@ -89,6 +89,16 @@ func exportEnvVars() {
|
||||
os.Setenv("LF_LEVEL", strconv.Itoa(level))
|
||||
}
|
||||
|
||||
func exportFlags() {
|
||||
os.Setenv("lf_flag_config", gConfigPath)
|
||||
os.Setenv("lf_flag_last_dir_path", gLastDirPath)
|
||||
os.Setenv("lf_flag_log", gLogPath)
|
||||
os.Setenv("lf_flag_print_last_dir", strconv.FormatBool(gPrintLastDir))
|
||||
os.Setenv("lf_flag_print_selection", strconv.FormatBool(gPrintSelection))
|
||||
os.Setenv("lf_flag_selection_path", gSelectionPath)
|
||||
os.Setenv("lf_flag_single", strconv.FormatBool(gSingleMode))
|
||||
}
|
||||
|
||||
// used by exportOpts below
|
||||
func fieldToString(field reflect.Value) string {
|
||||
kind := field.Kind()
|
||||
@@ -355,6 +365,7 @@ func main() {
|
||||
}
|
||||
|
||||
exportEnvVars()
|
||||
exportFlags()
|
||||
|
||||
run()
|
||||
}
|
||||
|
||||
@@ -32,14 +32,6 @@ func replaceTilde(s string) string {
|
||||
return s
|
||||
}
|
||||
|
||||
func evalSymlinks(path string) string {
|
||||
if target, err := filepath.EvalSymlinks(path); err == nil {
|
||||
return target
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
func runeSliceWidth(rs []rune) int {
|
||||
w := 0
|
||||
for _, r := range rs {
|
||||
@@ -86,7 +78,7 @@ func runeSliceWidthLastRange(rs []rune, maxWidth int) []rune {
|
||||
|
||||
// This function is used to escape whitespaces and special characters with
|
||||
// backslashes in a given string.
|
||||
func escape(s string) string {
|
||||
func cmdEscape(s string) string {
|
||||
buf := make([]rune, 0, len(s))
|
||||
for _, r := range s {
|
||||
if unicode.IsSpace(r) || r == '\\' || r == ';' || r == '#' {
|
||||
@@ -99,7 +91,7 @@ func escape(s string) string {
|
||||
|
||||
// This function is used to remove backslashes that are used to escape
|
||||
// whitespaces and special characters in a given string.
|
||||
func unescape(s string) string {
|
||||
func cmdUnescape(s string) string {
|
||||
esc := false
|
||||
buf := make([]rune, 0, len(s))
|
||||
for _, r := range s {
|
||||
@@ -125,27 +117,28 @@ func unescape(s string) string {
|
||||
}
|
||||
|
||||
// This function splits the given string by whitespaces. It is aware of escaped
|
||||
// whitespaces so that they are not split unintentionally.
|
||||
// and quoted whitespaces so that they are not split unintentionally.
|
||||
func tokenize(s string) []string {
|
||||
esc := false
|
||||
quote := false
|
||||
var buf []rune
|
||||
var toks []string
|
||||
for _, r := range s {
|
||||
if r == '\\' {
|
||||
esc = true
|
||||
buf = append(buf, r)
|
||||
continue
|
||||
}
|
||||
if esc {
|
||||
switch {
|
||||
case esc:
|
||||
esc = false
|
||||
buf = append(buf, r)
|
||||
continue
|
||||
}
|
||||
if !unicode.IsSpace(r) {
|
||||
case r == '\\':
|
||||
esc = true
|
||||
buf = append(buf, r)
|
||||
} else {
|
||||
case r == '"':
|
||||
quote = !quote
|
||||
buf = append(buf, r)
|
||||
case unicode.IsSpace(r) && !quote:
|
||||
toks = append(toks, string(buf))
|
||||
buf = nil
|
||||
default:
|
||||
buf = append(buf, r)
|
||||
}
|
||||
}
|
||||
return append(toks, string(buf))
|
||||
@@ -242,38 +235,43 @@ func readPairs(r io.Reader) ([][]string, error) {
|
||||
return readArrays(r, 2, 2)
|
||||
}
|
||||
|
||||
// This function converts a size in bytes to a human readable form using metric
|
||||
// suffixes (e.g. 1K = 1000). For values less than 10 the first significant
|
||||
// digit is shown, otherwise it is hidden. Numbers are always rounded down.
|
||||
// This should be fine for most human beings.
|
||||
func humanize(size int64) string {
|
||||
if size < 1000 {
|
||||
// This function converts a size in bytes to a human readable form using
|
||||
// prefixes for binary multiples (e.g., 1 KiB = 1024 B). The output should be
|
||||
// no more than 5 characters long.
|
||||
func humanize(size uint64) string {
|
||||
if size < 1024 {
|
||||
return fmt.Sprintf("%dB", size)
|
||||
}
|
||||
|
||||
suffix := []string{
|
||||
"K", // kilo
|
||||
"M", // mega
|
||||
"G", // giga
|
||||
"T", // tera
|
||||
"P", // peta
|
||||
"E", // exa
|
||||
"Z", // zeta
|
||||
"Y", // yotta
|
||||
// Shortened (due to TUI space constraints) version of
|
||||
// IEC 80000-13:2025 prefixes for binary multiples.
|
||||
// *Note*: due to [`FileSize.Size()`](https://pkg.go.dev/io/fs#FileInfo)
|
||||
// being `int64`, maximum possible representable value would be 8 EiB.
|
||||
prefixes := []string{
|
||||
"K", // kibi (2^10)
|
||||
"M", // mebi (2^20)
|
||||
"G", // gibi (2^30)
|
||||
"T", // tebi (2^40)
|
||||
"P", // pebi (2^50)
|
||||
"E", // exbi (2^60)
|
||||
"Z", // zebi (2^70)
|
||||
"Y", // yobi (2^80)
|
||||
"R", // robi (2^90)
|
||||
"Q", // quebi (2^100)
|
||||
}
|
||||
|
||||
curr := float64(size) / 1000
|
||||
for _, s := range suffix {
|
||||
if curr < 10 {
|
||||
return fmt.Sprintf("%.1f%s", curr-0.0499, s)
|
||||
curr := float64(size) / 1024
|
||||
for _, prefix := range prefixes {
|
||||
if curr < 99.95 {
|
||||
return fmt.Sprintf("%.1f%s", curr, prefix)
|
||||
}
|
||||
if curr < 1000 {
|
||||
return fmt.Sprintf("%d%s", int(curr), s)
|
||||
if curr < 1023.5 {
|
||||
return fmt.Sprintf("%.0f%s", curr, prefix)
|
||||
}
|
||||
curr /= 1000
|
||||
curr /= 1024
|
||||
}
|
||||
|
||||
return ""
|
||||
return fmt.Sprintf("+999%s", prefixes[len(prefixes)-1])
|
||||
}
|
||||
|
||||
// This function compares two strings for natural sorting which takes into
|
||||
|
||||
+47
-22
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -127,7 +128,7 @@ func TestRuneSliceWidthLastRange(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEscape(t *testing.T) {
|
||||
func TestCmdEscape(t *testing.T) {
|
||||
tests := []struct {
|
||||
s string
|
||||
exp string
|
||||
@@ -146,13 +147,13 @@ func TestEscape(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if got := escape(test.s); !reflect.DeepEqual(got, test.exp) {
|
||||
if got := cmdEscape(test.s); !reflect.DeepEqual(got, test.exp) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnescape(t *testing.T) {
|
||||
func TestCmdUnescape(t *testing.T) {
|
||||
tests := []struct {
|
||||
s string
|
||||
exp string
|
||||
@@ -171,7 +172,7 @@ func TestUnescape(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if got := unescape(test.s); !reflect.DeepEqual(got, test.exp) {
|
||||
if got := cmdUnescape(test.s); !reflect.DeepEqual(got, test.exp) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
|
||||
}
|
||||
}
|
||||
@@ -184,8 +185,17 @@ func TestTokenize(t *testing.T) {
|
||||
}{
|
||||
{"", []string{""}},
|
||||
{"foo", []string{"foo"}},
|
||||
{`foo\`, []string{`foo\`}},
|
||||
{`foo"`, []string{`foo"`}},
|
||||
{"foo bar", []string{"foo", "bar"}},
|
||||
{`foo\ bar`, []string{`foo\ bar`}},
|
||||
{`"foo bar"`, []string{`"foo bar"`}},
|
||||
{`"foo" "bar"`, []string{`"foo"`, `"bar"`}},
|
||||
{`"foo "bar"`, []string{`"foo "bar"`}},
|
||||
{`"foo\" bar"`, []string{`"foo\" bar"`}},
|
||||
{`\"foo bar\"`, []string{`\"foo`, `bar\"`}},
|
||||
{`:rename foo\ bar`, []string{":rename", `foo\ bar`}},
|
||||
{`!dir "C:\Program Files"`, []string{"!dir", `"C:\Program Files"`}},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@@ -247,29 +257,44 @@ func TestReadArrays(t *testing.T) {
|
||||
|
||||
func TestHumanize(t *testing.T) {
|
||||
tests := []struct {
|
||||
i int64
|
||||
exp string
|
||||
size uint64
|
||||
expected string
|
||||
}{
|
||||
{0, "0B"},
|
||||
{9, "9B"},
|
||||
{99, "99B"},
|
||||
{999, "999B"},
|
||||
{1000, "1.0K"},
|
||||
{1023, "1.0K"},
|
||||
{1025, "1.0K"},
|
||||
{1049, "1.0K"},
|
||||
{1050, "1.0K"},
|
||||
{1099, "1.0K"},
|
||||
{9999, "9.9K"},
|
||||
{10000, "10K"},
|
||||
{10100, "10K"},
|
||||
{10500, "10K"},
|
||||
{1000000, "1.0M"},
|
||||
{1, "1B"},
|
||||
{2, "2B"},
|
||||
{10, "10B"},
|
||||
{100, "100B"},
|
||||
{1000, "1000B"},
|
||||
{1023, "1023B"},
|
||||
{1024, "1.0K"},
|
||||
{1025, "1.0K"}, // 1.000976563 KiB
|
||||
{10188, "9.9K"}, // 9.94921875 KiB
|
||||
{10189, "10.0K"}, // 9.950195313 KiB
|
||||
{10240, "10.0K"}, // 10 KiB
|
||||
{10291, "10.0K"}, // 10.049804688 KiB
|
||||
{10292, "10.1K"}, // 10.05078125 KiB
|
||||
{10342, "10.1K"}, // 10.099609375 KiB
|
||||
{102348, "99.9K"}, // 99.94921875 KiB
|
||||
{102349, "100K"}, // 99.950195313 KiB
|
||||
{1023487, "999K"}, // 999.499023438 KiB
|
||||
{1023488, "1000K"}, // 999.5 KiB
|
||||
{1048063, "1023K"}, // 1023.499023438 KiB
|
||||
{1048064, "1.0M"}, // 1023.5 KiB
|
||||
{1072693248, "1023M"}, // 1023 MiB
|
||||
{1073217535, "1023M"}, // 1023.499999046 MiB
|
||||
{1073217536, "1.0G"}, // 1023.5 MiB
|
||||
{1073741824, "1.0G"}, // 1 GiB
|
||||
{1610612736, "1.5G"}, // 1.5 GiB
|
||||
{1319413953332, "1.2T"}, // 1.2 TiB
|
||||
{1463669878895412, "1.3P"}, // 1.3 PiB
|
||||
{7955158381787244544, "6.9E"}, // 6.9 EiB
|
||||
{math.MaxUint64, "16.0E"}, // 16 EiB
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if got := humanize(test.i); got != test.exp {
|
||||
t.Errorf("at input '%d' expected '%s' but got '%s'", test.i, test.exp, got)
|
||||
if got := humanize(test.size); got != test.expected {
|
||||
t.Errorf("at input '%d' expected '%s' but got '%s'", test.size, test.expected, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"maps"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -36,6 +38,7 @@ type file struct {
|
||||
dirCount int
|
||||
dirSize int64
|
||||
accessTime time.Time
|
||||
birthTime time.Time
|
||||
changeTime time.Time
|
||||
customInfo string
|
||||
ext string
|
||||
@@ -54,6 +57,7 @@ func newFile(path string) *file {
|
||||
dirCount: -1,
|
||||
dirSize: -1,
|
||||
accessTime: time.Unix(0, 0),
|
||||
birthTime: time.Unix(0, 0),
|
||||
changeTime: time.Unix(0, 0),
|
||||
customInfo: "",
|
||||
ext: "",
|
||||
@@ -80,13 +84,19 @@ func newFile(path string) *file {
|
||||
|
||||
ts := times.Get(lstat)
|
||||
at := ts.AccessTime()
|
||||
var ct time.Time
|
||||
// from times docs: ChangeTime() panics unless HasChangeTime() is true
|
||||
// from times docs:
|
||||
// ChangeTime() panics unless HasChangeTime() is true and
|
||||
// BirthTime() panics unless HasBirthTime() is true.
|
||||
|
||||
// default to ModTime if BirthTime cannot be determined
|
||||
bt := lstat.ModTime()
|
||||
if ts.HasBirthTime() {
|
||||
bt = ts.BirthTime()
|
||||
}
|
||||
// default to ModTime if ChangeTime cannot be determined
|
||||
ct := lstat.ModTime()
|
||||
if ts.HasChangeTime() {
|
||||
ct = ts.ChangeTime()
|
||||
} else {
|
||||
// fall back to ModTime if ChangeTime cannot be determined
|
||||
ct = lstat.ModTime()
|
||||
}
|
||||
|
||||
dirCount := -1
|
||||
@@ -95,7 +105,7 @@ func newFile(path string) *file {
|
||||
if err != nil {
|
||||
dirCount = -2
|
||||
} else {
|
||||
names, err := d.Readdirnames(1000)
|
||||
names, err := d.Readdirnames(10000)
|
||||
d.Close()
|
||||
|
||||
if names == nil && err != io.EOF {
|
||||
@@ -114,6 +124,7 @@ func newFile(path string) *file {
|
||||
dirCount: dirCount,
|
||||
dirSize: -1,
|
||||
accessTime: at,
|
||||
birthTime: bt,
|
||||
changeTime: ct,
|
||||
customInfo: "",
|
||||
ext: getFileExtension(lstat),
|
||||
@@ -160,18 +171,20 @@ func readdir(path string) ([]*file, error) {
|
||||
|
||||
type dir struct {
|
||||
loading bool // directory is loading from disk
|
||||
loadTime time.Time // current loading or last load time
|
||||
loadTime time.Time // last load time
|
||||
ind int // index of current entry in files
|
||||
pos int // position of current entry in ui
|
||||
path string // full path of directory
|
||||
files []*file // displayed files in directory including or excluding hidden ones
|
||||
allFiles []*file // all files in directory including hidden ones (same array as files)
|
||||
sortby sortMethod // sortby value from last sort
|
||||
dircounts bool // dircounts value from last sort
|
||||
dirfirst bool // dirfirst value from last sort
|
||||
dironly bool // dironly value from last sort
|
||||
hidden bool // hidden value from last sort
|
||||
reverse bool // reverse value from last sort
|
||||
visualAnchor int // index where visual mode was initiated
|
||||
visualAnchor int // index where Visual mode was initiated
|
||||
visualWrap int // wrap direction in Visual mode
|
||||
hiddenfiles []string // hiddenfiles value from last sort
|
||||
filter []string // last filter for this directory
|
||||
ignorecase bool // ignorecase value from last sort
|
||||
@@ -181,15 +194,13 @@ type dir struct {
|
||||
}
|
||||
|
||||
func newDir(path string) *dir {
|
||||
time := time.Now()
|
||||
|
||||
files, err := readdir(path)
|
||||
if err != nil {
|
||||
log.Printf("reading directory: %s", err)
|
||||
}
|
||||
|
||||
return &dir{
|
||||
loadTime: time,
|
||||
loadTime: time.Now(),
|
||||
path: path,
|
||||
files: files,
|
||||
allFiles: files,
|
||||
@@ -212,6 +223,7 @@ func normalize(s1, s2 string, ignorecase, ignoredia bool) (string, string) {
|
||||
|
||||
func (dir *dir) sort() {
|
||||
dir.sortby = getSortBy(dir.path)
|
||||
dir.dircounts = getDirCounts(dir.path)
|
||||
dir.dirfirst = getDirFirst(dir.path)
|
||||
dir.dironly = getDirOnly(dir.path)
|
||||
dir.hidden = getHidden(dir.path)
|
||||
@@ -290,11 +302,18 @@ func (dir *dir) sort() {
|
||||
})
|
||||
}
|
||||
case sizeSort:
|
||||
sizeVal := func(f *file) int64 {
|
||||
if f.IsDir() && dir.dircounts {
|
||||
return int64(f.dirCount)
|
||||
}
|
||||
return f.TotalSize()
|
||||
}
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
s1, s2 := sizeVal(dir.files[i]), sizeVal(dir.files[j])
|
||||
if !dir.reverse {
|
||||
return dir.files[i].TotalSize() < dir.files[j].TotalSize()
|
||||
return s1 < s2
|
||||
} else {
|
||||
return dir.files[j].TotalSize() < dir.files[i].TotalSize()
|
||||
return s2 < s1
|
||||
}
|
||||
})
|
||||
case timeSort:
|
||||
@@ -313,6 +332,14 @@ func (dir *dir) sort() {
|
||||
return dir.files[j].accessTime.Before(dir.files[i].accessTime)
|
||||
}
|
||||
})
|
||||
case btimeSort:
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
if !dir.reverse {
|
||||
return dir.files[i].birthTime.Before(dir.files[j].birthTime)
|
||||
} else {
|
||||
return dir.files[j].birthTime.Before(dir.files[i].birthTime)
|
||||
}
|
||||
})
|
||||
case ctimeSort:
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
if !dir.reverse {
|
||||
@@ -333,7 +360,9 @@ func (dir *dir) sort() {
|
||||
})
|
||||
}
|
||||
|
||||
if dir.dirfirst {
|
||||
// when sorting by size while also showing dircounts, we always display files
|
||||
// and directories separately to avoid mixing file sizes and file counts
|
||||
if dir.dirfirst || (dir.sortby == sizeSort && dir.dircounts) {
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
if dir.files[i].IsDir() == dir.files[j].IsDir() {
|
||||
return i < j
|
||||
@@ -413,15 +442,6 @@ func (dir *dir) name() string {
|
||||
return dir.files[dir.ind].Name()
|
||||
}
|
||||
|
||||
func (d *dir) fileNames() []string {
|
||||
names := []string{}
|
||||
for _, file := range d.files {
|
||||
names = append(names, file.path)
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
||||
|
||||
func (nav *nav) isVisualMode() bool {
|
||||
return nav.init && nav.currDir().visualAnchor != -1
|
||||
}
|
||||
@@ -432,13 +452,21 @@ func (dir *dir) visualSelections() []string {
|
||||
return paths
|
||||
}
|
||||
|
||||
beg, end := dir.ind, dir.visualAnchor
|
||||
if beg > end {
|
||||
beg, end = end, beg
|
||||
var beg, end int
|
||||
switch {
|
||||
case dir.visualWrap == 0:
|
||||
beg = min(dir.ind, dir.visualAnchor)
|
||||
end = max(dir.ind, dir.visualAnchor)
|
||||
case dir.visualWrap < 0:
|
||||
beg = dir.ind
|
||||
end = dir.visualAnchor - dir.visualWrap*len(dir.files)
|
||||
case dir.visualWrap > 0:
|
||||
beg = dir.visualAnchor
|
||||
end = dir.ind + dir.visualWrap*len(dir.files)
|
||||
}
|
||||
|
||||
for _, f := range dir.files[beg : end+1] {
|
||||
paths = append(paths, f.path)
|
||||
for i := beg; i < min(end+1, beg+len(dir.files)); i++ {
|
||||
paths = append(paths, dir.files[i%len(dir.files)].path)
|
||||
}
|
||||
|
||||
return paths
|
||||
@@ -485,9 +513,22 @@ func (dir *dir) boundPos(height int) {
|
||||
dir.pos = max(dir.pos, height-(len(dir.files)-dir.ind))
|
||||
}
|
||||
|
||||
type clipboardMode byte
|
||||
|
||||
const (
|
||||
clipboardCopy = iota
|
||||
clipboardCut
|
||||
)
|
||||
|
||||
type clipboard struct {
|
||||
paths []string
|
||||
mode clipboardMode
|
||||
}
|
||||
|
||||
type nav struct {
|
||||
init bool
|
||||
dirs []*dir
|
||||
copyJobs int
|
||||
copyBytes int64
|
||||
copyTotal int64
|
||||
copyUpdate int
|
||||
@@ -497,6 +538,7 @@ type nav struct {
|
||||
deleteCount int
|
||||
deleteTotal int
|
||||
deleteUpdate int
|
||||
copyJobsChan chan struct{}
|
||||
copyBytesChan chan int64
|
||||
copyTotalChan chan int64
|
||||
moveCountChan chan int
|
||||
@@ -510,7 +552,7 @@ type nav struct {
|
||||
delChan chan string
|
||||
dirCache map[string]*dir
|
||||
regCache map[string]*reg
|
||||
saves map[string]bool
|
||||
clipboard clipboard
|
||||
marks map[string]string
|
||||
renameOldPath string
|
||||
renameNewPath string
|
||||
@@ -535,9 +577,9 @@ type nav struct {
|
||||
func (nav *nav) loadDirInternal(path string) *dir {
|
||||
d := &dir{
|
||||
loading: true,
|
||||
loadTime: time.Now(),
|
||||
path: path,
|
||||
sortby: getSortBy(path),
|
||||
dircounts: getDirCounts(path),
|
||||
dirfirst: getDirFirst(path),
|
||||
dironly: getDirOnly(path),
|
||||
hidden: getHidden(path),
|
||||
@@ -549,10 +591,7 @@ func (nav *nav) loadDirInternal(path string) *dir {
|
||||
ignoredia: gOpts.ignoredia,
|
||||
}
|
||||
go func() {
|
||||
d := newDir(path)
|
||||
d.sort()
|
||||
d.ind, d.pos = 0, 0
|
||||
nav.dirChan <- d
|
||||
nav.dirChan <- newDir(path)
|
||||
}()
|
||||
return d
|
||||
}
|
||||
@@ -574,6 +613,10 @@ func (nav *nav) loadDir(path string) *dir {
|
||||
}
|
||||
|
||||
func (nav *nav) checkDir(dir *dir) {
|
||||
if dir.loading {
|
||||
return
|
||||
}
|
||||
|
||||
s, err := os.Stat(dir.path)
|
||||
if err != nil {
|
||||
log.Printf("getting directory info: %s", err)
|
||||
@@ -582,20 +625,24 @@ func (nav *nav) checkDir(dir *dir) {
|
||||
|
||||
switch {
|
||||
case s.ModTime().After(dir.loadTime):
|
||||
now := time.Now()
|
||||
|
||||
// XXX: Linux builtin exFAT drivers are able to predict modifications in the future
|
||||
// https://bugs.launchpad.net/ubuntu/+source/ubuntu-meta/+bug/1872504
|
||||
if s.ModTime().After(now) {
|
||||
if s.ModTime().After(time.Now()) {
|
||||
return
|
||||
}
|
||||
|
||||
dir.loading = true
|
||||
dir.loadTime = now
|
||||
go func() {
|
||||
nd := newDir(dir.path)
|
||||
nav.dirChan <- nd
|
||||
nav.dirChan <- newDir(dir.path)
|
||||
}()
|
||||
case dir.dircounts != getDirCounts(dir.path):
|
||||
dir.loading = true
|
||||
go func() {
|
||||
nav.dirChan <- newDir(dir.path)
|
||||
}()
|
||||
// Although toggling dircounts can affect sorting, it is already handled by
|
||||
// reloading the directory which should sort the files anyway, so it is not
|
||||
// checked below.
|
||||
case dir.sortby != getSortBy(dir.path) ||
|
||||
dir.dirfirst != getDirFirst(dir.path) ||
|
||||
dir.dironly != getDirOnly(dir.path) ||
|
||||
@@ -637,6 +684,7 @@ func (nav *nav) getDirs(wd string) {
|
||||
|
||||
func newNav(height int) *nav {
|
||||
nav := &nav{
|
||||
copyJobsChan: make(chan struct{}, 1024),
|
||||
copyBytesChan: make(chan int64, 1024),
|
||||
copyTotalChan: make(chan int64, 1024),
|
||||
moveCountChan: make(chan int, 1024),
|
||||
@@ -650,7 +698,6 @@ func newNav(height int) *nav {
|
||||
delChan: make(chan string),
|
||||
dirCache: make(map[string]*dir),
|
||||
regCache: make(map[string]*reg),
|
||||
saves: make(map[string]bool),
|
||||
marks: make(map[string]string),
|
||||
selections: make(map[string]int),
|
||||
tags: make(map[string]string),
|
||||
@@ -985,6 +1032,7 @@ func (nav *nav) up(dist int) bool {
|
||||
if dir.ind == 0 {
|
||||
if gOpts.wrapscroll {
|
||||
nav.bottom()
|
||||
dir.visualWrap -= 1
|
||||
}
|
||||
return old != dir.ind
|
||||
}
|
||||
@@ -1008,6 +1056,7 @@ func (nav *nav) down(dist int) bool {
|
||||
if dir.ind >= maxind {
|
||||
if gOpts.wrapscroll {
|
||||
nav.top()
|
||||
dir.visualWrap += 1
|
||||
}
|
||||
return old != dir.ind
|
||||
}
|
||||
@@ -1225,8 +1274,6 @@ func (nav *nav) toggle() {
|
||||
}
|
||||
|
||||
func (nav *nav) tagToggleSelection(path string, tag string) {
|
||||
path = evalSymlinks(path)
|
||||
|
||||
if _, ok := nav.tags[path]; ok {
|
||||
delete(nav.tags, path)
|
||||
} else {
|
||||
@@ -1262,7 +1309,7 @@ func (nav *nav) tag(tag string) error {
|
||||
}
|
||||
|
||||
for _, path := range list {
|
||||
nav.tags[evalSymlinks(path)] = tag
|
||||
nav.tags[path] = tag
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -1281,38 +1328,44 @@ func (nav *nav) unselect() {
|
||||
nav.selectionInd = 0
|
||||
}
|
||||
|
||||
func (nav *nav) save(cp bool) error {
|
||||
func (nav *nav) save(mode clipboardMode) error {
|
||||
list, err := nav.currFileOrSelections()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := saveFiles(list, cp); err != nil {
|
||||
clipboard := clipboard{list, mode}
|
||||
if err := saveFiles(clipboard); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clear(nav.saves)
|
||||
for _, f := range list {
|
||||
nav.saves[f] = cp
|
||||
}
|
||||
|
||||
nav.clipboard = clipboard
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) copyAsync(app *app, srcs []string, dstDir string) {
|
||||
echo := &callExpr{"echoerr", []string{""}, 1}
|
||||
errCount := 0
|
||||
sendErr := func(format string, a ...any) {
|
||||
errCount++
|
||||
msg := fmt.Sprintf("copy [%d]: %s", errCount, fmt.Sprintf(format, a...))
|
||||
app.ui.exprChan <- &callExpr{"echoerr", []string{msg}, 1}
|
||||
}
|
||||
|
||||
_, err := os.Stat(dstDir)
|
||||
if os.IsNotExist(err) {
|
||||
echo.args[0] = err.Error()
|
||||
app.ui.exprChan <- echo
|
||||
sendErr("%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// indicate that a copy operation is in progress
|
||||
// using the total bytes to determine this instead will mean that it is
|
||||
// possible for copySize to take a while, but not be reflected in the UI
|
||||
// until it has finished
|
||||
nav.copyJobsChan <- struct{}{}
|
||||
|
||||
total, err := copySize(srcs)
|
||||
if err != nil {
|
||||
echo.args[0] = err.Error()
|
||||
app.ui.exprChan <- echo
|
||||
sendErr("%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1320,7 +1373,6 @@ func (nav *nav) copyAsync(app *app, srcs []string, dstDir string) {
|
||||
|
||||
nums, errs := copyAll(srcs, dstDir, gOpts.preserve)
|
||||
|
||||
errCount := 0
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
@@ -1330,9 +1382,7 @@ loop:
|
||||
if !ok {
|
||||
break loop
|
||||
}
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
app.ui.exprChan <- echo
|
||||
sendErr("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1343,9 +1393,7 @@ loop:
|
||||
app.ui.loadFile(app, true)
|
||||
} else {
|
||||
if err := remote("send load"); err != nil {
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
app.ui.exprChan <- echo
|
||||
sendErr("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1355,26 +1403,27 @@ loop:
|
||||
}
|
||||
|
||||
func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
|
||||
echo := &callExpr{"echoerr", []string{""}, 1}
|
||||
errCount := 0
|
||||
sendErr := func(format string, a ...any) {
|
||||
errCount++
|
||||
msg := fmt.Sprintf("move [%d]: %s", errCount, fmt.Sprintf(format, a...))
|
||||
app.ui.exprChan <- &callExpr{"echoerr", []string{msg}, 1}
|
||||
}
|
||||
|
||||
_, err := os.Stat(dstDir)
|
||||
if os.IsNotExist(err) {
|
||||
echo.args[0] = err.Error()
|
||||
app.ui.exprChan <- echo
|
||||
sendErr("%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
nav.moveTotalChan <- len(srcs)
|
||||
|
||||
errCount := 0
|
||||
for _, src := range srcs {
|
||||
nav.moveCountChan <- 1
|
||||
|
||||
srcStat, err := os.Lstat(src)
|
||||
if err != nil {
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
app.ui.exprChan <- echo
|
||||
sendErr("%v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1383,9 +1432,7 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
|
||||
|
||||
if dstStat, err := os.Stat(dst); err == nil {
|
||||
if os.SameFile(srcStat, dstStat) {
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] rename %s %s: source and destination are the same file", errCount, src, dst)
|
||||
app.ui.exprChan <- echo
|
||||
sendErr("rename %s %s: source and destination are the same file", src, dst)
|
||||
continue
|
||||
}
|
||||
ext := getFileExtension(dstStat)
|
||||
@@ -1406,8 +1453,7 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
|
||||
if errCrossDevice(err) {
|
||||
total, err := copySize([]string{src})
|
||||
if err != nil {
|
||||
echo.args[0] = err.Error()
|
||||
app.ui.exprChan <- echo
|
||||
sendErr("%v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1425,9 +1471,7 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
|
||||
if !ok {
|
||||
break loop
|
||||
}
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
app.ui.exprChan <- echo
|
||||
sendErr("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1435,15 +1479,11 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
|
||||
|
||||
if errCount == oldCount {
|
||||
if err := os.RemoveAll(src); err != nil {
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
app.ui.exprChan <- echo
|
||||
sendErr("%v", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
app.ui.exprChan <- echo
|
||||
sendErr("%v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1455,9 +1495,7 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
|
||||
app.ui.loadFile(app, true)
|
||||
} else {
|
||||
if err := remote("send load"); err != nil {
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
app.ui.exprChan <- echo
|
||||
sendErr("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1468,21 +1506,21 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
|
||||
}
|
||||
|
||||
func (nav *nav) paste(app *app) error {
|
||||
srcs, cp, err := loadFiles()
|
||||
clipboard, err := loadFiles()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(srcs) == 0 {
|
||||
return errors.New("no file in copy/cut buffer")
|
||||
if len(clipboard.paths) == 0 {
|
||||
return errors.New("no files in clipboard")
|
||||
}
|
||||
|
||||
dstDir := nav.currDir().path
|
||||
|
||||
if cp {
|
||||
go nav.copyAsync(app, srcs, dstDir)
|
||||
if clipboard.mode == clipboardCopy {
|
||||
go nav.copyAsync(app, clipboard.paths, dstDir)
|
||||
} else {
|
||||
go nav.moveAsync(app, srcs, dstDir)
|
||||
go nav.moveAsync(app, clipboard.paths, dstDir)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -1564,15 +1602,12 @@ func (nav *nav) rename() error {
|
||||
}
|
||||
|
||||
func (nav *nav) sync() error {
|
||||
list, cp, err := loadFiles()
|
||||
clipboard, err := loadFiles()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clear(nav.saves)
|
||||
for _, f := range list {
|
||||
nav.saves[f] = cp
|
||||
}
|
||||
nav.clipboard = clipboard
|
||||
|
||||
tempmarks := make(map[string]string)
|
||||
for _, ch := range gOpts.tempmarks {
|
||||
@@ -1582,9 +1617,7 @@ func (nav *nav) sync() error {
|
||||
}
|
||||
}
|
||||
errMarks := nav.readMarks()
|
||||
for k, v := range tempmarks {
|
||||
nav.marks[k] = v
|
||||
}
|
||||
maps.Copy(nav.marks, tempmarks)
|
||||
|
||||
err = nav.readTags()
|
||||
|
||||
@@ -1723,6 +1756,7 @@ func (nav *nav) findNext() (bool, bool) {
|
||||
if gOpts.wrapscan {
|
||||
for i := range dir.ind {
|
||||
if findMatch(dir.files[i].Name(), nav.find) {
|
||||
dir.visualWrap += 1
|
||||
return nav.up(dir.ind - i), true
|
||||
}
|
||||
}
|
||||
@@ -1740,6 +1774,7 @@ func (nav *nav) findPrev() (bool, bool) {
|
||||
if gOpts.wrapscan {
|
||||
for i := len(dir.files) - 1; i > dir.ind; i-- {
|
||||
if findMatch(dir.files[i].Name(), nav.find) {
|
||||
dir.visualWrap -= 1
|
||||
return nav.down(i - dir.ind), true
|
||||
}
|
||||
}
|
||||
@@ -1747,7 +1782,7 @@ func (nav *nav) findPrev() (bool, bool) {
|
||||
return false, false
|
||||
}
|
||||
|
||||
func searchMatch(name, pattern string, glob bool) (matched bool, err error) {
|
||||
func searchMatch(name, pattern string, method searchMethod) (matched bool, err error) {
|
||||
if gOpts.ignorecase {
|
||||
lpattern := strings.ToLower(pattern)
|
||||
if !gOpts.smartcase || lpattern == pattern {
|
||||
@@ -1762,16 +1797,22 @@ func searchMatch(name, pattern string, glob bool) (matched bool, err error) {
|
||||
name = removeDiacritics(name)
|
||||
}
|
||||
}
|
||||
if glob {
|
||||
switch method {
|
||||
case textSearch:
|
||||
return strings.Contains(name, pattern), nil
|
||||
case globSearch:
|
||||
return filepath.Match(pattern, name)
|
||||
case regexSearch:
|
||||
return regexp.MatchString(pattern, name)
|
||||
default:
|
||||
return false, fmt.Errorf("searchMatch: invalid searchMethod")
|
||||
}
|
||||
return strings.Contains(name, pattern), nil
|
||||
}
|
||||
|
||||
func (nav *nav) searchNext() (bool, error) {
|
||||
dir := nav.currDir()
|
||||
for i := dir.ind + 1; i < len(dir.files); i++ {
|
||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
|
||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.searchmethod); err != nil {
|
||||
return false, err
|
||||
} else if matched {
|
||||
return nav.down(i - dir.ind), nil
|
||||
@@ -1779,9 +1820,10 @@ func (nav *nav) searchNext() (bool, error) {
|
||||
}
|
||||
if gOpts.wrapscan {
|
||||
for i := range dir.ind {
|
||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
|
||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.searchmethod); err != nil {
|
||||
return false, err
|
||||
} else if matched {
|
||||
dir.visualWrap += 1
|
||||
return nav.up(dir.ind - i), nil
|
||||
}
|
||||
}
|
||||
@@ -1792,7 +1834,7 @@ func (nav *nav) searchNext() (bool, error) {
|
||||
func (nav *nav) searchPrev() (bool, error) {
|
||||
dir := nav.currDir()
|
||||
for i := dir.ind - 1; i >= 0; i-- {
|
||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
|
||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.searchmethod); err != nil {
|
||||
return false, err
|
||||
} else if matched {
|
||||
return nav.up(dir.ind - i), nil
|
||||
@@ -1800,9 +1842,10 @@ func (nav *nav) searchPrev() (bool, error) {
|
||||
}
|
||||
if gOpts.wrapscan {
|
||||
for i := len(dir.files) - 1; i > dir.ind; i-- {
|
||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
|
||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.searchmethod); err != nil {
|
||||
return false, err
|
||||
} else if matched {
|
||||
dir.visualWrap -= 1
|
||||
return nav.down(i - dir.ind), nil
|
||||
}
|
||||
}
|
||||
@@ -1812,7 +1855,7 @@ func (nav *nav) searchPrev() (bool, error) {
|
||||
|
||||
func isFiltered(f os.FileInfo, filter []string) bool {
|
||||
for _, pattern := range filter {
|
||||
matched, err := searchMatch(f.Name(), strings.TrimPrefix(pattern, "!"), gOpts.globfilter)
|
||||
matched, err := searchMatch(f.Name(), strings.TrimPrefix(pattern, "!"), gOpts.filtermethod)
|
||||
if err != nil {
|
||||
log.Printf("Filter Error: %s", err)
|
||||
return false
|
||||
|
||||
@@ -15,6 +15,7 @@ const (
|
||||
sizeSort sortMethod = "size"
|
||||
timeSort sortMethod = "time"
|
||||
atimeSort sortMethod = "atime"
|
||||
btimeSort sortMethod = "btime"
|
||||
ctimeSort sortMethod = "ctime"
|
||||
extSort sortMethod = "ext"
|
||||
customSort sortMethod = "custom"
|
||||
@@ -26,17 +27,27 @@ func isValidSortMethod(method sortMethod) bool {
|
||||
method == sizeSort ||
|
||||
method == timeSort ||
|
||||
method == atimeSort ||
|
||||
method == btimeSort ||
|
||||
method == ctimeSort ||
|
||||
method == extSort ||
|
||||
method == customSort
|
||||
}
|
||||
|
||||
const invalidSortErrorMessage = `sortby: value should either be 'natural', 'name', 'size', 'time', 'atime', 'ctime', 'ext' or 'custom'`
|
||||
const invalidSortErrorMessage = `sortby: value should either be 'natural', 'name', 'size', 'time', 'atime', 'btime', 'ctime', 'ext' or 'custom'`
|
||||
|
||||
type searchMethod string
|
||||
|
||||
const (
|
||||
textSearch searchMethod = "text"
|
||||
globSearch searchMethod = "glob"
|
||||
regexSearch searchMethod = "regex"
|
||||
)
|
||||
|
||||
var gOpts struct {
|
||||
anchorfind bool
|
||||
autoquit bool
|
||||
borderfmt string
|
||||
cleaner string
|
||||
copyfmt string
|
||||
cursoractivefmt string
|
||||
cursorparentfmt string
|
||||
@@ -49,77 +60,76 @@ var gOpts struct {
|
||||
dirpreviews bool
|
||||
drawbox bool
|
||||
dupfilefmt string
|
||||
globfilter bool
|
||||
globsearch bool
|
||||
errorfmt string
|
||||
filesep string
|
||||
filtermethod searchMethod
|
||||
findlen int
|
||||
hidden bool
|
||||
hiddenfiles []string
|
||||
history bool
|
||||
icons bool
|
||||
ifs string
|
||||
ignorecase bool
|
||||
ignoredia bool
|
||||
incfilter bool
|
||||
incsearch bool
|
||||
info []string
|
||||
infotimefmtnew string
|
||||
infotimefmtold string
|
||||
locale string
|
||||
mouse bool
|
||||
number bool
|
||||
numberfmt string
|
||||
period int
|
||||
preserve []string
|
||||
preview bool
|
||||
previewer string
|
||||
promptfmt string
|
||||
ratios []int
|
||||
relativenumber bool
|
||||
reverse bool
|
||||
roundbox bool
|
||||
rulerfmt string
|
||||
scrolloff int
|
||||
searchmethod searchMethod
|
||||
selectfmt string
|
||||
visualfmt string
|
||||
selmode string
|
||||
shell string
|
||||
shellflag string
|
||||
shellopts []string
|
||||
showbinds bool
|
||||
sixel bool
|
||||
sortby sortMethod
|
||||
smartcase bool
|
||||
smartdia bool
|
||||
sortby sortMethod
|
||||
statfmt string
|
||||
tabstop int
|
||||
tagfmt string
|
||||
tempmarks string
|
||||
timefmt string
|
||||
truncatechar string
|
||||
truncatepct int
|
||||
visualfmt string
|
||||
waitmsg string
|
||||
watch bool
|
||||
wrapscan bool
|
||||
wrapscroll bool
|
||||
findlen int
|
||||
period int
|
||||
scrolloff int
|
||||
tabstop int
|
||||
errorfmt string
|
||||
filesep string
|
||||
ifs string
|
||||
previewer string
|
||||
cleaner string
|
||||
promptfmt string
|
||||
selmode string
|
||||
shell string
|
||||
shellflag string
|
||||
statfmt string
|
||||
timefmt string
|
||||
infotimefmtnew string
|
||||
infotimefmtold string
|
||||
truncatechar string
|
||||
truncatepct int
|
||||
ratios []int
|
||||
hiddenfiles []string
|
||||
history bool
|
||||
info []string
|
||||
rulerfmt string
|
||||
preserve []string
|
||||
shellopts []string
|
||||
nkeys map[string]expr
|
||||
vkeys map[string]expr
|
||||
cmdkeys map[string]expr
|
||||
cmds map[string]expr
|
||||
user map[string]string
|
||||
tempmarks string
|
||||
numberfmt string
|
||||
tagfmt string
|
||||
}
|
||||
|
||||
var gLocalOpts struct {
|
||||
sortby map[string]sortMethod
|
||||
dircounts map[string]bool
|
||||
dirfirst map[string]bool
|
||||
dironly map[string]bool
|
||||
hidden map[string]bool
|
||||
reverse map[string]bool
|
||||
info map[string][]string
|
||||
locale map[string]string
|
||||
reverse map[string]bool
|
||||
sortby map[string]sortMethod
|
||||
}
|
||||
|
||||
func localOptPaths(path string) []string {
|
||||
@@ -175,6 +185,15 @@ func getInfo(path string) []string {
|
||||
return gOpts.info
|
||||
}
|
||||
|
||||
func getLocale(path string) string {
|
||||
for _, key := range localOptPaths(path) {
|
||||
if val, ok := gLocalOpts.locale[key]; ok {
|
||||
return val
|
||||
}
|
||||
}
|
||||
return gOpts.locale
|
||||
}
|
||||
|
||||
func getReverse(path string) bool {
|
||||
for _, key := range localOptPaths(path) {
|
||||
if val, ok := gLocalOpts.reverse[key]; ok {
|
||||
@@ -193,18 +212,16 @@ func getSortBy(path string) sortMethod {
|
||||
return gOpts.sortby
|
||||
}
|
||||
|
||||
func getLocale(path string) string {
|
||||
for _, key := range localOptPaths(path) {
|
||||
if val, ok := gLocalOpts.locale[key]; ok {
|
||||
return val
|
||||
}
|
||||
}
|
||||
return gOpts.locale
|
||||
}
|
||||
|
||||
func init() {
|
||||
gOpts.anchorfind = true
|
||||
gOpts.autoquit = true
|
||||
gOpts.borderfmt = "\033[0m"
|
||||
gOpts.cleaner = ""
|
||||
gOpts.copyfmt = "\033[7;33m"
|
||||
gOpts.cursoractivefmt = "\033[7m"
|
||||
gOpts.cursorparentfmt = "\033[7m"
|
||||
gOpts.cursorpreviewfmt = "\033[4m"
|
||||
gOpts.cutfmt = "\033[7;31m"
|
||||
gOpts.dircache = true
|
||||
gOpts.dircounts = false
|
||||
gOpts.dirfirst = true
|
||||
@@ -212,69 +229,62 @@ func init() {
|
||||
gOpts.dirpreviews = false
|
||||
gOpts.drawbox = false
|
||||
gOpts.dupfilefmt = "%f.~%n~"
|
||||
gOpts.borderfmt = "\033[0m"
|
||||
gOpts.copyfmt = "\033[7;33m"
|
||||
gOpts.cursoractivefmt = "\033[7m"
|
||||
gOpts.cursorparentfmt = "\033[7m"
|
||||
gOpts.cursorpreviewfmt = "\033[4m"
|
||||
gOpts.cutfmt = "\033[7;31m"
|
||||
gOpts.globfilter = false
|
||||
gOpts.globsearch = false
|
||||
gOpts.errorfmt = "\033[7;31;47m"
|
||||
gOpts.filesep = "\n"
|
||||
gOpts.filtermethod = textSearch
|
||||
gOpts.findlen = 1
|
||||
gOpts.hidden = false
|
||||
gOpts.hiddenfiles = gDefaultHiddenFiles
|
||||
gOpts.history = true
|
||||
gOpts.icons = false
|
||||
gOpts.ifs = ""
|
||||
gOpts.ignorecase = true
|
||||
gOpts.ignoredia = true
|
||||
gOpts.incfilter = false
|
||||
gOpts.incsearch = false
|
||||
gOpts.info = nil
|
||||
gOpts.infotimefmtnew = "Jan _2 15:04"
|
||||
gOpts.infotimefmtold = "Jan _2 2006"
|
||||
gOpts.locale = localeStrDisable
|
||||
gOpts.mouse = false
|
||||
gOpts.number = false
|
||||
gOpts.numberfmt = "\033[33m"
|
||||
gOpts.period = 0
|
||||
gOpts.preserve = []string{"mode"}
|
||||
gOpts.preview = true
|
||||
gOpts.previewer = ""
|
||||
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"
|
||||
gOpts.ratios = []int{1, 2, 3}
|
||||
gOpts.relativenumber = false
|
||||
gOpts.reverse = false
|
||||
gOpts.roundbox = false
|
||||
gOpts.rulerfmt = " %a| %p| \033[7;31m %m \033[0m| \033[7;33m %c \033[0m| \033[7;35m %s \033[0m| \033[7;36m %v \033[0m| \033[7;34m %f \033[0m| %i/%t"
|
||||
gOpts.scrolloff = 0
|
||||
gOpts.searchmethod = textSearch
|
||||
gOpts.selectfmt = "\033[7;35m"
|
||||
gOpts.visualfmt = "\033[7;36m"
|
||||
gOpts.selmode = "all"
|
||||
gOpts.shell = gDefaultShell
|
||||
gOpts.shellflag = gDefaultShellFlag
|
||||
gOpts.shellopts = nil
|
||||
gOpts.showbinds = true
|
||||
gOpts.sixel = false
|
||||
gOpts.sortby = naturalSort
|
||||
gOpts.smartcase = true
|
||||
gOpts.smartdia = false
|
||||
gOpts.sortby = naturalSort
|
||||
gOpts.statfmt = "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l"
|
||||
gOpts.tabstop = 8
|
||||
gOpts.tagfmt = "\033[31m"
|
||||
gOpts.tempmarks = "'"
|
||||
gOpts.timefmt = time.ANSIC
|
||||
gOpts.truncatechar = "~"
|
||||
gOpts.truncatepct = 100
|
||||
gOpts.visualfmt = "\033[7;36m"
|
||||
gOpts.waitmsg = "Press any key to continue"
|
||||
gOpts.watch = false
|
||||
gOpts.wrapscan = true
|
||||
gOpts.wrapscroll = false
|
||||
gOpts.findlen = 1
|
||||
gOpts.period = 0
|
||||
gOpts.scrolloff = 0
|
||||
gOpts.tabstop = 8
|
||||
gOpts.errorfmt = "\033[7;31;47m"
|
||||
gOpts.filesep = "\n"
|
||||
gOpts.ifs = ""
|
||||
gOpts.previewer = ""
|
||||
gOpts.cleaner = ""
|
||||
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"
|
||||
gOpts.selmode = "all"
|
||||
gOpts.shell = gDefaultShell
|
||||
gOpts.shellflag = gDefaultShellFlag
|
||||
gOpts.statfmt = "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l"
|
||||
gOpts.timefmt = time.ANSIC
|
||||
gOpts.infotimefmtnew = "Jan _2 15:04"
|
||||
gOpts.infotimefmtold = "Jan _2 2006"
|
||||
gOpts.truncatechar = "~"
|
||||
gOpts.truncatepct = 100
|
||||
gOpts.ratios = []int{1, 2, 3}
|
||||
gOpts.hiddenfiles = gDefaultHiddenFiles
|
||||
gOpts.history = true
|
||||
gOpts.info = nil
|
||||
gOpts.rulerfmt = " %a| %p| \033[7;31m %m \033[0m| \033[7;33m %c \033[0m| \033[7;35m %s \033[0m| \033[7;36m %v \033[0m| \033[7;34m %f \033[0m| %i/%t"
|
||||
gOpts.preserve = []string{"mode"}
|
||||
gOpts.shellopts = nil
|
||||
gOpts.tempmarks = "'"
|
||||
gOpts.numberfmt = "\033[33m"
|
||||
gOpts.tagfmt = "\033[31m"
|
||||
|
||||
// normal and visual mode
|
||||
// Normal and Visual mode
|
||||
keys := map[string]expr{
|
||||
"k": &callExpr{"up", nil, 1},
|
||||
"<up>": &callExpr{"up", nil, 1},
|
||||
@@ -344,25 +354,26 @@ func init() {
|
||||
"ss": &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1},
|
||||
"st": &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}, 1},
|
||||
"sa": &listExpr{[]expr{&setExpr{"sortby", "atime"}, &setExpr{"info", "atime"}}, 1},
|
||||
"sb": &listExpr{[]expr{&setExpr{"sortby", "btime"}, &setExpr{"info", "btime"}}, 1},
|
||||
"sc": &listExpr{[]expr{&setExpr{"sortby", "ctime"}, &setExpr{"info", "ctime"}}, 1},
|
||||
"se": &listExpr{[]expr{&setExpr{"sortby", "ext"}, &setExpr{"info", ""}}, 1},
|
||||
"gh": &callExpr{"cd", []string{"~"}, 1},
|
||||
}
|
||||
|
||||
// insert bindings that apply to both normal & visual mode first
|
||||
// insert bindings that apply to both Normal & Visual mode first
|
||||
gOpts.nkeys = maps.Clone(keys)
|
||||
// now add normal mode specific ones
|
||||
// now add Normal mode specific ones
|
||||
gOpts.nkeys["<space>"] = &listExpr{[]expr{&callExpr{"toggle", nil, 1}, &callExpr{"down", nil, 1}}, 1}
|
||||
gOpts.nkeys["V"] = &callExpr{"visual", nil, 1}
|
||||
gOpts.nkeys["v"] = &callExpr{"invert", nil, 1}
|
||||
|
||||
// now do the same for visual mode
|
||||
// now do the same for Visual mode
|
||||
gOpts.vkeys = maps.Clone(keys)
|
||||
gOpts.vkeys["<esc>"] = &callExpr{"visual-discard", nil, 1}
|
||||
gOpts.vkeys["V"] = &callExpr{"visual-accept", nil, 1}
|
||||
gOpts.vkeys["o"] = &callExpr{"visual-change", nil, 1}
|
||||
|
||||
// command line mode bindings can be assigned directly
|
||||
// Command-line mode bindings can be assigned directly
|
||||
gOpts.cmdkeys = map[string]expr{
|
||||
"<space>": &callExpr{"cmd-insert", []string{" "}, 1},
|
||||
"<esc>": &callExpr{"cmd-escape", nil, 1},
|
||||
@@ -405,14 +416,14 @@ func init() {
|
||||
gOpts.cmds = make(map[string]expr)
|
||||
gOpts.user = make(map[string]string)
|
||||
|
||||
gLocalOpts.sortby = make(map[string]sortMethod)
|
||||
gLocalOpts.dircounts = make(map[string]bool)
|
||||
gLocalOpts.dirfirst = make(map[string]bool)
|
||||
gLocalOpts.dironly = make(map[string]bool)
|
||||
gLocalOpts.hidden = make(map[string]bool)
|
||||
gLocalOpts.reverse = make(map[string]bool)
|
||||
gLocalOpts.info = make(map[string][]string)
|
||||
gLocalOpts.locale = make(map[string]string)
|
||||
gLocalOpts.reverse = make(map[string]bool)
|
||||
gLocalOpts.sortby = make(map[string]sortMethod)
|
||||
|
||||
setDefaults()
|
||||
}
|
||||
@@ -229,3 +229,31 @@ func errCrossDevice(err error) bool {
|
||||
func quoteString(s string) string {
|
||||
return s
|
||||
}
|
||||
|
||||
func shellEscape(s string) string {
|
||||
buf := make([]rune, 0, len(s))
|
||||
for _, r := range s {
|
||||
if strings.ContainsRune(" !\"$&'()*,:;<=>?@[\\]^`{|}", r) {
|
||||
buf = append(buf, '\\')
|
||||
}
|
||||
buf = append(buf, r)
|
||||
}
|
||||
return string(buf)
|
||||
}
|
||||
|
||||
func shellUnescape(s string) string {
|
||||
esc := false
|
||||
buf := make([]rune, 0, len(s))
|
||||
for _, r := range s {
|
||||
if r == '\\' && !esc {
|
||||
esc = true
|
||||
continue
|
||||
}
|
||||
esc = false
|
||||
buf = append(buf, r)
|
||||
}
|
||||
if esc {
|
||||
buf = append(buf, '\\')
|
||||
}
|
||||
return string(buf)
|
||||
}
|
||||
+19
-4
@@ -74,23 +74,25 @@ func init() {
|
||||
Username: username,
|
||||
}
|
||||
|
||||
data := cmp.Or(os.Getenv("LF_CONFIG_HOME"), os.Getenv("LOCALAPPDATA"))
|
||||
config := cmp.Or(os.Getenv("LF_CONFIG_HOME"), os.Getenv("APPDATA"))
|
||||
|
||||
gConfigPaths = []string{
|
||||
filepath.Join(os.Getenv("ProgramData"), "lf", "lfrc"),
|
||||
filepath.Join(data, "lf", "lfrc"),
|
||||
filepath.Join(config, "lf", "lfrc"),
|
||||
}
|
||||
|
||||
gColorsPaths = []string{
|
||||
filepath.Join(os.Getenv("ProgramData"), "lf", "colors"),
|
||||
filepath.Join(data, "lf", "colors"),
|
||||
filepath.Join(config, "lf", "colors"),
|
||||
}
|
||||
|
||||
gIconsPaths = []string{
|
||||
filepath.Join(os.Getenv("ProgramData"), "lf", "icons"),
|
||||
filepath.Join(data, "lf", "icons"),
|
||||
filepath.Join(config, "lf", "icons"),
|
||||
}
|
||||
|
||||
data := cmp.Or(os.Getenv("LF_DATA_HOME"), os.Getenv("LOCALAPPDATA"))
|
||||
|
||||
gFilesPath = filepath.Join(data, "lf", "files")
|
||||
gMarksPath = filepath.Join(data, "lf", "marks")
|
||||
gTagsPath = filepath.Join(data, "lf", "tags")
|
||||
@@ -221,3 +223,16 @@ func quoteString(s string) string {
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func shellEscape(s string) string {
|
||||
for _, r := range s {
|
||||
if strings.ContainsRune(" !%&'()+,;=[]^`{}~", r) {
|
||||
return fmt.Sprintf(`"%s"`, s)
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func shellUnescape(s string) string {
|
||||
return strings.ReplaceAll(s, `"`, "")
|
||||
}
|
||||
@@ -301,13 +301,13 @@ func fileInfo(f *file, d *dir, userWidth int, groupWidth int, customWidth int) (
|
||||
if f.IsDir() && getDirCounts(d.path) {
|
||||
switch {
|
||||
case f.dirCount < -1:
|
||||
info.WriteString(" !")
|
||||
info.WriteString(" !")
|
||||
case f.dirCount < 0:
|
||||
info.WriteString(" ?")
|
||||
case f.dirCount < 1000:
|
||||
fmt.Fprintf(&info, " %4d", f.dirCount)
|
||||
info.WriteString(" ?")
|
||||
case f.dirCount < 10000:
|
||||
fmt.Fprintf(&info, " %5d", f.dirCount)
|
||||
default:
|
||||
info.WriteString(" 999+")
|
||||
info.WriteString(" 9999+")
|
||||
}
|
||||
continue
|
||||
}
|
||||
@@ -316,13 +316,15 @@ func fileInfo(f *file, d *dir, userWidth int, groupWidth int, customWidth int) (
|
||||
if f.IsDir() && f.dirSize < 0 {
|
||||
sz = "-"
|
||||
} else {
|
||||
sz = humanize(f.TotalSize())
|
||||
sz = humanize(uint64(f.TotalSize()))
|
||||
}
|
||||
fmt.Fprintf(&info, " %4s", sz)
|
||||
fmt.Fprintf(&info, " %5s", sz)
|
||||
case "time":
|
||||
fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.ModTime()))
|
||||
case "atime":
|
||||
fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.accessTime))
|
||||
case "btime":
|
||||
fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.birthTime))
|
||||
case "ctime":
|
||||
fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.changeTime))
|
||||
case "perm":
|
||||
@@ -347,7 +349,7 @@ func fileInfo(f *file, d *dir, userWidth int, groupWidth int, customWidth int) (
|
||||
|
||||
type dirContext struct {
|
||||
selections map[string]int
|
||||
saves map[string]bool
|
||||
clipboard clipboard
|
||||
tags map[string]string
|
||||
}
|
||||
|
||||
@@ -457,8 +459,8 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
|
||||
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.visualfmt), " ")
|
||||
} else if _, ok := context.selections[path]; ok {
|
||||
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.selectfmt), " ")
|
||||
} else if cp, ok := context.saves[path]; ok {
|
||||
if cp {
|
||||
} else if slices.Contains(context.clipboard.paths, path) {
|
||||
if context.clipboard.mode == clipboardCopy {
|
||||
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.copyfmt), " ")
|
||||
} else {
|
||||
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.cutfmt), " ")
|
||||
@@ -473,7 +475,7 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
|
||||
}
|
||||
|
||||
tag := " "
|
||||
if val, ok := context.tags[evalSymlinks(path)]; ok && len(val) > 0 {
|
||||
if val, ok := context.tags[path]; ok && len(val) > 0 {
|
||||
tag = val
|
||||
}
|
||||
|
||||
@@ -656,12 +658,12 @@ type ui struct {
|
||||
cmdAccLeft []rune
|
||||
cmdAccRight []rune
|
||||
cmdYankBuf []rune
|
||||
cmdTmp []rune
|
||||
keyAcc []rune
|
||||
keyCount []rune
|
||||
styles styleMap
|
||||
icons iconMap
|
||||
currentFile string
|
||||
pasteEvent bool
|
||||
}
|
||||
|
||||
func newUI(screen tcell.Screen) *ui {
|
||||
@@ -835,8 +837,8 @@ func (ui *ui) loadFileInfo(nav *nav) {
|
||||
replace("%c", linkCount(curr))
|
||||
replace("%u", userName(curr))
|
||||
replace("%g", groupName(curr))
|
||||
replace("%s", humanize(curr.Size()))
|
||||
replace("%S", fmt.Sprintf("%4s", humanize(curr.Size())))
|
||||
replace("%s", humanize(uint64(curr.Size())))
|
||||
replace("%S", fmt.Sprintf("%5s", humanize(uint64(curr.Size()))))
|
||||
replace("%t", curr.ModTime().Format(gOpts.timefmt))
|
||||
replace("%l", curr.linkTarget)
|
||||
|
||||
@@ -950,12 +952,10 @@ func (ui *ui) drawRuler(nav *nav) {
|
||||
|
||||
copy := 0
|
||||
move := 0
|
||||
for _, cp := range nav.saves {
|
||||
if cp {
|
||||
copy++
|
||||
} else {
|
||||
move++
|
||||
}
|
||||
if nav.clipboard.mode == clipboardCopy {
|
||||
copy = len(nav.clipboard.paths)
|
||||
} else {
|
||||
move = len(nav.clipboard.paths)
|
||||
}
|
||||
|
||||
currSelections := nav.currSelections()
|
||||
@@ -963,8 +963,12 @@ func (ui *ui) drawRuler(nav *nav) {
|
||||
|
||||
progress := []string{}
|
||||
|
||||
if nav.copyTotal > 0 {
|
||||
progress = append(progress, fmt.Sprintf("[%d%%]", nav.copyBytes*100/nav.copyTotal))
|
||||
if nav.copyJobs > 0 {
|
||||
if nav.copyTotal == 0 {
|
||||
progress = append(progress, fmt.Sprintf("[0%%]"))
|
||||
} else {
|
||||
progress = append(progress, fmt.Sprintf("[%d%%]", nav.copyBytes*100/nav.copyTotal))
|
||||
}
|
||||
}
|
||||
|
||||
if nav.moveTotal > 0 {
|
||||
@@ -1077,7 +1081,7 @@ func (ui *ui) dirOfWin(nav *nav, wind int) *dir {
|
||||
|
||||
func (ui *ui) draw(nav *nav) {
|
||||
st := tcell.StyleDefault
|
||||
context := dirContext{selections: nav.selections, saves: nav.saves, tags: nav.tags}
|
||||
context := dirContext{selections: nav.selections, clipboard: nav.clipboard, tags: nav.tags}
|
||||
|
||||
ui.screen.Clear()
|
||||
|
||||
@@ -1396,6 +1400,10 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
||||
|
||||
switch tev := ev.(type) {
|
||||
case *tcell.EventKey:
|
||||
if ui.pasteEvent {
|
||||
return nil
|
||||
}
|
||||
|
||||
// KeyRune is a regular character
|
||||
if tev.Key() == tcell.KeyRune {
|
||||
switch {
|
||||
@@ -1575,6 +1583,12 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
||||
} else {
|
||||
return &callExpr{"on-focus-lost", nil, 1}
|
||||
}
|
||||
case *tcell.EventPaste:
|
||||
if tev.Start() {
|
||||
ui.pasteEvent = true
|
||||
} else if tev.End() {
|
||||
ui.pasteEvent = false
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1655,7 +1669,7 @@ func anyKey() {
|
||||
os.Stdin.Read(b)
|
||||
}
|
||||
|
||||
func listMatches(screen tcell.Screen, matches []string, selectedInd int) string {
|
||||
func listMatches(screen tcell.Screen, matches []compMatch, selectedInd int) string {
|
||||
mlen := len(matches)
|
||||
if mlen < 2 {
|
||||
return ""
|
||||
@@ -1666,7 +1680,7 @@ func listMatches(screen tcell.Screen, matches []string, selectedInd int) string
|
||||
wtot, _ := screen.Size()
|
||||
wcol := 0
|
||||
for _, m := range matches {
|
||||
wcol = max(wcol, len(m))
|
||||
wcol = max(wcol, runeSliceWidth([]rune(m.name)))
|
||||
}
|
||||
wcol += gOpts.tabstop - wcol%gOpts.tabstop
|
||||
ncol := max(wtot/wcol, 1)
|
||||
@@ -1675,12 +1689,13 @@ func listMatches(screen tcell.Screen, matches []string, selectedInd int) string
|
||||
|
||||
for i := 0; i < mlen; {
|
||||
for j := 0; j < ncol && i < mlen; i, j = i+1, j+1 {
|
||||
target := matches[i]
|
||||
name := matches[i].name
|
||||
w := runeSliceWidth([]rune(name))
|
||||
|
||||
if selectedInd == i {
|
||||
fmt.Fprintf(&b, "\033[7m%s\033[0m%*s", target, wcol-len(target), "")
|
||||
if i == selectedInd {
|
||||
fmt.Fprintf(&b, "\033[7m%s\033[0m%*s", name, wcol-w, "")
|
||||
} else {
|
||||
fmt.Fprintf(&b, "%s%*s", target, wcol-len(target), "")
|
||||
fmt.Fprintf(&b, "%s%*s", name, wcol-w, "")
|
||||
}
|
||||
}
|
||||
b.WriteByte('\n')
|
||||
|
||||
Reference in new issue
Block a user