Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d205f05e3 | ||
|
|
1cb9e9d14a | ||
|
|
0df0c0f5ff | ||
|
|
3d5a418c6c | ||
|
|
841cc3da06 | ||
|
|
1878faa942 | ||
|
|
3fdd991040 | ||
|
|
9cad75867d | ||
|
|
970b31852d | ||
|
|
ffe4c97560 | ||
|
|
6718a36334 | ||
|
|
ad6fa3fa73 | ||
|
|
9b1f8386fa | ||
|
|
26259f777f | ||
|
|
9dc4e6b431 | ||
|
|
0e66d02746 | ||
|
|
938e02e126 | ||
|
|
2a3292560d | ||
|
|
f9813744f7 | ||
|
|
b087bf7d80 | ||
|
|
c42942d53e | ||
|
|
74b2954e6a | ||
|
|
7797ad695f | ||
|
|
b3c652c4d4 | ||
|
|
3b56a9fa64 | ||
|
|
5b1ec5b6fc | ||
|
|
ec42237563 | ||
|
|
c25647d364 | ||
|
|
4f0a5d6211 | ||
|
|
7595e05957 | ||
|
|
2745c1ab22 | ||
|
|
2375b651ce | ||
|
|
b34ca155ab | ||
|
|
df0b62af30 | ||
|
|
2095efa661 | ||
|
|
8bfa3a6d34 | ||
|
|
085717bc9f | ||
|
|
68a29c9284 | ||
|
|
f0dddccb04 | ||
|
|
23bef4dc0b | ||
|
|
4fefcf7aac | ||
|
|
0b5749f0ef | ||
|
|
dec026e2aa | ||
|
|
ce3dbea2ae | ||
|
|
670343a23f | ||
|
|
0b51987044 | ||
|
|
d9a6ca5766 | ||
|
|
b5b7b84568 | ||
|
|
fa2fa19ab0 | ||
|
|
0f48f36b0f | ||
|
|
f5a0e655a1 | ||
|
|
4408f37a9b | ||
|
|
1b1628c378 | ||
|
|
dda8e88aaf | ||
|
|
3f63bc980f | ||
|
|
4079aead14 | ||
|
|
f96a070ff0 | ||
|
|
78413a6c9e | ||
|
|
6cd51210e3 | ||
|
|
440c258287 | ||
|
|
4de690db5e | ||
|
|
f066df674a | ||
|
|
382095bfb5 | ||
|
|
0d4b545390 | ||
|
|
1c56620f57 | ||
|
|
e9cb31f2eb | ||
|
|
505c4ef6c0 | ||
|
|
efde1a2ef3 | ||
|
|
0f8359f301 | ||
|
|
b258d8fbf0 | ||
|
|
c2224cb97a | ||
|
|
534710dcc7 | ||
|
|
b819d90be2 | ||
|
|
26dc2f1ebd | ||
|
|
ddea7bff1b | ||
|
|
b1f3dbe5ed | ||
|
|
e9faf966a0 | ||
|
|
67038762cc | ||
|
|
38ddfea9a0 | ||
|
|
adaf464fea | ||
|
|
e350e0b735 | ||
|
|
73030b5607 | ||
|
|
8d7b192340 | ||
|
|
791341990c | ||
|
|
2d3cc97f78 | ||
|
|
0c72034322 | ||
|
|
9b9082a10b | ||
|
|
aaf5bbb22b | ||
|
|
12e99fdb64 | ||
|
|
a6375d56c6 | ||
|
|
a018257d50 | ||
|
|
6cabb0e8e4 | ||
|
|
ce12116418 | ||
|
|
63815aaa75 | ||
|
|
647fa469fb | ||
|
|
f507b618c9 | ||
|
|
5b108037a3 | ||
|
|
21d256d7da | ||
|
|
47634f22bd | ||
|
|
448d7b7631 | ||
|
|
6e6682fc1f | ||
|
|
d26eb0108a | ||
|
|
ac016fee16 | ||
|
|
702d67575e | ||
|
|
1e10e95f4d | ||
|
|
c9d28f6e9d | ||
|
|
a1edda1f70 | ||
|
|
ddcd308614 | ||
|
|
951795c789 | ||
|
|
c19cc15079 | ||
|
|
4b076d199b | ||
|
|
d2136df538 | ||
|
|
44c6aead23 | ||
|
|
43c2683ca8 | ||
|
|
d89afb8c7d | ||
|
|
853bcc524b | ||
|
|
055ce47224 | ||
|
|
8ee8592b91 | ||
|
|
0c02239b17 | ||
|
|
cf996263bb | ||
|
|
ab54329570 | ||
|
|
ac32468629 | ||
|
|
d654f09885 | ||
|
|
8374080815 | ||
|
|
8bbcbdd0ea | ||
|
|
2007ae51a1 | ||
|
|
8a14749154 | ||
|
|
b401318046 | ||
|
|
6af25565d4 | ||
|
|
ce32bc67b9 | ||
|
|
27c71f8210 | ||
|
|
43610eaf40 | ||
|
|
c88b8eaa65 | ||
|
|
f8399eb6e0 | ||
|
|
488294588e | ||
|
|
27cbf9403c | ||
|
|
12ce649681 | ||
|
|
e1ab72516d | ||
|
|
f13325f78d | ||
|
|
a51462dcb9 | ||
|
|
075caac3a9 | ||
|
|
2a4adb323f | ||
|
|
d8b7df87cb | ||
|
|
ec9bdad90d | ||
|
|
03b7321938 | ||
|
|
e9571ab1d7 | ||
|
|
31f4a4e16f | ||
|
|
cbdae8e7f3 | ||
|
|
ff0ca39a4c | ||
|
|
6abce04855 | ||
|
|
7bd5756330 | ||
|
|
9698ecddf1 | ||
|
|
ade9e986e5 | ||
|
|
ae678f7102 | ||
|
|
f6e7d0fd0e | ||
|
|
dcd2ea8164 | ||
|
|
f52fffbff6 | ||
|
|
b3cb2dc2b4 | ||
|
|
7c23c27c59 | ||
|
|
838fee6f13 | ||
|
|
b420dee145 | ||
|
|
9ab2c2ec6f | ||
|
|
1a3bcb28a1 | ||
|
|
154d7182c0 | ||
|
|
b4af8f47c8 | ||
|
|
beedda2d67 | ||
|
|
dddf437c42 |
No files matched your search
+11
-11
@@ -19,9 +19,9 @@ jobs:
|
|||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.18
|
go-version: "1.23"
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: go build -v ./...
|
run: go build -v ./...
|
||||||
@@ -29,9 +29,9 @@ jobs:
|
|||||||
- name: Test
|
- name: Test
|
||||||
run: go test -v ./...
|
run: go test -v ./...
|
||||||
|
|
||||||
- uses: dominikh/staticcheck-action@v1.3.0
|
- uses: dominikh/staticcheck-action@v1.3.1
|
||||||
with:
|
with:
|
||||||
version: "2022.1.3"
|
version: "2024.1.1"
|
||||||
install-go: false
|
install-go: false
|
||||||
|
|
||||||
cross-compile:
|
cross-compile:
|
||||||
@@ -42,14 +42,14 @@ jobs:
|
|||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.18
|
go-version: "1.23"
|
||||||
|
|
||||||
- name: Cross-compile on all supported platforms
|
- name: Cross-compile on all supported platforms
|
||||||
run: gen/xbuild.sh
|
run: gen/xbuild.sh
|
||||||
|
|
||||||
generate:
|
formatting:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -57,10 +57,10 @@ jobs:
|
|||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.19
|
go-version: "1.23"
|
||||||
|
|
||||||
- name: Test `go fmt && go generate` on Go 1.19 creates no diffs
|
- name: Test `go fmt` creates no diffs
|
||||||
run: go fmt && go generate && git diff --exit-code
|
run: go fmt && git diff --exit-code
|
||||||
|
|
||||||
@@ -13,15 +13,15 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.18
|
go-version: "1.23"
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: gen/xbuild.sh
|
run: gen/xbuild.sh
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
files: dist/*
|
files: dist/*
|
||||||
env:
|
env:
|
||||||
|
|||||||
+5
-17
@@ -15,7 +15,7 @@ Global variable names are prefixed with `g` as in `gFooBar`.
|
|||||||
Exceptions are variables holding values of environmental variables which are prefixed with `env` as in `envFooBar` and regular expressions which are prefixed with `re` as in `reFooBar` when they are global.
|
Exceptions are variables holding values of environmental variables which are prefixed with `env` as in `envFooBar` and regular expressions which are prefixed with `re` as in `reFooBar` when they are global.
|
||||||
- Type and function names are small case as in `fooBar` since we don't use exporting.
|
- Type and function names are small case as in `fooBar` since we don't use exporting.
|
||||||
- For file name variables, `name`, `fname`, or `filename` should refer to the base name of the file as in `baz.txt`, and `path`, `fpath`, or `filepath` should refer to the full path of the file as in `/foo/bar/baz.txt`.
|
- For file name variables, `name`, `fname`, or `filename` should refer to the base name of the file as in `baz.txt`, and `path`, `fpath`, or `filepath` should refer to the full path of the file as in `/foo/bar/baz.txt`.
|
||||||
- Run `go fmt && go generate` using Go 1.19+. On earlier versions of Go, `go generate` creates needless whitespace differences.
|
- Run `go fmt` to ensure that files are formatted correctly.
|
||||||
|
|
||||||
Use the surrounding code as reference when in doubt as usual.
|
Use the surrounding code as reference when in doubt as usual.
|
||||||
|
|
||||||
@@ -27,9 +27,8 @@ Adding a new option usually requires the following steps:
|
|||||||
- Add default option value to `init` function in `opts.go`
|
- Add default option value to `init` function in `opts.go`
|
||||||
- Add option evaluation logic to `setExpr.eval` in `eval.go`
|
- Add option evaluation logic to `setExpr.eval` in `eval.go`
|
||||||
- Implement the option somewhere in the code
|
- Implement the option somewhere in the code
|
||||||
- Add option name to `gOptWords` in `complete.go` for tab completion
|
- Add option name and its default value to `Quick Reference` and `Options` sections in `doc.md`
|
||||||
- Add option name and its default value to `Quick Reference` and `Options` sections in `doc.go`
|
- Run `gen/doc-with-docker.sh` to update the documentation
|
||||||
- Run `go generate` to update the documentation
|
|
||||||
- Commit your changes and send a pull request
|
- Commit your changes and send a pull request
|
||||||
|
|
||||||
## Adding a new builtin command
|
## Adding a new builtin command
|
||||||
@@ -40,8 +39,8 @@ Adding a new command usually requires the following steps:
|
|||||||
- Add command evaluation logic to `callExpr.eval` in `eval.go`
|
- Add command evaluation logic to `callExpr.eval` in `eval.go`
|
||||||
- Implement the command somewhere in the code
|
- Implement the command somewhere in the code
|
||||||
- Add command name to `gCmdWords` in `complete.go` for tab completion
|
- Add command name to `gCmdWords` in `complete.go` for tab completion
|
||||||
- Add command name to `Quick Reference` and `Commands` sections in `doc.go`
|
- Add command name to `Quick Reference` and `Commands` sections in `doc.md`
|
||||||
- Run `go generate` to update the documentation
|
- Optionally, run `gen/doc-with-docker.sh` to update the documentation
|
||||||
- Commit your changes and send a pull request
|
- Commit your changes and send a pull request
|
||||||
|
|
||||||
## Platform specific code
|
## Platform specific code
|
||||||
@@ -49,14 +48,3 @@ Adding a new command usually requires the following steps:
|
|||||||
There are two files named `os.go` and `os_windows.go` for unix and windows specific code respectively.
|
There are two files named `os.go` and `os_windows.go` for unix and windows specific code respectively.
|
||||||
If you add something to either of these files but not the other, you probably break the build for the other platform.
|
If you add something to either of these files but not the other, you probably break the build for the other platform.
|
||||||
If your addition works the same in both platforms, your addition probably belongs to `main.go` instead.
|
If your addition works the same in both platforms, your addition probably belongs to `main.go` instead.
|
||||||
|
|
||||||
## Make changes to the documentation
|
|
||||||
|
|
||||||
There are three files that contain the documentation in various formats:
|
|
||||||
|
|
||||||
- `doc.go` is the source of the [online documentation](https://pkg.go.dev/github.com/gokcehan/lf)
|
|
||||||
- `docstring.go` is used when running `lf -doc`
|
|
||||||
- `lf.1` is a man page which is commonly available on Unix-like operating systems (`man lf`)
|
|
||||||
|
|
||||||
You should only make changes to `doc.go`, the other files are automatically generated **and should not be edited manually**.
|
|
||||||
Run `go fmt && go generate` to ensure that the code is formatted and files are generated correctly.
|
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
# LF
|
# LF
|
||||||
|
|
||||||
[Google Groups](https://groups.google.com/forum/#!forum/lf-fm)
|
[Google Groups](https://groups.google.com/forum/#!forum/lf-fm)
|
||||||
|
| [Doc](doc.md)
|
||||||
| [Wiki](https://github.com/gokcehan/lf/wiki)
|
| [Wiki](https://github.com/gokcehan/lf/wiki)
|
||||||
| [#lf](https://web.libera.chat/#lf) (on Libera.Chat)
|
| [#lf](https://web.libera.chat/#lf) (on Libera.Chat)
|
||||||
| [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org) (with IRC bridge)
|
| [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org) (with IRC bridge)
|
||||||
|
|
||||||
[](https://github.com/gokcehan/lf/actions/workflows/go.yml)
|
[](https://github.com/gokcehan/lf/actions/workflows/go.yml)
|
||||||
[](https://goreportcard.com/report/github.com/gokcehan/lf)
|
[](https://goreportcard.com/report/github.com/gokcehan/lf)
|
||||||
[](https://pkg.go.dev/github.com/gokcehan/lf)
|
|
||||||
|
|
||||||
`lf` (as in "list files") is a terminal file manager written in Go with a heavy inspiration from ranger file manager.
|
`lf` (as in "list files") is a terminal file manager written in Go with a heavy inspiration from [`ranger`](https://github.com/ranger/ranger) file manager.
|
||||||
See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information and [tutorial](https://github.com/gokcehan/lf/wiki/Tutorial) for a gentle introduction with screencasts.
|
See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information and [tutorial](https://github.com/gokcehan/lf/wiki/Tutorial) for a gentle introduction with screencasts.
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information and [tut
|
|||||||
- Server/client architecture and remote commands to manage multiple instances
|
- Server/client architecture and remote commands to manage multiple instances
|
||||||
- Extendable and configurable with shell commands
|
- Extendable and configurable with shell commands
|
||||||
- Customizable keybindings (vi and readline defaults)
|
- Customizable keybindings (vi and readline defaults)
|
||||||
- A reasonable set of other features (see the [documentation](https://pkg.go.dev/github.com/gokcehan/lf))
|
- A reasonable set of other features (see the [documentation](doc.md))
|
||||||
|
|
||||||
## Non-Features
|
## Non-Features
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ After the installation `lf` command should start the application in the current
|
|||||||
|
|
||||||
Run `lf -help` to see command line options.
|
Run `lf -help` to see command line options.
|
||||||
|
|
||||||
Run `lf -doc` to see the [documentation](https://pkg.go.dev/github.com/gokcehan/lf).
|
Run `lf -doc` to see the [documentation](doc.md).
|
||||||
|
|
||||||
See [etc](etc) directory to integrate `lf` to your shell and/or editor.
|
See [etc](etc) directory to integrate `lf` to your shell and/or editor.
|
||||||
Example configuration files along with example colors and icons files can also be found in this directory.
|
Example configuration files along with example colors and icons files can also be found in this directory.
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ type app struct {
|
|||||||
menuComps []string
|
menuComps []string
|
||||||
menuCompInd int
|
menuCompInd int
|
||||||
selectionOut []string
|
selectionOut []string
|
||||||
|
watch *watch
|
||||||
|
quitting bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newApp(ui *ui, nav *nav) *app {
|
func newApp(ui *ui, nav *nav) *app {
|
||||||
@@ -44,25 +46,37 @@ func newApp(ui *ui, nav *nav) *app {
|
|||||||
nav: nav,
|
nav: nav,
|
||||||
ticker: new(time.Ticker),
|
ticker: new(time.Ticker),
|
||||||
quitChan: quitChan,
|
quitChan: quitChan,
|
||||||
|
watch: newWatch(nav.dirChan, nav.fileChan, nav.delChan),
|
||||||
}
|
}
|
||||||
|
|
||||||
sigChan := make(chan os.Signal, 1)
|
sigChan := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigChan, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM)
|
signal.Notify(sigChan, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM)
|
||||||
go func() {
|
go func() {
|
||||||
|
for {
|
||||||
switch <-sigChan {
|
switch <-sigChan {
|
||||||
case os.Interrupt:
|
case os.Interrupt:
|
||||||
return
|
|
||||||
case syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM:
|
case syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM:
|
||||||
app.quit()
|
app.quit()
|
||||||
os.Exit(3)
|
os.Exit(3)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *app) quit() {
|
func (app *app) quit() {
|
||||||
|
// Using synchronous shell commands for `on-quit` can cause this to be
|
||||||
|
// called again, so a guard variable is introduced here to prevent an
|
||||||
|
// infinite loop.
|
||||||
|
if app.quitting {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.quitting = true
|
||||||
|
|
||||||
|
onQuit(app)
|
||||||
|
|
||||||
if gOpts.history {
|
if gOpts.history {
|
||||||
if err := app.writeHistory(); err != nil {
|
if err := app.writeHistory(); err != nil {
|
||||||
log.Printf("writing history file: %s", err)
|
log.Printf("writing history file: %s", err)
|
||||||
@@ -164,6 +178,7 @@ func saveFiles(list []string, cp bool) error {
|
|||||||
fmt.Fprintln(files, f)
|
fmt.Fprintln(files, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
files.Sync()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +243,7 @@ func (app *app) writeHistory() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, cmd := range app.cmdHistory {
|
for _, cmd := range app.cmdHistory {
|
||||||
_, err = f.WriteString(fmt.Sprintf("%s %s\n", cmd.prefix, cmd.value))
|
_, err = fmt.Fprintf(f, "%s %s\n", cmd.prefix, cmd.value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("writing history file: %s", err)
|
return fmt.Errorf("writing history file: %s", err)
|
||||||
}
|
}
|
||||||
@@ -243,7 +258,6 @@ func (app *app) writeHistory() error {
|
|||||||
// separate goroutines and sent here for update.
|
// separate goroutines and sent here for update.
|
||||||
func (app *app) loop() {
|
func (app *app) loop() {
|
||||||
go app.nav.previewLoop(app.ui)
|
go app.nav.previewLoop(app.ui)
|
||||||
go app.nav.dirPreviewLoop(app.ui)
|
|
||||||
|
|
||||||
var serverChan <-chan expr
|
var serverChan <-chan expr
|
||||||
if !gSingleMode {
|
if !gSingleMode {
|
||||||
@@ -318,22 +332,17 @@ func (app *app) loop() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if cmd, ok := gOpts.cmds["on-quit"]; ok {
|
|
||||||
cmd.eval(app, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
app.quit()
|
app.quit()
|
||||||
|
|
||||||
app.nav.previewChan <- ""
|
app.nav.previewChan <- ""
|
||||||
app.nav.dirPreviewChan <- nil
|
|
||||||
|
|
||||||
log.Print("bye!")
|
log.Print("bye!")
|
||||||
|
|
||||||
return
|
return
|
||||||
case n := <-app.nav.copyBytesChan:
|
case n := <-app.nav.copyBytesChan:
|
||||||
app.nav.copyBytes += n
|
app.nav.copyBytes += n
|
||||||
// n is usually 4096B so update roughly per 4096B x 1024 = 4MB copied
|
// n is usually 32*1024B (default io.Copy() buffer) so update roughly per 32KB x 128 = 4MB copied
|
||||||
if app.nav.copyUpdate++; app.nav.copyUpdate >= 1024 {
|
if app.nav.copyUpdate++; app.nav.copyUpdate >= 128 {
|
||||||
app.nav.copyUpdate = 0
|
app.nav.copyUpdate = 0
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
}
|
}
|
||||||
@@ -377,20 +386,24 @@ func (app *app) loop() {
|
|||||||
}
|
}
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
case d := <-app.nav.dirChan:
|
case d := <-app.nav.dirChan:
|
||||||
|
|
||||||
app.nav.checkDir(d)
|
|
||||||
|
|
||||||
if gOpts.dircache {
|
if gOpts.dircache {
|
||||||
prev, ok := app.nav.dirCache[d.path]
|
prev, ok := app.nav.dirCache[d.path]
|
||||||
if ok {
|
if ok {
|
||||||
d.ind = prev.ind
|
d.ind = prev.ind
|
||||||
d.pos = prev.pos
|
d.pos = prev.pos
|
||||||
|
d.filter = prev.filter
|
||||||
|
d.sort()
|
||||||
d.sel(prev.name(), app.nav.height)
|
d.sel(prev.name(), app.nav.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.nav.dirCache[d.path] = d
|
app.nav.dirCache[d.path] = d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var oldCurrPath string
|
||||||
|
if curr, err := app.nav.currFile(); err == nil {
|
||||||
|
oldCurrPath = curr.path
|
||||||
|
}
|
||||||
|
|
||||||
for i := range app.nav.dirs {
|
for i := range app.nav.dirs {
|
||||||
if app.nav.dirs[i].path == d.path {
|
if app.nav.dirs[i].path == d.path {
|
||||||
app.nav.dirs[i] = d
|
app.nav.dirs[i] = d
|
||||||
@@ -401,9 +414,9 @@ func (app *app) loop() {
|
|||||||
|
|
||||||
curr, err := app.nav.currFile()
|
curr, err := app.nav.currFile()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if d.path == app.nav.currDir().path {
|
if curr.path != oldCurrPath {
|
||||||
app.ui.loadFile(app, true)
|
app.ui.loadFile(app, true)
|
||||||
if app.ui.msg == "" {
|
if app.ui.msgIsStat {
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -412,10 +425,10 @@ func (app *app) loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.watchDir(d)
|
||||||
|
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
case r := <-app.nav.regChan:
|
case r := <-app.nav.regChan:
|
||||||
app.nav.checkReg(r)
|
|
||||||
|
|
||||||
app.nav.regCache[r.path] = r
|
app.nav.regCache[r.path] = r
|
||||||
|
|
||||||
curr, err := app.nav.currFile()
|
curr, err := app.nav.currFile()
|
||||||
@@ -426,6 +439,37 @@ func (app *app) loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
|
case f := <-app.nav.fileChan:
|
||||||
|
for _, dir := range app.nav.dirCache {
|
||||||
|
if dir.path != filepath.Dir(f.path) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range dir.allFiles {
|
||||||
|
if dir.allFiles[i].path == f.path {
|
||||||
|
dir.allFiles[i] = f
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
name := dir.name()
|
||||||
|
dir.sort()
|
||||||
|
dir.sel(name, app.nav.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
app.ui.loadFile(app, false)
|
||||||
|
if app.ui.msgIsStat {
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
|
app.ui.draw(app.nav)
|
||||||
|
case path := <-app.nav.delChan:
|
||||||
|
delete(app.nav.dirCache, path)
|
||||||
|
delete(app.nav.regCache, path)
|
||||||
|
|
||||||
|
delete(app.nav.selections, path)
|
||||||
|
if len(app.nav.selections) == 0 {
|
||||||
|
app.nav.selectionInd = 0
|
||||||
|
}
|
||||||
case ev := <-app.ui.evChan:
|
case ev := <-app.ui.evChan:
|
||||||
e := app.ui.readEvent(ev, app.nav)
|
e := app.ui.readEvent(ev, app.nav)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
@@ -455,7 +499,6 @@ func (app *app) loop() {
|
|||||||
case <-app.ticker.C:
|
case <-app.ticker.C:
|
||||||
app.nav.renew()
|
app.nav.renew()
|
||||||
app.ui.loadFile(app, false)
|
app.ui.loadFile(app, false)
|
||||||
app.ui.draw(app.nav)
|
|
||||||
case <-app.nav.previewTimer.C:
|
case <-app.nav.previewTimer.C:
|
||||||
app.nav.previewLoading = true
|
app.nav.previewLoading = true
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
@@ -465,7 +508,6 @@ func (app *app) loop() {
|
|||||||
|
|
||||||
func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
|
func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
|
||||||
app.nav.previewChan <- ""
|
app.nav.previewChan <- ""
|
||||||
app.nav.dirPreviewChan <- nil
|
|
||||||
|
|
||||||
if err := app.ui.suspend(); err != nil {
|
if err := app.ui.suspend(); err != nil {
|
||||||
log.Printf("suspend: %s", err)
|
log.Printf("suspend: %s", err)
|
||||||
@@ -498,14 +540,16 @@ func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
|
|||||||
func (app *app) runShell(s string, args []string, prefix string) {
|
func (app *app) runShell(s string, args []string, prefix string) {
|
||||||
app.nav.exportFiles()
|
app.nav.exportFiles()
|
||||||
app.ui.exportSizes()
|
app.ui.exportSizes()
|
||||||
|
app.ui.exportMode()
|
||||||
exportOpts()
|
exportOpts()
|
||||||
|
|
||||||
gState.mutex.Lock()
|
gState.mutex.Lock()
|
||||||
gState.data["maps"] = listBinds(gOpts.keys).String()
|
gState.data["maps"] = listBinds(gOpts.keys)
|
||||||
gState.data["cmaps"] = listBinds(gOpts.cmdkeys).String()
|
gState.data["cmaps"] = listBinds(gOpts.cmdkeys)
|
||||||
gState.data["cmds"] = listCmds().String()
|
gState.data["cmds"] = listCmds()
|
||||||
gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd).String()
|
gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd)
|
||||||
gState.data["history"] = listHistory(app.cmdHistory).String()
|
gState.data["history"] = listHistory(app.cmdHistory)
|
||||||
|
gState.data["files"] = listFilesInCurrDir(app.nav)
|
||||||
gState.mutex.Unlock()
|
gState.mutex.Unlock()
|
||||||
|
|
||||||
cmd := shellCommand(s, args)
|
cmd := shellCommand(s, args)
|
||||||
@@ -590,5 +634,19 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
app.ui.exprChan <- &callExpr{"load", nil, 1}
|
app.ui.exprChan <- &callExpr{"load", nil, 1}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *app) watchDir(dir *dir) {
|
||||||
|
if !gOpts.watch {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
app.watch.add(dir.path)
|
||||||
|
|
||||||
|
// ensure dircounts are updated for child directories
|
||||||
|
for _, file := range dir.allFiles {
|
||||||
|
if file.IsDir() {
|
||||||
|
app.watch.add(file.path)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,19 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() {
|
func run() {
|
||||||
|
if gLogPath != "" {
|
||||||
|
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to open log file: %s", err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
log.SetOutput(f)
|
||||||
|
} else {
|
||||||
|
log.SetOutput(io.Discard)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Print("hi!")
|
||||||
|
|
||||||
var screen tcell.Screen
|
var screen tcell.Screen
|
||||||
var err error
|
var err error
|
||||||
if screen, err = tcell.NewScreen(); err != nil {
|
if screen, err = tcell.NewScreen(); err != nil {
|
||||||
@@ -37,19 +50,6 @@ func run() {
|
|||||||
screen.EnableMouse()
|
screen.EnableMouse()
|
||||||
}
|
}
|
||||||
|
|
||||||
if gLogPath != "" {
|
|
||||||
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
log.SetOutput(f)
|
|
||||||
} else {
|
|
||||||
log.SetOutput(io.Discard)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Print("hi!")
|
|
||||||
|
|
||||||
ui := newUI(screen)
|
ui := newUI(screen)
|
||||||
nav := newNav(ui.wins[0].h)
|
nav := newNav(ui.wins[0].h)
|
||||||
app := newApp(ui, nav)
|
app := newApp(ui, nav)
|
||||||
@@ -58,14 +58,6 @@ func run() {
|
|||||||
app.ui.echoerrf("sync: %s", err)
|
app.ui.echoerrf("sync: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.nav.readMarks(); err != nil {
|
|
||||||
app.ui.echoerrf("reading marks file: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := app.nav.readTags(); err != nil {
|
|
||||||
app.ui.echoerrf("reading tags file: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := app.readHistory(); err != nil {
|
if err := app.readHistory(); err != nil {
|
||||||
app.ui.echoerrf("reading history file: %s", err)
|
app.ui.echoerrf("reading history file: %s", err)
|
||||||
}
|
}
|
||||||
@@ -125,7 +117,7 @@ func readExpr() <-chan expr {
|
|||||||
ch := make(chan expr)
|
ch := make(chan expr)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
duration := 1 * time.Second
|
duration := 100 * time.Millisecond
|
||||||
|
|
||||||
c, err := net.Dial(gSocketProt, gSocketPath)
|
c, err := net.Dial(gSocketProt, gSocketPath)
|
||||||
for err != nil {
|
for err != nil {
|
||||||
@@ -138,6 +130,7 @@ func readExpr() <-chan expr {
|
|||||||
fmt.Fprintf(c, "conn %d\n", gClientID)
|
fmt.Fprintf(c, "conn %d\n", gClientID)
|
||||||
|
|
||||||
ch <- &callExpr{"sync", nil, 1}
|
ch <- &callExpr{"sync", nil, 1}
|
||||||
|
ch <- &callExpr{"on-init", nil, 1}
|
||||||
|
|
||||||
s := bufio.NewScanner(c)
|
s := bufio.NewScanner(c)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -10,10 +11,16 @@ import (
|
|||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type styleMap map[string]tcell.Style
|
type styleMap struct {
|
||||||
|
styles map[string]tcell.Style
|
||||||
|
useLinkTarget bool
|
||||||
|
}
|
||||||
|
|
||||||
func parseStyles() styleMap {
|
func parseStyles() styleMap {
|
||||||
sm := make(styleMap)
|
sm := styleMap{
|
||||||
|
styles: make(map[string]tcell.Style),
|
||||||
|
useLinkTarget: false,
|
||||||
|
}
|
||||||
|
|
||||||
// Default values from dircolors
|
// Default values from dircolors
|
||||||
//
|
//
|
||||||
@@ -89,85 +96,121 @@ func parseEscapeSequence(s string) tcell.Style {
|
|||||||
return applyAnsiCodes(s, tcell.StyleDefault)
|
return applyAnsiCodes(s, tcell.StyleDefault)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseColor(toks []string) (tcell.Color, int, error) {
|
||||||
|
if len(toks) == 0 {
|
||||||
|
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
|
||||||
|
}
|
||||||
|
|
||||||
|
if toks[0] == "5" && len(toks) >= 2 {
|
||||||
|
n, err := strconv.Atoi(toks[1])
|
||||||
|
if err != nil {
|
||||||
|
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tcell.PaletteColor(n), 2, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if toks[0] == "2" && len(toks) >= 4 {
|
||||||
|
r, err := strconv.Atoi(toks[1])
|
||||||
|
if err != nil {
|
||||||
|
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
|
||||||
|
}
|
||||||
|
|
||||||
|
g, err := strconv.Atoi(toks[2])
|
||||||
|
if err != nil {
|
||||||
|
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := strconv.Atoi(toks[3])
|
||||||
|
if err != nil {
|
||||||
|
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tcell.NewRGBColor(int32(r), int32(g), int32(b)), 4, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
|
||||||
|
}
|
||||||
|
|
||||||
func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
|
func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
|
||||||
toks := strings.Split(s, ";")
|
toks := strings.Split(s, ";")
|
||||||
|
|
||||||
var nums []int
|
|
||||||
for _, tok := range toks {
|
|
||||||
if tok == "" {
|
|
||||||
nums = append(nums, 0)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
n, err := strconv.Atoi(tok)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("converting escape code: %s", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
nums = append(nums, n)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ECMA-48 details the standard
|
// ECMA-48 details the standard
|
||||||
// TODO: should we support turning off attributes?
|
// TODO: should we support turning off attributes?
|
||||||
// Probably because this is used for previewers too
|
// Probably because this is used for previewers too
|
||||||
for i := 0; i < len(nums); i++ {
|
tokslen := len(toks)
|
||||||
n := nums[i]
|
|
||||||
switch {
|
loop:
|
||||||
case n == 0:
|
for i := 0; i < tokslen; i++ {
|
||||||
|
switch strings.TrimLeft(toks[i], "0") {
|
||||||
|
case "":
|
||||||
st = tcell.StyleDefault
|
st = tcell.StyleDefault
|
||||||
case n == 1:
|
case "1":
|
||||||
st = st.Bold(true)
|
st = st.Bold(true)
|
||||||
case n == 2:
|
case "2":
|
||||||
st = st.Dim(true)
|
st = st.Dim(true)
|
||||||
case n == 3:
|
case "3":
|
||||||
st = st.Italic(true)
|
st = st.Italic(true)
|
||||||
case n == 4:
|
case "4:0":
|
||||||
|
st = st.Underline(false)
|
||||||
|
case "4", "4:1":
|
||||||
st = st.Underline(true)
|
st = st.Underline(true)
|
||||||
case n == 5 || n == 6:
|
case "4:2":
|
||||||
|
st = st.Underline(tcell.UnderlineStyleDouble)
|
||||||
|
case "4:3":
|
||||||
|
st = st.Underline(tcell.UnderlineStyleCurly)
|
||||||
|
case "4:4":
|
||||||
|
st = st.Underline(tcell.UnderlineStyleDotted)
|
||||||
|
case "4:5":
|
||||||
|
st = st.Underline(tcell.UnderlineStyleDashed)
|
||||||
|
case "5", "6":
|
||||||
st = st.Blink(true)
|
st = st.Blink(true)
|
||||||
case n == 7:
|
case "7":
|
||||||
st = st.Reverse(true)
|
st = st.Reverse(true)
|
||||||
case n == 8:
|
case "8":
|
||||||
// TODO: tcell PR for proper conceal
|
// TODO: tcell PR for proper conceal
|
||||||
_, bg, _ := st.Decompose()
|
_, bg, _ := st.Decompose()
|
||||||
st = st.Foreground(bg)
|
st = st.Foreground(bg)
|
||||||
case n == 9:
|
case "9":
|
||||||
st = st.StrikeThrough(true)
|
st = st.StrikeThrough(true)
|
||||||
case n >= 30 && n <= 37:
|
case "30", "31", "32", "33", "34", "35", "36", "37":
|
||||||
|
n, _ := strconv.Atoi(toks[i])
|
||||||
st = st.Foreground(tcell.PaletteColor(n - 30))
|
st = st.Foreground(tcell.PaletteColor(n - 30))
|
||||||
case n >= 90 && n <= 97:
|
case "90", "91", "92", "93", "94", "95", "96", "97":
|
||||||
|
n, _ := strconv.Atoi(toks[i])
|
||||||
st = st.Foreground(tcell.PaletteColor(n - 82))
|
st = st.Foreground(tcell.PaletteColor(n - 82))
|
||||||
case n == 38:
|
case "38":
|
||||||
if i+3 <= len(nums) && nums[i+1] == 5 {
|
color, offset, err := parseColor(toks[i+1:])
|
||||||
st = st.Foreground(tcell.PaletteColor(nums[i+2]))
|
if err != nil {
|
||||||
i += 2
|
log.Printf("error processing ansi code 38: %s", err)
|
||||||
} else if i+5 <= len(nums) && nums[i+1] == 2 {
|
break loop
|
||||||
st = st.Foreground(tcell.NewRGBColor(
|
|
||||||
int32(nums[i+2]),
|
|
||||||
int32(nums[i+3]),
|
|
||||||
int32(nums[i+4])))
|
|
||||||
i += 4
|
|
||||||
} else {
|
|
||||||
log.Printf("unknown ansi code or incorrect form: %d", n)
|
|
||||||
}
|
}
|
||||||
case n >= 40 && n <= 47:
|
st = st.Foreground(color)
|
||||||
|
i += offset
|
||||||
|
case "40", "41", "42", "43", "44", "45", "46", "47":
|
||||||
|
n, _ := strconv.Atoi(toks[i])
|
||||||
st = st.Background(tcell.PaletteColor(n - 40))
|
st = st.Background(tcell.PaletteColor(n - 40))
|
||||||
case n >= 100 && n <= 107:
|
case "100", "101", "102", "103", "104", "105", "106", "107":
|
||||||
|
n, _ := strconv.Atoi(toks[i])
|
||||||
st = st.Background(tcell.PaletteColor(n - 92))
|
st = st.Background(tcell.PaletteColor(n - 92))
|
||||||
case n == 48:
|
case "48":
|
||||||
if i+3 <= len(nums) && nums[i+1] == 5 {
|
color, offset, err := parseColor(toks[i+1:])
|
||||||
st = st.Background(tcell.PaletteColor(nums[i+2]))
|
if err != nil {
|
||||||
i += 2
|
log.Printf("error processing ansi code 48: %s", err)
|
||||||
} else if i+5 <= len(nums) && nums[i+1] == 2 {
|
break loop
|
||||||
st = st.Background(tcell.NewRGBColor(
|
|
||||||
int32(nums[i+2]),
|
|
||||||
int32(nums[i+3]),
|
|
||||||
int32(nums[i+4])))
|
|
||||||
i += 4
|
|
||||||
} else {
|
|
||||||
log.Printf("unknown ansi code or incorrect form: %d", n)
|
|
||||||
}
|
}
|
||||||
|
st = st.Background(color)
|
||||||
|
i += offset
|
||||||
|
case "58":
|
||||||
|
color, offset, err := parseColor(toks[i+1:])
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error processing ansi code 58: %s", err)
|
||||||
|
break loop
|
||||||
|
}
|
||||||
|
st = st.Underline(color)
|
||||||
|
i += offset
|
||||||
default:
|
default:
|
||||||
log.Printf("unknown ansi code: %d", n)
|
log.Printf("unknown ansi code: %s", toks[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,20 +234,12 @@ func (sm styleMap) parseFile(path string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, pair := range pairs {
|
for _, pair := range pairs {
|
||||||
key, val := pair[0], pair[1]
|
sm.parsePair(pair)
|
||||||
|
|
||||||
key = replaceTilde(key)
|
|
||||||
|
|
||||||
if filepath.IsAbs(key) {
|
|
||||||
key = filepath.Clean(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
sm[key] = applyAnsiCodes(val, tcell.StyleDefault)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function parses $LS_COLORS environment variable.
|
// This function parses $LS_COLORS environment variable.
|
||||||
func (sm styleMap) parseGNU(env string) {
|
func (sm *styleMap) parseGNU(env string) {
|
||||||
for _, entry := range strings.Split(env, ":") {
|
for _, entry := range strings.Split(env, ":") {
|
||||||
if entry == "" {
|
if entry == "" {
|
||||||
continue
|
continue
|
||||||
@@ -217,6 +252,11 @@ func (sm styleMap) parseGNU(env string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sm.parsePair(pair)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sm *styleMap) parsePair(pair []string) {
|
||||||
key, val := pair[0], pair[1]
|
key, val := pair[0], pair[1]
|
||||||
|
|
||||||
key = replaceTilde(key)
|
key = replaceTilde(key)
|
||||||
@@ -225,8 +265,11 @@ func (sm styleMap) parseGNU(env string) {
|
|||||||
key = filepath.Clean(key)
|
key = filepath.Clean(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
sm[key] = applyAnsiCodes(val, tcell.StyleDefault)
|
if key == "ln" && val == "target" {
|
||||||
|
sm.useLinkTarget = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sm.styles[key] = applyAnsiCodes(val, tcell.StyleDefault)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function parses $LSCOLORS environment variable.
|
// This function parses $LSCOLORS environment variable.
|
||||||
@@ -267,17 +310,17 @@ func (sm styleMap) parseBSD(env string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, key := range colorNames {
|
for i, key := range colorNames {
|
||||||
sm[key] = getStyle(env[i*2], env[i*2+1])
|
sm.styles[key] = getStyle(env[i*2], env[i*2+1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm styleMap) get(f *file) tcell.Style {
|
func (sm styleMap) get(f *file) tcell.Style {
|
||||||
if val, ok := sm[f.path]; ok {
|
if val, ok := sm.styles[f.path]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
if val, ok := sm[f.Name()+"/"]; ok {
|
if val, ok := sm.styles[f.Name()+"/"]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,13 +328,13 @@ func (sm styleMap) get(f *file) tcell.Style {
|
|||||||
var key string
|
var key string
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case f.linkState == working:
|
case f.linkState == working && !sm.useLinkTarget:
|
||||||
key = "ln"
|
key = "ln"
|
||||||
case f.linkState == broken:
|
case f.linkState == broken:
|
||||||
key = "or"
|
key = "or"
|
||||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
|
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0o002 != 0:
|
||||||
key = "tw"
|
key = "tw"
|
||||||
case f.IsDir() && f.Mode()&0002 != 0:
|
case f.IsDir() && f.Mode()&0o002 != 0:
|
||||||
key = "ow"
|
key = "ow"
|
||||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
||||||
key = "st"
|
key = "st"
|
||||||
@@ -301,39 +344,39 @@ func (sm styleMap) get(f *file) tcell.Style {
|
|||||||
key = "pi"
|
key = "pi"
|
||||||
case f.Mode()&os.ModeSocket != 0:
|
case f.Mode()&os.ModeSocket != 0:
|
||||||
key = "so"
|
key = "so"
|
||||||
case f.Mode()&os.ModeDevice != 0:
|
|
||||||
key = "bd"
|
|
||||||
case f.Mode()&os.ModeCharDevice != 0:
|
case f.Mode()&os.ModeCharDevice != 0:
|
||||||
key = "cd"
|
key = "cd"
|
||||||
|
case f.Mode()&os.ModeDevice != 0:
|
||||||
|
key = "bd"
|
||||||
case f.Mode()&os.ModeSetuid != 0:
|
case f.Mode()&os.ModeSetuid != 0:
|
||||||
key = "su"
|
key = "su"
|
||||||
case f.Mode()&os.ModeSetgid != 0:
|
case f.Mode()&os.ModeSetgid != 0:
|
||||||
key = "sg"
|
key = "sg"
|
||||||
case f.Mode()&0111 != 0:
|
case f.Mode()&0o111 != 0:
|
||||||
key = "ex"
|
key = "ex"
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := sm[key]; ok {
|
if val, ok := sm.styles[key]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := sm[f.Name()+"*"]; ok {
|
if val, ok := sm.styles[f.Name()+"*"]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := sm["*"+f.Name()]; ok {
|
if val, ok := sm.styles["*"+f.Name()]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := sm[filepath.Base(f.Name())+".*"]; ok {
|
if val, ok := sm.styles[filepath.Base(f.Name())+".*"]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := sm["*"+strings.ToLower(f.ext)]; ok {
|
if val, ok := sm.styles["*"+strings.ToLower(f.ext)]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := sm["fi"]; ok {
|
if val, ok := sm.styles["fi"]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,35 @@ import (
|
|||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestParseColor(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
toks []string
|
||||||
|
color tcell.Color
|
||||||
|
offset int
|
||||||
|
success bool
|
||||||
|
}{
|
||||||
|
{[]string{}, tcell.ColorDefault, 0, false},
|
||||||
|
{[]string{"foo"}, tcell.ColorDefault, 0, false},
|
||||||
|
{[]string{"5"}, tcell.ColorDefault, 0, false},
|
||||||
|
{[]string{"5", "foo"}, tcell.ColorDefault, 0, false},
|
||||||
|
{[]string{"5", "42"}, tcell.PaletteColor(42), 2, true},
|
||||||
|
{[]string{"2"}, tcell.ColorDefault, 0, false},
|
||||||
|
{[]string{"2", "foo"}, tcell.ColorDefault, 0, false},
|
||||||
|
{[]string{"2", "42", "foo"}, tcell.ColorDefault, 0, false},
|
||||||
|
{[]string{"2", "42", "43", "foo"}, tcell.ColorDefault, 0, false},
|
||||||
|
{[]string{"2", "42", "43", "44"}, tcell.NewRGBColor(42, 43, 44), 4, true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
color, offset, err := parseColor(test.toks)
|
||||||
|
success := err == nil
|
||||||
|
if color != test.color || offset != test.offset || success != test.success {
|
||||||
|
t.Errorf("at input %v expected (%v, %v, %v) but got (%v, %v, %v)",
|
||||||
|
test.toks, test.color, test.offset, test.success, color, offset, success)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestApplyAnsiCodes(t *testing.T) {
|
func TestApplyAnsiCodes(t *testing.T) {
|
||||||
none := tcell.StyleDefault
|
none := tcell.StyleDefault
|
||||||
|
|
||||||
@@ -35,6 +64,14 @@ func TestApplyAnsiCodes(t *testing.T) {
|
|||||||
{"4", none.Bold(true), none.Bold(true).Underline(true)},
|
{"4", none.Bold(true), none.Bold(true).Underline(true)},
|
||||||
{"4", none.Foreground(tcell.ColorMaroon).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true).Underline(true)},
|
{"4", none.Foreground(tcell.ColorMaroon).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true).Underline(true)},
|
||||||
|
|
||||||
|
{"4:0", none, none},
|
||||||
|
{"4:0", none.Underline(true), none},
|
||||||
|
{"4:1", none, none.Underline(true)},
|
||||||
|
{"4:2", none, none.Underline(tcell.UnderlineStyleDouble)},
|
||||||
|
{"4:3", none, none.Underline(tcell.UnderlineStyleCurly)},
|
||||||
|
{"4:4", none, none.Underline(tcell.UnderlineStyleDotted)},
|
||||||
|
{"4:5", none, none.Underline(tcell.UnderlineStyleDashed)},
|
||||||
|
|
||||||
{"31", none, none.Foreground(tcell.ColorMaroon)},
|
{"31", none, none.Foreground(tcell.ColorMaroon)},
|
||||||
{"31", none.Foreground(tcell.ColorGreen), 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)},
|
{"31", none.Foreground(tcell.ColorGreen).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||||
@@ -45,6 +82,9 @@ func TestApplyAnsiCodes(t *testing.T) {
|
|||||||
{"1;31", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
|
{"1;31", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||||
{"1;31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
|
{"1;31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||||
|
|
||||||
|
{"01;31", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||||
|
{"01;31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||||
|
|
||||||
{"38;5;0", none, none.Foreground(tcell.ColorBlack)},
|
{"38;5;0", none, none.Foreground(tcell.ColorBlack)},
|
||||||
{"38;5;1", none, none.Foreground(tcell.ColorMaroon)},
|
{"38;5;1", none, none.Foreground(tcell.ColorMaroon)},
|
||||||
{"38;5;8", none, none.Foreground(tcell.ColorGray)},
|
{"38;5;8", none, none.Foreground(tcell.ColorGray)},
|
||||||
|
|||||||
+41
-131
@@ -4,6 +4,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -79,6 +80,7 @@ var (
|
|||||||
"mark-remove",
|
"mark-remove",
|
||||||
"tag",
|
"tag",
|
||||||
"tag-toggle",
|
"tag-toggle",
|
||||||
|
"tty-write",
|
||||||
"cmd-escape",
|
"cmd-escape",
|
||||||
"cmd-complete",
|
"cmd-complete",
|
||||||
"cmd-menu-complete",
|
"cmd-menu-complete",
|
||||||
@@ -109,138 +111,45 @@ var (
|
|||||||
"cmd-lowercase-word",
|
"cmd-lowercase-word",
|
||||||
}
|
}
|
||||||
|
|
||||||
gOptWords = []string{
|
gOptWords = getOptWords(gOpts)
|
||||||
"anchorfind",
|
gLocalOptWords = getLocalOptWords(gLocalOpts)
|
||||||
"noanchorfind",
|
)
|
||||||
"anchorfind!",
|
|
||||||
"autoquit",
|
func getOptWords(opts any) (optWords []string) {
|
||||||
"noautoquit",
|
t := reflect.TypeOf(opts)
|
||||||
"autoquit!",
|
for i := range t.NumField() {
|
||||||
"borderfmt",
|
field := t.Field(i)
|
||||||
"cursoractivefmt",
|
switch field.Type.Kind() {
|
||||||
"cursorparentfmt",
|
case reflect.Map:
|
||||||
"cursorpreviewfmt",
|
continue
|
||||||
"dircache",
|
case reflect.Bool:
|
||||||
"nodircache",
|
name := field.Name
|
||||||
"dircache!",
|
optWords = append(optWords, name, "no"+name, name+"!")
|
||||||
"dircounts",
|
default:
|
||||||
"nodircounts",
|
optWords = append(optWords, field.Name)
|
||||||
"dircounts!",
|
}
|
||||||
"dirfirst",
|
}
|
||||||
"nodirfirst",
|
sort.Strings(optWords)
|
||||||
"dirfirst!",
|
return
|
||||||
"dironly",
|
|
||||||
"nodironly",
|
|
||||||
"dironly!",
|
|
||||||
"dirpreviews",
|
|
||||||
"nodirpreviews",
|
|
||||||
"dirpreviews!",
|
|
||||||
"drawbox",
|
|
||||||
"nodrawbox",
|
|
||||||
"drawbox!",
|
|
||||||
"dupfilefmt",
|
|
||||||
"globsearch",
|
|
||||||
"noglobsearch",
|
|
||||||
"globsearch!",
|
|
||||||
"hidden",
|
|
||||||
"nohidden",
|
|
||||||
"hidden!",
|
|
||||||
"icons",
|
|
||||||
"noicons",
|
|
||||||
"icons!",
|
|
||||||
"ignorecase",
|
|
||||||
"noignorecase",
|
|
||||||
"ignorecase!",
|
|
||||||
"ignoredia",
|
|
||||||
"noignoredia",
|
|
||||||
"ignoredia!",
|
|
||||||
"incsearch",
|
|
||||||
"noincsearch",
|
|
||||||
"incsearch!",
|
|
||||||
"incfilter",
|
|
||||||
"noincfilter",
|
|
||||||
"incfilter!",
|
|
||||||
"mouse",
|
|
||||||
"nomouse",
|
|
||||||
"mouse!",
|
|
||||||
"number",
|
|
||||||
"nonumber",
|
|
||||||
"number!",
|
|
||||||
"preview",
|
|
||||||
"nopreview",
|
|
||||||
"preview!",
|
|
||||||
"relativenumber",
|
|
||||||
"norelativenumber",
|
|
||||||
"relativenumber!",
|
|
||||||
"reverse",
|
|
||||||
"noreverse",
|
|
||||||
"reverse!",
|
|
||||||
"ruler",
|
|
||||||
"rulerfmt",
|
|
||||||
"preserve",
|
|
||||||
"sixel",
|
|
||||||
"nosixel",
|
|
||||||
"sixel!",
|
|
||||||
"smartcase",
|
|
||||||
"nosmartcase",
|
|
||||||
"smartcase!",
|
|
||||||
"smartdia",
|
|
||||||
"nosmartdia",
|
|
||||||
"smartdia!",
|
|
||||||
"waitmsg",
|
|
||||||
"wrapscan",
|
|
||||||
"nowrapscan",
|
|
||||||
"wrapscan!",
|
|
||||||
"wrapscroll",
|
|
||||||
"nowrapscroll",
|
|
||||||
"wrapscroll!",
|
|
||||||
"findlen",
|
|
||||||
"period",
|
|
||||||
"scrolloff",
|
|
||||||
"tabstop",
|
|
||||||
"errorfmt",
|
|
||||||
"filesep",
|
|
||||||
"hiddenfiles",
|
|
||||||
"history",
|
|
||||||
"ifs",
|
|
||||||
"info",
|
|
||||||
"numberfmt",
|
|
||||||
"previewer",
|
|
||||||
"cleaner",
|
|
||||||
"promptfmt",
|
|
||||||
"ratios",
|
|
||||||
"selmode",
|
|
||||||
"shell",
|
|
||||||
"shellflag",
|
|
||||||
"shellopts",
|
|
||||||
"sortby",
|
|
||||||
"statfmt",
|
|
||||||
"timefmt",
|
|
||||||
"tempmarks",
|
|
||||||
"tagfmt",
|
|
||||||
"infotimefmtnew",
|
|
||||||
"infotimefmtold",
|
|
||||||
"truncatechar",
|
|
||||||
"truncatepct",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gLocalOptWords = []string{
|
func getLocalOptWords(localOpts any) (localOptWords []string) {
|
||||||
"dirfirst",
|
t := reflect.TypeOf(localOpts)
|
||||||
"nodirfirst",
|
for i := range t.NumField() {
|
||||||
"dirfirst!",
|
field := t.Field(i)
|
||||||
"dironly",
|
name := field.Name
|
||||||
"nodironly",
|
if field.Type.Kind() != reflect.Map {
|
||||||
"dironly!",
|
continue
|
||||||
"hidden",
|
}
|
||||||
"nohidden",
|
if field.Type.Elem().Kind() == reflect.Bool {
|
||||||
"hidden!",
|
localOptWords = append(localOptWords, name, "no"+name, name+"!")
|
||||||
"info",
|
} else {
|
||||||
"reverse",
|
localOptWords = append(localOptWords, name)
|
||||||
"noreverse",
|
}
|
||||||
"reverse!",
|
}
|
||||||
"sortby",
|
sort.Strings(localOptWords)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
func matchLongest(s1, s2 []rune) []rune {
|
func matchLongest(s1, s2 []rune) []rune {
|
||||||
i := 0
|
i := 0
|
||||||
@@ -307,9 +216,9 @@ func matchExec(s string) (matches []string, longest []rune) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(words) > 0 {
|
||||||
sort.Strings(words)
|
sort.Strings(words)
|
||||||
|
|
||||||
if len(words) > 0 {
|
|
||||||
uniq := words[:1]
|
uniq := words[:1]
|
||||||
for i := 1; i < len(words); i++ {
|
for i := 1; i < len(words); i++ {
|
||||||
if words[i] != words[i-1] {
|
if words[i] != words[i-1] {
|
||||||
@@ -386,7 +295,8 @@ func matchFile(s string) (matches []string, longest []rune) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func matchCmd(s string) (matches []string, longest []rune) {
|
func matchCmd(s string) (matches []string, longest []rune) {
|
||||||
words := gCmdWords
|
words := make([]string, 0, len(gCmdWords)+len(gOpts.cmds))
|
||||||
|
words = append(words, gCmdWords...)
|
||||||
for c := range gOpts.cmds {
|
for c := range gOpts.cmds {
|
||||||
words = append(words, c)
|
words = append(words, c)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,3 +54,41 @@ func TestMatchWord(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetOptWords(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
opts any
|
||||||
|
exp []string
|
||||||
|
}{
|
||||||
|
{struct{ feature bool }{}, []string{"feature", "feature!", "nofeature"}},
|
||||||
|
{struct{ feature int }{}, []string{"feature"}},
|
||||||
|
{struct{ feature string }{}, []string{"feature"}},
|
||||||
|
{struct{ feature []string }{}, []string{"feature"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
result := getOptWords(test.opts)
|
||||||
|
if !reflect.DeepEqual(result, test.exp) {
|
||||||
|
t.Errorf("at input '%#v' expected '%s' but got '%s'", test.opts, test.exp, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetLocalOptWords(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
localOpts any
|
||||||
|
exp []string
|
||||||
|
}{
|
||||||
|
{struct{ feature map[string]bool }{}, []string{"feature", "feature!", "nofeature"}},
|
||||||
|
{struct{ feature map[string]int }{}, []string{"feature"}},
|
||||||
|
{struct{ feature map[string]string }{}, []string{"feature"}},
|
||||||
|
{struct{ feature map[string][]string }{}, []string{"feature"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
result := getLocalOptWords(test.localOpts)
|
||||||
|
if !reflect.DeepEqual(result, test.exp) {
|
||||||
|
t.Errorf("at input '%#v' expected '%s' but got '%s'", test.localOpts, test.exp, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,24 @@ import (
|
|||||||
"github.com/djherbis/times"
|
"github.com/djherbis/times"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ProgressWriter struct {
|
||||||
|
writer io.Writer
|
||||||
|
nums chan<- int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewProgressWriter(writer io.Writer, nums chan<- int64) *ProgressWriter {
|
||||||
|
return &ProgressWriter{
|
||||||
|
writer: writer,
|
||||||
|
nums: nums,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (progressWriter *ProgressWriter) Write(b []byte) (int, error) {
|
||||||
|
n, err := progressWriter.writer.Write(b)
|
||||||
|
progressWriter.nums <- int64(n)
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
|
||||||
func copySize(srcs []string) (int64, error) {
|
func copySize(srcs []string) (int64, error) {
|
||||||
var total int64
|
var total int64
|
||||||
|
|
||||||
@@ -20,14 +38,13 @@ func copySize(srcs []string) (int64, error) {
|
|||||||
return total, fmt.Errorf("src does not exist: %q", src)
|
return total, fmt.Errorf("src does not exist: %q", src)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
|
err = filepath.Walk(src, func(_ string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("walk: %s", err)
|
return fmt.Errorf("walk: %s", err)
|
||||||
}
|
}
|
||||||
total += info.Size()
|
total += info.Size()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return total, err
|
return total, err
|
||||||
}
|
}
|
||||||
@@ -36,10 +53,10 @@ func copySize(srcs []string) (int64, error) {
|
|||||||
return total, nil
|
return total, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
|
func copyFile(src, dst string, preserve []string, info os.FileInfo, nums chan int64) error {
|
||||||
var dst_mode os.FileMode = 0666
|
var dst_mode os.FileMode = 0o666
|
||||||
preserve_timestamps := false
|
preserve_timestamps := false
|
||||||
for _, s := range gOpts.preserve {
|
for _, s := range preserve {
|
||||||
switch s {
|
switch s {
|
||||||
case "timestamps":
|
case "timestamps":
|
||||||
preserve_timestamps = true
|
preserve_timestamps = true
|
||||||
@@ -48,8 +65,6 @@ func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := make([]byte, 4096)
|
|
||||||
|
|
||||||
r, err := os.Open(src)
|
r, err := os.Open(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -61,25 +76,13 @@ func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
_, err = io.Copy(NewProgressWriter(w, nums), r)
|
||||||
n, err := r.Read(buf)
|
if err != nil {
|
||||||
if err != nil && err != io.EOF {
|
|
||||||
w.Close()
|
w.Close()
|
||||||
os.Remove(dst)
|
os.Remove(dst)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if n == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := w.Write(buf[:n]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
nums <- int64(n)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := w.Close(); err != nil {
|
if err := w.Close(); err != nil {
|
||||||
os.Remove(dst)
|
os.Remove(dst)
|
||||||
return err
|
return err
|
||||||
@@ -98,7 +101,7 @@ func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
|
func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64, errs chan error) {
|
||||||
nums = make(chan int64, 1024)
|
nums = make(chan int64, 1024)
|
||||||
errs = make(chan error, 1024)
|
errs = make(chan error, 1024)
|
||||||
|
|
||||||
@@ -107,10 +110,10 @@ func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
|
|||||||
file := filepath.Base(src)
|
file := filepath.Base(src)
|
||||||
dst := filepath.Join(dstDir, file)
|
dst := filepath.Join(dstDir, file)
|
||||||
|
|
||||||
_, err := os.Lstat(dst)
|
lstat, err := os.Lstat(dst)
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
ext := filepath.Ext(file)
|
ext := getFileExtension(lstat)
|
||||||
basename := filepath.Base(file[:len(file)-len(ext)])
|
basename := file[:len(file)-len(ext)]
|
||||||
var newPath string
|
var newPath string
|
||||||
for i := 1; !os.IsNotExist(err); i++ {
|
for i := 1; !os.IsNotExist(err); i++ {
|
||||||
file = strings.ReplaceAll(gOpts.dupfilefmt, "%f", basename+ext)
|
file = strings.ReplaceAll(gOpts.dupfilefmt, "%f", basename+ext)
|
||||||
@@ -149,7 +152,7 @@ func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
|
|||||||
}
|
}
|
||||||
nums <- info.Size()
|
nums <- info.Size()
|
||||||
} else {
|
} else {
|
||||||
if err := copyFile(path, newPath, info, nums); err != nil {
|
if err := copyFile(path, newPath, preserve, info, nums); err != nil {
|
||||||
errs <- fmt.Errorf("copy: %s", err)
|
errs <- fmt.Errorf("copy: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-42
@@ -1,51 +1,45 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
var normMap = map[rune]rune{
|
||||||
"strconv"
|
// lowercase (not only) european
|
||||||
"unicode"
|
'ě': 'e', 'ř': 'r', 'ů': 'u', 'ø': 'o', 'ĉ': 'c', 'ĝ': 'g', 'ĥ': 'h', 'ĵ': 'j', 'ŝ': 's',
|
||||||
)
|
'ŭ': 'u', 'è': 'e', 'ù': 'u', 'ÿ': 'y', 'ė': 'e', 'į': 'i', 'ų': 'u', 'ā': 'a', 'ē': 'e',
|
||||||
|
'ī': 'i', 'ū': 'u', 'ļ': 'l', 'ķ': 'k', 'ņ': 'n', 'ģ': 'g', 'ő': 'o', 'ű': 'u', 'ë': 'e',
|
||||||
|
'ï': 'i', 'ą': 'a', 'ć': 'c', 'ę': 'e', 'ł': 'l', 'ń': 'n', 'ś': 's', 'ź': 'z', 'ż': 'z',
|
||||||
|
'õ': 'o', 'ș': 's', 'ț': 't', 'č': 'c', 'ď': 'd', 'ĺ': 'l', 'ľ': 'l', 'ň': 'n', 'ŕ': 'r',
|
||||||
|
'š': 's', 'ť': 't', 'ý': 'y', 'ž': 'z', 'é': 'e', 'í': 'i', 'ñ': 'n', 'ó': 'o', 'ú': 'u',
|
||||||
|
'ü': 'u', 'å': 'a', 'ä': 'a', 'ö': 'o', 'ç': 'c', 'î': 'i', 'ş': 's', 'û': 'u', 'ğ': 'g',
|
||||||
|
'ă': 'a', 'â': 'a', 'đ': 'd', 'ê': 'e', 'ô': 'o', 'ơ': 'o', 'ư': 'u', 'á': 'a', 'à': 'a',
|
||||||
|
'ã': 'a', 'ả': 'a', 'ạ': 'a',
|
||||||
|
// uppercase (not only) european
|
||||||
|
'Ě': 'E', 'Ř': 'R', 'Ů': 'U', 'Ø': 'O', 'Ĉ': 'C', 'Ĝ': 'G', 'Ĥ': 'H', 'Ĵ': 'J', 'Ŝ': 'S',
|
||||||
|
'Ŭ': 'U', 'È': 'E', 'Ù': 'U', 'Ÿ': 'Y', 'Ė': 'E', 'Į': 'I', 'Ų': 'U', 'Ā': 'A', 'Ē': 'E',
|
||||||
|
'Ī': 'I', 'Ū': 'U', 'Ļ': 'L', 'Ķ': 'K', 'Ņ': 'N', 'Ģ': 'G', 'Ő': 'O', 'Ű': 'U', 'Ë': 'E',
|
||||||
|
'Ï': 'I', 'Ą': 'A', 'Ć': 'C', 'Ę': 'E', 'Ł': 'L', 'Ń': 'N', 'Ś': 'S', 'Ź': 'Z', 'Ż': 'Z',
|
||||||
|
'Õ': 'O', 'Ș': 'S', 'Ț': 'T', 'Č': 'C', 'Ď': 'D', 'Ĺ': 'L', 'Ľ': 'L', 'Ň': 'N', 'Ŕ': 'R',
|
||||||
|
'Š': 'S', 'Ť': 'T', 'Ý': 'Y', 'Ž': 'Z', 'É': 'E', 'Í': 'I', 'Ñ': 'N', 'Ó': 'O', 'Ú': 'U',
|
||||||
|
'Ü': 'U', 'Å': 'A', 'Ä': 'A', 'Ö': 'O', 'Ç': 'C', 'Î': 'I', 'Ş': 'S', 'Û': 'U', 'Ğ': 'G',
|
||||||
|
'Ă': 'A', 'Â': 'A', 'Đ': 'D', 'Ê': 'E', 'Ô': 'O', 'Ơ': 'O', 'Ư': 'U', 'Á': 'A', 'À': 'A',
|
||||||
|
'Ã': 'A', 'Ả': 'A', 'Ạ': 'A',
|
||||||
|
|
||||||
var normMap map[rune]rune
|
// lowercase Vietnamese
|
||||||
|
'ắ': 'a', 'ặ': 'a', 'ằ': 'a', 'ẳ': 'a', 'ẵ': 'a', 'ấ': 'a', 'ậ': 'a', 'ầ': 'a', 'ẩ': 'a',
|
||||||
func init() {
|
'ẫ': 'a', 'ẹ': 'e', 'ẻ': 'e', 'ẽ': 'e', 'ế': 'e', 'ệ': 'e', 'ề': 'e', 'ể': 'e', 'ễ': 'e',
|
||||||
normMap = make(map[rune]rune)
|
'i': 'i', 'ị': 'i', 'ì': 'i', 'ỉ': 'i', 'ĩ': 'i', 'o': 'o', 'ọ': 'o', 'ò': 'o', 'ỏ': 'o',
|
||||||
|
'ố': 'o', 'ộ': 'o', 'ồ': 'o', 'ổ': 'o', 'ỗ': 'o', 'ớ': 'o', 'ợ': 'o', 'ờ': 'o', 'ở': 'o',
|
||||||
// (not only) european
|
'ỡ': 'o', 'ụ': 'u', 'ủ': 'u', 'ũ': 'u', 'ứ': 'u', 'ự': 'u', 'ừ': 'u', 'ử': 'u', 'ữ': 'u',
|
||||||
appendTransliterate(
|
'y': 'y', 'ỵ': 'y', 'ỳ': 'y', 'ỷ': 'y', 'ỹ': 'y',
|
||||||
"ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ",
|
// uppercase Vietnamese
|
||||||
"eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa",
|
'Ắ': 'A', 'Ặ': 'A', 'Ằ': 'A', 'Ẳ': 'A', 'Ẵ': 'A', 'Ấ': 'A', 'Ậ': 'A', 'Ầ': 'A', 'Ẩ': 'A',
|
||||||
)
|
'Ẫ': 'A', 'Ẹ': 'E', 'Ẻ': 'E', 'Ẽ': 'E', 'Ế': 'E', 'Ệ': 'E', 'Ề': 'E', 'Ể': 'E', 'Ễ': 'E',
|
||||||
|
'I': 'I', 'Ị': 'I', 'Ì': 'I', 'Ỉ': 'I', 'Ĩ': 'I', 'O': 'O', 'Ọ': 'O', 'Ò': 'O', 'Ỏ': 'O',
|
||||||
// Vietnamese
|
'Ố': 'O', 'Ộ': 'O', 'Ồ': 'O', 'Ổ': 'O', 'Ỗ': 'O', 'Ớ': 'O', 'Ợ': 'O', 'Ờ': 'O', 'Ở': 'O',
|
||||||
appendTransliterate(
|
'Ỡ': 'O', 'Ụ': 'U', 'Ủ': 'U', 'Ũ': 'U', 'Ứ': 'U', 'Ự': 'U', 'Ừ': 'U', 'Ử': 'U', 'Ữ': 'U',
|
||||||
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
|
'Y': 'Y', 'Ỵ': 'Y', 'Ỳ': 'Y', 'Ỷ': 'Y', 'Ỹ': 'Y',
|
||||||
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendTransliterate(base, norm string) {
|
|
||||||
normRunes := []rune(norm)
|
|
||||||
baseRunes := []rune(base)
|
|
||||||
|
|
||||||
lenNorm := len(normRunes)
|
|
||||||
lenBase := len(baseRunes)
|
|
||||||
if lenNorm != lenBase {
|
|
||||||
panic("Base and normalized strings have differend length: base=" + strconv.Itoa(lenBase) + ", norm=" + strconv.Itoa(lenNorm)) // programmer error in constant length
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < lenBase; i++ {
|
|
||||||
normMap[baseRunes[i]] = normRunes[i]
|
|
||||||
|
|
||||||
baseUpper := unicode.ToUpper(baseRunes[i])
|
|
||||||
normUpper := unicode.ToUpper(normRunes[i])
|
|
||||||
|
|
||||||
normMap[baseUpper] = normUpper
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove diacritics and make lowercase.
|
|
||||||
func removeDiacritics(baseString string) string {
|
func removeDiacritics(baseString string) string {
|
||||||
var normalizedRunes []rune
|
normalizedRunes := make([]rune, 0, len(baseString))
|
||||||
for _, baseRune := range baseString {
|
for _, baseRune := range baseString {
|
||||||
if normRune, ok := normMap[baseRune]; ok {
|
if normRune, ok := normMap[baseRune]; ok {
|
||||||
normalizedRunes = append(normalizedRunes, normRune)
|
normalizedRunes = append(normalizedRunes, normRune)
|
||||||
|
|||||||
+7
-8
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,7 +12,7 @@ func TestRemoveDiacritics(t *testing.T) {
|
|||||||
expStr := "Prilis zlutoucky kun priserne upel dabelske ody"
|
expStr := "Prilis zlutoucky kun priserne upel dabelske ody"
|
||||||
checkRemoveDiacritics(testStr, expStr, t)
|
checkRemoveDiacritics(testStr, expStr, t)
|
||||||
|
|
||||||
// other accents (non comlete, but all I founded)
|
// other accents (non complete, but all I found)
|
||||||
testStr = "áéíóúýčďěňřšťžůåøĉĝĥĵŝŭšžõäöüàâçéèêëîïôùûüÿžščćđáéíóúąęėįųūčšžāēīūčšžļķņģáéíóúöüőűäöüëïąćęłńóśźżáàãâçéêíóõôăâîșțáäčďéíĺľňóôŕšťúýžáéíñóúüåäöâçîşûğăâđêôơưáàãảạ"
|
testStr = "áéíóúýčďěňřšťžůåøĉĝĥĵŝŭšžõäöüàâçéèêëîïôùûüÿžščćđáéíóúąęėįųūčšžāēīūčšžļķņģáéíóúöüőűäöüëïąćęłńóśźżáàãâçéêíóõôăâîșțáäčďéíĺľňóôŕšťúýžáéíñóúüåäöâçîşûğăâđêôơưáàãảạ"
|
||||||
expStr = "aeiouycdenrstzuaocghjsuszoaouaaceeeeiiouuuyzsccdaeiouaeeiuucszaeiucszlkngaeiouououaoueiacelnoszzaaaaceeioooaaistaacdeillnoorstuyzaeinouuaaoacisugaadeoouaaaaa"
|
expStr = "aeiouycdenrstzuaocghjsuszoaouaaceeeeiiouuuyzsccdaeiouaeeiuucszaeiucszlkngaeiouououaoueiacelnoszzaaaaceeioooaaistaacdeillnoorstuyzaeinouuaaoacisugaadeoouaaaaa"
|
||||||
checkRemoveDiacritics(testStr, expStr, t)
|
checkRemoveDiacritics(testStr, expStr, t)
|
||||||
@@ -61,12 +60,12 @@ func runSearch(t *testing.T, ignorecase, smartcase, ignorediacritics, smartdiacr
|
|||||||
gOpts.smartcase = smartcase
|
gOpts.smartcase = smartcase
|
||||||
gOpts.ignoredia = ignorediacritics
|
gOpts.ignoredia = ignorediacritics
|
||||||
gOpts.smartdia = smartdiacritics
|
gOpts.smartdia = smartdiacritics
|
||||||
matched, _ := searchMatch(base, pattern)
|
matched, _ := searchMatch(base, pattern, false)
|
||||||
if matched != expected {
|
if matched != expected {
|
||||||
t.Errorf("False search for" +
|
t.Errorf("False search for ignorecase = %t, smartcase = %t, ignoredia = %t, smartdia = %t",
|
||||||
" ignorecase = " + strconv.FormatBool(gOpts.ignorecase) + ", " +
|
gOpts.ignorecase,
|
||||||
" smartcase = " + strconv.FormatBool(gOpts.smartcase) + ", " +
|
gOpts.smartcase,
|
||||||
" ignoredia = " + strconv.FormatBool(gOpts.ignoredia) + ", " +
|
gOpts.ignoredia,
|
||||||
" smartdia = " + strconv.FormatBool(gOpts.smartdia) + ", ")
|
gOpts.smartdia)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+553
-495
File diff suppressed because it is too large.
Load diff
-1983
File diff suppressed because it is too large.
Load diff
@@ -35,6 +35,22 @@ sg g # SETGID
|
|||||||
ex # EXEC
|
ex # EXEC
|
||||||
fi # FILE
|
fi # FILE
|
||||||
|
|
||||||
|
# disable some default filetype icons, let them choose icon by filename
|
||||||
|
# ln # LINK
|
||||||
|
# or # ORPHAN
|
||||||
|
# tw # STICKY_OTHER_WRITABLE
|
||||||
|
# ow # OTHER_WRITABLE
|
||||||
|
# st # STICKY
|
||||||
|
# di # DIR
|
||||||
|
# pi # FIFO
|
||||||
|
# so # SOCK
|
||||||
|
# bd # BLK
|
||||||
|
# cd # CHR
|
||||||
|
# su # SETUID
|
||||||
|
# sg # SETGID
|
||||||
|
# ex # EXEC
|
||||||
|
# fi # FILE
|
||||||
|
|
||||||
# file extensions (vim-devicons)
|
# file extensions (vim-devicons)
|
||||||
*.styl
|
*.styl
|
||||||
*.sass
|
*.sass
|
||||||
@@ -188,6 +204,9 @@ fi # FILE
|
|||||||
*procfile
|
*procfile
|
||||||
*dockerfile
|
*dockerfile
|
||||||
*docker-compose.yml
|
*docker-compose.yml
|
||||||
|
*docker-compose.yaml
|
||||||
|
*compose.yml
|
||||||
|
*compose.yaml
|
||||||
*rakefile
|
*rakefile
|
||||||
*config.ru
|
*config.ru
|
||||||
*gemfile
|
*gemfile
|
||||||
@@ -209,6 +228,7 @@ fi # FILE
|
|||||||
*Procfile
|
*Procfile
|
||||||
*Dockerfile
|
*Dockerfile
|
||||||
*Docker-compose.yml
|
*Docker-compose.yml
|
||||||
|
*Docker-compose.yaml
|
||||||
*Rakefile
|
*Rakefile
|
||||||
*Gemfile
|
*Gemfile
|
||||||
*Makefile
|
*Makefile
|
||||||
|
|||||||
@@ -0,0 +1,377 @@
|
|||||||
|
# vim:ft=conf
|
||||||
|
|
||||||
|
# These examples require Nerd Fonts or a compatible font to be used.
|
||||||
|
# See https://www.nerdfonts.com for more information.
|
||||||
|
|
||||||
|
# default values from lf (with matching order)
|
||||||
|
# ln l # LINK
|
||||||
|
# or l # ORPHAN
|
||||||
|
# tw t # STICKY_OTHER_WRITABLE
|
||||||
|
# ow d # OTHER_WRITABLE
|
||||||
|
# st t # STICKY
|
||||||
|
# di d # DIR
|
||||||
|
# pi p # FIFO
|
||||||
|
# so s # SOCK
|
||||||
|
# bd b # BLK
|
||||||
|
# cd c # CHR
|
||||||
|
# su u # SETUID
|
||||||
|
# sg g # SETGID
|
||||||
|
# ex x # EXEC
|
||||||
|
# fi - # FILE
|
||||||
|
|
||||||
|
# file types (with matching order)
|
||||||
|
ln # LINK
|
||||||
|
or # ORPHAN
|
||||||
|
tw t # STICKY_OTHER_WRITABLE
|
||||||
|
ow # OTHER_WRITABLE
|
||||||
|
st t # STICKY
|
||||||
|
di # DIR
|
||||||
|
pi p # FIFO
|
||||||
|
so s # SOCK
|
||||||
|
bd b # BLK
|
||||||
|
cd c # CHR
|
||||||
|
su u # SETUID
|
||||||
|
sg g # SETGID
|
||||||
|
ex # EXEC
|
||||||
|
fi # FILE
|
||||||
|
|
||||||
|
# disable some default filetype icons, let them choose icon by filename
|
||||||
|
# ln # LINK
|
||||||
|
# or # ORPHAN
|
||||||
|
# tw # STICKY_OTHER_WRITABLE
|
||||||
|
# ow # OTHER_WRITABLE
|
||||||
|
# st # STICKY
|
||||||
|
# di # DIR
|
||||||
|
# pi # FIFO
|
||||||
|
# so # SOCK
|
||||||
|
# bd # BLK
|
||||||
|
# cd # CHR
|
||||||
|
# su # SETUID
|
||||||
|
# sg # SETGID
|
||||||
|
# ex # EXEC
|
||||||
|
# fi # FILE
|
||||||
|
|
||||||
|
# file extensions (vim-devicons)
|
||||||
|
*.styl 00;38;2;141;193;73
|
||||||
|
*.sass 00;38;2;245;83;133
|
||||||
|
*.scss 00;38;2;245;83;133
|
||||||
|
*.htm 00;38;2;227;76;38
|
||||||
|
*.html 00;38;2;227;76;38
|
||||||
|
*.slim 00;38;2;227;76;38
|
||||||
|
*.haml 00;38;2;234;234;225
|
||||||
|
*.ejs 00;38;2;203;203;65
|
||||||
|
*.css 00;38;2;86;61;124
|
||||||
|
*.less 00;38;2;86;61;124
|
||||||
|
*.md 00;38;2;81;154;186
|
||||||
|
*.mdx 00;38;2;81;154;186
|
||||||
|
*.markdown 00;38;2;81;154;186
|
||||||
|
*.rmd 00;38;2;81;154;186
|
||||||
|
*.json 00;38;2;149;157;165
|
||||||
|
*.webmanifest 00;38;2;241;224;90
|
||||||
|
*.js 00;38;2;203;203;65
|
||||||
|
*.mjs 00;38;2;241;224;90
|
||||||
|
*.jsx 00;38;2;81;154;186
|
||||||
|
*.rb 00;38;2;112;21;22
|
||||||
|
*.gemspec 00;38;2;112;21;22
|
||||||
|
*.rake 00;38;2;112;21;22
|
||||||
|
*.php 00;38;2;160;116;196
|
||||||
|
*.py 00;38;2;81;154;186
|
||||||
|
*.pyc 00;38;2;81;154;186
|
||||||
|
*.pyo 00;38;2;81;154;186
|
||||||
|
*.pyd 00;38;2;81;154;186
|
||||||
|
*.coffee 00;38;2;203;203;65
|
||||||
|
*.mustache 00;38;2;227;121;51
|
||||||
|
*.hbs 00;38;2;240;119;43
|
||||||
|
*.conf 00;38;2;109;128;134
|
||||||
|
*.ini 00;38;2;109;128;134
|
||||||
|
*.yml 00;38;2;149;157;165
|
||||||
|
*.yaml 00;38;2;149;157;165
|
||||||
|
*.toml 00;38;2;109;128;134
|
||||||
|
*.bat 00;38;2;193;241;46
|
||||||
|
*.mk 00;38;2;109;128;134
|
||||||
|
*.jpg 00;38;2;160;116;196
|
||||||
|
*.jpeg 00;38;2;160;116;196
|
||||||
|
*.bmp 00;38;2;160;116;196
|
||||||
|
*.png 00;38;2;160;116;196
|
||||||
|
*.webp 00;38;2;160;116;196
|
||||||
|
*.gif 00;38;2;160;116;196
|
||||||
|
*.ico 00;38;2;203;203;65
|
||||||
|
*.twig 00;38;2;141;193;73
|
||||||
|
*.cpp 00;38;2;81;154;186
|
||||||
|
*.c++ 00;38;2;89;158;255
|
||||||
|
*.cxx 00;38;2;81;154;186
|
||||||
|
*.cc 00;38;2;81;154;186
|
||||||
|
*.cp 00;38;2;81;154;186
|
||||||
|
*.c 00;38;2;89;158;255
|
||||||
|
*.cs 00;38;2;89;103;6
|
||||||
|
*.h 00;38;2;160;116;196
|
||||||
|
*.hh 00;38;2;160;116;196
|
||||||
|
*.hpp 00;38;2;160;116;196
|
||||||
|
*.hxx 00;38;2;160;116;196
|
||||||
|
*.hs 00;38;2;160;116;196
|
||||||
|
*.lhs 00;38;2;160;116;196
|
||||||
|
*.nix 00;38;2;126;186;228
|
||||||
|
*.lua 00;38;2;81;160;207
|
||||||
|
*.java 00;38;2;204;62;68
|
||||||
|
*.sh 00;38;2;137;224;81
|
||||||
|
*.fish 00;38;2;137;224;81
|
||||||
|
*.bash 00;38;2;137;224;81
|
||||||
|
*.zsh 00;38;2;137;224;81
|
||||||
|
*.ksh 00;38;2;137;224;81
|
||||||
|
*.csh 00;38;2;137;224;81
|
||||||
|
*.awk 00;38;2;137;224;81
|
||||||
|
*.ps1 00;38;2;137;224;81
|
||||||
|
*.ml λ 00;38;2;227;121;51
|
||||||
|
*.mli λ 00;38;2;227;121;51
|
||||||
|
*.diff 00;38;2;65;83;91
|
||||||
|
*.db 00;38;2;218;216;216
|
||||||
|
*.sql 00;38;2;218;216;216
|
||||||
|
*.dump 00;38;2;218;216;216
|
||||||
|
*.clj 00;38;2;141;193;73
|
||||||
|
*.cljc 00;38;2;141;193;73
|
||||||
|
*.cljs 00;38;2;81;154;186
|
||||||
|
*.edn 00;38;2;81;154;186
|
||||||
|
*.scala 00;38;2;204;62;68
|
||||||
|
*.go 00;38;2;81;154;186
|
||||||
|
*.dart 00;38;2;3;88;156
|
||||||
|
*.xul 00;38;2;227;121;51
|
||||||
|
*.sln 00;38;2;133;76;199
|
||||||
|
*.suo 00;38;2;133;76;199
|
||||||
|
*.pl 00;38;2;81;154;186
|
||||||
|
*.pm 00;38;2;81;154;186
|
||||||
|
*.t 00;38;2;81;154;186
|
||||||
|
*.rss 00;38;2;251;157;59
|
||||||
|
'*.f#' 00;38;2;81;154;186
|
||||||
|
*.fsscript 00;38;2;81;154;186
|
||||||
|
*.fsx 00;38;2;81;154;186
|
||||||
|
*.fs 00;38;2;81;154;186
|
||||||
|
*.fsi 00;38;2;81;154;186
|
||||||
|
*.rs 00;38;2;222;165;132
|
||||||
|
*.rlib 00;38;2;222;165;132
|
||||||
|
*.d 00;38;2;66;120;25
|
||||||
|
*.erl 00;38;2;184;57;152
|
||||||
|
*.hrl 00;38;2;184;57;152
|
||||||
|
*.ex 00;38;2;160;116;196
|
||||||
|
*.exs 00;38;2;160;116;196
|
||||||
|
*.eex 00;38;2;160;116;196
|
||||||
|
*.leex 00;38;2;160;116;196
|
||||||
|
*.heex 00;38;2;160;116;196
|
||||||
|
*.vim 00;38;2;1;152;51
|
||||||
|
*.ai 00;38;2;203;203;65
|
||||||
|
*.psd 00;38;2;81;154;186
|
||||||
|
*.psb 00;38;2;81;154;186
|
||||||
|
*.ts 00;38;2;81;154;186
|
||||||
|
*.tsx 00;38;2;81;154;186
|
||||||
|
*.jl 00;38;2;162;112;186
|
||||||
|
*.pp 00;38;2;255;166;26
|
||||||
|
*.vue 00;38;2;141;193;73
|
||||||
|
*.elm 00;38;2;81;154;186
|
||||||
|
*.swift 00;38;2;227;121;51
|
||||||
|
*.xcplayground 00;38;2;227;121;51
|
||||||
|
*.tex 00;38;2;61;97;23
|
||||||
|
*.r 00;38;2;53;138;91
|
||||||
|
*.rproj 00;38;2;53;138;91
|
||||||
|
*.sol 00;38;2;81;154;186
|
||||||
|
*.pem 00;38;2;205;155;62
|
||||||
|
|
||||||
|
# file names (vim-devicons) (case-insensitive not supported in lf)
|
||||||
|
*gruntfile.coffee 00;38;2;227;121;51
|
||||||
|
*gruntfile.js 00;38;2;227;121;51
|
||||||
|
*gruntfile.ls 00;38;2;227;121;51
|
||||||
|
*gulpfile.coffee 00;38;2;204;62;68
|
||||||
|
*gulpfile.js 00;38;2;204;62;68
|
||||||
|
*gulpfile.ls 00;38;2;204;62;68
|
||||||
|
*mix.lock 00;38;2;160;116;196
|
||||||
|
*dropbox 00;38;2;0;97;254
|
||||||
|
*.ds_store 00;38;2;77;90;94
|
||||||
|
*.gitconfig 00;38;2;65;83;91
|
||||||
|
*.gitignore 00;38;2;65;83;91
|
||||||
|
*.gitattributes 00;38;2;65;83;91
|
||||||
|
*.gitlab-ci.yml 00;38;2;226;67;41
|
||||||
|
*.bashrc 00;38;2;137;224;81
|
||||||
|
*.zshrc 00;38;2;137;224;81
|
||||||
|
*.zshenv 00;38;2;137;224;81
|
||||||
|
*.zprofile 00;38;2;137;224;81
|
||||||
|
*.vimrc 00;38;2;1;152;51
|
||||||
|
*.gvimrc 00;38;2;1;152;51
|
||||||
|
*_vimrc 00;38;2;1;152;51
|
||||||
|
*_gvimrc 00;38;2;1;152;51
|
||||||
|
*.bashprofile 00;38;2;137;224;81
|
||||||
|
*favicon.ico 00;38;2;203;203;65
|
||||||
|
*license 00;38;2;203;203;65
|
||||||
|
*node_modules 00;38;2;232;39;75
|
||||||
|
*react.jsx 00;38;2;81;154;186
|
||||||
|
*procfile 00;38;2;160;116;196
|
||||||
|
*dockerfile 00;38;2;81;154;186
|
||||||
|
*docker-compose.yml 00;38;2;81;154;186
|
||||||
|
*docker-compose.yaml 00;38;2;81;154;186
|
||||||
|
*compose.yml 00;38;2;81;154;186
|
||||||
|
*compose.yaml 00;38;2;81;154;186
|
||||||
|
*rakefile 00;38;2;112;21;22
|
||||||
|
*config.ru 00;38;2;112;21;22
|
||||||
|
*gemfile 00;38;2;112;21;22
|
||||||
|
*makefile 00;38;2;109;128;134
|
||||||
|
*cmakelists.txt 00;38;2;109;128;134
|
||||||
|
*robots.txt 00;38;2;109;128;134
|
||||||
|
|
||||||
|
# file names (case-sensitive adaptations)
|
||||||
|
*Gruntfile.coffee 00;38;2;227;121;51
|
||||||
|
*Gruntfile.js 00;38;2;227;121;51
|
||||||
|
*Gruntfile.ls 00;38;2;227;121;51
|
||||||
|
*Gulpfile.coffee 00;38;2;204;62;68
|
||||||
|
*Gulpfile.js 00;38;2;204;62;68
|
||||||
|
*Gulpfile.ls 00;38;2;204;62;68
|
||||||
|
*Dropbox 00;38;2;0;97;254
|
||||||
|
*.DS_Store 00;38;2;193;241;46
|
||||||
|
*LICENSE 00;38;2;203;203;65
|
||||||
|
*React.jsx 00;38;2;81;154;186
|
||||||
|
*Procfile 00;38;2;160;116;196
|
||||||
|
*Dockerfile 00;38;2;81;154;186
|
||||||
|
*Docker-compose.yml 00;38;2;81;154;186
|
||||||
|
*Docker-compose.yaml 00;38;2;81;154;186
|
||||||
|
*Rakefile 00;38;2;112;21;22
|
||||||
|
*Gemfile 00;38;2;112;21;22
|
||||||
|
*Makefile 00;38;2;109;128;134
|
||||||
|
*CMakeLists.txt 00;38;2;109;128;134
|
||||||
|
|
||||||
|
# file patterns (vim-devicons) (patterns not supported in lf)
|
||||||
|
# .*jquery.*\.js$ 00;38;2;227;117;187
|
||||||
|
# .*angular.*\.js$ 00;38;2;226;50;55
|
||||||
|
# .*backbone.*\.js$ 00;38;2;0;113;181
|
||||||
|
# .*require.*\.js$ 00;38;2;244;74;65
|
||||||
|
# .*materialize.*\.js$ 00;38;2;238;110;115
|
||||||
|
# .*materialize.*\.css$ 00;38;2;238;110;115
|
||||||
|
# .*mootools.*\.js$ 00;38;2;236;236;236
|
||||||
|
# .*vimrc.* 00;38;2;1;152;51
|
||||||
|
# Vagrantfile$ 00;38;2;21;99;255
|
||||||
|
|
||||||
|
# file patterns (file name adaptations)
|
||||||
|
*jquery.min.js 00;38;2;227;117;187
|
||||||
|
*angular.min.js 00;38;2;226;50;55
|
||||||
|
*backbone.min.js 00;38;2;0;113;181
|
||||||
|
*require.min.js 00;38;2;244;74;65
|
||||||
|
*materialize.min.js 00;38;2;238;110;115
|
||||||
|
*materialize.min.css 00;38;2;238;110;115
|
||||||
|
*mootools.min.js 00;38;2;236;236;236
|
||||||
|
*vimrc 00;38;2;1;152;51
|
||||||
|
Vagrantfile 00;38;2;21;99;255
|
||||||
|
|
||||||
|
# archives or compressed (extensions from dircolors defaults)
|
||||||
|
*.tar
|
||||||
|
*.tgz
|
||||||
|
*.arc
|
||||||
|
*.arj
|
||||||
|
*.taz
|
||||||
|
*.lha
|
||||||
|
*.lz4
|
||||||
|
*.lzh
|
||||||
|
*.lzma
|
||||||
|
*.tlz
|
||||||
|
*.txz
|
||||||
|
*.tzo
|
||||||
|
*.t7z
|
||||||
|
*.zip
|
||||||
|
*.z
|
||||||
|
*.dz
|
||||||
|
*.gz
|
||||||
|
*.lrz
|
||||||
|
*.lz
|
||||||
|
*.lzo
|
||||||
|
*.xz
|
||||||
|
*.zst
|
||||||
|
*.tzst
|
||||||
|
*.bz2
|
||||||
|
*.bz
|
||||||
|
*.tbz
|
||||||
|
*.tbz2
|
||||||
|
*.tz
|
||||||
|
*.deb
|
||||||
|
*.rpm
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.ear
|
||||||
|
*.sar
|
||||||
|
*.rar
|
||||||
|
*.alz
|
||||||
|
*.ace
|
||||||
|
*.zoo
|
||||||
|
*.cpio
|
||||||
|
*.7z
|
||||||
|
*.rz
|
||||||
|
*.cab
|
||||||
|
*.wim
|
||||||
|
*.swm
|
||||||
|
*.dwm
|
||||||
|
*.esd
|
||||||
|
|
||||||
|
# image formats (extensions from dircolors defaults)
|
||||||
|
*.jpg
|
||||||
|
*.jpeg
|
||||||
|
*.mjpg
|
||||||
|
*.mjpeg
|
||||||
|
*.gif
|
||||||
|
*.bmp
|
||||||
|
*.pbm
|
||||||
|
*.pgm
|
||||||
|
*.ppm
|
||||||
|
*.tga
|
||||||
|
*.xbm
|
||||||
|
*.xpm
|
||||||
|
*.tif
|
||||||
|
*.tiff
|
||||||
|
*.png
|
||||||
|
*.svg
|
||||||
|
*.svgz
|
||||||
|
*.mng
|
||||||
|
*.pcx
|
||||||
|
*.mov
|
||||||
|
*.mpg
|
||||||
|
*.mpeg
|
||||||
|
*.m2v
|
||||||
|
*.mkv
|
||||||
|
*.webm
|
||||||
|
*.ogm
|
||||||
|
*.mp4
|
||||||
|
*.m4v
|
||||||
|
*.mp4v
|
||||||
|
*.vob
|
||||||
|
*.qt
|
||||||
|
*.nuv
|
||||||
|
*.wmv
|
||||||
|
*.asf
|
||||||
|
*.rm
|
||||||
|
*.rmvb
|
||||||
|
*.flc
|
||||||
|
*.avi
|
||||||
|
*.fli
|
||||||
|
*.flv
|
||||||
|
*.gl
|
||||||
|
*.dl
|
||||||
|
*.xcf
|
||||||
|
*.xwd
|
||||||
|
*.yuv
|
||||||
|
*.cgm
|
||||||
|
*.emf
|
||||||
|
*.ogv
|
||||||
|
*.ogx
|
||||||
|
|
||||||
|
# audio formats (extensions from dircolors defaults)
|
||||||
|
*.aac
|
||||||
|
*.au
|
||||||
|
*.flac
|
||||||
|
*.m4a
|
||||||
|
*.mid
|
||||||
|
*.midi
|
||||||
|
*.mka
|
||||||
|
*.mp3
|
||||||
|
*.mpc
|
||||||
|
*.ogg
|
||||||
|
*.ra
|
||||||
|
*.wav
|
||||||
|
*.oga
|
||||||
|
*.opus
|
||||||
|
*.spx
|
||||||
|
*.xspf
|
||||||
|
|
||||||
|
# other formats
|
||||||
|
*.pdf 00;38;2;179;11;0
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
#compdef lf
|
#compdef lf lfcd
|
||||||
|
|
||||||
# Autocompletion for zsh shell.
|
# Autocompletion for zsh shell.
|
||||||
#
|
#
|
||||||
|
|||||||
+2
-10
@@ -3,13 +3,5 @@ rem Change working dir in cmd.exe to last dir in lf on exit.
|
|||||||
rem
|
rem
|
||||||
rem You need to put this file to a folder in %PATH% variable.
|
rem You need to put this file to a folder in %PATH% variable.
|
||||||
|
|
||||||
:tmploop
|
chcp 65001 > nul 2>&1
|
||||||
set tmpfile="%tmp%\lf.%random%.tmp"
|
for /f "usebackq tokens=*" %%d in (`lf -print-last-dir %*`) do cd /d %%d
|
||||||
if exist %tmpfile% goto:tmploop
|
|
||||||
lf -last-dir-path=%tmpfile% %*
|
|
||||||
if not exist %tmpfile% exit
|
|
||||||
set /p dir=<%tmpfile%
|
|
||||||
del /f %tmpfile%
|
|
||||||
if not exist "%dir%" exit
|
|
||||||
if "%dir%" == "%cd%" exit
|
|
||||||
cd /d "%dir%"
|
|
||||||
+4
-13
@@ -11,17 +11,8 @@
|
|||||||
#
|
#
|
||||||
# You may put this in a function called fish_user_key_bindings.
|
# You may put this in a function called fish_user_key_bindings.
|
||||||
|
|
||||||
function lfcd
|
function lfcd --wraps="lf" --description="lf - Terminal file manager (changing directory on exit)"
|
||||||
set tmp (mktemp)
|
# `command` is needed in case `lfcd` is aliased to `lf`.
|
||||||
# `command` is needed in case `lfcd` is aliased to `lf`
|
# Quotes will cause `cd` to not change directory if `lf` prints nothing to stdout due to an error.
|
||||||
command lf -last-dir-path=$tmp $argv
|
cd "$(command lf -print-last-dir $argv)"
|
||||||
if test -f "$tmp"
|
|
||||||
set dir (cat $tmp)
|
|
||||||
rm -f $tmp
|
|
||||||
if test -d "$dir"
|
|
||||||
if test "$dir" != (pwd)
|
|
||||||
cd $dir
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
+3
-12
@@ -19,16 +19,7 @@
|
|||||||
# }
|
# }
|
||||||
# ]
|
# ]
|
||||||
|
|
||||||
def-env lfcd [] {
|
# For nushell version >= 0.87.0
|
||||||
let tmp = (mktemp)
|
def --env --wrapped lfcd [...args: string] {
|
||||||
lf -last-dir-path $tmp
|
cd (lf -print-last-dir ...$args)
|
||||||
try {
|
|
||||||
let target_dir = (open --raw $tmp)
|
|
||||||
rm -f $tmp
|
|
||||||
try {
|
|
||||||
if ($target_dir != $env.PWD) { cd $target_dir }
|
|
||||||
} catch { |e| print -e $'lfcd: Can not change to ($target_dir): ($e | get debug)' }
|
|
||||||
} catch {
|
|
||||||
|e| print -e $'lfcd: Reading ($tmp) returned an error: ($e | get debug)'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+1
-11
@@ -13,14 +13,4 @@
|
|||||||
# You may put this in one of the profiles found in $PROFILE.
|
# You may put this in one of the profiles found in $PROFILE.
|
||||||
#
|
#
|
||||||
|
|
||||||
$tmp = [System.IO.Path]::GetTempFileName()
|
lf -print-last-dir $args | Set-Location
|
||||||
lf -last-dir-path="$tmp" $args
|
|
||||||
if (Test-Path -PathType Leaf "$tmp") {
|
|
||||||
$dir = Get-Content "$tmp"
|
|
||||||
Remove-Item -Force "$tmp"
|
|
||||||
if (Test-Path -PathType Container "$dir") {
|
|
||||||
if ("$dir" -ne "$pwd") {
|
|
||||||
cd "$dir"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -60,7 +60,7 @@ map a :push %mkdir<space>
|
|||||||
|
|
||||||
# move current file or selected files to trash folder
|
# move current file or selected files to trash folder
|
||||||
# (also see 'man mv' for backup/overwrite options)
|
# (also see 'man mv' for backup/overwrite options)
|
||||||
cmd trash %set -f; mv $fx ~/.trash
|
cmd trash %set -f; mv -t ~/.trash $fx
|
||||||
|
|
||||||
# define a custom 'delete' command
|
# define a custom 'delete' command
|
||||||
# cmd delete ${{
|
# cmd delete ${{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -537,3 +538,73 @@ func TestSplitKeys(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestApplyBoolOpt(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
opt bool
|
||||||
|
e setExpr
|
||||||
|
exp bool
|
||||||
|
}{
|
||||||
|
{true, setExpr{"feature", ""}, true},
|
||||||
|
{true, setExpr{"feature", "true"}, true},
|
||||||
|
{true, setExpr{"feature", "false"}, false},
|
||||||
|
{false, setExpr{"feature", ""}, true},
|
||||||
|
{false, setExpr{"feature", "true"}, true},
|
||||||
|
{false, setExpr{"feature", "false"}, false},
|
||||||
|
{true, setExpr{"nofeature", ""}, false},
|
||||||
|
{false, setExpr{"nofeature", ""}, false},
|
||||||
|
{true, setExpr{"feature!", ""}, false},
|
||||||
|
{false, setExpr{"feature!", ""}, true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
testStr := fmt.Sprintf("%v", test)
|
||||||
|
if err := applyBoolOpt(&test.opt, &test.e); err != nil {
|
||||||
|
t.Errorf("at test '%s' expected '%t' but got an error '%s'", testStr, test.exp, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if test.opt != test.exp {
|
||||||
|
t.Errorf("at test '%s' expected '%t' but got '%t'", testStr, test.exp, test.opt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApplyLocalBoolOpt(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
localOpt map[string]bool
|
||||||
|
globalOpt bool
|
||||||
|
e setLocalExpr
|
||||||
|
exp bool
|
||||||
|
}{
|
||||||
|
{map[string]bool{}, false, setLocalExpr{"/", "feature", ""}, true},
|
||||||
|
{map[string]bool{}, false, setLocalExpr{"/", "feature", "true"}, true},
|
||||||
|
{map[string]bool{}, false, setLocalExpr{"/", "feature", "false"}, false},
|
||||||
|
{map[string]bool{}, false, setLocalExpr{"/", "nofeature", ""}, false},
|
||||||
|
{map[string]bool{}, true, setLocalExpr{"/", "feature!", ""}, false},
|
||||||
|
{map[string]bool{}, false, setLocalExpr{"/", "feature!", ""}, true},
|
||||||
|
{map[string]bool{"/": true}, false, setLocalExpr{"/", "feature", ""}, true},
|
||||||
|
{map[string]bool{"/": true}, false, setLocalExpr{"/", "feature", "true"}, true},
|
||||||
|
{map[string]bool{"/": true}, false, setLocalExpr{"/", "feature", "false"}, false},
|
||||||
|
{map[string]bool{"/": true}, false, setLocalExpr{"/", "nofeature", ""}, false},
|
||||||
|
{map[string]bool{"/": true}, true, setLocalExpr{"/", "feature!", ""}, false},
|
||||||
|
{map[string]bool{"/": true}, false, setLocalExpr{"/", "feature!", ""}, false},
|
||||||
|
{map[string]bool{"/": false}, false, setLocalExpr{"/", "feature", ""}, true},
|
||||||
|
{map[string]bool{"/": false}, false, setLocalExpr{"/", "feature", "true"}, true},
|
||||||
|
{map[string]bool{"/": false}, false, setLocalExpr{"/", "feature", "false"}, false},
|
||||||
|
{map[string]bool{"/": false}, false, setLocalExpr{"/", "nofeature", ""}, false},
|
||||||
|
{map[string]bool{"/": false}, true, setLocalExpr{"/", "feature!", ""}, true},
|
||||||
|
{map[string]bool{"/": false}, false, setLocalExpr{"/", "feature!", ""}, true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
testStr := fmt.Sprintf("%v", test)
|
||||||
|
if err := applyLocalBoolOpt(test.localOpt, test.globalOpt, &test.e); err != nil {
|
||||||
|
t.Errorf("at test '%s' expected '%t' but got an error '%s'", testStr, test.exp, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
result := test.localOpt[test.e.path]
|
||||||
|
if result != test.exp {
|
||||||
|
t.Errorf("at test '%s' expected '%t' but got '%t'", testStr, test.exp, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+32
@@ -0,0 +1,32 @@
|
|||||||
|
#!/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:2.11
|
||||||
|
|
||||||
|
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
|
||||||
Executable
+30
@@ -0,0 +1,30 @@
|
|||||||
|
#!/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 \
|
||||||
|
--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
|
||||||
|
|
||||||
|
pandoc \
|
||||||
|
--standalone \
|
||||||
|
--from gfm --to plain \
|
||||||
|
doc.md -o doc.txt
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Generates `docstring.go` having `genDocString` variable with `go doc` output.
|
|
||||||
#
|
|
||||||
# This script is called in `doc.go` using `go generate` to embed the
|
|
||||||
# documentation inside the binary in order to show it on request with `-doc`
|
|
||||||
# command line flag. Thus the same documentation is used for online and
|
|
||||||
# terminal display.
|
|
||||||
|
|
||||||
tmp=gen/docstring.go
|
|
||||||
|
|
||||||
echo "// Code generated by gen/docstring.sh DO NOT EDIT." >> $tmp
|
|
||||||
echo >> $tmp
|
|
||||||
echo "package main" >> $tmp
|
|
||||||
echo >> $tmp
|
|
||||||
echo "var genDocString = \`" >> $tmp
|
|
||||||
go doc | tr "\`" "'" >> $tmp
|
|
||||||
echo "\`" >> $tmp
|
|
||||||
|
|
||||||
mv $tmp docstring.go
|
|
||||||
-75
@@ -1,75 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Generates `lf.1` man page using man macros with `go doc` output.
|
|
||||||
#
|
|
||||||
# This script is called in `doc.go` using `go generate` to generate a man page
|
|
||||||
# formatted with man macros from the documentation. A few additional sections
|
|
||||||
# such as `NAME` and `SYNOPSIS` are added to comply with man page conventions.
|
|
||||||
#
|
|
||||||
# Conversion logic implemented here from godoc output to man macros should not
|
|
||||||
# be considered compliant, as such it has inexact assumptions such as the use
|
|
||||||
# of spaces over tabs along with various corner cases that are not handled
|
|
||||||
# properly like character escaping. The intention here is to come up with
|
|
||||||
# something that can convert the current content in the documentation. For this
|
|
||||||
# reason, it is recommended to check the output after generation especially
|
|
||||||
# when the documentation is changed in a significant way.
|
|
||||||
|
|
||||||
out=lf.1
|
|
||||||
|
|
||||||
echo '.\" Code generated by gen/man.sh DO NOT EDIT.' > $out
|
|
||||||
|
|
||||||
cat << END >> $out
|
|
||||||
.TH LF 1
|
|
||||||
.SH NAME
|
|
||||||
lf \- terminal file manager
|
|
||||||
.SH SYNOPSIS
|
|
||||||
.SY lf
|
|
||||||
.OP \-command command
|
|
||||||
.OP \-config path
|
|
||||||
.OP \-cpuprofile path
|
|
||||||
.OP \-doc
|
|
||||||
.OP \-last-dir-path path
|
|
||||||
.OP \-log path
|
|
||||||
.OP \-memprofile path
|
|
||||||
.OP \-remote command
|
|
||||||
.OP \-selection-path path
|
|
||||||
.OP \-server
|
|
||||||
.OP \-single
|
|
||||||
.OP \-version
|
|
||||||
.OP \-help
|
|
||||||
.RI [ cd-or-select-path ]
|
|
||||||
.YS
|
|
||||||
.SH DESCRIPTION
|
|
||||||
END
|
|
||||||
|
|
||||||
go doc | awk '
|
|
||||||
BEGIN {
|
|
||||||
RS = ""
|
|
||||||
start = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# preformatted
|
|
||||||
/^ / {
|
|
||||||
gsub("\\\\", "\\e", $0)
|
|
||||||
print ".PP"
|
|
||||||
print ".EX"
|
|
||||||
print $0
|
|
||||||
print ".EE"
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
# heading
|
|
||||||
/^# *[^[:punct:]]*$/ {
|
|
||||||
gsub(/# */, "", $0)
|
|
||||||
print ".SH", toupper($0)
|
|
||||||
start = 1
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
# paragraph
|
|
||||||
{
|
|
||||||
gsub("\n", " ", $0)
|
|
||||||
gsub("\\\\", "\\e", $0)
|
|
||||||
if (start) { start = 0 } else { print ".PP" }
|
|
||||||
print $0
|
|
||||||
}
|
|
||||||
' >> $out
|
|
||||||
@@ -1,18 +1,20 @@
|
|||||||
module github.com/gokcehan/lf
|
module github.com/gokcehan/lf
|
||||||
|
|
||||||
go 1.18
|
go 1.23.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/djherbis/times v1.5.0
|
github.com/Xuanwo/go-locale v1.1.3
|
||||||
github.com/gdamore/tcell/v2 v2.6.0
|
github.com/djherbis/times v1.6.0
|
||||||
github.com/mattn/go-runewidth v0.0.15
|
github.com/fsnotify/fsnotify v1.9.0
|
||||||
golang.org/x/sys v0.12.0
|
github.com/gdamore/tcell/v2 v2.8.1
|
||||||
golang.org/x/term v0.12.0
|
github.com/mattn/go-runewidth v0.0.16
|
||||||
|
golang.org/x/sys v0.32.0
|
||||||
|
golang.org/x/term v0.31.0
|
||||||
|
golang.org/x/text v0.24.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gdamore/encoding v1.0.0 // indirect
|
github.com/gdamore/encoding v1.0.1 // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
github.com/rivo/uniseg v0.4.3 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
golang.org/x/text v0.7.0 // indirect
|
|
||||||
)
|
)
|
||||||
@@ -1,45 +1,88 @@
|
|||||||
github.com/djherbis/times v1.5.0 h1:79myA211VwPhFTqUk8xehWrsEO+zcIZj0zT8mXPVARU=
|
github.com/Xuanwo/go-locale v1.1.3 h1:EWZZJJt5rqPHHbqPRH1zFCn5D7xHjjebODctA4aUO3A=
|
||||||
github.com/djherbis/times v1.5.0/go.mod h1:5q7FDLvbNg1L/KaBmPcWlVR9NmoKo3+ucqUA3ijQhA0=
|
github.com/Xuanwo/go-locale v1.1.3/go.mod h1:REn+F/c+AtGSWYACBSYZgl23AP+0lfQC+SEFPN+hj30=
|
||||||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
|
||||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
|
||||||
github.com/gdamore/tcell/v2 v2.6.0 h1:OKbluoP9VYmJwZwq/iLb4BxwKcwGthaa1YNBJIyCySg=
|
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||||
github.com/gdamore/tcell/v2 v2.6.0/go.mod h1:be9omFATkdr0D9qewWW3d+MEvl5dha+Etb5y65J2H8Y=
|
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||||
|
github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw=
|
||||||
|
github.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo=
|
||||||
|
github.com/gdamore/tcell/v2 v2.8.1 h1:KPNxyqclpWpWQlPLx6Xui1pMk8S+7+R37h3g07997NU=
|
||||||
|
github.com/gdamore/tcell/v2 v2.8.1/go.mod h1:bj8ori1BG3OYMjmb3IklZVWfZUJ1UBQt9JXrOCOhGWw=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
|
|
||||||
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
|
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||||
|
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||||
|
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
|
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
|
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||||
|
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
|
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||||
|
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||||
|
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||||
|
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
|
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
|
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
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.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
|
||||||
|
golang.org/x/sys v0.32.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-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
|
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||||
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
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.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o=
|
||||||
|
golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
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.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
|
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.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
||||||
|
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
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.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
|
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||||
|
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
@@ -5,12 +5,34 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gdamore/tcell/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type iconMap map[string]string
|
type iconDef struct {
|
||||||
|
icon string
|
||||||
|
hasStyle bool
|
||||||
|
style tcell.Style
|
||||||
|
}
|
||||||
|
|
||||||
|
type iconMap struct {
|
||||||
|
icons map[string]iconDef
|
||||||
|
useLinkTarget bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func iconWithoutStyle(icon string) iconDef {
|
||||||
|
return iconDef{icon, false, tcell.StyleDefault}
|
||||||
|
}
|
||||||
|
|
||||||
|
func iconWithStyle(icon string, style tcell.Style) iconDef {
|
||||||
|
return iconDef{icon, true, style}
|
||||||
|
}
|
||||||
|
|
||||||
func parseIcons() iconMap {
|
func parseIcons() iconMap {
|
||||||
im := make(iconMap)
|
im := iconMap{
|
||||||
|
icons: make(map[string]iconDef),
|
||||||
|
useLinkTarget: false,
|
||||||
|
}
|
||||||
|
|
||||||
defaultIcons := []string{
|
defaultIcons := []string{
|
||||||
"ln=l",
|
"ln=l",
|
||||||
@@ -44,7 +66,7 @@ func parseIcons() iconMap {
|
|||||||
return im
|
return im
|
||||||
}
|
}
|
||||||
|
|
||||||
func (im iconMap) parseFile(path string) {
|
func (im *iconMap) parseFile(path string) {
|
||||||
log.Printf("reading file: %s", path)
|
log.Printf("reading file: %s", path)
|
||||||
|
|
||||||
f, err := os.Open(path)
|
f, err := os.Open(path)
|
||||||
@@ -54,26 +76,18 @@ func (im iconMap) parseFile(path string) {
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
pairs, err := readPairs(f)
|
arrs, err := readArrays(f, 1, 3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("reading icons file: %s", err)
|
log.Printf("reading icons file: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pair := range pairs {
|
for _, arr := range arrs {
|
||||||
key, val := pair[0], pair[1]
|
im.parseArray(arr)
|
||||||
|
|
||||||
key = replaceTilde(key)
|
|
||||||
|
|
||||||
if filepath.IsAbs(key) {
|
|
||||||
key = filepath.Clean(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
im[key] = val
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (im iconMap) parseEnv(env string) {
|
func (im *iconMap) parseEnv(env string) {
|
||||||
for _, entry := range strings.Split(env, ":") {
|
for _, entry := range strings.Split(env, ":") {
|
||||||
if entry == "" {
|
if entry == "" {
|
||||||
continue
|
continue
|
||||||
@@ -86,25 +100,40 @@ func (im iconMap) parseEnv(env string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
key, val := pair[0], pair[1]
|
im.parseArray(pair)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
key = replaceTilde(key)
|
func (im *iconMap) parseArray(arr []string) {
|
||||||
|
key := replaceTilde(arr[0])
|
||||||
|
|
||||||
if filepath.IsAbs(key) {
|
if filepath.IsAbs(key) {
|
||||||
key = filepath.Clean(key)
|
key = filepath.Clean(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
im[key] = val
|
switch len(arr) {
|
||||||
|
case 1:
|
||||||
|
delete(im.icons, key)
|
||||||
|
case 2:
|
||||||
|
icon := arr[1]
|
||||||
|
if key == "ln" && icon == "target" {
|
||||||
|
im.useLinkTarget = true
|
||||||
|
} else {
|
||||||
|
im.icons[key] = iconWithoutStyle(icon)
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
icon, color := arr[1], arr[2]
|
||||||
|
im.icons[key] = iconWithStyle(icon, applyAnsiCodes(color, tcell.StyleDefault))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (im iconMap) get(f *file) string {
|
func (im iconMap) get(f *file) iconDef {
|
||||||
if val, ok := im[f.path]; ok {
|
if val, ok := im.icons[f.path]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
if val, ok := im[f.Name()+"/"]; ok {
|
if val, ok := im.icons[f.Name()+"/"]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,13 +141,13 @@ func (im iconMap) get(f *file) string {
|
|||||||
var key string
|
var key string
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case f.linkState == working:
|
case f.linkState == working && !im.useLinkTarget:
|
||||||
key = "ln"
|
key = "ln"
|
||||||
case f.linkState == broken:
|
case f.linkState == broken:
|
||||||
key = "or"
|
key = "or"
|
||||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
|
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0o002 != 0:
|
||||||
key = "tw"
|
key = "tw"
|
||||||
case f.IsDir() && f.Mode()&0002 != 0:
|
case f.IsDir() && f.Mode()&0o002 != 0:
|
||||||
key = "ow"
|
key = "ow"
|
||||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
||||||
key = "st"
|
key = "st"
|
||||||
@@ -128,41 +157,41 @@ func (im iconMap) get(f *file) string {
|
|||||||
key = "pi"
|
key = "pi"
|
||||||
case f.Mode()&os.ModeSocket != 0:
|
case f.Mode()&os.ModeSocket != 0:
|
||||||
key = "so"
|
key = "so"
|
||||||
case f.Mode()&os.ModeDevice != 0:
|
|
||||||
key = "bd"
|
|
||||||
case f.Mode()&os.ModeCharDevice != 0:
|
case f.Mode()&os.ModeCharDevice != 0:
|
||||||
key = "cd"
|
key = "cd"
|
||||||
|
case f.Mode()&os.ModeDevice != 0:
|
||||||
|
key = "bd"
|
||||||
case f.Mode()&os.ModeSetuid != 0:
|
case f.Mode()&os.ModeSetuid != 0:
|
||||||
key = "su"
|
key = "su"
|
||||||
case f.Mode()&os.ModeSetgid != 0:
|
case f.Mode()&os.ModeSetgid != 0:
|
||||||
key = "sg"
|
key = "sg"
|
||||||
case f.Mode()&0111 != 0:
|
case f.Mode()&0o111 != 0:
|
||||||
key = "ex"
|
key = "ex"
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := im[key]; ok {
|
if val, ok := im.icons[key]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := im[f.Name()+"*"]; ok {
|
if val, ok := im.icons[f.Name()+"*"]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := im["*"+f.Name()]; ok {
|
if val, ok := im.icons["*"+f.Name()]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := im[filepath.Base(f.Name())+".*"]; ok {
|
if val, ok := im.icons[filepath.Base(f.Name())+".*"]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := im["*"+strings.ToLower(f.ext)]; ok {
|
if val, ok := im.icons["*"+strings.ToLower(f.ext)]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := im["fi"]; ok {
|
if val, ok := im.icons["fi"]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
return " "
|
return iconWithoutStyle(" ")
|
||||||
}
|
}
|
||||||
@@ -9,11 +9,17 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/debug"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
_ "embed"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed doc.txt
|
||||||
|
var genDocString string
|
||||||
|
|
||||||
var (
|
var (
|
||||||
envPath = os.Getenv("PATH")
|
envPath = os.Getenv("PATH")
|
||||||
envLevel = os.Getenv("LF_LEVEL")
|
envLevel = os.Getenv("LF_LEVEL")
|
||||||
@@ -101,7 +107,7 @@ func fieldToString(field reflect.Value) string {
|
|||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
value = strconv.FormatBool(field.Bool())
|
value = strconv.FormatBool(field.Bool())
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
for i := 0; i < field.Len(); i++ {
|
for i := range field.Len() {
|
||||||
element := field.Index(i)
|
element := field.Index(i)
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
@@ -122,7 +128,7 @@ func getOptsMap() map[string]string {
|
|||||||
v := reflect.ValueOf(gOpts)
|
v := reflect.ValueOf(gOpts)
|
||||||
t := v.Type()
|
t := v.Type()
|
||||||
|
|
||||||
for i := 0; i < v.NumField(); i++ {
|
for i := range v.NumField() {
|
||||||
// Get field name and prefix it with lf_
|
// Get field name and prefix it with lf_
|
||||||
name := "lf_" + t.Field(i).Name
|
name := "lf_" + t.Field(i).Name
|
||||||
|
|
||||||
@@ -131,32 +137,7 @@ func getOptsMap() map[string]string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get string representation of the value
|
if name == "lf_user" {
|
||||||
if name == "lf_sortType" {
|
|
||||||
var sortby string
|
|
||||||
|
|
||||||
switch gOpts.sortType.method {
|
|
||||||
case naturalSort:
|
|
||||||
sortby = "natural"
|
|
||||||
case nameSort:
|
|
||||||
sortby = "name"
|
|
||||||
case sizeSort:
|
|
||||||
sortby = "size"
|
|
||||||
case timeSort:
|
|
||||||
sortby = "time"
|
|
||||||
case ctimeSort:
|
|
||||||
sortby = "ctime"
|
|
||||||
case atimeSort:
|
|
||||||
sortby = "atime"
|
|
||||||
case extSort:
|
|
||||||
sortby = "ext"
|
|
||||||
}
|
|
||||||
|
|
||||||
opts["lf_sortby"] = sortby
|
|
||||||
opts["lf_reverse"] = strconv.FormatBool(gOpts.sortType.option&reverseSort != 0)
|
|
||||||
opts["lf_hidden"] = strconv.FormatBool(gOpts.sortType.option&hiddenSort != 0)
|
|
||||||
opts["lf_dirfirst"] = strconv.FormatBool(gOpts.sortType.option&dirfirstSort != 0)
|
|
||||||
} else if name == "lf_user" {
|
|
||||||
// set each user option
|
// set each user option
|
||||||
for key, value := range gOpts.user {
|
for key, value := range gOpts.user {
|
||||||
opts[name+"_"+key] = value
|
opts[name+"_"+key] = value
|
||||||
@@ -197,6 +178,37 @@ func checkServer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printVersion() {
|
||||||
|
if gVersion != "" {
|
||||||
|
fmt.Println(gVersion)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
buildInfo, ok := debug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var vcsRevision, vcsTime, vcsModified string
|
||||||
|
for _, setting := range buildInfo.Settings {
|
||||||
|
switch setting.Key {
|
||||||
|
case "vcs.revision":
|
||||||
|
vcsRevision = setting.Value
|
||||||
|
case "vcs.time":
|
||||||
|
vcsTime = setting.Value
|
||||||
|
case "vcs.modified":
|
||||||
|
if setting.Value == "true" {
|
||||||
|
vcsModified = " (dirty)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if vcsRevision != "" {
|
||||||
|
fmt.Printf("Built at commit: %s%s %s\n", vcsRevision, vcsModified, vcsTime)
|
||||||
|
}
|
||||||
|
fmt.Printf("Go version: %s\n", buildInfo.GoVersion)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
f := flag.CommandLine.Output()
|
f := flag.CommandLine.Output()
|
||||||
@@ -299,7 +311,7 @@ func main() {
|
|||||||
case *showDoc:
|
case *showDoc:
|
||||||
fmt.Print(genDocString)
|
fmt.Print(genDocString)
|
||||||
case *showVersion:
|
case *showVersion:
|
||||||
fmt.Println(gVersion)
|
printVersion()
|
||||||
case *remoteCmd != "":
|
case *remoteCmd != "":
|
||||||
if err := remote(*remoteCmd); err != nil {
|
if err := remote(*remoteCmd); err != nil {
|
||||||
log.Fatalf("remote command: %s", err)
|
log.Fatalf("remote command: %s", err)
|
||||||
|
|||||||
@@ -4,20 +4,29 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/Xuanwo/go-locale"
|
||||||
"github.com/mattn/go-runewidth"
|
"github.com/mattn/go-runewidth"
|
||||||
|
"golang.org/x/text/collate"
|
||||||
|
"golang.org/x/text/language"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
localeStrDisable = "" // disable locale ordering for this locale value
|
||||||
|
localeStrSys = "*" // replace this locale value with locale value read from environment
|
||||||
)
|
)
|
||||||
|
|
||||||
func isRoot(name string) bool { return filepath.Dir(name) == name }
|
func isRoot(name string) bool { return filepath.Dir(name) == name }
|
||||||
|
|
||||||
func replaceTilde(s string) string {
|
func replaceTilde(s string) string {
|
||||||
if strings.HasPrefix(s, "~") {
|
if strings.HasPrefix(s, "~") {
|
||||||
s = strings.Replace(s, "~", gUser.HomeDir, 1)
|
return gUser.HomeDir + s[1:]
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
@@ -67,7 +76,7 @@ func runeSliceWidthLastRange(rs []rune, maxWidth int) []rune {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This function is used to escape whitespaces and special characters with
|
// This function is used to escape whitespaces and special characters with
|
||||||
// backlashes in a given string.
|
// backslashes in a given string.
|
||||||
func escape(s string) string {
|
func escape(s string) string {
|
||||||
buf := make([]rune, 0, len(s))
|
buf := make([]rune, 0, len(s))
|
||||||
for _, r := range s {
|
for _, r := range s {
|
||||||
@@ -79,7 +88,7 @@ func escape(s string) string {
|
|||||||
return string(buf)
|
return string(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is used to remove backlashes that are used to escape
|
// This function is used to remove backslashes that are used to escape
|
||||||
// whitespaces and special characters in a given string.
|
// whitespaces and special characters in a given string.
|
||||||
func unescape(s string) string {
|
func unescape(s string) string {
|
||||||
esc := false
|
esc := false
|
||||||
@@ -130,8 +139,7 @@ func tokenize(s string) []string {
|
|||||||
buf = nil
|
buf = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toks = append(toks, string(buf))
|
return append(toks, string(buf))
|
||||||
return toks
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function splits the first word of a string delimited by whitespace from
|
// This function splits the first word of a string delimited by whitespace from
|
||||||
@@ -151,18 +159,18 @@ func splitWord(s string) (word, rest string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function reads whitespace separated string pairs at each line. Single
|
// This function reads whitespace separated string arrays at each line. Single
|
||||||
// or double quotes can be used to escape whitespaces. Hash characters can be
|
// or double quotes can be used to escape whitespaces. Hash characters can be
|
||||||
// used to add a comment until the end of line. Leading and trailing space is
|
// used to add a comment until the end of line. Leading and trailing space is
|
||||||
// trimmed. Empty lines are skipped.
|
// trimmed. Empty lines are skipped.
|
||||||
func readPairs(r io.Reader) ([][]string, error) {
|
func readArrays(r io.Reader, min_cols, max_cols int) ([][]string, error) {
|
||||||
var pairs [][]string
|
var arrays [][]string
|
||||||
s := bufio.NewScanner(r)
|
s := bufio.NewScanner(r)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
line := s.Text()
|
line := s.Text()
|
||||||
|
|
||||||
squote, dquote := false, false
|
squote, dquote := false, false
|
||||||
for i := 0; i < len(line); i++ {
|
for i := range len(line) {
|
||||||
if line[i] == '\'' && !dquote {
|
if line[i] == '\'' && !dquote {
|
||||||
squote = !squote
|
squote = !squote
|
||||||
} else if line[i] == '"' && !squote {
|
} else if line[i] == '"' && !squote {
|
||||||
@@ -181,7 +189,7 @@ func readPairs(r io.Reader) ([][]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
squote, dquote = false, false
|
squote, dquote = false, false
|
||||||
pair := strings.FieldsFunc(line, func(r rune) bool {
|
arr := strings.FieldsFunc(line, func(r rune) bool {
|
||||||
if r == '\'' && !dquote {
|
if r == '\'' && !dquote {
|
||||||
squote = !squote
|
squote = !squote
|
||||||
} else if r == '"' && !squote {
|
} else if r == '"' && !squote {
|
||||||
@@ -189,15 +197,19 @@ func readPairs(r io.Reader) ([][]string, error) {
|
|||||||
}
|
}
|
||||||
return !squote && !dquote && unicode.IsSpace(r)
|
return !squote && !dquote && unicode.IsSpace(r)
|
||||||
})
|
})
|
||||||
|
arrlen := len(arr)
|
||||||
|
|
||||||
if len(pair) != 2 {
|
if arrlen < min_cols || arrlen > max_cols {
|
||||||
return nil, fmt.Errorf("expected pair but found: %s", s.Text())
|
if min_cols == max_cols {
|
||||||
|
return nil, fmt.Errorf("expected %d columns but found: %s", min_cols, s.Text())
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("expected %d~%d columns but found: %s", min_cols, max_cols, s.Text())
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(pair); i++ {
|
for i := range arrlen {
|
||||||
squote, dquote = false, false
|
squote, dquote = false, false
|
||||||
buf := make([]rune, 0, len(pair[i]))
|
buf := make([]rune, 0, len(arr[i]))
|
||||||
for _, r := range pair[i] {
|
for _, r := range arr[i] {
|
||||||
if r == '\'' && !dquote {
|
if r == '\'' && !dquote {
|
||||||
squote = !squote
|
squote = !squote
|
||||||
continue
|
continue
|
||||||
@@ -208,13 +220,17 @@ func readPairs(r io.Reader) ([][]string, error) {
|
|||||||
}
|
}
|
||||||
buf = append(buf, r)
|
buf = append(buf, r)
|
||||||
}
|
}
|
||||||
pair[i] = string(buf)
|
arr[i] = string(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
pairs = append(pairs, pair)
|
arrays = append(arrays, arr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pairs, nil
|
return arrays, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
// This function converts a size in bytes to a human readable form using metric
|
||||||
@@ -241,7 +257,8 @@ func humanize(size int64) string {
|
|||||||
for _, s := range suffix {
|
for _, s := range suffix {
|
||||||
if curr < 10 {
|
if curr < 10 {
|
||||||
return fmt.Sprintf("%.1f%s", curr-0.0499, s)
|
return fmt.Sprintf("%.1f%s", curr-0.0499, s)
|
||||||
} else if curr < 1000 {
|
}
|
||||||
|
if curr < 1000 {
|
||||||
return fmt.Sprintf("%d%s", int(curr), s)
|
return fmt.Sprintf("%d%s", int(curr), s)
|
||||||
}
|
}
|
||||||
curr /= 1000
|
curr /= 1000
|
||||||
@@ -256,22 +273,24 @@ func humanize(size int64) string {
|
|||||||
// than 'foo10bar'.
|
// than 'foo10bar'.
|
||||||
func naturalLess(s1, s2 string) bool {
|
func naturalLess(s1, s2 string) bool {
|
||||||
lo1, lo2, hi1, hi2 := 0, 0, 0, 0
|
lo1, lo2, hi1, hi2 := 0, 0, 0, 0
|
||||||
|
s1len := len(s1)
|
||||||
|
s2len := len(s2)
|
||||||
for {
|
for {
|
||||||
if hi1 >= len(s1) {
|
if hi1 >= s1len {
|
||||||
return hi2 != len(s2)
|
return hi2 != s2len
|
||||||
}
|
}
|
||||||
|
|
||||||
if hi2 >= len(s2) {
|
if hi2 >= s2len {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
isDigit1 := isDigit(s1[hi1])
|
isDigit1 := isDigit(s1[hi1])
|
||||||
isDigit2 := isDigit(s2[hi2])
|
isDigit2 := isDigit(s2[hi2])
|
||||||
|
|
||||||
for lo1 = hi1; hi1 < len(s1) && isDigit(s1[hi1]) == isDigit1; hi1++ {
|
for lo1 = hi1; hi1 < s1len && isDigit(s1[hi1]) == isDigit1; hi1++ {
|
||||||
}
|
}
|
||||||
|
|
||||||
for lo2 = hi2; hi2 < len(s2) && isDigit(s2[hi2]) == isDigit2; hi2++ {
|
for lo2 = hi2; hi2 < s2len && isDigit(s2[hi2]) == isDigit2; hi2++ {
|
||||||
}
|
}
|
||||||
|
|
||||||
if s1[lo1:hi1] == s2[lo2:hi2] {
|
if s1[lo1:hi1] == s2[lo2:hi2] {
|
||||||
@@ -291,25 +310,63 @@ func naturalLess(s1, s2 string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var reModKey = regexp.MustCompile(`<(c|s|a)-(.+)>`)
|
// This function returns the extension of a file with a leading dot
|
||||||
var reRulerSub = regexp.MustCompile(`%[apmcsfithd]|%\{[^}]+\}`)
|
// it returns an empty string if extension could not be determined
|
||||||
|
// i.e. directories, filenames without extensions
|
||||||
var reWord = regexp.MustCompile(`(\pL|\pN)+`)
|
func getFileExtension(file fs.FileInfo) string {
|
||||||
var reWordBeg = regexp.MustCompile(`([^\pL\pN]|^)(\pL|\pN)`)
|
if file.IsDir() {
|
||||||
var reWordEnd = regexp.MustCompile(`(\pL|\pN)([^\pL\pN]|$)`)
|
return ""
|
||||||
|
|
||||||
func min(a, b int) int {
|
|
||||||
if a < b {
|
|
||||||
return a
|
|
||||||
}
|
}
|
||||||
return b
|
if strings.Count(file.Name(), ".") == 1 && file.Name()[0] == '.' {
|
||||||
|
// hidden file without extension
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return filepath.Ext(file.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
func max(a, b int) int {
|
var (
|
||||||
if a > b {
|
reModKey = regexp.MustCompile(`<(c|s|a)-(.+)>`)
|
||||||
return a
|
reRulerSub = regexp.MustCompile(`%[apmcsfithd]|%\{[^}]+\}`)
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
reWord = regexp.MustCompile(`(\pL|\pN)+`)
|
||||||
|
reWordBeg = regexp.MustCompile(`([^\pL\pN]|^)(\pL|\pN)`)
|
||||||
|
reWordEnd = regexp.MustCompile(`(\pL|\pN)([^\pL\pN]|$)`)
|
||||||
|
)
|
||||||
|
|
||||||
|
// This function parses given locale string into language tag value. Passing empty
|
||||||
|
// string as locale means reading locale value from environment.
|
||||||
|
func getLocaleTag(localeStr string) (language.Tag, error) {
|
||||||
|
if localeStr == localeStrSys {
|
||||||
|
// read environment locale
|
||||||
|
return locale.Detect()
|
||||||
}
|
}
|
||||||
return b
|
|
||||||
|
localeTag, err := language.Parse(localeStr)
|
||||||
|
if err != nil {
|
||||||
|
return localeTag, fmt.Errorf("invalid locale %q: %s", localeStr, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return localeTag, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function creates new collator for given locale. Passing empty string as
|
||||||
|
// as locale means reading locale value from environment.
|
||||||
|
//
|
||||||
|
// *Note*: this function returns error when given `localeStr` has value `localeStrDisable`
|
||||||
|
// or is an invalid locale tag.
|
||||||
|
func makeCollator(localeStr string, opts ...collate.Option) (*collate.Collator, error) {
|
||||||
|
if localeStr == localeStrDisable {
|
||||||
|
return nil, fmt.Errorf("locale is disabled")
|
||||||
|
}
|
||||||
|
|
||||||
|
localeTag, err := getLocaleTag(localeStr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return collate.New(localeTag, opts...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't need no generic code
|
// We don't need no generic code
|
||||||
|
|||||||
+103
-10
@@ -5,6 +5,9 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/text/collate"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsRoot(t *testing.T) {
|
func TestIsRoot(t *testing.T) {
|
||||||
@@ -216,23 +219,27 @@ func TestSplitWord(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadPairs(t *testing.T) {
|
func TestReadArrays(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
s string
|
s string
|
||||||
|
min_cols int
|
||||||
|
max_cols int
|
||||||
exp [][]string
|
exp [][]string
|
||||||
}{
|
}{
|
||||||
{"foo bar", [][]string{{"foo", "bar"}}},
|
{"foo bar", 2, 2, [][]string{{"foo", "bar"}}},
|
||||||
{"foo bar ", [][]string{{"foo", "bar"}}},
|
{"foo bar ", 2, 2, [][]string{{"foo", "bar"}}},
|
||||||
{" foo bar", [][]string{{"foo", "bar"}}},
|
{" foo bar", 2, 2, [][]string{{"foo", "bar"}}},
|
||||||
{" foo bar ", [][]string{{"foo", "bar"}}},
|
{" foo bar ", 2, 2, [][]string{{"foo", "bar"}}},
|
||||||
{"foo bar#baz", [][]string{{"foo", "bar"}}},
|
{"foo bar#baz", 2, 2, [][]string{{"foo", "bar"}}},
|
||||||
{"foo bar #baz", [][]string{{"foo", "bar"}}},
|
{"foo bar #baz", 2, 2, [][]string{{"foo", "bar"}}},
|
||||||
{`'foo#baz' bar`, [][]string{{"foo#baz", "bar"}}},
|
{`'foo#baz' bar`, 2, 2, [][]string{{"foo#baz", "bar"}}},
|
||||||
{`"foo#baz" bar`, [][]string{{"foo#baz", "bar"}}},
|
{`"foo#baz" bar`, 2, 2, [][]string{{"foo#baz", "bar"}}},
|
||||||
|
{"foo bar baz", 3, 3, [][]string{{"foo", "bar", "baz"}}},
|
||||||
|
{`"foo bar baz"`, 1, 1, [][]string{{"foo bar baz"}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
if got, _ := readPairs(strings.NewReader(test.s)); !reflect.DeepEqual(got, test.exp) {
|
if got, _ := readArrays(strings.NewReader(test.s), test.min_cols, test.max_cols); !reflect.DeepEqual(got, test.exp) {
|
||||||
t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
|
t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -293,3 +300,89 @@ func TestNaturalLess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type fakeFileInfo struct {
|
||||||
|
name string
|
||||||
|
isDir bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fileinfo fakeFileInfo) Name() string { return fileinfo.name }
|
||||||
|
func (fileinfo fakeFileInfo) Size() int64 { return 0 }
|
||||||
|
func (fileinfo fakeFileInfo) Mode() os.FileMode { return os.FileMode(0o000) }
|
||||||
|
func (fileinfo fakeFileInfo) ModTime() time.Time { return time.Unix(0, 0) }
|
||||||
|
func (fileinfo fakeFileInfo) IsDir() bool { return fileinfo.isDir }
|
||||||
|
func (fileinfo fakeFileInfo) Sys() any { return nil }
|
||||||
|
|
||||||
|
func TestGetFileExtension(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fileName string
|
||||||
|
isDir bool
|
||||||
|
expectedExtension string
|
||||||
|
}{
|
||||||
|
{"normal file", "file.txt", false, ".txt"},
|
||||||
|
{"file without extension", "file", false, ""},
|
||||||
|
{"hidden file", ".gitignore", false, ""},
|
||||||
|
{"hidden file with extension", ".file.txt", false, ".txt"},
|
||||||
|
{"directory", "dir", true, ""},
|
||||||
|
{"hidden directory", ".git", true, ""},
|
||||||
|
{"directory with dot", "profile.d", true, ""},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
if got := getFileExtension(fakeFileInfo{test.fileName, test.isDir}); got != test.expectedExtension {
|
||||||
|
t.Errorf("at input '%s' expected '%s' but got '%s'", test.fileName, test.expectedExtension, got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLocaleNaturalLess(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
s1 string
|
||||||
|
s2 string
|
||||||
|
exp bool
|
||||||
|
}{
|
||||||
|
// preserving behavior of `naturalLess`
|
||||||
|
{"foo", "bar", false},
|
||||||
|
{"bar", "baz", true},
|
||||||
|
{"foo", "123", false},
|
||||||
|
{"foo1", "foobar", true},
|
||||||
|
{"foo1", "foo10", true},
|
||||||
|
{"foo2", "foo10", true},
|
||||||
|
{"foo1", "foo10bar", true},
|
||||||
|
{"foo2", "foo10bar", true},
|
||||||
|
{"foo1bar", "foo10bar", true},
|
||||||
|
{"foo2bar", "foo10bar", true},
|
||||||
|
{"foo1bar", "foo10", true},
|
||||||
|
{"foo2bar", "foo10", true},
|
||||||
|
|
||||||
|
// locale sort
|
||||||
|
{"你好", "他好", true}, // \u4F60\u597D, \u4ED6\u597D
|
||||||
|
{"到这", "到那", false}, // \u5230\u8FD9, \u5230\u90A3
|
||||||
|
{"你说", "什么", true}, // \u4f60\u8bf4, \u4ec0\u4e48
|
||||||
|
{"你好", "World", false}, // \u4F60\u597D, \u57\u6f\u72\u6c\u64
|
||||||
|
{"甲1", "甲乙", true},
|
||||||
|
{"甲1", "甲10", true},
|
||||||
|
{"甲2", "甲10", true},
|
||||||
|
{"甲1", "甲10乙", true},
|
||||||
|
{"甲2", "甲10乙", true},
|
||||||
|
{"甲1乙", "甲10乙", true},
|
||||||
|
{"甲2乙", "甲10乙", true},
|
||||||
|
{"甲1乙", "甲10", true},
|
||||||
|
{"甲2乙", "甲10", true},
|
||||||
|
}
|
||||||
|
|
||||||
|
localeStr := "zh-CN"
|
||||||
|
collator, err := makeCollator(localeStr, collate.Numeric)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create collator for %q: %s", localeStr, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
if got := collator.CompareString(test.s1, test.s2) < 0; got != test.exp {
|
||||||
|
t.Errorf("at input '%s' and '%s' expected '%t' but got '%t'", test.s1, test.s2, test.exp, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -11,12 +10,14 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/djherbis/times"
|
"github.com/djherbis/times"
|
||||||
|
"golang.org/x/text/collate"
|
||||||
)
|
)
|
||||||
|
|
||||||
type linkState byte
|
type linkState byte
|
||||||
@@ -40,73 +41,37 @@ type file struct {
|
|||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (file *file) TotalSize() int64 {
|
func newFile(path string) *file {
|
||||||
if file.IsDir() {
|
lstat, err := os.Lstat(path)
|
||||||
if file.dirSize >= 0 {
|
|
||||||
return file.dirSize
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return file.Size()
|
|
||||||
}
|
|
||||||
|
|
||||||
type fakeStat struct {
|
|
||||||
name string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fs *fakeStat) Name() string { return fs.name }
|
|
||||||
func (fs *fakeStat) Size() int64 { return 0 }
|
|
||||||
func (fs *fakeStat) Mode() os.FileMode { return os.FileMode(0000) }
|
|
||||||
func (fs *fakeStat) ModTime() time.Time { return time.Unix(0, 0) }
|
|
||||||
func (fs *fakeStat) IsDir() bool { return false }
|
|
||||||
func (fs *fakeStat) Sys() any { return nil }
|
|
||||||
|
|
||||||
func readdir(path string) ([]*file, error) {
|
|
||||||
f, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
names, err := f.Readdirnames(-1)
|
|
||||||
f.Close()
|
|
||||||
|
|
||||||
files := make([]*file, 0, len(names))
|
|
||||||
for _, fname := range names {
|
|
||||||
fpath := filepath.Join(path, fname)
|
|
||||||
|
|
||||||
lstat, err := os.Lstat(fpath)
|
|
||||||
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("getting file information: %s", err)
|
log.Printf("getting file information: %s", err)
|
||||||
files = append(files, &file{
|
return &file{
|
||||||
FileInfo: &fakeStat{name: fname},
|
FileInfo: &fakeStat{name: filepath.Base(path)},
|
||||||
linkState: notLink,
|
linkState: notLink,
|
||||||
linkTarget: "",
|
linkTarget: "",
|
||||||
path: fpath,
|
path: path,
|
||||||
dirCount: -1,
|
dirCount: -1,
|
||||||
dirSize: -1,
|
dirSize: -1,
|
||||||
accessTime: time.Unix(0, 0),
|
accessTime: time.Unix(0, 0),
|
||||||
changeTime: time.Unix(0, 0),
|
changeTime: time.Unix(0, 0),
|
||||||
ext: filepath.Ext(fpath),
|
ext: "",
|
||||||
err: err,
|
err: err,
|
||||||
})
|
}
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var linkState linkState
|
var linkState linkState
|
||||||
var linkTarget string
|
var linkTarget string
|
||||||
|
|
||||||
if lstat.Mode()&os.ModeSymlink != 0 {
|
if lstat.Mode()&os.ModeSymlink != 0 {
|
||||||
stat, err := os.Stat(fpath)
|
stat, err := os.Stat(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
linkState = working
|
linkState = working
|
||||||
lstat = stat
|
lstat = stat
|
||||||
} else {
|
} else {
|
||||||
linkState = broken
|
linkState = broken
|
||||||
}
|
}
|
||||||
linkTarget, err = os.Readlink(fpath)
|
linkTarget, err = os.Readlink(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("reading link target: %s", err)
|
log.Printf("reading link target: %s", err)
|
||||||
}
|
}
|
||||||
@@ -123,13 +88,9 @@ func readdir(path string) ([]*file, error) {
|
|||||||
ct = lstat.ModTime()
|
ct = lstat.ModTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns an empty string if extension could not be determined
|
|
||||||
// i.e. directories, filenames without extensions
|
|
||||||
ext := filepath.Ext(fpath)
|
|
||||||
|
|
||||||
dirCount := -1
|
dirCount := -1
|
||||||
if lstat.IsDir() && gOpts.dircounts {
|
if lstat.IsDir() && getDirCounts(filepath.Dir(path)) {
|
||||||
d, err := os.Open(fpath)
|
d, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dirCount = -2
|
dirCount = -2
|
||||||
} else {
|
} else {
|
||||||
@@ -144,18 +105,52 @@ func readdir(path string) ([]*file, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
files = append(files, &file{
|
return &file{
|
||||||
FileInfo: lstat,
|
FileInfo: lstat,
|
||||||
linkState: linkState,
|
linkState: linkState,
|
||||||
linkTarget: linkTarget,
|
linkTarget: linkTarget,
|
||||||
path: fpath,
|
path: path,
|
||||||
dirCount: dirCount,
|
dirCount: dirCount,
|
||||||
dirSize: -1,
|
dirSize: -1,
|
||||||
accessTime: at,
|
accessTime: at,
|
||||||
changeTime: ct,
|
changeTime: ct,
|
||||||
ext: ext,
|
ext: getFileExtension(lstat),
|
||||||
err: nil,
|
err: nil,
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (file *file) TotalSize() int64 {
|
||||||
|
if file.IsDir() {
|
||||||
|
if file.dirSize >= 0 {
|
||||||
|
return file.dirSize
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return file.Size()
|
||||||
|
}
|
||||||
|
|
||||||
|
type fakeStat struct {
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fs *fakeStat) Name() string { return fs.name }
|
||||||
|
func (fs *fakeStat) Size() int64 { return 0 }
|
||||||
|
func (fs *fakeStat) Mode() os.FileMode { return os.FileMode(0o000) }
|
||||||
|
func (fs *fakeStat) ModTime() time.Time { return time.Unix(0, 0) }
|
||||||
|
func (fs *fakeStat) IsDir() bool { return false }
|
||||||
|
func (fs *fakeStat) Sys() any { return nil }
|
||||||
|
|
||||||
|
func readdir(path string) ([]*file, error) {
|
||||||
|
f, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
names, err := f.Readdirnames(-1)
|
||||||
|
f.Close()
|
||||||
|
|
||||||
|
files := make([]*file, 0, len(names))
|
||||||
|
for _, fname := range names {
|
||||||
|
files = append(files, newFile(filepath.Join(path, fname)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return files, err
|
return files, err
|
||||||
@@ -169,14 +164,17 @@ type dir struct {
|
|||||||
path string // full path of directory
|
path string // full path of directory
|
||||||
files []*file // displayed files in directory including or excluding hidden ones
|
files []*file // displayed files in directory including or excluding hidden ones
|
||||||
allFiles []*file // all files in directory including hidden ones (same array as files)
|
allFiles []*file // all files in directory including hidden ones (same array as files)
|
||||||
sortType sortType // sort method and options from last sort
|
sortby sortMethod // sortby value from last sort
|
||||||
|
dirfirst bool // dirfirst value from last sort
|
||||||
dironly bool // dironly 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
|
||||||
hiddenfiles []string // hiddenfiles value from last sort
|
hiddenfiles []string // hiddenfiles value from last sort
|
||||||
filter []string // last filter for this directory
|
filter []string // last filter for this directory
|
||||||
ignorecase bool // ignorecase value from last sort
|
ignorecase bool // ignorecase value from last sort
|
||||||
ignoredia bool // ignoredia value from last sort
|
ignoredia bool // ignoredia value from last sort
|
||||||
|
locale string // locale value from last sort
|
||||||
noPerm bool // whether lf has no permission to open the directory
|
noPerm bool // whether lf has no permission to open the directory
|
||||||
lines []string // lines of text to display if directory previews are enabled
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDir(path string) *dir {
|
func newDir(path string) *dir {
|
||||||
@@ -188,7 +186,6 @@ func newDir(path string) *dir {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &dir{
|
return &dir{
|
||||||
loading: gOpts.dirpreviews, // Directory is loaded after previewer function exits.
|
|
||||||
loadTime: time,
|
loadTime: time,
|
||||||
path: path,
|
path: path,
|
||||||
files: files,
|
files: files,
|
||||||
@@ -198,11 +195,11 @@ func newDir(path string) *dir {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func normalize(s1, s2 string, ignorecase, ignoredia bool) (string, string) {
|
func normalize(s1, s2 string, ignorecase, ignoredia bool) (string, string) {
|
||||||
if gOpts.ignorecase {
|
if ignorecase {
|
||||||
s1 = strings.ToLower(s1)
|
s1 = strings.ToLower(s1)
|
||||||
s2 = strings.ToLower(s2)
|
s2 = strings.ToLower(s2)
|
||||||
}
|
}
|
||||||
if gOpts.ignoredia {
|
if ignoredia {
|
||||||
s1 = removeDiacritics(s1)
|
s1 = removeDiacritics(s1)
|
||||||
s2 = removeDiacritics(s2)
|
s2 = removeDiacritics(s2)
|
||||||
}
|
}
|
||||||
@@ -210,8 +207,12 @@ func normalize(s1, s2 string, ignorecase, ignoredia bool) (string, string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dir *dir) sort() {
|
func (dir *dir) sort() {
|
||||||
dir.sortType = getSortType(dir.path)
|
dir.sortby = getSortBy(dir.path)
|
||||||
|
dir.dirfirst = getDirFirst(dir.path)
|
||||||
dir.dironly = getDirOnly(dir.path)
|
dir.dironly = getDirOnly(dir.path)
|
||||||
|
dir.hidden = getHidden(dir.path)
|
||||||
|
dir.reverse = getReverse(dir.path)
|
||||||
|
dir.locale = getLocale(dir.path)
|
||||||
dir.hiddenfiles = gOpts.hiddenfiles
|
dir.hiddenfiles = gOpts.hiddenfiles
|
||||||
dir.ignorecase = gOpts.ignorecase
|
dir.ignorecase = gOpts.ignorecase
|
||||||
dir.ignoredia = gOpts.ignoredia
|
dir.ignoredia = gOpts.ignoredia
|
||||||
@@ -220,30 +221,52 @@ func (dir *dir) sort() {
|
|||||||
|
|
||||||
// reverse order cannot be applied after stable sorting, otherwise the order
|
// reverse order cannot be applied after stable sorting, otherwise the order
|
||||||
// of equivalent elements will be reversed
|
// of equivalent elements will be reversed
|
||||||
reverse := dir.sortType.option&reverseSort != 0
|
switch dir.sortby {
|
||||||
|
|
||||||
switch dir.sortType.method {
|
|
||||||
case naturalSort:
|
case naturalSort:
|
||||||
|
if collator, err := makeCollator(dir.locale, collate.Numeric); err == nil {
|
||||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
|
s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
|
||||||
if !reverse {
|
result := collator.CompareString(s1, s2)
|
||||||
|
if !dir.reverse {
|
||||||
|
return result < 0
|
||||||
|
} else {
|
||||||
|
return result > 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
|
s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
|
||||||
|
if !dir.reverse {
|
||||||
return naturalLess(s1, s2)
|
return naturalLess(s1, s2)
|
||||||
} else {
|
} else {
|
||||||
return naturalLess(s2, s1)
|
return naturalLess(s2, s1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
case nameSort:
|
case nameSort:
|
||||||
|
if collator, err := makeCollator(dir.locale); err == nil {
|
||||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
|
s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
|
||||||
if !reverse {
|
result := collator.CompareString(s1, s2)
|
||||||
|
if !dir.reverse {
|
||||||
|
return result < 0
|
||||||
|
} else {
|
||||||
|
return result > 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
|
s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
|
||||||
|
if !dir.reverse {
|
||||||
return s1 < s2
|
return s1 < s2
|
||||||
} else {
|
} else {
|
||||||
return s2 < s1
|
return s2 < s1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
case sizeSort:
|
case sizeSort:
|
||||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
if !reverse {
|
if !dir.reverse {
|
||||||
return dir.files[i].TotalSize() < dir.files[j].TotalSize()
|
return dir.files[i].TotalSize() < dir.files[j].TotalSize()
|
||||||
} else {
|
} else {
|
||||||
return dir.files[j].TotalSize() < dir.files[i].TotalSize()
|
return dir.files[j].TotalSize() < dir.files[i].TotalSize()
|
||||||
@@ -251,7 +274,7 @@ func (dir *dir) sort() {
|
|||||||
})
|
})
|
||||||
case timeSort:
|
case timeSort:
|
||||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
if !reverse {
|
if !dir.reverse {
|
||||||
return dir.files[i].ModTime().Before(dir.files[j].ModTime())
|
return dir.files[i].ModTime().Before(dir.files[j].ModTime())
|
||||||
} else {
|
} else {
|
||||||
return dir.files[j].ModTime().Before(dir.files[i].ModTime())
|
return dir.files[j].ModTime().Before(dir.files[i].ModTime())
|
||||||
@@ -259,7 +282,7 @@ func (dir *dir) sort() {
|
|||||||
})
|
})
|
||||||
case atimeSort:
|
case atimeSort:
|
||||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
if !reverse {
|
if !dir.reverse {
|
||||||
return dir.files[i].accessTime.Before(dir.files[j].accessTime)
|
return dir.files[i].accessTime.Before(dir.files[j].accessTime)
|
||||||
} else {
|
} else {
|
||||||
return dir.files[j].accessTime.Before(dir.files[i].accessTime)
|
return dir.files[j].accessTime.Before(dir.files[i].accessTime)
|
||||||
@@ -267,7 +290,7 @@ func (dir *dir) sort() {
|
|||||||
})
|
})
|
||||||
case ctimeSort:
|
case ctimeSort:
|
||||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
if !reverse {
|
if !dir.reverse {
|
||||||
return dir.files[i].changeTime.Before(dir.files[j].changeTime)
|
return dir.files[i].changeTime.Before(dir.files[j].changeTime)
|
||||||
} else {
|
} else {
|
||||||
return dir.files[j].changeTime.Before(dir.files[i].changeTime)
|
return dir.files[j].changeTime.Before(dir.files[i].changeTime)
|
||||||
@@ -276,21 +299,8 @@ func (dir *dir) sort() {
|
|||||||
case extSort:
|
case extSort:
|
||||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
ext1, ext2 := normalize(dir.files[i].ext, dir.files[j].ext, dir.ignorecase, dir.ignoredia)
|
ext1, ext2 := normalize(dir.files[i].ext, dir.files[j].ext, dir.ignorecase, dir.ignoredia)
|
||||||
|
|
||||||
// if the extension could not be determined (directories, files without)
|
|
||||||
// use a zero byte so that these files can be ranked higher
|
|
||||||
if ext1 == "" {
|
|
||||||
ext1 = "\x00"
|
|
||||||
}
|
|
||||||
if ext2 == "" {
|
|
||||||
ext2 = "\x00"
|
|
||||||
}
|
|
||||||
|
|
||||||
name1, name2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
|
name1, name2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
|
||||||
|
if !dir.reverse {
|
||||||
// in order to also have natural sorting with the filenames
|
|
||||||
// combine the name with the ext but have the ext at the front
|
|
||||||
if !reverse {
|
|
||||||
return ext1 < ext2 || ext1 == ext2 && name1 < name2
|
return ext1 < ext2 || ext1 == ext2 && name1 < name2
|
||||||
} else {
|
} else {
|
||||||
return ext2 < ext1 || ext2 == ext1 && name2 < name1
|
return ext2 < ext1 || ext2 == ext1 && name2 < name1
|
||||||
@@ -298,7 +308,7 @@ func (dir *dir) sort() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if dir.sortType.option&dirfirstSort != 0 {
|
if dir.dirfirst {
|
||||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
if dir.files[i].IsDir() == dir.files[j].IsDir() {
|
if dir.files[i].IsDir() == dir.files[j].IsDir() {
|
||||||
return i < j
|
return i < j
|
||||||
@@ -330,7 +340,7 @@ func (dir *dir) sort() {
|
|||||||
// when hidden option is disabled, we move hidden files to the
|
// when hidden option is disabled, we move hidden files to the
|
||||||
// beginning of our file list and then set the beginning of displayed
|
// beginning of our file list and then set the beginning of displayed
|
||||||
// files to the first non-hidden file in the list
|
// files to the first non-hidden file in the list
|
||||||
if dir.sortType.option&hiddenSort == 0 {
|
if !dir.hidden {
|
||||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
if isHidden(dir.files[i], dir.path, dir.hiddenfiles) && isHidden(dir.files[j], dir.path, dir.hiddenfiles) {
|
if isHidden(dir.files[i], dir.path, dir.hiddenfiles) && isHidden(dir.files[j], dir.path, dir.hiddenfiles) {
|
||||||
return i < j
|
return i < j
|
||||||
@@ -438,9 +448,10 @@ type nav struct {
|
|||||||
deleteCountChan chan int
|
deleteCountChan chan int
|
||||||
deleteTotalChan chan int
|
deleteTotalChan chan int
|
||||||
previewChan chan string
|
previewChan chan string
|
||||||
dirPreviewChan chan *dir
|
|
||||||
dirChan chan *dir
|
dirChan chan *dir
|
||||||
regChan chan *reg
|
regChan chan *reg
|
||||||
|
fileChan chan *file
|
||||||
|
delChan chan string
|
||||||
dirCache map[string]*dir
|
dirCache map[string]*dir
|
||||||
regCache map[string]*reg
|
regCache map[string]*reg
|
||||||
saves map[string]bool
|
saves map[string]bool
|
||||||
@@ -466,13 +477,16 @@ type nav struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) loadDirInternal(path string) *dir {
|
func (nav *nav) loadDirInternal(path string) *dir {
|
||||||
nav.startPreview()
|
|
||||||
|
|
||||||
d := &dir{
|
d := &dir{
|
||||||
loading: true,
|
loading: true,
|
||||||
loadTime: time.Now(),
|
loadTime: time.Now(),
|
||||||
path: path,
|
path: path,
|
||||||
sortType: getSortType(path),
|
sortby: getSortBy(path),
|
||||||
|
dirfirst: getDirFirst(path),
|
||||||
|
dironly: getDirOnly(path),
|
||||||
|
hidden: getHidden(path),
|
||||||
|
reverse: getReverse(path),
|
||||||
|
locale: getLocale(path),
|
||||||
hiddenfiles: gOpts.hiddenfiles,
|
hiddenfiles: gOpts.hiddenfiles,
|
||||||
ignorecase: gOpts.ignorecase,
|
ignorecase: gOpts.ignorecase,
|
||||||
ignoredia: gOpts.ignoredia,
|
ignoredia: gOpts.ignoredia,
|
||||||
@@ -481,11 +495,7 @@ func (nav *nav) loadDirInternal(path string) *dir {
|
|||||||
d := newDir(path)
|
d := newDir(path)
|
||||||
d.sort()
|
d.sort()
|
||||||
d.ind, d.pos = 0, 0
|
d.ind, d.pos = 0, 0
|
||||||
if gOpts.dirpreviews {
|
|
||||||
nav.dirPreviewChan <- d
|
|
||||||
}
|
|
||||||
nav.dirChan <- d
|
nav.dirChan <- d
|
||||||
|
|
||||||
}()
|
}()
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
@@ -523,20 +533,18 @@ func (nav *nav) checkDir(dir *dir) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.startPreview()
|
|
||||||
dir.loading = true
|
dir.loading = true
|
||||||
dir.loadTime = now
|
dir.loadTime = now
|
||||||
go func() {
|
go func() {
|
||||||
nd := newDir(dir.path)
|
nd := newDir(dir.path)
|
||||||
nd.filter = dir.filter
|
|
||||||
nd.sort()
|
|
||||||
if gOpts.dirpreviews {
|
|
||||||
nav.dirPreviewChan <- nd
|
|
||||||
}
|
|
||||||
nav.dirChan <- nd
|
nav.dirChan <- nd
|
||||||
}()
|
}()
|
||||||
case dir.sortType != getSortType(dir.path) ||
|
case dir.sortby != getSortBy(dir.path) ||
|
||||||
|
dir.dirfirst != getDirFirst(dir.path) ||
|
||||||
dir.dironly != getDirOnly(dir.path) ||
|
dir.dironly != getDirOnly(dir.path) ||
|
||||||
|
dir.hidden != getHidden(dir.path) ||
|
||||||
|
dir.reverse != getReverse(dir.path) ||
|
||||||
|
dir.locale != getLocale(dir.path) ||
|
||||||
!reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) ||
|
!reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) ||
|
||||||
dir.ignorecase != gOpts.ignorecase ||
|
dir.ignorecase != gOpts.ignorecase ||
|
||||||
dir.ignoredia != gOpts.ignoredia:
|
dir.ignoredia != gOpts.ignoredia:
|
||||||
@@ -579,9 +587,10 @@ func newNav(height int) *nav {
|
|||||||
deleteCountChan: make(chan int, 1024),
|
deleteCountChan: make(chan int, 1024),
|
||||||
deleteTotalChan: make(chan int, 1024),
|
deleteTotalChan: make(chan int, 1024),
|
||||||
previewChan: make(chan string, 1024),
|
previewChan: make(chan string, 1024),
|
||||||
dirPreviewChan: make(chan *dir, 1024),
|
|
||||||
dirChan: make(chan *dir),
|
dirChan: make(chan *dir),
|
||||||
regChan: make(chan *reg),
|
regChan: make(chan *reg),
|
||||||
|
fileChan: make(chan *file),
|
||||||
|
delChan: make(chan string),
|
||||||
dirCache: make(map[string]*dir),
|
dirCache: make(map[string]*dir),
|
||||||
regCache: make(map[string]*reg),
|
regCache: make(map[string]*reg),
|
||||||
saves: make(map[string]bool),
|
saves: make(map[string]bool),
|
||||||
@@ -644,8 +653,8 @@ func (nav *nav) renew() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) reload() error {
|
func (nav *nav) reload() error {
|
||||||
nav.dirCache = make(map[string]*dir)
|
clear(nav.dirCache)
|
||||||
nav.regCache = make(map[string]*reg)
|
clear(nav.regCache)
|
||||||
|
|
||||||
curr, err := nav.currFile()
|
curr, err := nav.currFile()
|
||||||
nav.getDirs(nav.currDir().path)
|
nav.getDirs(nav.currDir().path)
|
||||||
@@ -696,23 +705,6 @@ func (nav *nav) exportFiles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) dirPreviewLoop(ui *ui) {
|
|
||||||
var prevPath string
|
|
||||||
for dir := range nav.dirPreviewChan {
|
|
||||||
if dir == nil && len(gOpts.previewer) != 0 && len(gOpts.cleaner) != 0 && nav.volatilePreview {
|
|
||||||
cmd := exec.Command(gOpts.cleaner, prevPath)
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
log.Printf("cleaning preview: %s", err)
|
|
||||||
}
|
|
||||||
nav.volatilePreview = false
|
|
||||||
} else if dir != nil {
|
|
||||||
win := ui.wins[len(ui.wins)-1]
|
|
||||||
nav.previewDir(dir, win)
|
|
||||||
prevPath = dir.path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) previewLoop(ui *ui) {
|
func (nav *nav) previewLoop(ui *ui) {
|
||||||
var prev string
|
var prev string
|
||||||
for path := range nav.previewChan {
|
for path := range nav.previewChan {
|
||||||
@@ -746,7 +738,6 @@ func (nav *nav) previewLoop(ui *ui) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//lint:ignore U1000 This function is not used on Windows
|
|
||||||
func matchPattern(pattern, name, path string) bool {
|
func matchPattern(pattern, name, path string) bool {
|
||||||
s := name
|
s := name
|
||||||
|
|
||||||
@@ -762,72 +753,11 @@ func matchPattern(pattern, name, path string) bool {
|
|||||||
return matched
|
return matched
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) previewDir(dir *dir, win *win) {
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
dir.loading = false
|
|
||||||
nav.dirChan <- dir
|
|
||||||
}()
|
|
||||||
|
|
||||||
var reader io.Reader
|
|
||||||
|
|
||||||
if len(gOpts.previewer) != 0 {
|
|
||||||
cmd := exec.Command(gOpts.previewer, dir.path,
|
|
||||||
strconv.Itoa(win.w),
|
|
||||||
strconv.Itoa(win.h),
|
|
||||||
strconv.Itoa(win.x),
|
|
||||||
strconv.Itoa(win.y))
|
|
||||||
|
|
||||||
out, err := cmd.StdoutPipe()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("previewing dir: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
|
||||||
log.Printf("previewing dir: %s", err)
|
|
||||||
out.Close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if err := cmd.Wait(); err != nil {
|
|
||||||
if e, ok := err.(*exec.ExitError); ok {
|
|
||||||
if e.ExitCode() != 0 {
|
|
||||||
nav.volatilePreview = true
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.Printf("loading dir: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
defer out.Close()
|
|
||||||
reader = out
|
|
||||||
buf := bufio.NewScanner(reader)
|
|
||||||
|
|
||||||
for i := 0; i < win.h && buf.Scan(); i++ {
|
|
||||||
for _, r := range buf.Text() {
|
|
||||||
if r == 0 {
|
|
||||||
dir.lines = []string{"\033[7mbinary\033[0m"}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dir.lines = append(dir.lines, buf.Text())
|
|
||||||
}
|
|
||||||
|
|
||||||
if buf.Err() != nil {
|
|
||||||
log.Printf("loading dir: %s", buf.Err())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) preview(path string, win *win) {
|
func (nav *nav) preview(path string, win *win) {
|
||||||
|
|
||||||
reg := ®{loadTime: time.Now(), path: path}
|
reg := ®{loadTime: time.Now(), path: path}
|
||||||
defer func() { nav.regChan <- reg }()
|
defer func() { nav.regChan <- reg }()
|
||||||
|
|
||||||
var reader io.Reader
|
var reader *bufio.Reader
|
||||||
|
|
||||||
if len(gOpts.previewer) != 0 {
|
if len(gOpts.previewer) != 0 {
|
||||||
cmd := exec.Command(gOpts.previewer, path,
|
cmd := exec.Command(gOpts.previewer, path,
|
||||||
@@ -861,7 +791,7 @@ func (nav *nav) preview(path string, win *win) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
defer out.Close()
|
defer out.Close()
|
||||||
reader = out
|
reader = bufio.NewReader(out)
|
||||||
} else {
|
} else {
|
||||||
f, err := os.Open(path)
|
f, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -870,14 +800,11 @@ func (nav *nav) preview(path string, win *win) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
reader = f
|
reader = bufio.NewReader(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix := make([]byte, 2)
|
|
||||||
if gOpts.sixel {
|
if gOpts.sixel {
|
||||||
n, err := reader.Read(prefix)
|
prefix, err := reader.Peek(2)
|
||||||
reader = io.MultiReader(bytes.NewReader(prefix[:n]), reader)
|
|
||||||
|
|
||||||
if err == nil && string(prefix) == gSixelBegin {
|
if err == nil && string(prefix) == gSixelBegin {
|
||||||
b, err := io.ReadAll(reader)
|
b, err := io.ReadAll(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -889,20 +816,29 @@ func (nav *nav) preview(path string, win *win) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := bufio.NewScanner(reader)
|
// bufio.Scanner can't handle files containing long lines if they exceed the
|
||||||
|
// size of its internal buffer
|
||||||
|
line := []byte{}
|
||||||
|
for len(reg.lines) < win.h {
|
||||||
|
bytes, isPrefix, err := reader.ReadLine()
|
||||||
|
if err != nil {
|
||||||
|
if len(line) > 0 {
|
||||||
|
reg.lines = append(reg.lines, string(line))
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < win.h && buf.Scan(); i++ {
|
if slices.Contains(bytes, 0) {
|
||||||
for _, r := range buf.Text() {
|
|
||||||
if r == 0 {
|
|
||||||
reg.lines = []string{"\033[7mbinary\033[0m"}
|
reg.lines = []string{"\033[7mbinary\033[0m"}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
reg.lines = append(reg.lines, buf.Text())
|
|
||||||
}
|
|
||||||
|
|
||||||
if buf.Err() != nil {
|
line = append(line, bytes...)
|
||||||
log.Printf("loading file: %s", buf.Err())
|
|
||||||
|
if !isPrefix {
|
||||||
|
reg.lines = append(reg.lines, string(line))
|
||||||
|
line = []byte{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1141,7 +1077,7 @@ func (nav *nav) high() bool {
|
|||||||
|
|
||||||
old := dir.ind
|
old := dir.ind
|
||||||
beg := max(dir.ind-dir.pos, 0)
|
beg := max(dir.ind-dir.pos, 0)
|
||||||
offs := gOpts.scrolloff
|
offs := min(nav.height/2, gOpts.scrolloff)
|
||||||
if beg == 0 {
|
if beg == 0 {
|
||||||
offs = 0
|
offs = 0
|
||||||
}
|
}
|
||||||
@@ -1172,7 +1108,14 @@ func (nav *nav) low() bool {
|
|||||||
old := dir.ind
|
old := dir.ind
|
||||||
beg := max(dir.ind-dir.pos, 0)
|
beg := max(dir.ind-dir.pos, 0)
|
||||||
end := min(beg+nav.height, len(dir.files))
|
end := min(beg+nav.height, len(dir.files))
|
||||||
offs := gOpts.scrolloff
|
|
||||||
|
offs := min(nav.height/2, gOpts.scrolloff)
|
||||||
|
// use a smaller value for half when the height is even and scrolloff is
|
||||||
|
// maxed in order to stay at the same row when using both high and low
|
||||||
|
if nav.height%2 == 0 {
|
||||||
|
offs = min(nav.height/2-1, gOpts.scrolloff)
|
||||||
|
}
|
||||||
|
|
||||||
if end == len(dir.files) {
|
if end == len(dir.files) {
|
||||||
offs = 0
|
offs = 0
|
||||||
}
|
}
|
||||||
@@ -1276,7 +1219,7 @@ func (nav *nav) invertBelow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) unselect() {
|
func (nav *nav) unselect() {
|
||||||
nav.selections = make(map[string]int)
|
clear(nav.selections)
|
||||||
nav.selectionInd = 0
|
nav.selectionInd = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1290,7 +1233,7 @@ func (nav *nav) save(cp bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
clear(nav.saves)
|
||||||
for _, f := range list {
|
for _, f := range list {
|
||||||
nav.saves[f] = cp
|
nav.saves[f] = cp
|
||||||
}
|
}
|
||||||
@@ -1317,7 +1260,7 @@ func (nav *nav) copyAsync(app *app, srcs []string, dstDir string) {
|
|||||||
|
|
||||||
nav.copyTotalChan <- total
|
nav.copyTotalChan <- total
|
||||||
|
|
||||||
nums, errs := copyAll(srcs, dstDir)
|
nums, errs := copyAll(srcs, dstDir, gOpts.preserve)
|
||||||
|
|
||||||
errCount := 0
|
errCount := 0
|
||||||
loop:
|
loop:
|
||||||
@@ -1387,8 +1330,8 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
|
|||||||
app.ui.exprChan <- echo
|
app.ui.exprChan <- echo
|
||||||
continue
|
continue
|
||||||
} else if !os.IsNotExist(err) {
|
} else if !os.IsNotExist(err) {
|
||||||
ext := filepath.Ext(file)
|
ext := getFileExtension(dstStat)
|
||||||
basename := filepath.Base(file[:len(file)-len(ext)])
|
basename := file[:len(file)-len(ext)]
|
||||||
var newPath string
|
var newPath string
|
||||||
for i := 1; !os.IsNotExist(err); i++ {
|
for i := 1; !os.IsNotExist(err); i++ {
|
||||||
file = strings.ReplaceAll(gOpts.dupfilefmt, "%f", basename+ext)
|
file = strings.ReplaceAll(gOpts.dupfilefmt, "%f", basename+ext)
|
||||||
@@ -1412,7 +1355,7 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
|
|||||||
|
|
||||||
nav.copyTotalChan <- total
|
nav.copyTotalChan <- total
|
||||||
|
|
||||||
nums, errs := copyAll([]string{src}, dstDir)
|
nums, errs := copyAll([]string{src}, dstDir, []string{"mode", "timestamps"})
|
||||||
|
|
||||||
oldCount := errCount
|
oldCount := errCount
|
||||||
loop:
|
loop:
|
||||||
@@ -1461,6 +1404,7 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if errCount == 0 {
|
if errCount == 0 {
|
||||||
|
app.ui.exprChan <- &callExpr{"clear", nil, 1}
|
||||||
app.ui.exprChan <- &callExpr{"echo", []string{"\033[0;32mMoved successfully\033[0m"}, 1}
|
app.ui.exprChan <- &callExpr{"echo", []string{"\033[0;32mMoved successfully\033[0m"}, 1}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1481,19 +1425,6 @@ func (nav *nav) paste(app *app) error {
|
|||||||
go nav.copyAsync(app, srcs, dstDir)
|
go nav.copyAsync(app, srcs, dstDir)
|
||||||
} else {
|
} else {
|
||||||
go nav.moveAsync(app, srcs, dstDir)
|
go nav.moveAsync(app, srcs, dstDir)
|
||||||
if err := saveFiles(nil, false); err != nil {
|
|
||||||
return fmt.Errorf("clearing copy/cut buffer: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if gSingleMode {
|
|
||||||
if err := nav.sync(); err != nil {
|
|
||||||
return fmt.Errorf("paste: %s", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if err := remote("send sync"); err != nil {
|
|
||||||
return fmt.Errorf("paste: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -1560,7 +1491,13 @@ func (nav *nav) rename() error {
|
|||||||
dir := nav.loadDir(filepath.Dir(newPath))
|
dir := nav.loadDir(filepath.Dir(newPath))
|
||||||
|
|
||||||
if dir.loading {
|
if dir.loading {
|
||||||
dir.files = append(dir.files, &file{FileInfo: lstat})
|
for i := range dir.allFiles {
|
||||||
|
if dir.allFiles[i].path == oldPath {
|
||||||
|
dir.allFiles[i] = &file{FileInfo: lstat}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dir.sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
dir.sel(lstat.Name(), nav.height)
|
dir.sel(lstat.Name(), nav.height)
|
||||||
@@ -1574,7 +1511,7 @@ func (nav *nav) sync() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
clear(nav.saves)
|
||||||
for _, f := range list {
|
for _, f := range list {
|
||||||
nav.saves[f] = cp
|
nav.saves[f] = cp
|
||||||
}
|
}
|
||||||
@@ -1648,7 +1585,7 @@ func (nav *nav) globSel(pattern string, invert bool) error {
|
|||||||
dir := nav.currDir()
|
dir := nav.currDir()
|
||||||
anyMatched := false
|
anyMatched := false
|
||||||
|
|
||||||
for i := 0; i < len(dir.files); i++ {
|
for i := range dir.files {
|
||||||
matched, err := filepath.Match(pattern, dir.files[i].Name())
|
matched, err := filepath.Match(pattern, dir.files[i].Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("glob-select: %s", err)
|
return fmt.Errorf("glob-select: %s", err)
|
||||||
@@ -1694,7 +1631,7 @@ func (nav *nav) findSingle() int {
|
|||||||
count := 0
|
count := 0
|
||||||
index := 0
|
index := 0
|
||||||
dir := nav.currDir()
|
dir := nav.currDir()
|
||||||
for i := 0; i < len(dir.files); i++ {
|
for i := range dir.files {
|
||||||
if findMatch(dir.files[i].Name(), nav.find) {
|
if findMatch(dir.files[i].Name(), nav.find) {
|
||||||
count++
|
count++
|
||||||
if count > 1 {
|
if count > 1 {
|
||||||
@@ -1721,7 +1658,7 @@ func (nav *nav) findNext() (bool, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := 0; i < dir.ind; i++ {
|
for i := range dir.ind {
|
||||||
if findMatch(dir.files[i].Name(), nav.find) {
|
if findMatch(dir.files[i].Name(), nav.find) {
|
||||||
return nav.up(dir.ind - i), true
|
return nav.up(dir.ind - i), true
|
||||||
}
|
}
|
||||||
@@ -1747,7 +1684,7 @@ func (nav *nav) findPrev() (bool, bool) {
|
|||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func searchMatch(name, pattern string) (matched bool, err error) {
|
func searchMatch(name, pattern string, glob bool) (matched bool, err error) {
|
||||||
if gOpts.ignorecase {
|
if gOpts.ignorecase {
|
||||||
lpattern := strings.ToLower(pattern)
|
lpattern := strings.ToLower(pattern)
|
||||||
if !gOpts.smartcase || lpattern == pattern {
|
if !gOpts.smartcase || lpattern == pattern {
|
||||||
@@ -1762,7 +1699,7 @@ func searchMatch(name, pattern string) (matched bool, err error) {
|
|||||||
name = removeDiacritics(name)
|
name = removeDiacritics(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if gOpts.globsearch {
|
if glob {
|
||||||
return filepath.Match(pattern, name)
|
return filepath.Match(pattern, name)
|
||||||
}
|
}
|
||||||
return strings.Contains(name, pattern), nil
|
return strings.Contains(name, pattern), nil
|
||||||
@@ -1771,15 +1708,15 @@ func searchMatch(name, pattern string) (matched bool, err error) {
|
|||||||
func (nav *nav) searchNext() (bool, error) {
|
func (nav *nav) searchNext() (bool, error) {
|
||||||
dir := nav.currDir()
|
dir := nav.currDir()
|
||||||
for i := dir.ind + 1; i < len(dir.files); i++ {
|
for i := dir.ind + 1; i < len(dir.files); i++ {
|
||||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil {
|
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
} else if matched {
|
} else if matched {
|
||||||
return nav.down(i - dir.ind), nil
|
return nav.down(i - dir.ind), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := 0; i < dir.ind; i++ {
|
for i := range dir.ind {
|
||||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil {
|
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
} else if matched {
|
} else if matched {
|
||||||
return nav.up(dir.ind - i), nil
|
return nav.up(dir.ind - i), nil
|
||||||
@@ -1792,7 +1729,7 @@ func (nav *nav) searchNext() (bool, error) {
|
|||||||
func (nav *nav) searchPrev() (bool, error) {
|
func (nav *nav) searchPrev() (bool, error) {
|
||||||
dir := nav.currDir()
|
dir := nav.currDir()
|
||||||
for i := dir.ind - 1; i >= 0; i-- {
|
for i := dir.ind - 1; i >= 0; i-- {
|
||||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil {
|
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
} else if matched {
|
} else if matched {
|
||||||
return nav.up(dir.ind - i), nil
|
return nav.up(dir.ind - i), nil
|
||||||
@@ -1800,7 +1737,7 @@ func (nav *nav) searchPrev() (bool, error) {
|
|||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := len(dir.files) - 1; i > dir.ind; i-- {
|
for i := len(dir.files) - 1; i > dir.ind; i-- {
|
||||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil {
|
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
} else if matched {
|
} else if matched {
|
||||||
return nav.down(i - dir.ind), nil
|
return nav.down(i - dir.ind), nil
|
||||||
@@ -1812,7 +1749,7 @@ func (nav *nav) searchPrev() (bool, error) {
|
|||||||
|
|
||||||
func isFiltered(f os.FileInfo, filter []string) bool {
|
func isFiltered(f os.FileInfo, filter []string) bool {
|
||||||
for _, pattern := range filter {
|
for _, pattern := range filter {
|
||||||
matched, err := searchMatch(f.Name(), strings.TrimPrefix(pattern, "!"))
|
matched, err := searchMatch(f.Name(), strings.TrimPrefix(pattern, "!"), gOpts.globfilter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Filter Error: %s", err)
|
log.Printf("Filter Error: %s", err)
|
||||||
return false
|
return false
|
||||||
@@ -1835,7 +1772,7 @@ func (nav *nav) removeMark(mark string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) readMarks() error {
|
func (nav *nav) readMarks() error {
|
||||||
nav.marks = make(map[string]string)
|
clear(nav.marks)
|
||||||
f, err := os.Open(gMarksPath)
|
f, err := os.Open(gMarksPath)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
@@ -1847,9 +1784,12 @@ func (nav *nav) readMarks() error {
|
|||||||
|
|
||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
toks := strings.SplitN(scanner.Text(), ":", 2)
|
mark, path, found := strings.Cut(scanner.Text(), ":")
|
||||||
if _, ok := nav.marks[toks[0]]; !ok {
|
if !found {
|
||||||
nav.marks[toks[0]] = toks[1]
|
return fmt.Errorf("invalid marks file entry: %s", scanner.Text())
|
||||||
|
}
|
||||||
|
if _, ok := nav.marks[mark]; !ok {
|
||||||
|
nav.marks[mark] = path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1880,7 +1820,7 @@ func (nav *nav) writeMarks() error {
|
|||||||
sort.Strings(keys)
|
sort.Strings(keys)
|
||||||
|
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
_, err = f.WriteString(fmt.Sprintf("%s:%s\n", k, nav.marks[k]))
|
_, err = fmt.Fprintf(f, "%s:%s\n", k, nav.marks[k])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("writing marks file: %s", err)
|
return fmt.Errorf("writing marks file: %s", err)
|
||||||
}
|
}
|
||||||
@@ -1890,7 +1830,7 @@ func (nav *nav) writeMarks() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) readTags() error {
|
func (nav *nav) readTags() error {
|
||||||
nav.tags = make(map[string]string)
|
clear(nav.tags)
|
||||||
f, err := os.Open(gTagsPath)
|
f, err := os.Open(gTagsPath)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
@@ -1903,11 +1843,16 @@ func (nav *nav) readTags() error {
|
|||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
text := scanner.Text()
|
text := scanner.Text()
|
||||||
|
|
||||||
ind := strings.LastIndex(text, ":")
|
ind := strings.LastIndex(text, ":")
|
||||||
|
if ind == -1 {
|
||||||
|
return fmt.Errorf("invalid tags file entry: %s", text)
|
||||||
|
}
|
||||||
|
|
||||||
path := text[0:ind]
|
path := text[0:ind]
|
||||||
mark := text[ind+1:]
|
tag := text[ind+1:]
|
||||||
if _, ok := nav.tags[path]; !ok {
|
if _, ok := nav.tags[path]; !ok {
|
||||||
nav.tags[path] = mark
|
nav.tags[path] = tag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1936,7 +1881,7 @@ func (nav *nav) writeTags() error {
|
|||||||
sort.Strings(keys)
|
sort.Strings(keys)
|
||||||
|
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
_, err = f.WriteString(fmt.Sprintf("%s:%s\n", k, nav.tags[k]))
|
_, err = fmt.Fprintf(f, "%s:%s\n", k, nav.tags[k])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("writing tags file: %s", err)
|
return fmt.Errorf("writing tags file: %s", err)
|
||||||
}
|
}
|
||||||
@@ -1974,7 +1919,6 @@ func (m indexedSelections) Swap(i, j int) {
|
|||||||
func (m indexedSelections) Less(i, j int) bool { return m.indices[i] < m.indices[j] }
|
func (m indexedSelections) Less(i, j int) bool { return m.indices[i] < m.indices[j] }
|
||||||
|
|
||||||
func (nav *nav) currSelections() []string {
|
func (nav *nav) currSelections() []string {
|
||||||
|
|
||||||
currDirOnly := gOpts.selmode == "dir"
|
currDirOnly := gOpts.selmode == "dir"
|
||||||
currDirPath := ""
|
currDirPath := ""
|
||||||
if currDirOnly {
|
if currDirOnly {
|
||||||
|
|||||||
@@ -5,58 +5,70 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type sortMethod byte
|
// String values match the sortby string sent by the user at startup
|
||||||
|
type sortMethod string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
naturalSort sortMethod = iota
|
naturalSort sortMethod = "natural"
|
||||||
nameSort
|
nameSort sortMethod = "name"
|
||||||
sizeSort
|
sizeSort sortMethod = "size"
|
||||||
timeSort
|
timeSort sortMethod = "time"
|
||||||
atimeSort
|
atimeSort sortMethod = "atime"
|
||||||
ctimeSort
|
ctimeSort sortMethod = "ctime"
|
||||||
extSort
|
extSort sortMethod = "ext"
|
||||||
)
|
)
|
||||||
|
|
||||||
type sortOption byte
|
func isValidSortMethod(method sortMethod) bool {
|
||||||
|
return method == naturalSort ||
|
||||||
const (
|
method == nameSort ||
|
||||||
dirfirstSort sortOption = 1 << iota
|
method == sizeSort ||
|
||||||
hiddenSort
|
method == timeSort ||
|
||||||
reverseSort
|
method == atimeSort ||
|
||||||
)
|
method == ctimeSort ||
|
||||||
|
method == extSort
|
||||||
type sortType struct {
|
|
||||||
method sortMethod
|
|
||||||
option sortOption
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const invalidSortErrorMessage = `sortby: value should either be 'natural', 'name', 'size', 'time', 'atime', 'ctime' or 'ext'`
|
||||||
|
|
||||||
var gOpts struct {
|
var gOpts struct {
|
||||||
anchorfind bool
|
anchorfind bool
|
||||||
autoquit bool
|
autoquit bool
|
||||||
borderfmt string
|
borderfmt string
|
||||||
|
copyfmt string
|
||||||
cursoractivefmt string
|
cursoractivefmt string
|
||||||
cursorparentfmt string
|
cursorparentfmt string
|
||||||
cursorpreviewfmt string
|
cursorpreviewfmt string
|
||||||
|
cutfmt string
|
||||||
dircache bool
|
dircache bool
|
||||||
dircounts bool
|
dircounts bool
|
||||||
|
dirfirst bool
|
||||||
dironly bool
|
dironly bool
|
||||||
dirpreviews bool
|
dirpreviews bool
|
||||||
drawbox bool
|
drawbox bool
|
||||||
dupfilefmt string
|
dupfilefmt string
|
||||||
|
globfilter bool
|
||||||
globsearch bool
|
globsearch bool
|
||||||
|
hidden bool
|
||||||
icons bool
|
icons bool
|
||||||
ignorecase bool
|
ignorecase bool
|
||||||
ignoredia bool
|
ignoredia bool
|
||||||
incfilter bool
|
incfilter bool
|
||||||
incsearch bool
|
incsearch bool
|
||||||
|
locale string
|
||||||
mouse bool
|
mouse bool
|
||||||
number bool
|
number bool
|
||||||
preview bool
|
preview bool
|
||||||
sixel bool
|
|
||||||
relativenumber bool
|
relativenumber bool
|
||||||
|
reverse bool
|
||||||
|
roundbox bool
|
||||||
|
selectfmt string
|
||||||
|
showbinds bool
|
||||||
|
sixel bool
|
||||||
|
sortby sortMethod
|
||||||
smartcase bool
|
smartcase bool
|
||||||
smartdia bool
|
smartdia bool
|
||||||
waitmsg string
|
waitmsg string
|
||||||
|
watch bool
|
||||||
wrapscan bool
|
wrapscan bool
|
||||||
wrapscroll bool
|
wrapscroll bool
|
||||||
findlen int
|
findlen int
|
||||||
@@ -82,7 +94,6 @@ var gOpts struct {
|
|||||||
hiddenfiles []string
|
hiddenfiles []string
|
||||||
history bool
|
history bool
|
||||||
info []string
|
info []string
|
||||||
ruler []string
|
|
||||||
rulerfmt string
|
rulerfmt string
|
||||||
preserve []string
|
preserve []string
|
||||||
shellopts []string
|
shellopts []string
|
||||||
@@ -90,124 +101,141 @@ var gOpts struct {
|
|||||||
cmdkeys map[string]expr
|
cmdkeys map[string]expr
|
||||||
cmds map[string]expr
|
cmds map[string]expr
|
||||||
user map[string]string
|
user map[string]string
|
||||||
sortType sortType
|
|
||||||
tempmarks string
|
tempmarks string
|
||||||
numberfmt string
|
numberfmt string
|
||||||
tagfmt string
|
tagfmt string
|
||||||
}
|
}
|
||||||
|
|
||||||
var gLocalOpts struct {
|
var gLocalOpts struct {
|
||||||
sortMethods map[string]sortMethod
|
sortby map[string]sortMethod
|
||||||
dirfirsts map[string]bool
|
dircounts map[string]bool
|
||||||
dironlys map[string]bool
|
dirfirst map[string]bool
|
||||||
hiddens map[string]bool
|
dironly map[string]bool
|
||||||
reverses map[string]bool
|
hidden map[string]bool
|
||||||
infos map[string][]string
|
reverse map[string]bool
|
||||||
|
info map[string][]string
|
||||||
|
locale map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func localOptPaths(path string) []string {
|
func localOptPaths(path string) []string {
|
||||||
var list []string
|
list := []string{path}
|
||||||
list = append(list, path)
|
|
||||||
for curr := path; !isRoot(curr); curr = filepath.Dir(curr) {
|
for curr := path; !isRoot(curr); curr = filepath.Dir(curr) {
|
||||||
list = append(list, curr+string(filepath.Separator))
|
list = append(list, curr+string(filepath.Separator))
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSortMethod(path string) sortMethod {
|
func getDirCounts(path string) bool {
|
||||||
for _, key := range localOptPaths(path) {
|
for _, key := range localOptPaths(path) {
|
||||||
if val, ok := gLocalOpts.sortMethods[key]; ok {
|
if val, ok := gLocalOpts.dircounts[key]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return gOpts.sortType.method
|
return gOpts.dircounts
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSortType(path string) sortType {
|
func getDirFirst(path string) bool {
|
||||||
method := getSortMethod(path)
|
|
||||||
option := gOpts.sortType.option
|
|
||||||
for _, key := range localOptPaths(path) {
|
for _, key := range localOptPaths(path) {
|
||||||
if val, ok := gLocalOpts.dirfirsts[key]; ok {
|
if val, ok := gLocalOpts.dirfirst[key]; ok {
|
||||||
if val {
|
|
||||||
option |= dirfirstSort
|
|
||||||
} else {
|
|
||||||
option &= ^dirfirstSort
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, key := range localOptPaths(path) {
|
|
||||||
if val, ok := gLocalOpts.hiddens[key]; ok {
|
|
||||||
if val {
|
|
||||||
option |= hiddenSort
|
|
||||||
} else {
|
|
||||||
option &= ^hiddenSort
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, key := range localOptPaths(path) {
|
|
||||||
if val, ok := gLocalOpts.reverses[key]; ok {
|
|
||||||
if val {
|
|
||||||
option |= reverseSort
|
|
||||||
} else {
|
|
||||||
option &= ^reverseSort
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val := sortType{
|
|
||||||
method: method,
|
|
||||||
option: option,
|
|
||||||
}
|
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return gOpts.dirfirst
|
||||||
|
}
|
||||||
|
|
||||||
func getDirOnly(path string) bool {
|
func getDirOnly(path string) bool {
|
||||||
for _, key := range localOptPaths(path) {
|
for _, key := range localOptPaths(path) {
|
||||||
if val, ok := gLocalOpts.dironlys[key]; ok {
|
if val, ok := gLocalOpts.dironly[key]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return gOpts.dironly
|
return gOpts.dironly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getHidden(path string) bool {
|
||||||
|
for _, key := range localOptPaths(path) {
|
||||||
|
if val, ok := gLocalOpts.hidden[key]; ok {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gOpts.hidden
|
||||||
|
}
|
||||||
|
|
||||||
func getInfo(path string) []string {
|
func getInfo(path string) []string {
|
||||||
for _, key := range localOptPaths(path) {
|
for _, key := range localOptPaths(path) {
|
||||||
if val, ok := gLocalOpts.infos[key]; ok {
|
if val, ok := gLocalOpts.info[key]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return gOpts.info
|
return gOpts.info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getReverse(path string) bool {
|
||||||
|
for _, key := range localOptPaths(path) {
|
||||||
|
if val, ok := gLocalOpts.reverse[key]; ok {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gOpts.reverse
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSortBy(path string) sortMethod {
|
||||||
|
for _, key := range localOptPaths(path) {
|
||||||
|
if val, ok := gLocalOpts.sortby[key]; ok {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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() {
|
func init() {
|
||||||
gOpts.anchorfind = true
|
gOpts.anchorfind = true
|
||||||
gOpts.autoquit = false
|
gOpts.autoquit = true
|
||||||
gOpts.dircache = true
|
gOpts.dircache = true
|
||||||
gOpts.dircounts = false
|
gOpts.dircounts = false
|
||||||
|
gOpts.dirfirst = true
|
||||||
gOpts.dironly = false
|
gOpts.dironly = false
|
||||||
gOpts.dirpreviews = false
|
gOpts.dirpreviews = false
|
||||||
gOpts.drawbox = false
|
gOpts.drawbox = false
|
||||||
gOpts.dupfilefmt = "%f.~%n~"
|
gOpts.dupfilefmt = "%f.~%n~"
|
||||||
gOpts.borderfmt = "\033[0m"
|
gOpts.borderfmt = "\033[0m"
|
||||||
|
gOpts.copyfmt = "\033[7;33m"
|
||||||
gOpts.cursoractivefmt = "\033[7m"
|
gOpts.cursoractivefmt = "\033[7m"
|
||||||
gOpts.cursorparentfmt = "\033[7m"
|
gOpts.cursorparentfmt = "\033[7m"
|
||||||
gOpts.cursorpreviewfmt = "\033[4m"
|
gOpts.cursorpreviewfmt = "\033[4m"
|
||||||
|
gOpts.cutfmt = "\033[7;31m"
|
||||||
|
gOpts.globfilter = false
|
||||||
gOpts.globsearch = false
|
gOpts.globsearch = false
|
||||||
|
gOpts.hidden = false
|
||||||
gOpts.icons = false
|
gOpts.icons = false
|
||||||
gOpts.ignorecase = true
|
gOpts.ignorecase = true
|
||||||
gOpts.ignoredia = true
|
gOpts.ignoredia = true
|
||||||
gOpts.incfilter = false
|
gOpts.incfilter = false
|
||||||
gOpts.incsearch = false
|
gOpts.incsearch = false
|
||||||
|
gOpts.locale = localeStrDisable
|
||||||
gOpts.mouse = false
|
gOpts.mouse = false
|
||||||
gOpts.number = false
|
gOpts.number = false
|
||||||
gOpts.preview = true
|
gOpts.preview = true
|
||||||
gOpts.sixel = false
|
|
||||||
gOpts.relativenumber = false
|
gOpts.relativenumber = false
|
||||||
|
gOpts.reverse = false
|
||||||
|
gOpts.roundbox = false
|
||||||
|
gOpts.selectfmt = "\033[7;35m"
|
||||||
|
gOpts.showbinds = true
|
||||||
|
gOpts.sixel = false
|
||||||
|
gOpts.sortby = naturalSort
|
||||||
gOpts.smartcase = true
|
gOpts.smartcase = true
|
||||||
gOpts.smartdia = false
|
gOpts.smartdia = false
|
||||||
gOpts.waitmsg = "Press any key to continue"
|
gOpts.waitmsg = "Press any key to continue"
|
||||||
|
gOpts.watch = false
|
||||||
gOpts.wrapscan = true
|
gOpts.wrapscan = true
|
||||||
gOpts.wrapscroll = false
|
gOpts.wrapscroll = false
|
||||||
gOpts.findlen = 1
|
gOpts.findlen = 1
|
||||||
@@ -230,142 +258,142 @@ func init() {
|
|||||||
gOpts.truncatechar = "~"
|
gOpts.truncatechar = "~"
|
||||||
gOpts.truncatepct = 100
|
gOpts.truncatepct = 100
|
||||||
gOpts.ratios = []int{1, 2, 3}
|
gOpts.ratios = []int{1, 2, 3}
|
||||||
gOpts.hiddenfiles = []string{".*"}
|
gOpts.hiddenfiles = gDefaultHiddenFiles
|
||||||
gOpts.history = true
|
gOpts.history = true
|
||||||
gOpts.info = nil
|
gOpts.info = nil
|
||||||
gOpts.ruler = 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;34m %f \033[0m| %i/%t"
|
gOpts.rulerfmt = " %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"
|
||||||
gOpts.preserve = []string{"mode"}
|
gOpts.preserve = []string{"mode"}
|
||||||
gOpts.shellopts = nil
|
gOpts.shellopts = nil
|
||||||
gOpts.sortType = sortType{naturalSort, dirfirstSort}
|
|
||||||
gOpts.tempmarks = "'"
|
gOpts.tempmarks = "'"
|
||||||
gOpts.numberfmt = "\033[33m"
|
gOpts.numberfmt = "\033[33m"
|
||||||
gOpts.tagfmt = "\033[31m"
|
gOpts.tagfmt = "\033[31m"
|
||||||
|
|
||||||
gOpts.keys = make(map[string]expr)
|
gOpts.keys = map[string]expr{
|
||||||
|
"k": &callExpr{"up", nil, 1},
|
||||||
|
"<up>": &callExpr{"up", nil, 1},
|
||||||
|
"<m-up>": &callExpr{"up", nil, 1},
|
||||||
|
"<c-u>": &callExpr{"half-up", nil, 1},
|
||||||
|
"<c-b>": &callExpr{"page-up", nil, 1},
|
||||||
|
"<pgup>": &callExpr{"page-up", nil, 1},
|
||||||
|
"<c-y>": &callExpr{"scroll-up", nil, 1},
|
||||||
|
"<c-m-up>": &callExpr{"scroll-up", nil, 1},
|
||||||
|
"j": &callExpr{"down", nil, 1},
|
||||||
|
"<down>": &callExpr{"down", nil, 1},
|
||||||
|
"<m-down>": &callExpr{"down", nil, 1},
|
||||||
|
"<c-d>": &callExpr{"half-down", nil, 1},
|
||||||
|
"<c-f>": &callExpr{"page-down", nil, 1},
|
||||||
|
"<pgdn>": &callExpr{"page-down", nil, 1},
|
||||||
|
"<c-e>": &callExpr{"scroll-down", nil, 1},
|
||||||
|
"<c-m-down>": &callExpr{"scroll-down", nil, 1},
|
||||||
|
"h": &callExpr{"updir", nil, 1},
|
||||||
|
"<left>": &callExpr{"updir", nil, 1},
|
||||||
|
"l": &callExpr{"open", nil, 1},
|
||||||
|
"<right>": &callExpr{"open", nil, 1},
|
||||||
|
"q": &callExpr{"quit", nil, 1},
|
||||||
|
"gg": &callExpr{"top", nil, 1},
|
||||||
|
"<home>": &callExpr{"top", nil, 1},
|
||||||
|
"G": &callExpr{"bottom", nil, 1},
|
||||||
|
"<end>": &callExpr{"bottom", nil, 1},
|
||||||
|
"H": &callExpr{"high", nil, 1},
|
||||||
|
"M": &callExpr{"middle", nil, 1},
|
||||||
|
"L": &callExpr{"low", nil, 1},
|
||||||
|
"[": &callExpr{"jump-prev", nil, 1},
|
||||||
|
"]": &callExpr{"jump-next", nil, 1},
|
||||||
|
"<space>": &listExpr{[]expr{&callExpr{"toggle", nil, 1}, &callExpr{"down", nil, 1}}, 1},
|
||||||
|
"t": &callExpr{"tag-toggle", nil, 1},
|
||||||
|
"v": &callExpr{"invert", nil, 1},
|
||||||
|
"u": &callExpr{"unselect", nil, 1},
|
||||||
|
"y": &callExpr{"copy", nil, 1},
|
||||||
|
"d": &callExpr{"cut", nil, 1},
|
||||||
|
"c": &callExpr{"clear", nil, 1},
|
||||||
|
"p": &callExpr{"paste", nil, 1},
|
||||||
|
"<c-l>": &callExpr{"redraw", nil, 1},
|
||||||
|
"<c-r>": &callExpr{"reload", nil, 1},
|
||||||
|
":": &callExpr{"read", nil, 1},
|
||||||
|
"$": &callExpr{"shell", nil, 1},
|
||||||
|
"%": &callExpr{"shell-pipe", nil, 1},
|
||||||
|
"!": &callExpr{"shell-wait", nil, 1},
|
||||||
|
"&": &callExpr{"shell-async", nil, 1},
|
||||||
|
"f": &callExpr{"find", nil, 1},
|
||||||
|
"F": &callExpr{"find-back", nil, 1},
|
||||||
|
";": &callExpr{"find-next", nil, 1},
|
||||||
|
",": &callExpr{"find-prev", nil, 1},
|
||||||
|
"/": &callExpr{"search", nil, 1},
|
||||||
|
"?": &callExpr{"search-back", nil, 1},
|
||||||
|
"n": &callExpr{"search-next", nil, 1},
|
||||||
|
"N": &callExpr{"search-prev", nil, 1},
|
||||||
|
"m": &callExpr{"mark-save", nil, 1},
|
||||||
|
"'": &callExpr{"mark-load", nil, 1},
|
||||||
|
`"`: &callExpr{"mark-remove", nil, 1},
|
||||||
|
`r`: &callExpr{"rename", nil, 1},
|
||||||
|
"<c-n>": &callExpr{"cmd-history-next", nil, 1},
|
||||||
|
"<c-p>": &callExpr{"cmd-history-prev", nil, 1},
|
||||||
|
|
||||||
gOpts.keys["k"] = &callExpr{"up", nil, 1}
|
"zh": &setExpr{"hidden!", ""},
|
||||||
gOpts.keys["<up>"] = &callExpr{"up", nil, 1}
|
"zr": &setExpr{"reverse!", ""},
|
||||||
gOpts.keys["<m-up>"] = &callExpr{"up", nil, 1}
|
"zn": &setExpr{"info", ""},
|
||||||
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil, 1}
|
"zs": &setExpr{"info", "size"},
|
||||||
gOpts.keys["<c-b>"] = &callExpr{"page-up", nil, 1}
|
"zt": &setExpr{"info", "time"},
|
||||||
gOpts.keys["<pgup>"] = &callExpr{"page-up", nil, 1}
|
"za": &setExpr{"info", "size:time"},
|
||||||
gOpts.keys["<c-y>"] = &callExpr{"scroll-up", nil, 1}
|
"sn": &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}, 1},
|
||||||
gOpts.keys["<c-m-up>"] = &callExpr{"scroll-up", nil, 1}
|
"ss": &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1},
|
||||||
gOpts.keys["j"] = &callExpr{"down", nil, 1}
|
"st": &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}, 1},
|
||||||
gOpts.keys["<down>"] = &callExpr{"down", nil, 1}
|
"sa": &listExpr{[]expr{&setExpr{"sortby", "atime"}, &setExpr{"info", "atime"}}, 1},
|
||||||
gOpts.keys["<m-down>"] = &callExpr{"down", nil, 1}
|
"sc": &listExpr{[]expr{&setExpr{"sortby", "ctime"}, &setExpr{"info", "ctime"}}, 1},
|
||||||
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil, 1}
|
"se": &listExpr{[]expr{&setExpr{"sortby", "ext"}, &setExpr{"info", ""}}, 1},
|
||||||
gOpts.keys["<c-f>"] = &callExpr{"page-down", nil, 1}
|
"gh": &callExpr{"cd", []string{"~"}, 1},
|
||||||
gOpts.keys["<pgdn>"] = &callExpr{"page-down", nil, 1}
|
}
|
||||||
gOpts.keys["<c-e>"] = &callExpr{"scroll-down", nil, 1}
|
|
||||||
gOpts.keys["<c-m-down>"] = &callExpr{"scroll-down", nil, 1}
|
|
||||||
gOpts.keys["h"] = &callExpr{"updir", nil, 1}
|
|
||||||
gOpts.keys["<left>"] = &callExpr{"updir", nil, 1}
|
|
||||||
gOpts.keys["l"] = &callExpr{"open", nil, 1}
|
|
||||||
gOpts.keys["<right>"] = &callExpr{"open", nil, 1}
|
|
||||||
gOpts.keys["q"] = &callExpr{"quit", nil, 1}
|
|
||||||
gOpts.keys["gg"] = &callExpr{"top", nil, 1}
|
|
||||||
gOpts.keys["<home>"] = &callExpr{"top", nil, 1}
|
|
||||||
gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
|
|
||||||
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
|
|
||||||
gOpts.keys["H"] = &callExpr{"high", nil, 1}
|
|
||||||
gOpts.keys["M"] = &callExpr{"middle", nil, 1}
|
|
||||||
gOpts.keys["L"] = &callExpr{"low", nil, 1}
|
|
||||||
gOpts.keys["["] = &callExpr{"jump-prev", nil, 1}
|
|
||||||
gOpts.keys["]"] = &callExpr{"jump-next", nil, 1}
|
|
||||||
gOpts.keys["<space>"] = &listExpr{[]expr{&callExpr{"toggle", nil, 1}, &callExpr{"down", nil, 1}}, 1}
|
|
||||||
gOpts.keys["t"] = &callExpr{"tag-toggle", nil, 1}
|
|
||||||
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
|
||||||
gOpts.keys["u"] = &callExpr{"unselect", nil, 1}
|
|
||||||
gOpts.keys["y"] = &callExpr{"copy", nil, 1}
|
|
||||||
gOpts.keys["d"] = &callExpr{"cut", nil, 1}
|
|
||||||
gOpts.keys["c"] = &callExpr{"clear", nil, 1}
|
|
||||||
gOpts.keys["p"] = &callExpr{"paste", nil, 1}
|
|
||||||
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil, 1}
|
|
||||||
gOpts.keys["<c-r>"] = &callExpr{"reload", nil, 1}
|
|
||||||
gOpts.keys[":"] = &callExpr{"read", nil, 1}
|
|
||||||
gOpts.keys["$"] = &callExpr{"shell", nil, 1}
|
|
||||||
gOpts.keys["%"] = &callExpr{"shell-pipe", nil, 1}
|
|
||||||
gOpts.keys["!"] = &callExpr{"shell-wait", nil, 1}
|
|
||||||
gOpts.keys["&"] = &callExpr{"shell-async", nil, 1}
|
|
||||||
gOpts.keys["f"] = &callExpr{"find", nil, 1}
|
|
||||||
gOpts.keys["F"] = &callExpr{"find-back", nil, 1}
|
|
||||||
gOpts.keys[";"] = &callExpr{"find-next", nil, 1}
|
|
||||||
gOpts.keys[","] = &callExpr{"find-prev", nil, 1}
|
|
||||||
gOpts.keys["/"] = &callExpr{"search", nil, 1}
|
|
||||||
gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
|
|
||||||
gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
|
|
||||||
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
|
||||||
gOpts.keys["m"] = &callExpr{"mark-save", nil, 1}
|
|
||||||
gOpts.keys["'"] = &callExpr{"mark-load", nil, 1}
|
|
||||||
gOpts.keys[`"`] = &callExpr{"mark-remove", nil, 1}
|
|
||||||
gOpts.keys[`r`] = &callExpr{"rename", nil, 1}
|
|
||||||
gOpts.keys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
|
||||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
|
||||||
|
|
||||||
gOpts.keys["zh"] = &setExpr{"hidden!", ""}
|
gOpts.cmdkeys = map[string]expr{
|
||||||
gOpts.keys["zr"] = &setExpr{"reverse!", ""}
|
"<space>": &callExpr{"cmd-insert", []string{" "}, 1},
|
||||||
gOpts.keys["zn"] = &setExpr{"info", ""}
|
"<esc>": &callExpr{"cmd-escape", nil, 1},
|
||||||
gOpts.keys["zs"] = &setExpr{"info", "size"}
|
"<tab>": &callExpr{"cmd-complete", nil, 1},
|
||||||
gOpts.keys["zt"] = &setExpr{"info", "time"}
|
"<enter>": &callExpr{"cmd-enter", nil, 1},
|
||||||
gOpts.keys["za"] = &setExpr{"info", "size:time"}
|
"<c-j>": &callExpr{"cmd-enter", nil, 1},
|
||||||
gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}, 1}
|
"<down>": &callExpr{"cmd-history-next", nil, 1},
|
||||||
gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1}
|
"<c-n>": &callExpr{"cmd-history-next", nil, 1},
|
||||||
gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}, 1}
|
"<up>": &callExpr{"cmd-history-prev", nil, 1},
|
||||||
gOpts.keys["sa"] = &listExpr{[]expr{&setExpr{"sortby", "atime"}, &setExpr{"info", "atime"}}, 1}
|
"<c-p>": &callExpr{"cmd-history-prev", nil, 1},
|
||||||
gOpts.keys["sc"] = &listExpr{[]expr{&setExpr{"sortby", "ctime"}, &setExpr{"info", "ctime"}}, 1}
|
"<delete>": &callExpr{"cmd-delete", nil, 1},
|
||||||
gOpts.keys["se"] = &listExpr{[]expr{&setExpr{"sortby", "ext"}, &setExpr{"info", ""}}, 1}
|
"<c-d>": &callExpr{"cmd-delete", nil, 1},
|
||||||
gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}, 1}
|
"<backspace>": &callExpr{"cmd-delete-back", nil, 1},
|
||||||
|
"<backspace2>": &callExpr{"cmd-delete-back", nil, 1},
|
||||||
gOpts.cmdkeys = make(map[string]expr)
|
"<left>": &callExpr{"cmd-left", nil, 1},
|
||||||
|
"<c-b>": &callExpr{"cmd-left", nil, 1},
|
||||||
gOpts.cmdkeys["<space>"] = &callExpr{"cmd-insert", []string{" "}, 1}
|
"<right>": &callExpr{"cmd-right", nil, 1},
|
||||||
gOpts.cmdkeys["<esc>"] = &callExpr{"cmd-escape", nil, 1}
|
"<c-f>": &callExpr{"cmd-right", nil, 1},
|
||||||
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-complete", nil, 1}
|
"<home>": &callExpr{"cmd-home", nil, 1},
|
||||||
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil, 1}
|
"<c-a>": &callExpr{"cmd-home", nil, 1},
|
||||||
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil, 1}
|
"<end>": &callExpr{"cmd-end", nil, 1},
|
||||||
gOpts.cmdkeys["<down>"] = &callExpr{"cmd-history-next", nil, 1}
|
"<c-e>": &callExpr{"cmd-end", nil, 1},
|
||||||
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
"<c-u>": &callExpr{"cmd-delete-home", nil, 1},
|
||||||
gOpts.cmdkeys["<up>"] = &callExpr{"cmd-history-prev", nil, 1}
|
"<c-k>": &callExpr{"cmd-delete-end", nil, 1},
|
||||||
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
"<c-w>": &callExpr{"cmd-delete-unix-word", nil, 1},
|
||||||
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil, 1}
|
"<c-y>": &callExpr{"cmd-yank", nil, 1},
|
||||||
gOpts.cmdkeys["<c-d>"] = &callExpr{"cmd-delete", nil, 1}
|
"<c-t>": &callExpr{"cmd-transpose", nil, 1},
|
||||||
gOpts.cmdkeys["<backspace>"] = &callExpr{"cmd-delete-back", nil, 1}
|
"<c-c>": &callExpr{"cmd-interrupt", nil, 1},
|
||||||
gOpts.cmdkeys["<backspace2>"] = &callExpr{"cmd-delete-back", nil, 1}
|
"<a-f>": &callExpr{"cmd-word", nil, 1},
|
||||||
gOpts.cmdkeys["<left>"] = &callExpr{"cmd-left", nil, 1}
|
"<a-b>": &callExpr{"cmd-word-back", nil, 1},
|
||||||
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil, 1}
|
"<a-c>": &callExpr{"cmd-capitalize-word", nil, 1},
|
||||||
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil, 1}
|
"<a-d>": &callExpr{"cmd-delete-word", nil, 1},
|
||||||
gOpts.cmdkeys["<c-f>"] = &callExpr{"cmd-right", nil, 1}
|
"<a-backspace>": &callExpr{"cmd-delete-word-back", nil, 1},
|
||||||
gOpts.cmdkeys["<home>"] = &callExpr{"cmd-home", nil, 1}
|
"<a-backspace2>": &callExpr{"cmd-delete-word-back", nil, 1},
|
||||||
gOpts.cmdkeys["<c-a>"] = &callExpr{"cmd-home", nil, 1}
|
"<a-u>": &callExpr{"cmd-uppercase-word", nil, 1},
|
||||||
gOpts.cmdkeys["<end>"] = &callExpr{"cmd-end", nil, 1}
|
"<a-l>": &callExpr{"cmd-lowercase-word", nil, 1},
|
||||||
gOpts.cmdkeys["<c-e>"] = &callExpr{"cmd-end", nil, 1}
|
"<a-t>": &callExpr{"cmd-transpose-word", nil, 1},
|
||||||
gOpts.cmdkeys["<c-u>"] = &callExpr{"cmd-delete-home", nil, 1}
|
}
|
||||||
gOpts.cmdkeys["<c-k>"] = &callExpr{"cmd-delete-end", nil, 1}
|
|
||||||
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-unix-word", nil, 1}
|
|
||||||
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-yank", nil, 1}
|
|
||||||
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil, 1}
|
|
||||||
gOpts.cmdkeys["<c-c>"] = &callExpr{"cmd-interrupt", nil, 1}
|
|
||||||
gOpts.cmdkeys["<a-f>"] = &callExpr{"cmd-word", nil, 1}
|
|
||||||
gOpts.cmdkeys["<a-b>"] = &callExpr{"cmd-word-back", nil, 1}
|
|
||||||
gOpts.cmdkeys["<a-c>"] = &callExpr{"cmd-capitalize-word", nil, 1}
|
|
||||||
gOpts.cmdkeys["<a-d>"] = &callExpr{"cmd-delete-word", nil, 1}
|
|
||||||
gOpts.cmdkeys["<a-backspace>"] = &callExpr{"cmd-delete-word-back", nil, 1}
|
|
||||||
gOpts.cmdkeys["<a-backspace2>"] = &callExpr{"cmd-delete-word-back", nil, 1}
|
|
||||||
gOpts.cmdkeys["<a-u>"] = &callExpr{"cmd-uppercase-word", nil, 1}
|
|
||||||
gOpts.cmdkeys["<a-l>"] = &callExpr{"cmd-lowercase-word", nil, 1}
|
|
||||||
gOpts.cmdkeys["<a-t>"] = &callExpr{"cmd-transpose-word", nil, 1}
|
|
||||||
|
|
||||||
gOpts.cmds = make(map[string]expr)
|
gOpts.cmds = make(map[string]expr)
|
||||||
gOpts.user = make(map[string]string)
|
gOpts.user = make(map[string]string)
|
||||||
|
|
||||||
gLocalOpts.sortMethods = make(map[string]sortMethod)
|
gLocalOpts.sortby = make(map[string]sortMethod)
|
||||||
gLocalOpts.dirfirsts = make(map[string]bool)
|
gLocalOpts.dircounts = make(map[string]bool)
|
||||||
gLocalOpts.dironlys = make(map[string]bool)
|
gLocalOpts.dirfirst = make(map[string]bool)
|
||||||
gLocalOpts.hiddens = make(map[string]bool)
|
gLocalOpts.dironly = make(map[string]bool)
|
||||||
gLocalOpts.reverses = make(map[string]bool)
|
gLocalOpts.hidden = make(map[string]bool)
|
||||||
gLocalOpts.infos = make(map[string][]string)
|
gLocalOpts.reverse = make(map[string]bool)
|
||||||
|
gLocalOpts.info = make(map[string][]string)
|
||||||
|
gLocalOpts.locale = make(map[string]string)
|
||||||
|
|
||||||
setDefaults()
|
setDefaults()
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -10,6 +11,7 @@ import (
|
|||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@@ -28,6 +30,7 @@ var (
|
|||||||
gDefaultShellFlag = "-c"
|
gDefaultShellFlag = "-c"
|
||||||
gDefaultSocketProt = "unix"
|
gDefaultSocketProt = "unix"
|
||||||
gDefaultSocketPath string
|
gDefaultSocketPath string
|
||||||
|
gDefaultHiddenFiles = []string{".*"}
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -51,10 +54,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if envEditor == "" {
|
if envEditor == "" {
|
||||||
envEditor = os.Getenv("EDITOR")
|
envEditor = cmp.Or(os.Getenv("EDITOR"), "vi")
|
||||||
if envEditor == "" {
|
|
||||||
envEditor = "vi"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if envPager == "" {
|
if envPager == "" {
|
||||||
@@ -84,13 +84,11 @@ func init() {
|
|||||||
}
|
}
|
||||||
gUser = u
|
gUser = u
|
||||||
|
|
||||||
config := os.Getenv("LF_CONFIG_HOME")
|
config := cmp.Or(
|
||||||
if config == "" {
|
os.Getenv("LF_CONFIG_HOME"),
|
||||||
config = os.Getenv("XDG_CONFIG_HOME")
|
os.Getenv("XDG_CONFIG_HOME"),
|
||||||
}
|
filepath.Join(gUser.HomeDir, ".config"),
|
||||||
if config == "" {
|
)
|
||||||
config = filepath.Join(gUser.HomeDir, ".config")
|
|
||||||
}
|
|
||||||
|
|
||||||
gConfigPaths = []string{
|
gConfigPaths = []string{
|
||||||
filepath.Join("/etc", "lf", "lfrc"),
|
filepath.Join("/etc", "lf", "lfrc"),
|
||||||
@@ -107,23 +105,18 @@ func init() {
|
|||||||
filepath.Join(config, "lf", "icons"),
|
filepath.Join(config, "lf", "icons"),
|
||||||
}
|
}
|
||||||
|
|
||||||
data := os.Getenv("LF_DATA_HOME")
|
data := cmp.Or(
|
||||||
if data == "" {
|
os.Getenv("LF_DATA_HOME"),
|
||||||
data = os.Getenv("XDG_DATA_HOME")
|
os.Getenv("XDG_DATA_HOME"),
|
||||||
}
|
filepath.Join(gUser.HomeDir, ".local", "share"),
|
||||||
if data == "" {
|
)
|
||||||
data = filepath.Join(gUser.HomeDir, ".local", "share")
|
|
||||||
}
|
|
||||||
|
|
||||||
gFilesPath = filepath.Join(data, "lf", "files")
|
gFilesPath = filepath.Join(data, "lf", "files")
|
||||||
gMarksPath = filepath.Join(data, "lf", "marks")
|
gMarksPath = filepath.Join(data, "lf", "marks")
|
||||||
gTagsPath = filepath.Join(data, "lf", "tags")
|
gTagsPath = filepath.Join(data, "lf", "tags")
|
||||||
gHistoryPath = filepath.Join(data, "lf", "history")
|
gHistoryPath = filepath.Join(data, "lf", "history")
|
||||||
|
|
||||||
runtime := os.Getenv("XDG_RUNTIME_DIR")
|
runtime := cmp.Or(os.Getenv("XDG_RUNTIME_DIR"), os.TempDir())
|
||||||
if runtime == "" {
|
|
||||||
runtime = os.TempDir()
|
|
||||||
}
|
|
||||||
|
|
||||||
gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username))
|
gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username))
|
||||||
}
|
}
|
||||||
@@ -154,7 +147,7 @@ func shellKill(cmd *exec.Cmd) error {
|
|||||||
pgid, err := unix.Getpgid(cmd.Process.Pid)
|
pgid, err := unix.Getpgid(cmd.Process.Pid)
|
||||||
if err == nil && cmd.Process.Pid == pgid {
|
if err == nil && cmd.Process.Pid == pgid {
|
||||||
// kill the process group
|
// kill the process group
|
||||||
err = unix.Kill(-pgid, 15)
|
err = unix.Kill(-pgid, syscall.SIGTERM)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -177,21 +170,18 @@ func setDefaults() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setUserUmask() {
|
func setUserUmask() {
|
||||||
unix.Umask(0077)
|
unix.Umask(0o077)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isExecutable(f os.FileInfo) bool {
|
func isExecutable(f os.FileInfo) bool {
|
||||||
return f.Mode()&0111 != 0
|
return f.Mode()&0o111 != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
|
func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
|
||||||
hidden := false
|
hidden := false
|
||||||
for _, pattern := range hiddenfiles {
|
for _, pattern := range hiddenfiles {
|
||||||
matched := matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path)
|
if matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path) {
|
||||||
if strings.HasPrefix(pattern, "!") && matched {
|
hidden = !strings.HasPrefix(pattern, "!")
|
||||||
hidden = false
|
|
||||||
} else if matched {
|
|
||||||
hidden = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hidden
|
return hidden
|
||||||
@@ -199,25 +189,29 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
|
|||||||
|
|
||||||
func userName(f os.FileInfo) string {
|
func userName(f os.FileInfo) string {
|
||||||
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
||||||
if u, err := user.LookupId(fmt.Sprint(stat.Uid)); err == nil {
|
uid := strconv.FormatUint(uint64(stat.Uid), 10)
|
||||||
|
if u, err := user.LookupId(uid); err == nil {
|
||||||
return u.Username
|
return u.Username
|
||||||
}
|
}
|
||||||
|
return uid
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func groupName(f os.FileInfo) string {
|
func groupName(f os.FileInfo) string {
|
||||||
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
||||||
if g, err := user.LookupGroupId(fmt.Sprint(stat.Gid)); err == nil {
|
gid := strconv.FormatUint(uint64(stat.Gid), 10)
|
||||||
|
if g, err := user.LookupGroupId(gid); err == nil {
|
||||||
return g.Name
|
return g.Name
|
||||||
}
|
}
|
||||||
|
return gid
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func linkCount(f os.FileInfo) string {
|
func linkCount(f os.FileInfo) string {
|
||||||
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
||||||
return fmt.Sprint(stat.Nlink)
|
return strconv.FormatUint(uint64(stat.Nlink), 10)
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
+45
-20
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -8,6 +9,7 @@ import (
|
|||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
@@ -24,8 +26,9 @@ var envPathExt = os.Getenv("PATHEXT")
|
|||||||
var (
|
var (
|
||||||
gDefaultShell = "cmd"
|
gDefaultShell = "cmd"
|
||||||
gDefaultShellFlag = "/c"
|
gDefaultShellFlag = "/c"
|
||||||
gDefaultSocketProt = "tcp"
|
gDefaultSocketProt = "unix"
|
||||||
gDefaultSocketPath = "127.0.0.1:12345"
|
gDefaultSocketPath string
|
||||||
|
gDefaultHiddenFiles []string
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -45,10 +48,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if envEditor == "" {
|
if envEditor == "" {
|
||||||
envEditor = os.Getenv("EDITOR")
|
envEditor = cmp.Or(os.Getenv("EDITOR"), "notepad")
|
||||||
if envEditor == "" {
|
|
||||||
envEditor = "notepad"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if envPager == "" {
|
if envPager == "" {
|
||||||
@@ -59,20 +59,23 @@ func init() {
|
|||||||
envShell = "cmd"
|
envShell = "cmd"
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := user.Current()
|
homeDir, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("user: %s", err)
|
panic(err)
|
||||||
}
|
}
|
||||||
gUser = u
|
|
||||||
|
|
||||||
// remove domain prefix
|
username := os.Getenv("USERNAME")
|
||||||
gUser.Username = strings.Split(gUser.Username, `\`)[1]
|
if username == "" {
|
||||||
|
panic("$USERNAME variable is empty or not set")
|
||||||
data := os.Getenv("LF_CONFIG_HOME")
|
|
||||||
if data == "" {
|
|
||||||
data = os.Getenv("LOCALAPPDATA")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gUser = &user.User{
|
||||||
|
HomeDir: homeDir,
|
||||||
|
Username: username,
|
||||||
|
}
|
||||||
|
|
||||||
|
data := cmp.Or(os.Getenv("LF_CONFIG_HOME"), os.Getenv("LOCALAPPDATA"))
|
||||||
|
|
||||||
gConfigPaths = []string{
|
gConfigPaths = []string{
|
||||||
filepath.Join(os.Getenv("ProgramData"), "lf", "lfrc"),
|
filepath.Join(os.Getenv("ProgramData"), "lf", "lfrc"),
|
||||||
filepath.Join(data, "lf", "lfrc"),
|
filepath.Join(data, "lf", "lfrc"),
|
||||||
@@ -92,6 +95,16 @@ func init() {
|
|||||||
gMarksPath = filepath.Join(data, "lf", "marks")
|
gMarksPath = filepath.Join(data, "lf", "marks")
|
||||||
gTagsPath = filepath.Join(data, "lf", "tags")
|
gTagsPath = filepath.Join(data, "lf", "tags")
|
||||||
gHistoryPath = filepath.Join(data, "lf", "history")
|
gHistoryPath = filepath.Join(data, "lf", "history")
|
||||||
|
|
||||||
|
socket, err := syscall.Socket(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
|
||||||
|
if err != nil {
|
||||||
|
gDefaultSocketProt = "tcp"
|
||||||
|
gDefaultSocketPath = "127.0.0.1:12345"
|
||||||
|
} else {
|
||||||
|
runtime := os.TempDir()
|
||||||
|
gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username))
|
||||||
|
syscall.Close(socket)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func detachedCommand(name string, arg ...string) *exec.Cmd {
|
func detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||||
@@ -164,23 +177,35 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return attrs&windows.FILE_ATTRIBUTE_HIDDEN != 0
|
|
||||||
|
if attrs&windows.FILE_ATTRIBUTE_HIDDEN != 0 {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func userName(f os.FileInfo) string {
|
hidden := false
|
||||||
|
for _, pattern := range hiddenfiles {
|
||||||
|
if matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path) {
|
||||||
|
hidden = !strings.HasPrefix(pattern, "!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hidden
|
||||||
|
}
|
||||||
|
|
||||||
|
func userName(_ os.FileInfo) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func groupName(f os.FileInfo) string {
|
func groupName(_ os.FileInfo) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func linkCount(f os.FileInfo) string {
|
func linkCount(_ os.FileInfo) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func errCrossDevice(err error) bool {
|
func errCrossDevice(err error) bool {
|
||||||
return err.(*os.LinkError).Err.(windows.Errno) == 17
|
return err.(*os.LinkError).Err.(windows.Errno) == windows.ERROR_NOT_SAME_DEVICE
|
||||||
}
|
}
|
||||||
|
|
||||||
func quoteString(s string) string {
|
func quoteString(s string) string {
|
||||||
|
|||||||
@@ -324,9 +324,6 @@ func (p *parser) parseExpr() expr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) parse() bool {
|
func (p *parser) parse() bool {
|
||||||
if p.expr = p.parseExpr(); p.expr == nil {
|
p.expr = p.parseExpr()
|
||||||
return false
|
return p.expr != nil
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
@@ -17,9 +17,9 @@ var (
|
|||||||
|
|
||||||
func serve() {
|
func serve() {
|
||||||
if gLogPath != "" {
|
if gLogPath != "" {
|
||||||
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
|
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatalf("failed to open log file: %s", err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
log.SetOutput(f)
|
log.SetOutput(f)
|
||||||
@@ -64,7 +64,7 @@ func echoerr(c net.Conn, msg string) {
|
|||||||
log.Print(msg)
|
log.Print(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func echoerrf(c net.Conn, format string, a ...interface{}) {
|
func echoerrf(c net.Conn, format string, a ...any) {
|
||||||
echoerr(c, fmt.Sprintf(format, a...))
|
echoerr(c, fmt.Sprintf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
@@ -9,6 +10,13 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
gSixelBegin = "\033P"
|
gSixelBegin = "\033P"
|
||||||
|
|
||||||
|
// The filler character should be:
|
||||||
|
// - rarely used: the filler is used to trick tcell into redrawing, if the
|
||||||
|
// filler character appears in the user's preview, that cell might not
|
||||||
|
// be cleaned up properly
|
||||||
|
// - ideally renders as empty space: the filler alternates between bold
|
||||||
|
// and regular, using a non-space would look weird to the user.
|
||||||
gSixelFiller = '\u2000'
|
gSixelFiller = '\u2000'
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,12 +44,12 @@ func (sxs *sixelScreen) showSixels() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XXX: workaround for bug where quitting lf might leave the terminal in bold
|
// XXX: workaround for bug where quitting lf might leave the terminal in bold
|
||||||
fmt.Print("\033[0m")
|
fmt.Fprint(os.Stderr, "\033[0m")
|
||||||
|
|
||||||
fmt.Print("\0337") // Save cursor position
|
fmt.Fprint(os.Stderr, "\0337") // Save cursor position
|
||||||
fmt.Printf("\033[%d;%dH", sxs.yprev, sxs.xprev) // Move cursor to position
|
fmt.Fprintf(os.Stderr, "\033[%d;%dH", sxs.yprev, sxs.xprev) // Move cursor to position
|
||||||
fmt.Print(*sxs.sixel) //
|
fmt.Fprint(os.Stderr, *sxs.sixel) //
|
||||||
fmt.Print("\0338") // Restore cursor position
|
fmt.Fprint(os.Stderr, "\0338") // Restore cursor position
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sxs *sixelScreen) printSixel(win *win, screen tcell.Screen, reg *reg) {
|
func (sxs *sixelScreen) printSixel(win *win, screen tcell.Screen, reg *reg) {
|
||||||
@@ -52,7 +60,7 @@ func (sxs *sixelScreen) printSixel(win *win, screen tcell.Screen, reg *reg) {
|
|||||||
// HACK: fillers are used to control when tcell redraws the region where a sixel image is drawn.
|
// HACK: fillers are used to control when tcell redraws the region where a sixel image is drawn.
|
||||||
// alternating between bold and regular is to clear the image before drawing a new one.
|
// alternating between bold and regular is to clear the image before drawing a new one.
|
||||||
st := sxs.fillerStyle(reg.path)
|
st := sxs.fillerStyle(reg.path)
|
||||||
for y := 0; y < win.h; y++ {
|
for y := range win.h {
|
||||||
st = win.print(screen, 0, y, st, strings.Repeat(string(gSixelFiller), win.w))
|
st = win.print(screen, 0, y, st, strings.Repeat(string(gSixelFiller), win.w))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ var gKeyVal = map[tcell.Key]string{
|
|||||||
var gValKey map[string]tcell.Key
|
var gValKey map[string]tcell.Key
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
gValKey = make(map[string]tcell.Key)
|
gValKey = make(map[string]tcell.Key, len(gKeyVal))
|
||||||
for k, v := range gKeyVal {
|
for k, v := range gKeyVal {
|
||||||
gValKey[v] = k
|
gValKey[v] = k
|
||||||
}
|
}
|
||||||
@@ -166,11 +166,12 @@ func (win *win) renew(w, h, x, y int) {
|
|||||||
func printLength(s string) int {
|
func printLength(s string) int {
|
||||||
ind := 0
|
ind := 0
|
||||||
off := 0
|
off := 0
|
||||||
for i := 0; i < len(s); i++ {
|
slen := len(s)
|
||||||
|
for i := 0; i < slen; i++ {
|
||||||
r, w := utf8.DecodeRuneInString(s[i:])
|
r, w := utf8.DecodeRuneInString(s[i:])
|
||||||
|
|
||||||
if r == gEscapeCode && i+1 < len(s) && s[i+1] == '[' {
|
if r == gEscapeCode && i+1 < slen && s[i+1] == '[' {
|
||||||
j := strings.IndexAny(s[i:min(len(s), i+64)], "mK")
|
j := strings.IndexAny(s[i:min(slen, i+64)], "mK")
|
||||||
if j == -1 {
|
if j == -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -194,11 +195,12 @@ func printLength(s string) int {
|
|||||||
func (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s string) tcell.Style {
|
func (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s string) tcell.Style {
|
||||||
off := x
|
off := x
|
||||||
var comb []rune
|
var comb []rune
|
||||||
for i := 0; i < len(s); i++ {
|
slen := len(s)
|
||||||
|
for i := 0; i < slen; i++ {
|
||||||
r, w := utf8.DecodeRuneInString(s[i:])
|
r, w := utf8.DecodeRuneInString(s[i:])
|
||||||
|
|
||||||
if r == gEscapeCode && i+1 < len(s) && s[i+1] == '[' {
|
if r == gEscapeCode && i+1 < slen && s[i+1] == '[' {
|
||||||
j := strings.IndexAny(s[i:min(len(s), i+64)], "mK")
|
j := strings.IndexAny(s[i:min(slen, i+64)], "mK")
|
||||||
if j == -1 {
|
if j == -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -227,11 +229,11 @@ func (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s string) t
|
|||||||
i += w - 1
|
i += w - 1
|
||||||
|
|
||||||
if r == '\t' {
|
if r == '\t' {
|
||||||
s := gOpts.tabstop - (x-off)%gOpts.tabstop
|
ind := gOpts.tabstop - (x-off)%gOpts.tabstop
|
||||||
for i := 0; i < s && x+i < win.w; i++ {
|
for i := 0; i < ind && x+i < win.w; i++ {
|
||||||
screen.SetContent(win.x+x+i, win.y+y, ' ', nil, st)
|
screen.SetContent(win.x+x+i, win.y+y, ' ', nil, st)
|
||||||
}
|
}
|
||||||
x += s
|
x += ind
|
||||||
} else {
|
} else {
|
||||||
x += runewidth.RuneWidth(r)
|
x += runewidth.RuneWidth(r)
|
||||||
}
|
}
|
||||||
@@ -240,7 +242,7 @@ func (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s string) t
|
|||||||
return st
|
return st
|
||||||
}
|
}
|
||||||
|
|
||||||
func (win *win) printf(screen tcell.Screen, x, y int, st tcell.Style, format string, a ...interface{}) {
|
func (win *win) printf(screen tcell.Screen, x, y int, st tcell.Style, format string, a ...any) {
|
||||||
win.print(screen, x, y, st, fmt.Sprintf(format, a...))
|
win.print(screen, x, y, st, fmt.Sprintf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,45 +289,51 @@ func infotimefmt(t time.Time) string {
|
|||||||
return t.Format(gOpts.infotimefmtold)
|
return t.Format(gOpts.infotimefmtold)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileInfo(f *file, d *dir) string {
|
func fileInfo(f *file, d *dir, userWidth int, groupWidth int) string {
|
||||||
var info string
|
var info strings.Builder
|
||||||
|
|
||||||
for _, s := range getInfo(d.path) {
|
for _, s := range getInfo(d.path) {
|
||||||
switch s {
|
switch s {
|
||||||
case "size":
|
case "size":
|
||||||
if !(f.IsDir() && gOpts.dircounts) {
|
if f.IsDir() && getDirCounts(d.path) {
|
||||||
|
switch {
|
||||||
|
case f.dirCount < -1:
|
||||||
|
info.WriteString(" !")
|
||||||
|
case f.dirCount < 0:
|
||||||
|
info.WriteString(" ?")
|
||||||
|
case f.dirCount < 1000:
|
||||||
|
fmt.Fprintf(&info, " %4d", f.dirCount)
|
||||||
|
default:
|
||||||
|
info.WriteString(" 999+")
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
var sz string
|
var sz string
|
||||||
if f.IsDir() && f.dirSize < 0 {
|
if f.IsDir() && f.dirSize < 0 {
|
||||||
sz = "-"
|
sz = "-"
|
||||||
} else {
|
} else {
|
||||||
sz = humanize(f.TotalSize())
|
sz = humanize(f.TotalSize())
|
||||||
}
|
}
|
||||||
info = fmt.Sprintf("%s %4s", info, sz)
|
fmt.Fprintf(&info, " %4s", sz)
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case f.dirCount < -1:
|
|
||||||
info = fmt.Sprintf("%s !", info)
|
|
||||||
case f.dirCount < 0:
|
|
||||||
info = fmt.Sprintf("%s ?", info)
|
|
||||||
case f.dirCount < 1000:
|
|
||||||
info = fmt.Sprintf("%s %4d", info, f.dirCount)
|
|
||||||
default:
|
|
||||||
info = fmt.Sprintf("%s 999+", info)
|
|
||||||
}
|
|
||||||
case "time":
|
case "time":
|
||||||
info = fmt.Sprintf("%s %*s", info, max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.ModTime()))
|
fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.ModTime()))
|
||||||
case "atime":
|
case "atime":
|
||||||
info = fmt.Sprintf("%s %*s", info, max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.accessTime))
|
fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.accessTime))
|
||||||
case "ctime":
|
case "ctime":
|
||||||
info = fmt.Sprintf("%s %*s", info, max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.changeTime))
|
fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.changeTime))
|
||||||
|
case "perm":
|
||||||
|
info.WriteString(" " + f.FileInfo.Mode().String())
|
||||||
|
case "user":
|
||||||
|
fmt.Fprintf(&info, " %-*s", userWidth, userName(f.FileInfo))
|
||||||
|
case "group":
|
||||||
|
fmt.Fprintf(&info, " %-*s", groupWidth, groupName(f.FileInfo))
|
||||||
default:
|
default:
|
||||||
log.Printf("unknown info type: %s", s)
|
log.Printf("unknown info type: %s", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return info
|
return info.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
type dirContext struct {
|
type dirContext struct {
|
||||||
@@ -348,12 +356,7 @@ type dirStyle struct {
|
|||||||
role dirRole
|
role dirRole
|
||||||
}
|
}
|
||||||
|
|
||||||
// These colors are not currently customizeable
|
func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirStyle) {
|
||||||
const SelectionColor = tcell.ColorPurple
|
|
||||||
const YankColor = tcell.ColorOlive
|
|
||||||
const CutColor = tcell.ColorMaroon
|
|
||||||
|
|
||||||
func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dirStyle *dirStyle, previewLoading bool) {
|
|
||||||
if win.w < 5 || dir == nil {
|
if win.w < 5 || dir == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -361,35 +364,22 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
|
|||||||
messageStyle := tcell.StyleDefault.Reverse(true)
|
messageStyle := tcell.StyleDefault.Reverse(true)
|
||||||
|
|
||||||
if dir.noPerm {
|
if dir.noPerm {
|
||||||
win.print(screen, 2, 0, messageStyle, "permission denied")
|
win.print(ui.screen, 2, 0, messageStyle, "permission denied")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (dir.loading && len(dir.files) == 0) || (dirStyle.role == Preview && dir.loading && gOpts.dirpreviews) {
|
fileslen := len(dir.files)
|
||||||
if dirStyle.role != Preview || previewLoading {
|
if dir.loading && fileslen == 0 {
|
||||||
win.print(screen, 2, 0, messageStyle, "loading...")
|
win.print(ui.screen, 2, 0, messageStyle, "loading...")
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if dirStyle.role == Preview && gOpts.dirpreviews && len(gOpts.previewer) > 0 {
|
if fileslen == 0 {
|
||||||
// Print previewer result instead of default directory print operation.
|
win.print(ui.screen, 2, 0, messageStyle, "empty")
|
||||||
st := tcell.StyleDefault
|
|
||||||
for i, l := range dir.lines {
|
|
||||||
if i > win.h-1 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
st = win.print(screen, 2, i, st, l)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(dir.files) == 0 {
|
|
||||||
win.print(screen, 2, 0, messageStyle, "empty")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
beg := max(dir.ind-dir.pos, 0)
|
beg := max(dir.ind-dir.pos, 0)
|
||||||
end := min(beg+win.h, len(dir.files))
|
end := min(beg+win.h, fileslen)
|
||||||
|
|
||||||
if beg > end {
|
if beg > end {
|
||||||
return
|
return
|
||||||
@@ -397,16 +387,33 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
|
|||||||
|
|
||||||
var lnwidth int
|
var lnwidth int
|
||||||
|
|
||||||
if gOpts.number || gOpts.relativenumber {
|
if dirStyle.role == Active && (gOpts.number || gOpts.relativenumber) {
|
||||||
lnwidth = 1
|
lnwidth = 1
|
||||||
if gOpts.number && gOpts.relativenumber {
|
if gOpts.number && gOpts.relativenumber {
|
||||||
lnwidth++
|
lnwidth++
|
||||||
}
|
}
|
||||||
for j := 10; j <= len(dir.files); j *= 10 {
|
for j := 10; j <= fileslen; j *= 10 {
|
||||||
lnwidth++
|
lnwidth++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var userWidth int
|
||||||
|
var groupWidth int
|
||||||
|
|
||||||
|
// Only fetch user/group widths if configured to display them
|
||||||
|
for _, s := range getInfo(dir.path) {
|
||||||
|
switch s {
|
||||||
|
case "user":
|
||||||
|
userWidth = getUserWidth(dir, beg, end)
|
||||||
|
case "group":
|
||||||
|
groupWidth = getGroupWidth(dir, beg, end)
|
||||||
|
}
|
||||||
|
|
||||||
|
if userWidth > 0 && groupWidth > 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for i, f := range dir.files[beg:end] {
|
for i, f := range dir.files[beg:end] {
|
||||||
st := dirStyle.colors.get(f)
|
st := dirStyle.colors.get(f)
|
||||||
|
|
||||||
@@ -428,18 +435,18 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
win.print(screen, 0, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.numberfmt), ln))
|
win.print(ui.screen, 0, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.numberfmt), ln))
|
||||||
}
|
}
|
||||||
|
|
||||||
path := filepath.Join(dir.path, f.Name())
|
path := filepath.Join(dir.path, f.Name())
|
||||||
|
|
||||||
if _, ok := context.selections[path]; ok {
|
if _, ok := context.selections[path]; ok {
|
||||||
win.print(screen, lnwidth, i, st.Background(SelectionColor), " ")
|
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.selectfmt), " ")
|
||||||
} else if cp, ok := context.saves[path]; ok {
|
} else if cp, ok := context.saves[path]; ok {
|
||||||
if cp {
|
if cp {
|
||||||
win.print(screen, lnwidth, i, st.Background(YankColor), " ")
|
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.copyfmt), " ")
|
||||||
} else {
|
} else {
|
||||||
win.print(screen, lnwidth, i, st.Background(CutColor), " ")
|
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.cutfmt), " ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,22 +457,27 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
|
|||||||
maxWidth -= 1
|
maxWidth -= 1
|
||||||
}
|
}
|
||||||
|
|
||||||
var s []rune
|
tag := " "
|
||||||
|
if val, ok := context.tags[path]; ok && len(val) > 0 {
|
||||||
// leave space for displaying the tag
|
tag = val
|
||||||
s = append(s, ' ')
|
|
||||||
|
|
||||||
if gOpts.icons {
|
|
||||||
s = append(s, []rune(dirStyle.icons.get(f))...)
|
|
||||||
s = append(s, ' ')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
maxFilenameWidth := maxWidth - runeSliceWidth(s)
|
var icon []rune
|
||||||
|
var iconDef iconDef
|
||||||
|
if gOpts.icons {
|
||||||
|
iconDef = dirStyle.icons.get(f)
|
||||||
|
icon = append(icon, []rune(iconDef.icon)...)
|
||||||
|
icon = append(icon, ' ')
|
||||||
|
}
|
||||||
|
|
||||||
info := fileInfo(f, dir)
|
// subtract space for tag and icon
|
||||||
showInfo := len(info) > 0 && 2*len(info) < maxWidth
|
maxFilenameWidth := maxWidth - 1 - runeSliceWidth(icon)
|
||||||
|
|
||||||
|
info := fileInfo(f, dir, userWidth, groupWidth)
|
||||||
|
infolen := len(info)
|
||||||
|
showInfo := infolen > 0 && 2*infolen < maxWidth
|
||||||
if showInfo {
|
if showInfo {
|
||||||
maxFilenameWidth -= len(info)
|
maxFilenameWidth -= infolen
|
||||||
}
|
}
|
||||||
|
|
||||||
filename := []rune(f.Name())
|
filename := []rune(f.Name())
|
||||||
@@ -476,41 +488,71 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
|
|||||||
filename = append(filename, []rune(gOpts.truncatechar)...)
|
filename = append(filename, []rune(gOpts.truncatechar)...)
|
||||||
filename = append(filename, lastPart...)
|
filename = append(filename, lastPart...)
|
||||||
}
|
}
|
||||||
for i := runeSliceWidth(filename); i < maxFilenameWidth; i++ {
|
for j := runeSliceWidth(filename); j < maxFilenameWidth; j++ {
|
||||||
filename = append(filename, ' ')
|
filename = append(filename, ' ')
|
||||||
}
|
}
|
||||||
s = append(s, filename...)
|
|
||||||
|
|
||||||
if showInfo {
|
if showInfo {
|
||||||
s = append(s, []rune(info)...)
|
filename = append(filename, []rune(info)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
ce := ""
|
|
||||||
if i == dir.pos {
|
if i == dir.pos {
|
||||||
|
var cursorFmt string
|
||||||
switch dirStyle.role {
|
switch dirStyle.role {
|
||||||
case Active:
|
case Active:
|
||||||
ce = gOpts.cursoractivefmt
|
cursorFmt = optionToFmtstr(gOpts.cursoractivefmt)
|
||||||
case Parent:
|
case Parent:
|
||||||
ce = gOpts.cursorparentfmt
|
cursorFmt = optionToFmtstr(gOpts.cursorparentfmt)
|
||||||
case Preview:
|
case Preview:
|
||||||
ce = gOpts.cursorpreviewfmt
|
cursorFmt = optionToFmtstr(gOpts.cursorpreviewfmt)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
cursorescapefmt := optionToFmtstr(ce)
|
|
||||||
|
|
||||||
s = append(s, ' ')
|
// print tag separately as it can contain color escape sequences
|
||||||
styledFilename := fmt.Sprintf(cursorescapefmt, string(s))
|
win.print(ui.screen, lnwidth+1, i, st, fmt.Sprintf(cursorFmt, tag))
|
||||||
win.print(screen, lnwidth+1, i, st, styledFilename)
|
|
||||||
|
|
||||||
tag, ok := context.tags[path]
|
line := append(icon, filename...)
|
||||||
if ok {
|
line = append(line, ' ')
|
||||||
if i == dir.pos {
|
win.print(ui.screen, lnwidth+2, i, st, fmt.Sprintf(cursorFmt, string(line)))
|
||||||
win.print(screen, lnwidth+1, i, st, fmt.Sprintf(cursorescapefmt, tag))
|
|
||||||
} else {
|
} else {
|
||||||
win.print(screen, lnwidth+1, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), tag))
|
if tag == " " {
|
||||||
|
win.print(ui.screen, lnwidth+1, i, st, " ")
|
||||||
|
} else {
|
||||||
|
tagStr := fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), tag)
|
||||||
|
win.print(ui.screen, lnwidth+1, i, tcell.StyleDefault, tagStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(icon) > 0 {
|
||||||
|
iconStyle := st
|
||||||
|
if iconDef.hasStyle {
|
||||||
|
iconStyle = iconDef.style
|
||||||
|
}
|
||||||
|
win.print(ui.screen, lnwidth+2, i, iconStyle, string(icon))
|
||||||
|
}
|
||||||
|
|
||||||
|
line := append(filename, ' ')
|
||||||
|
win.print(ui.screen, lnwidth+2+runeSliceWidth(icon), i, st, string(line))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getUserWidth(dir *dir, beg int, end int) int {
|
||||||
|
maxw := 0
|
||||||
|
|
||||||
|
for _, f := range dir.files[beg:end] {
|
||||||
|
maxw = max(len(userName(f.FileInfo)), maxw)
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxw
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupWidth(dir *dir, beg int, end int) int {
|
||||||
|
maxw := 0
|
||||||
|
|
||||||
|
for _, f := range dir.files[beg:end] {
|
||||||
|
maxw = max(len(groupName(f.FileInfo)), maxw)
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxw
|
||||||
}
|
}
|
||||||
|
|
||||||
func getWidths(wtot int) []int {
|
func getWidths(wtot int) []int {
|
||||||
@@ -527,7 +569,7 @@ func getWidths(wtot int) []int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wsum := 0
|
wsum := 0
|
||||||
for i := 0; i < wlen-1; i++ {
|
for i := range wlen - 1 {
|
||||||
widths[i] = gOpts.ratios[i] * wtot / rsum
|
widths[i] = gOpts.ratios[i] * wtot / rsum
|
||||||
wsum += widths[i]
|
wsum += widths[i]
|
||||||
}
|
}
|
||||||
@@ -539,13 +581,12 @@ func getWidths(wtot int) []int {
|
|||||||
func getWins(screen tcell.Screen) []*win {
|
func getWins(screen tcell.Screen) []*win {
|
||||||
wtot, htot := screen.Size()
|
wtot, htot := screen.Size()
|
||||||
|
|
||||||
var wins []*win
|
|
||||||
|
|
||||||
widths := getWidths(wtot)
|
widths := getWidths(wtot)
|
||||||
|
|
||||||
wacc := 0
|
wacc := 0
|
||||||
wlen := len(widths)
|
wlen := len(widths)
|
||||||
for i := 0; i < wlen; i++ {
|
wins := make([]*win, 0, wlen)
|
||||||
|
for i := range wlen {
|
||||||
if gOpts.drawbox {
|
if gOpts.drawbox {
|
||||||
wacc++
|
wacc++
|
||||||
wins = append(wins, newWin(widths[i], htot-4, wacc, 2))
|
wins = append(wins, newWin(widths[i], htot-4, wacc, 2))
|
||||||
@@ -567,13 +608,14 @@ type ui struct {
|
|||||||
msgWin *win
|
msgWin *win
|
||||||
menuWin *win
|
menuWin *win
|
||||||
msg string
|
msg string
|
||||||
|
msgIsStat bool
|
||||||
regPrev *reg
|
regPrev *reg
|
||||||
dirPrev *dir
|
dirPrev *dir
|
||||||
exprChan chan expr
|
exprChan chan expr
|
||||||
keyChan chan string
|
keyChan chan string
|
||||||
tevChan chan tcell.Event
|
tevChan chan tcell.Event
|
||||||
evChan chan tcell.Event
|
evChan chan tcell.Event
|
||||||
menuBuf *bytes.Buffer
|
menu string
|
||||||
cmdPrefix string
|
cmdPrefix string
|
||||||
cmdAccLeft []rune
|
cmdAccLeft []rune
|
||||||
cmdAccRight []rune
|
cmdAccRight []rune
|
||||||
@@ -596,6 +638,7 @@ func newUI(screen tcell.Screen) *ui {
|
|||||||
promptWin: newWin(wtot, 1, 0, 0),
|
promptWin: newWin(wtot, 1, 0, 0),
|
||||||
msgWin: newWin(wtot, 1, 0, htot-1),
|
msgWin: newWin(wtot, 1, 0, htot-1),
|
||||||
menuWin: newWin(wtot, 1, 0, htot-2),
|
menuWin: newWin(wtot, 1, 0, htot-2),
|
||||||
|
msgIsStat: true,
|
||||||
exprChan: make(chan expr, 1000),
|
exprChan: make(chan expr, 1000),
|
||||||
keyChan: make(chan string, 1000),
|
keyChan: make(chan string, 1000),
|
||||||
tevChan: make(chan tcell.Event, 1000),
|
tevChan: make(chan tcell.Event, 1000),
|
||||||
@@ -653,10 +696,11 @@ func (ui *ui) sort() {
|
|||||||
|
|
||||||
func (ui *ui) echo(msg string) {
|
func (ui *ui) echo(msg string) {
|
||||||
ui.msg = msg
|
ui.msg = msg
|
||||||
|
ui.msgIsStat = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) echomsg(msg string) {
|
func (ui *ui) echomsg(msg string) {
|
||||||
ui.msg = msg
|
ui.echo(msg)
|
||||||
log.Print(msg)
|
log.Print(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,14 +713,17 @@ func optionToFmtstr(optstr string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) echoerr(msg string) {
|
func (ui *ui) echoerr(msg string) {
|
||||||
ui.msg = fmt.Sprintf(optionToFmtstr(gOpts.errorfmt), msg)
|
ui.echo(fmt.Sprintf(optionToFmtstr(gOpts.errorfmt), msg))
|
||||||
log.Printf("error: %s", msg)
|
log.Printf("error: %s", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) echoerrf(format string, a ...interface{}) {
|
func (ui *ui) echoerrf(format string, a ...any) {
|
||||||
ui.echoerr(fmt.Sprintf(format, a...))
|
ui.echoerr(fmt.Sprintf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This represents the preview for a regular file.
|
||||||
|
// This can also be used to represent the preview of a directory if
|
||||||
|
// `dirpreviews` is enabled.
|
||||||
type reg struct {
|
type reg struct {
|
||||||
loading bool
|
loading bool
|
||||||
volatile bool
|
volatile bool
|
||||||
@@ -709,10 +756,10 @@ func (ui *ui) loadFile(app *app, volatile bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if curr.IsDir() {
|
if curr.Mode().IsRegular() || (curr.IsDir() && gOpts.dirpreviews) {
|
||||||
ui.dirPrev = app.nav.loadDir(curr.path)
|
|
||||||
} else if curr.Mode().IsRegular() {
|
|
||||||
ui.regPrev = app.nav.loadReg(curr.path, volatile)
|
ui.regPrev = app.nav.loadReg(curr.path, volatile)
|
||||||
|
} else if curr.IsDir() {
|
||||||
|
ui.dirPrev = app.nav.loadDir(curr.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,6 +768,9 @@ func (ui *ui) loadFileInfo(nav *nav) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.msg = ""
|
||||||
|
ui.msgIsStat = true
|
||||||
|
|
||||||
curr, err := nav.currFile()
|
curr, err := nav.currFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -747,14 +797,14 @@ func (ui *ui) loadFileInfo(nav *nav) {
|
|||||||
replace("%t", curr.ModTime().Format(gOpts.timefmt))
|
replace("%t", curr.ModTime().Format(gOpts.timefmt))
|
||||||
replace("%l", curr.linkTarget)
|
replace("%l", curr.linkTarget)
|
||||||
|
|
||||||
fileInfo := ""
|
var fileInfo strings.Builder
|
||||||
for _, section := range strings.Split(statfmt, "\x1f") {
|
for _, section := range strings.Split(statfmt, "\x1f") {
|
||||||
if !strings.Contains(section, "\x00") {
|
if !strings.Contains(section, "\x00") {
|
||||||
fileInfo += section
|
fileInfo.WriteString(section)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.echo(fileInfo)
|
ui.msg = fileInfo.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) drawPromptLine(nav *nav) {
|
func (ui *ui) drawPromptLine(nav *nav) {
|
||||||
@@ -777,11 +827,11 @@ func (ui *ui) drawPromptLine(nav *nav) {
|
|||||||
|
|
||||||
var prompt string
|
var prompt string
|
||||||
|
|
||||||
prompt = strings.Replace(gOpts.promptfmt, "%u", gUser.Username, -1)
|
prompt = strings.ReplaceAll(gOpts.promptfmt, "%u", gUser.Username)
|
||||||
prompt = strings.Replace(prompt, "%h", gHostname, -1)
|
prompt = strings.ReplaceAll(prompt, "%h", gHostname)
|
||||||
prompt = strings.Replace(prompt, "%f", fname, -1)
|
prompt = strings.ReplaceAll(prompt, "%f", fname)
|
||||||
|
|
||||||
if printLength(strings.Replace(strings.Replace(prompt, "%w", pwd, -1), "%d", pwd, -1)) > ui.promptWin.w {
|
if printLength(strings.ReplaceAll(strings.ReplaceAll(prompt, "%w", pwd), "%d", pwd)) > ui.promptWin.w {
|
||||||
names := strings.Split(pwd, sep)
|
names := strings.Split(pwd, sep)
|
||||||
for i := range names {
|
for i := range names {
|
||||||
if names[i] == "" {
|
if names[i] == "" {
|
||||||
@@ -789,23 +839,23 @@ func (ui *ui) drawPromptLine(nav *nav) {
|
|||||||
}
|
}
|
||||||
r, _ := utf8.DecodeRuneInString(names[i])
|
r, _ := utf8.DecodeRuneInString(names[i])
|
||||||
names[i] = string(r)
|
names[i] = string(r)
|
||||||
if printLength(strings.Replace(strings.Replace(prompt, "%w", strings.Join(names, sep), -1), "%d", strings.Join(names, sep), -1)) <= ui.promptWin.w {
|
if printLength(strings.ReplaceAll(strings.ReplaceAll(prompt, "%w", strings.Join(names, sep)), "%d", strings.Join(names, sep))) <= ui.promptWin.w {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pwd = strings.Join(names, sep)
|
pwd = strings.Join(names, sep)
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt = strings.Replace(prompt, "%w", pwd, -1)
|
prompt = strings.ReplaceAll(prompt, "%w", pwd)
|
||||||
if !strings.HasSuffix(pwd, sep) {
|
if !strings.HasSuffix(pwd, sep) {
|
||||||
pwd += sep
|
pwd += sep
|
||||||
}
|
}
|
||||||
prompt = strings.Replace(prompt, "%d", pwd, -1)
|
prompt = strings.ReplaceAll(prompt, "%d", pwd)
|
||||||
|
|
||||||
if len(dir.filter) != 0 {
|
if len(dir.filter) != 0 {
|
||||||
prompt = strings.Replace(prompt, "%F", fmt.Sprint(dir.filter), -1)
|
prompt = strings.ReplaceAll(prompt, "%F", fmt.Sprint(dir.filter))
|
||||||
} else {
|
} else {
|
||||||
prompt = strings.Replace(prompt, "%F", "", -1)
|
prompt = strings.ReplaceAll(prompt, "%F", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// spacer
|
// spacer
|
||||||
@@ -813,7 +863,7 @@ func (ui *ui) drawPromptLine(nav *nav) {
|
|||||||
if avail > 0 {
|
if avail > 0 {
|
||||||
prompt = strings.Replace(prompt, "%S", strings.Repeat(" ", avail), 1)
|
prompt = strings.Replace(prompt, "%S", strings.Repeat(" ", avail), 1)
|
||||||
}
|
}
|
||||||
prompt = strings.Replace(prompt, "%S", "", -1)
|
prompt = strings.ReplaceAll(prompt, "%S", "")
|
||||||
|
|
||||||
ui.promptWin.print(ui.screen, 0, 0, st, prompt)
|
ui.promptWin.print(ui.screen, 0, 0, st, prompt)
|
||||||
}
|
}
|
||||||
@@ -824,7 +874,7 @@ func formatRulerOpt(name string, val string) string {
|
|||||||
|
|
||||||
// display name of builtin options for clarity
|
// display name of builtin options for clarity
|
||||||
if !strings.HasPrefix(name, "lf_user_") {
|
if !strings.HasPrefix(name, "lf_user_") {
|
||||||
val = fmt.Sprintf("%s=%s", strings.TrimPrefix(name, "lf_"), val)
|
return fmt.Sprintf("%s=%s", strings.TrimPrefix(name, "lf_"), val)
|
||||||
}
|
}
|
||||||
|
|
||||||
return val
|
return val
|
||||||
@@ -842,11 +892,8 @@ func (ui *ui) drawRuler(nav *nav) {
|
|||||||
hid := len(dir.allFiles) - tot
|
hid := len(dir.allFiles) - tot
|
||||||
acc := string(ui.keyCount) + string(ui.keyAcc)
|
acc := string(ui.keyCount) + string(ui.keyAcc)
|
||||||
|
|
||||||
selection := []string{}
|
|
||||||
|
|
||||||
copy := 0
|
copy := 0
|
||||||
move := 0
|
move := 0
|
||||||
if len(nav.saves) > 0 {
|
|
||||||
for _, cp := range nav.saves {
|
for _, cp := range nav.saves {
|
||||||
if cp {
|
if cp {
|
||||||
copy++
|
copy++
|
||||||
@@ -854,18 +901,8 @@ func (ui *ui) drawRuler(nav *nav) {
|
|||||||
move++
|
move++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if copy > 0 {
|
|
||||||
selection = append(selection, fmt.Sprintf("\033[33;7m %d \033[0m", copy))
|
|
||||||
}
|
|
||||||
if move > 0 {
|
|
||||||
selection = append(selection, fmt.Sprintf("\033[31;7m %d \033[0m", move))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
currSelections := nav.currSelections()
|
currSelections := nav.currSelections()
|
||||||
if len(currSelections) > 0 {
|
|
||||||
selection = append(selection, fmt.Sprintf("\033[35;7m %d \033[0m", len(currSelections)))
|
|
||||||
}
|
|
||||||
|
|
||||||
progress := []string{}
|
progress := []string{}
|
||||||
|
|
||||||
@@ -884,39 +921,6 @@ func (ui *ui) drawRuler(nav *nav) {
|
|||||||
|
|
||||||
opts := getOptsMap()
|
opts := getOptsMap()
|
||||||
|
|
||||||
// 'ruler' option is deprecated and can be removed in future
|
|
||||||
if len(gOpts.ruler) > 0 {
|
|
||||||
ruler := []string{}
|
|
||||||
for _, s := range gOpts.ruler {
|
|
||||||
switch s {
|
|
||||||
case "df":
|
|
||||||
df := diskFree(dir.path)
|
|
||||||
if df != "" {
|
|
||||||
ruler = append(ruler, df)
|
|
||||||
}
|
|
||||||
case "acc":
|
|
||||||
ruler = append(ruler, acc)
|
|
||||||
case "progress":
|
|
||||||
ruler = append(ruler, progress...)
|
|
||||||
case "selection":
|
|
||||||
ruler = append(ruler, selection...)
|
|
||||||
case "filter":
|
|
||||||
if len(dir.filter) != 0 {
|
|
||||||
ruler = append(ruler, "\033[34;7m F \033[0m")
|
|
||||||
}
|
|
||||||
case "ind":
|
|
||||||
ruler = append(ruler, fmt.Sprintf("%d/%d", ind, tot))
|
|
||||||
default:
|
|
||||||
if val, ok := opts[s]; ok {
|
|
||||||
ruler = append(ruler, formatRulerOpt(s, val))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.msgWin.printRight(ui.screen, 0, st, strings.Join(ruler, " "))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
rulerfmt := strings.ReplaceAll(gOpts.rulerfmt, "|", "\x1f")
|
rulerfmt := strings.ReplaceAll(gOpts.rulerfmt, "|", "\x1f")
|
||||||
rulerfmt = reRulerSub.ReplaceAllStringFunc(rulerfmt, func(s string) string {
|
rulerfmt = reRulerSub.ReplaceAllStringFunc(rulerfmt, func(s string) string {
|
||||||
var result string
|
var result string
|
||||||
@@ -934,11 +938,11 @@ func (ui *ui) drawRuler(nav *nav) {
|
|||||||
case "%f":
|
case "%f":
|
||||||
result = strings.Join(dir.filter, " ")
|
result = strings.Join(dir.filter, " ")
|
||||||
case "%i":
|
case "%i":
|
||||||
result = fmt.Sprint(ind)
|
result = strconv.Itoa(ind)
|
||||||
case "%t":
|
case "%t":
|
||||||
result = fmt.Sprint(tot)
|
result = strconv.Itoa(tot)
|
||||||
case "%h":
|
case "%h":
|
||||||
result = fmt.Sprint(hid)
|
result = strconv.Itoa(hid)
|
||||||
case "%d":
|
case "%d":
|
||||||
result = diskFree(dir.path)
|
result = diskFree(dir.path)
|
||||||
default:
|
default:
|
||||||
@@ -952,13 +956,13 @@ func (ui *ui) drawRuler(nav *nav) {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
ruler := ""
|
var ruler strings.Builder
|
||||||
for _, section := range strings.Split(rulerfmt, "\x1f") {
|
for _, section := range strings.Split(rulerfmt, "\x1f") {
|
||||||
if !strings.Contains(section, "\x00") {
|
if !strings.Contains(section, "\x00") {
|
||||||
ruler += section
|
ruler.WriteString(section)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui.msgWin.printRight(ui.screen, 0, st, ruler)
|
ui.msgWin.printRight(ui.screen, 0, st, ruler.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) drawBox() {
|
func (ui *ui) drawBox() {
|
||||||
@@ -976,13 +980,20 @@ func (ui *ui) drawBox() {
|
|||||||
ui.screen.SetContent(w-1, i, tcell.RuneVLine, nil, st)
|
ui.screen.SetContent(w-1, i, tcell.RuneVLine, nil, st)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if gOpts.roundbox {
|
||||||
|
ui.screen.SetContent(0, 1, '╭', nil, st)
|
||||||
|
ui.screen.SetContent(w-1, 1, '╮', nil, st)
|
||||||
|
ui.screen.SetContent(0, h-2, '╰', nil, st)
|
||||||
|
ui.screen.SetContent(w-1, h-2, '╯', nil, st)
|
||||||
|
} else {
|
||||||
ui.screen.SetContent(0, 1, tcell.RuneULCorner, nil, st)
|
ui.screen.SetContent(0, 1, tcell.RuneULCorner, nil, st)
|
||||||
ui.screen.SetContent(w-1, 1, tcell.RuneURCorner, nil, st)
|
ui.screen.SetContent(w-1, 1, tcell.RuneURCorner, nil, st)
|
||||||
ui.screen.SetContent(0, h-2, tcell.RuneLLCorner, nil, st)
|
ui.screen.SetContent(0, h-2, tcell.RuneLLCorner, nil, st)
|
||||||
ui.screen.SetContent(w-1, h-2, tcell.RuneLRCorner, nil, st)
|
ui.screen.SetContent(w-1, h-2, tcell.RuneLRCorner, nil, st)
|
||||||
|
}
|
||||||
|
|
||||||
wacc := 0
|
wacc := 0
|
||||||
for wind := 0; wind < len(ui.wins)-1; wind++ {
|
for wind := range len(ui.wins) - 1 {
|
||||||
wacc += ui.wins[wind].w + 1
|
wacc += ui.wins[wind].w + 1
|
||||||
ui.screen.SetContent(wacc, 1, tcell.RuneTTee, nil, st)
|
ui.screen.SetContent(wacc, 1, tcell.RuneTTee, nil, st)
|
||||||
for i := 2; i < h-2; i++ {
|
for i := 2; i < h-2; i++ {
|
||||||
@@ -1008,13 +1019,7 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
st := tcell.StyleDefault
|
st := tcell.StyleDefault
|
||||||
context := dirContext{selections: nav.selections, saves: nav.saves, tags: nav.tags}
|
context := dirContext{selections: nav.selections, saves: nav.saves, tags: nav.tags}
|
||||||
|
|
||||||
// XXX: manual clean without flush to avoid flicker on Windows
|
ui.screen.Clear()
|
||||||
wtot, htot := ui.screen.Size()
|
|
||||||
for i := 0; i < wtot; i++ {
|
|
||||||
for j := 0; j < htot; j++ {
|
|
||||||
ui.screen.SetContent(i, j, ' ', nil, st)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ui.sxScreen.sixel = nil
|
ui.sxScreen.sixel = nil
|
||||||
|
|
||||||
ui.drawPromptLine(nav)
|
ui.drawPromptLine(nav)
|
||||||
@@ -1023,15 +1028,14 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
if gOpts.preview {
|
if gOpts.preview {
|
||||||
wins--
|
wins--
|
||||||
}
|
}
|
||||||
for i := 0; i < wins; i++ {
|
for i := range wins {
|
||||||
role := Parent
|
role := Parent
|
||||||
if i == wins-1 {
|
if i == wins-1 {
|
||||||
role = Active
|
role = Active
|
||||||
}
|
}
|
||||||
if dir := ui.dirOfWin(nav, i); dir != nil {
|
if dir := ui.dirOfWin(nav, i); dir != nil {
|
||||||
ui.wins[i].printDir(ui.screen, dir, &context,
|
ui.wins[i].printDir(ui, dir, &context,
|
||||||
&dirStyle{colors: ui.styles, icons: ui.icons, role: role},
|
&dirStyle{colors: ui.styles, icons: ui.icons, role: role})
|
||||||
nav.previewLoading)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1059,12 +1063,11 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
preview := ui.wins[len(ui.wins)-1]
|
preview := ui.wins[len(ui.wins)-1]
|
||||||
|
|
||||||
if curr.IsDir() {
|
if curr.Mode().IsRegular() || (curr.IsDir() && gOpts.dirpreviews) {
|
||||||
preview.printDir(ui.screen, ui.dirPrev, &context,
|
|
||||||
&dirStyle{colors: ui.styles, icons: ui.icons, role: Preview},
|
|
||||||
nav.previewLoading)
|
|
||||||
} else if curr.Mode().IsRegular() {
|
|
||||||
preview.printReg(ui.screen, ui.regPrev, nav.previewLoading, &ui.sxScreen)
|
preview.printReg(ui.screen, ui.regPrev, nav.previewLoading, &ui.sxScreen)
|
||||||
|
} else if curr.IsDir() {
|
||||||
|
preview.printDir(ui, ui.dirPrev, &context,
|
||||||
|
&dirStyle{colors: ui.styles, icons: ui.icons, role: Preview})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1073,8 +1076,8 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
ui.drawBox()
|
ui.drawBox()
|
||||||
}
|
}
|
||||||
|
|
||||||
if ui.menuBuf != nil {
|
if ui.menu != "" {
|
||||||
lines := strings.Split(ui.menuBuf.String(), "\n")
|
lines := strings.Split(ui.menu, "\n")
|
||||||
|
|
||||||
lines = lines[:len(lines)-1]
|
lines = lines[:len(lines)-1]
|
||||||
|
|
||||||
@@ -1094,11 +1097,10 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui.screen.Show()
|
ui.screen.Show()
|
||||||
if ui.menuBuf == nil && ui.cmdPrefix == "" && ui.sxScreen.sixel != nil {
|
if ui.menu == "" && ui.cmdPrefix == "" && ui.sxScreen.sixel != nil {
|
||||||
ui.sxScreen.lastFile = ui.regPrev.path
|
ui.sxScreen.lastFile = ui.regPrev.path
|
||||||
ui.sxScreen.showSixels()
|
ui.sxScreen.showSixels()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) {
|
func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) {
|
||||||
@@ -1115,11 +1117,11 @@ func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok b
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func listExprMap(binds map[string]expr, title string) *bytes.Buffer {
|
func listExprMap(binds map[string]expr, title string) string {
|
||||||
t := new(tabwriter.Writer)
|
t := new(tabwriter.Writer)
|
||||||
b := new(bytes.Buffer)
|
b := new(bytes.Buffer)
|
||||||
|
|
||||||
var keys []string
|
keys := make([]string, 0, len(binds))
|
||||||
for k := range binds {
|
for k := range binds {
|
||||||
keys = append(keys, k)
|
keys = append(keys, k)
|
||||||
}
|
}
|
||||||
@@ -1132,18 +1134,18 @@ func listExprMap(binds map[string]expr, title string) *bytes.Buffer {
|
|||||||
}
|
}
|
||||||
t.Flush()
|
t.Flush()
|
||||||
|
|
||||||
return b
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func listBinds(binds map[string]expr) *bytes.Buffer {
|
func listBinds(binds map[string]expr) string {
|
||||||
return listExprMap(binds, "keys")
|
return listExprMap(binds, "keys")
|
||||||
}
|
}
|
||||||
|
|
||||||
func listCmds() *bytes.Buffer {
|
func listCmds() string {
|
||||||
return listExprMap(gOpts.cmds, "name")
|
return listExprMap(gOpts.cmds, "name")
|
||||||
}
|
}
|
||||||
|
|
||||||
func listJumps(jumps []string, ind int) *bytes.Buffer {
|
func listJumps(jumps []string, ind int) string {
|
||||||
t := new(tabwriter.Writer)
|
t := new(tabwriter.Writer)
|
||||||
b := new(bytes.Buffer)
|
b := new(bytes.Buffer)
|
||||||
|
|
||||||
@@ -1164,10 +1166,10 @@ func listJumps(jumps []string, ind int) *bytes.Buffer {
|
|||||||
}
|
}
|
||||||
t.Flush()
|
t.Flush()
|
||||||
|
|
||||||
return b
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func listHistory(history []cmdItem) *bytes.Buffer {
|
func listHistory(history []cmdItem) string {
|
||||||
t := new(tabwriter.Writer)
|
t := new(tabwriter.Writer)
|
||||||
b := new(bytes.Buffer)
|
b := new(bytes.Buffer)
|
||||||
|
|
||||||
@@ -1180,14 +1182,14 @@ func listHistory(history []cmdItem) *bytes.Buffer {
|
|||||||
}
|
}
|
||||||
t.Flush()
|
t.Flush()
|
||||||
|
|
||||||
return b
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func listMarks(marks map[string]string) *bytes.Buffer {
|
func listMarks(marks map[string]string) string {
|
||||||
t := new(tabwriter.Writer)
|
t := new(tabwriter.Writer)
|
||||||
b := new(bytes.Buffer)
|
b := new(bytes.Buffer)
|
||||||
|
|
||||||
var keys []string
|
keys := make([]string, 0, len(marks))
|
||||||
for k := range marks {
|
for k := range marks {
|
||||||
keys = append(keys, k)
|
keys = append(keys, k)
|
||||||
}
|
}
|
||||||
@@ -1200,7 +1202,25 @@ func listMarks(marks map[string]string) *bytes.Buffer {
|
|||||||
}
|
}
|
||||||
t.Flush()
|
t.Flush()
|
||||||
|
|
||||||
return b
|
return b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func listFilesInCurrDir(nav *nav) string {
|
||||||
|
if !nav.init {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
dir := nav.currDir()
|
||||||
|
if dir.loading {
|
||||||
|
log.Printf("listFilesInCurrDir(): %s is still loading, `files` isn't ready for remote query", dir.path)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
b := new(strings.Builder)
|
||||||
|
for _, file := range dir.files {
|
||||||
|
fmt.Fprintln(b, file.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) pollEvent() tcell.Event {
|
func (ui *ui) pollEvent() tcell.Event {
|
||||||
@@ -1296,10 +1316,10 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
|||||||
} else {
|
} else {
|
||||||
val := gKeyVal[tev.Key()]
|
val := gKeyVal[tev.Key()]
|
||||||
val = addSpecialKeyModifier(val, tev.Modifiers())
|
val = addSpecialKeyModifier(val, tev.Modifiers())
|
||||||
if val == "<esc>" && string(ui.keyAcc) != "" {
|
if val == "<esc>" && len(ui.keyAcc) != 0 {
|
||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
ui.keyCount = nil
|
ui.keyCount = nil
|
||||||
ui.menuBuf = nil
|
ui.menu = ""
|
||||||
return draw
|
return draw
|
||||||
}
|
}
|
||||||
ui.keyAcc = append(ui.keyAcc, []rune(val)...)
|
ui.keyAcc = append(ui.keyAcc, []rune(val)...)
|
||||||
@@ -1316,7 +1336,7 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
|||||||
ui.echoerrf("unknown mapping: %s", string(ui.keyAcc))
|
ui.echoerrf("unknown mapping: %s", string(ui.keyAcc))
|
||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
ui.keyCount = nil
|
ui.keyCount = nil
|
||||||
ui.menuBuf = nil
|
ui.menu = ""
|
||||||
return draw
|
return draw
|
||||||
default:
|
default:
|
||||||
if ok {
|
if ok {
|
||||||
@@ -1329,20 +1349,23 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
|||||||
}
|
}
|
||||||
expr := gOpts.keys[string(ui.keyAcc)]
|
expr := gOpts.keys[string(ui.keyAcc)]
|
||||||
|
|
||||||
if e, ok := expr.(*callExpr); ok && count != 0 {
|
if count != 0 {
|
||||||
expr = &callExpr{e.name, e.args, e.count}
|
switch e := expr.(type) {
|
||||||
expr.(*callExpr).count = count
|
case *callExpr:
|
||||||
} else if e, ok := expr.(*listExpr); ok && count != 0 {
|
expr = &callExpr{name: e.name, args: e.args, count: count}
|
||||||
expr = &listExpr{e.exprs, e.count}
|
case *listExpr:
|
||||||
expr.(*listExpr).count = count
|
expr = &listExpr{exprs: e.exprs, count: count}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
ui.keyCount = nil
|
ui.keyCount = nil
|
||||||
ui.menuBuf = nil
|
ui.menu = ""
|
||||||
return expr
|
return expr
|
||||||
}
|
}
|
||||||
ui.menuBuf = listBinds(binds)
|
if gOpts.showbinds {
|
||||||
|
ui.menu = listBinds(binds)
|
||||||
|
}
|
||||||
return draw
|
return draw
|
||||||
}
|
}
|
||||||
case *tcell.EventMouse:
|
case *tcell.EventMouse:
|
||||||
@@ -1390,7 +1413,7 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
|||||||
ui.echoerrf("unknown mapping: %s", button)
|
ui.echoerrf("unknown mapping: %s", button)
|
||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
ui.keyCount = nil
|
ui.keyCount = nil
|
||||||
ui.menuBuf = nil
|
ui.menu = ""
|
||||||
return draw
|
return draw
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1445,6 +1468,12 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
|||||||
log.Printf("Got EventError: '%s' at %s", tev.Error(), tev.When())
|
log.Printf("Got EventError: '%s' at %s", tev.Error(), tev.When())
|
||||||
case *tcell.EventInterrupt:
|
case *tcell.EventInterrupt:
|
||||||
log.Printf("Got EventInterrupt: at %s", tev.When())
|
log.Printf("Got EventInterrupt: at %s", tev.When())
|
||||||
|
case *tcell.EventFocus:
|
||||||
|
if tev.Focused {
|
||||||
|
return &callExpr{"on-focus-gained", nil, 1}
|
||||||
|
} else {
|
||||||
|
return &callExpr{"on-focus-lost", nil, 1}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1505,6 +1534,43 @@ func (ui *ui) resume() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ui *ui) exportMode() {
|
||||||
|
getMode := func() string {
|
||||||
|
if strings.HasPrefix(ui.cmdPrefix, "delete") {
|
||||||
|
return "delete"
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(ui.cmdPrefix, "replace") || strings.HasPrefix(ui.cmdPrefix, "create") {
|
||||||
|
return "rename"
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ui.cmdPrefix {
|
||||||
|
case "filter: ":
|
||||||
|
return "filter"
|
||||||
|
case "find: ", "find-back: ":
|
||||||
|
return "find"
|
||||||
|
case "mark-save: ", "mark-load: ", "mark-remove: ":
|
||||||
|
return "mark"
|
||||||
|
case "rename: ":
|
||||||
|
return "rename"
|
||||||
|
case "/", "?":
|
||||||
|
return "search"
|
||||||
|
case ":":
|
||||||
|
return "command"
|
||||||
|
case "$", "%", "!", "&":
|
||||||
|
return "shell"
|
||||||
|
case ">":
|
||||||
|
return "pipe"
|
||||||
|
case "":
|
||||||
|
return "normal"
|
||||||
|
default:
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Setenv("lf_mode", getMode())
|
||||||
|
}
|
||||||
|
|
||||||
func (ui *ui) exportSizes() {
|
func (ui *ui) exportSizes() {
|
||||||
w, h := ui.screen.Size()
|
w, h := ui.screen.Size()
|
||||||
os.Setenv("lf_width", strconv.Itoa(w))
|
os.Setenv("lf_width", strconv.Itoa(w))
|
||||||
@@ -1520,15 +1586,17 @@ func anyKey() {
|
|||||||
}
|
}
|
||||||
defer term.Restore(int(os.Stdin.Fd()), oldState)
|
defer term.Restore(int(os.Stdin.Fd()), oldState)
|
||||||
|
|
||||||
b := make([]byte, 1)
|
b := make([]byte, 8)
|
||||||
os.Stdin.Read(b)
|
os.Stdin.Read(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func listMatches(screen tcell.Screen, matches []string, selectedInd int) *bytes.Buffer {
|
func listMatches(screen tcell.Screen, matches []string, selectedInd int) string {
|
||||||
if len(matches) < 2 {
|
mlen := len(matches)
|
||||||
return nil
|
if mlen < 2 {
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
b := new(bytes.Buffer)
|
|
||||||
|
var b strings.Builder
|
||||||
|
|
||||||
wtot, _ := screen.Size()
|
wtot, _ := screen.Size()
|
||||||
wcol := 0
|
wcol := 0
|
||||||
@@ -1540,19 +1608,18 @@ func listMatches(screen tcell.Screen, matches []string, selectedInd int) *bytes.
|
|||||||
|
|
||||||
b.WriteString("possible matches\n")
|
b.WriteString("possible matches\n")
|
||||||
|
|
||||||
for i := 0; i < len(matches); {
|
for i := 0; i < mlen; {
|
||||||
for j := 0; j < ncol && i < len(matches); i, j = i+1, j+1 {
|
for j := 0; j < ncol && i < mlen; i, j = i+1, j+1 {
|
||||||
target := matches[i]
|
target := matches[i]
|
||||||
|
|
||||||
if selectedInd == i {
|
if selectedInd == i {
|
||||||
target = fmt.Sprintf("\033[7m%s\033[0m%*s", target, wcol-len(target), "")
|
fmt.Fprintf(&b, "\033[7m%s\033[0m%*s", target, wcol-len(target), "")
|
||||||
} else {
|
} else {
|
||||||
target = fmt.Sprintf("%s%*s", target, wcol-len(target), "")
|
fmt.Fprintf(&b, "%s%*s", target, wcol-len(target), "")
|
||||||
}
|
}
|
||||||
b.WriteString(target)
|
|
||||||
}
|
}
|
||||||
b.WriteByte('\n')
|
b.WriteByte('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
return b
|
return b.String()
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/fsnotify/fsnotify"
|
||||||
|
)
|
||||||
|
|
||||||
|
type watch struct {
|
||||||
|
watcher *fsnotify.Watcher
|
||||||
|
events <-chan fsnotify.Event
|
||||||
|
quit chan struct{}
|
||||||
|
loads map[string]bool
|
||||||
|
loadTimer *time.Timer
|
||||||
|
updates map[string]bool
|
||||||
|
updateTimer *time.Timer
|
||||||
|
dirChan chan<- *dir
|
||||||
|
fileChan chan<- *file
|
||||||
|
delChan chan<- string
|
||||||
|
}
|
||||||
|
|
||||||
|
func newWatch(dirChan chan<- *dir, fileChan chan<- *file, delChan chan<- string) *watch {
|
||||||
|
return &watch{
|
||||||
|
quit: make(chan struct{}),
|
||||||
|
loads: make(map[string]bool),
|
||||||
|
loadTimer: time.NewTimer(0),
|
||||||
|
updates: make(map[string]bool),
|
||||||
|
updateTimer: time.NewTimer(0),
|
||||||
|
dirChan: dirChan,
|
||||||
|
fileChan: fileChan,
|
||||||
|
delChan: delChan,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (watch *watch) start() {
|
||||||
|
if watch.watcher != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
watcher, err := fsnotify.NewWatcher()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("start watcher: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
watch.watcher = watcher
|
||||||
|
watch.events = watcher.Events
|
||||||
|
|
||||||
|
go watch.loop()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (watch *watch) stop() {
|
||||||
|
if watch.watcher == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
watch.quit <- struct{}{}
|
||||||
|
watch.watcher.Close()
|
||||||
|
|
||||||
|
watch.watcher = nil
|
||||||
|
watch.events = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (watch *watch) add(path string) {
|
||||||
|
if watch.watcher == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore /dev since write updates to /dev/tty causes high cpu usage
|
||||||
|
if path != "/dev" {
|
||||||
|
watch.watcher.Add(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (watch *watch) loop() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case ev := <-watch.events:
|
||||||
|
if ev.Has(fsnotify.Create) {
|
||||||
|
for _, path := range watch.getSameDirs(filepath.Dir(ev.Name)) {
|
||||||
|
watch.addLoad(path)
|
||||||
|
watch.addUpdate(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ev.Has(fsnotify.Remove) || ev.Has(fsnotify.Rename) {
|
||||||
|
dir, file := filepath.Split(ev.Name)
|
||||||
|
for _, path := range watch.getSameDirs(dir) {
|
||||||
|
watch.delChan <- filepath.Join(path, file)
|
||||||
|
watch.addLoad(path)
|
||||||
|
watch.addUpdate(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ev.Has(fsnotify.Write) || ev.Has(fsnotify.Chmod) {
|
||||||
|
dir, file := filepath.Split(ev.Name)
|
||||||
|
for _, path := range watch.getSameDirs(dir) {
|
||||||
|
watch.addUpdate(filepath.Join(path, file))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case <-watch.loadTimer.C:
|
||||||
|
for path := range watch.loads {
|
||||||
|
if _, err := os.Lstat(path); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
dir := newDir(path)
|
||||||
|
dir.sort()
|
||||||
|
watch.dirChan <- dir
|
||||||
|
}
|
||||||
|
clear(watch.loads)
|
||||||
|
case <-watch.updateTimer.C:
|
||||||
|
for path := range watch.updates {
|
||||||
|
if _, err := os.Lstat(path); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
watch.fileChan <- newFile(path)
|
||||||
|
}
|
||||||
|
clear(watch.updates)
|
||||||
|
case <-watch.quit:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (watch *watch) addLoad(path string) {
|
||||||
|
if len(watch.loads) == 0 {
|
||||||
|
watch.loadTimer.Stop()
|
||||||
|
watch.loadTimer.Reset(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
watch.loads[path] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (watch *watch) addUpdate(path string) {
|
||||||
|
if len(watch.updates) == 0 {
|
||||||
|
watch.updateTimer.Stop()
|
||||||
|
watch.updateTimer.Reset(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
watch.updates[path] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hacky workaround since fsnotify reports changes for only one path if a
|
||||||
|
// directory is located at more than one path (e.g. bind mounts).
|
||||||
|
func (watch *watch) getSameDirs(dir string) []string {
|
||||||
|
var paths []string
|
||||||
|
|
||||||
|
dirStat, err := os.Stat(dir)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, path := range watch.watcher.WatchList() {
|
||||||
|
if path == dir {
|
||||||
|
paths = append(paths, path)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
stat, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if os.SameFile(stat, dirStat) {
|
||||||
|
paths = append(paths, path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths
|
||||||
|
}
|
||||||
Reference in new issue
Block a user