Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8163439f5 | ||
|
|
6c54b8870c | ||
|
|
ffc756c5ff | ||
|
|
9068801831 | ||
|
|
c56e319211 | ||
|
|
a67e43ab66 | ||
|
|
072818982c | ||
|
|
1dd269ec42 | ||
|
|
764fbe65ef | ||
|
|
1a1537946c | ||
|
|
791dfff8dc | ||
|
|
439fb038e5 | ||
|
|
8d013c9375 | ||
|
|
990cea7e04 | ||
|
|
6aa3d2aa18 | ||
|
|
63d21b5a3e | ||
|
|
e0abb29a00 | ||
|
|
a280b6c7d3 | ||
|
|
219ebe5c31 | ||
|
|
59dd325439 | ||
|
|
dd8294952f | ||
|
|
b2f8673cb9 | ||
|
|
687ac4b23c | ||
|
|
1c52e3ad68 | ||
|
|
b3ac207c34 | ||
|
|
2620f492c2 | ||
|
|
95b3613a68 | ||
|
|
42c16f1882 | ||
|
|
23418adc00 | ||
|
|
443838e06f | ||
|
|
3c681c2fac | ||
|
|
a3127a2dc3 | ||
|
|
a7541390f3 | ||
|
|
ac40dddfa1 | ||
|
|
ddb86396ab | ||
|
|
b98ef3f935 | ||
|
|
2f3c170d1b | ||
|
|
dc2627de23 | ||
|
|
f20d0e5fb4 | ||
|
|
835c5b35e2 | ||
|
|
592e7fe4be | ||
|
|
56ab5ccc61 | ||
|
|
067ffa8f1a | ||
|
|
bc0bc6e3be | ||
|
|
807d2f5f2d | ||
|
|
c11931d3e6 | ||
|
|
b1a851953b | ||
|
|
e885abe1a3 | ||
|
|
2ab4b14e88 | ||
|
|
59f32193ae | ||
|
|
07cf7dd1bd | ||
|
|
027538eabf | ||
|
|
2c13e0d7d6 | ||
|
|
c874a2c56f | ||
|
|
751788ee84 | ||
|
|
51d0fec017 | ||
|
|
7c33da2bc2 | ||
|
|
014d18d3ea | ||
|
|
c3d44123bb | ||
|
|
14fb8a0aac | ||
|
|
06d0a7eeac | ||
|
|
9e1edcd9d3 | ||
|
|
b57d76bf97 | ||
|
|
a9d90bc560 | ||
|
|
ae1c1389dd | ||
|
|
e08eebb115 | ||
|
|
0ac1491bfb | ||
|
|
fdb320d30c | ||
|
|
24bba6288d | ||
|
|
5b934c2b91 | ||
|
|
346c439f76 | ||
|
|
5bf78dc087 | ||
|
|
8fee7f0927 | ||
|
|
3b942a8a39 | ||
|
|
1be7d2689a | ||
|
|
88b3c999af | ||
|
|
24e224ca65 | ||
|
|
2a5c54c81a | ||
|
|
db46fb2b37 | ||
|
|
f036e07a5c | ||
|
|
8f630e0cab | ||
|
|
35990bed12 | ||
|
|
f04401ba4d | ||
|
|
2c86577b95 | ||
|
|
4dbc15e4b0 | ||
|
|
c0dfb3c4f5 | ||
|
|
55ad40ac0a | ||
|
|
c1583032aa | ||
|
|
eb84772032 | ||
|
|
821b2fcd51 | ||
|
|
734f11d61b | ||
|
|
28b550a7ec | ||
|
|
1e1486fc02 | ||
|
|
bb45d15b83 | ||
|
|
b5c83dbf7a | ||
|
|
27d316c006 | ||
|
|
83af3e1cb0 | ||
|
|
27ab67aab7 | ||
|
|
3ae67fc361 | ||
|
|
f563263add | ||
|
|
70171adf40 | ||
|
|
11caeddb35 | ||
|
|
6ffc4a4c8a | ||
|
|
0eddc1e724 | ||
|
|
43fced28e3 | ||
|
|
68e2433d48 | ||
|
|
25288fd90b | ||
|
|
122dee1f45 | ||
|
|
8652707299 | ||
|
|
41cdd02572 | ||
|
|
207de6a506 | ||
|
|
acb5693b11 | ||
|
|
85512625f8 | ||
|
|
0bf17dd3f0 | ||
|
|
db9de4d4de | ||
|
|
9440b1b319 | ||
|
|
a85ce898a1 | ||
|
|
9f1428582f | ||
|
|
bcd058ace2 | ||
|
|
382534c4ba | ||
|
|
c2cbc39ce5 | ||
|
|
a8e95ae40a | ||
|
|
3fc1db5d14 | ||
|
|
7a7e81e88c | ||
|
|
b02fd42df4 | ||
|
|
752f059068 | ||
|
|
326930f46f | ||
|
|
6c3366eec4 | ||
|
|
28936c7506 | ||
|
|
960f23c288 | ||
|
|
95a6f9584f | ||
|
|
cae576bb1d | ||
|
|
6afefa5d09 | ||
|
|
c0c85f206f | ||
|
|
530ab2c40a | ||
|
|
4a443cae58 | ||
|
|
0b99aaed4e | ||
|
|
6440281e82 | ||
|
|
2fe5e4d54e | ||
|
|
a4fa5d36c9 | ||
|
|
b47cf6d5a5 | ||
|
|
aa78b26e44 | ||
|
|
4440a15a8c | ||
|
|
887748cefd | ||
|
|
c1bcf71ece | ||
|
|
459608e096 | ||
|
|
9bb2487b14 | ||
|
|
48d1899ec8 | ||
|
|
a94015d221 | ||
|
|
8e919b8268 | ||
|
|
e4fa885d26 | ||
|
|
624992ad7b | ||
|
|
04d40832f1 | ||
|
|
f1312ca969 | ||
|
|
e570d5f65b | ||
|
|
654b8737b8 | ||
|
|
e10ef9111b | ||
|
|
747aff8763 | ||
|
|
8b11ffd698 | ||
|
|
cdbc9948f8 | ||
|
|
8c490dddd2 | ||
|
|
a2fed6d16e | ||
|
|
62621736b3 | ||
|
|
21a32a7603 | ||
|
|
479ed924f7 | ||
|
|
4968b1da42 | ||
|
|
fc71c6f8b9 | ||
|
|
0906d39676 | ||
|
|
c5dfd6df51 | ||
|
|
165fecbea0 | ||
|
|
75869f0ac3 | ||
|
|
cb7aa13218 | ||
|
|
5ba70d0f61 | ||
|
|
01d3b69de0 | ||
|
|
17e1a84646 | ||
|
|
b0cb9268d8 | ||
|
|
e03143299d | ||
|
|
da2d8a2979 | ||
|
|
aee5c3371f | ||
|
|
36a7a18316 | ||
|
|
2104a501aa | ||
|
|
addb6e243e | ||
|
|
a89f0242bf | ||
|
|
6e17d2bd20 | ||
|
|
b0f2a2875a | ||
|
|
745f1588ed | ||
|
|
7feb42db34 | ||
|
|
01fe12b2ce | ||
|
|
50f11ad3de | ||
|
|
da7a366584 | ||
|
|
5eb5d9bdb8 | ||
|
|
82dfce2e96 | ||
|
|
69fc98f992 | ||
|
|
fe59f0f30c | ||
|
|
4db1a63b75 | ||
|
|
afa90fe647 | ||
|
|
304026d680 | ||
|
|
9144df10ad | ||
|
|
27a11ae507 | ||
|
|
5a5628d667 | ||
|
|
2f9d840eda | ||
|
|
8c71e5ba9f | ||
|
|
e6a1621261 | ||
|
|
97e7a6239f | ||
|
|
1b82f1db0b | ||
|
|
19aad41b8e | ||
|
|
2ddaf43421 | ||
|
|
5927a506f4 | ||
|
|
c712d304f2 | ||
|
|
076ab8ea9d | ||
|
|
12f0f0da68 | ||
|
|
f66e5824a1 | ||
|
|
fb3c31d3c7 | ||
|
|
089e6dc705 | ||
|
|
8954e9f16a | ||
|
|
07b35def77 | ||
|
|
25476e79ef | ||
|
|
fb66a21577 | ||
|
|
b4637f91aa | ||
|
|
7005815671 | ||
|
|
03de10ba69 | ||
|
|
e3c191acec | ||
|
|
f736f44e4e | ||
|
|
c5bd676c3a | ||
|
|
3e3a4a6386 | ||
|
|
17453f10f5 | ||
|
|
375133e483 | ||
|
|
1718527e90 | ||
|
|
b5de2cd666 | ||
|
|
73f990cdb6 | ||
|
|
b08ab8dfb7 | ||
|
|
cbb80a0d44 | ||
|
|
86e84c9151 | ||
|
|
1703dcc11f | ||
|
|
47620fa680 | ||
|
|
5d393da572 | ||
|
|
26455dca09 | ||
|
|
895e22a1b5 | ||
|
|
761aa23483 | ||
|
|
a4842e19d4 | ||
|
|
958857f4c4 | ||
|
|
18fb632efa | ||
|
|
1bb7a17c81 | ||
|
|
94e06201f9 | ||
|
|
930364ce78 | ||
|
|
85c73978fe | ||
|
|
92e8a247b1 | ||
|
|
76338f1a4d | ||
|
|
081d0585cd | ||
|
|
ac4bdccf8d | ||
|
|
286bf75aa9 | ||
|
|
fea4ededb6 | ||
|
|
673dad9f07 | ||
|
|
d879e8f8f8 | ||
|
|
78d4e3a2b4 | ||
|
|
1a264b2f77 |
No files matched your search
@@ -0,0 +1,10 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
- package-ecosystem: "gomod"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
@@ -8,18 +8,59 @@ on:
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
tests:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: 1.15
|
||||
go-version: 1.18
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
- name: Test
|
||||
run: go test -v ./...
|
||||
|
||||
- uses: dominikh/staticcheck-action@v1.3.0
|
||||
with:
|
||||
version: "2022.1.3"
|
||||
install-go: false
|
||||
|
||||
cross-compile:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: 1.18
|
||||
|
||||
- name: Cross-compile on all supported platforms
|
||||
run: gen/xbuild.sh
|
||||
|
||||
generate:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: 1.19
|
||||
|
||||
- name: Test `go fmt && go generate` on Go 1.19 creates no diffs
|
||||
run: go fmt && go generate && git diff --exit-code
|
||||
|
||||
@@ -10,12 +10,12 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: 1.15
|
||||
go-version: 1.18
|
||||
|
||||
- name: Build
|
||||
run: gen/xbuild.sh
|
||||
@@ -26,3 +26,14 @@ jobs:
|
||||
files: dist/*
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
winget:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
steps:
|
||||
- uses: vedantmgoyal2009/winget-releaser@v2
|
||||
with:
|
||||
identifier: gokcehan.lf
|
||||
version: ${{ github.ref_name }}
|
||||
installers-regex: '-windows-\w+\.zip$'
|
||||
token: ${{ secrets.WINGET_TOKEN }}
|
||||
@@ -0,0 +1,62 @@
|
||||
# Contributing
|
||||
|
||||
Code contributions are always welcomed in lf.
|
||||
|
||||
If you are going to introduce a new feature, it is best to open an issue first for discussion. If your feature can be implemented as a configuration option **please add it to the [wiki](https://github.com/gokcehan/lf/wiki)**.
|
||||
|
||||
For bug fixes, you can simply send a pull request.
|
||||
|
||||
## Code conventions
|
||||
|
||||
In addition to `gofmt` and friends (e.g. [go vet](https://pkg.go.dev/cmd/vet), [staticcheck](https://staticcheck.dev/), [golangci-lint](https://golangci-lint.run/)), we have a few conventions:
|
||||
|
||||
- Global variables are best avoided except when they are not.
|
||||
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.
|
||||
- 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`.
|
||||
- Run `go fmt && go generate` using Go 1.19+. On earlier versions of Go, `go generate` creates needless whitespace differences.
|
||||
|
||||
Use the surrounding code as reference when in doubt as usual.
|
||||
|
||||
## Adding a new option
|
||||
|
||||
Adding a new option usually requires the following steps:
|
||||
|
||||
- Add option name/type to `gOpts` struct in `opts.go`
|
||||
- Add default option value to `init` function in `opts.go`
|
||||
- Add option evaluation logic to `setExpr.eval` in `eval.go`
|
||||
- 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.go`
|
||||
- Run `go generate` to update the documentation
|
||||
- Commit your changes and send a pull request
|
||||
|
||||
## Adding a new builtin command
|
||||
|
||||
Adding a new command usually requires the following steps:
|
||||
|
||||
- Add default key if any to `init` function in `opts.go`
|
||||
- Add command evaluation logic to `callExpr.eval` in `eval.go`
|
||||
- Implement the command somewhere in the code
|
||||
- Add command name to `gCmdWords` in `complete.go` for tab completion
|
||||
- Add command name to `Quick Reference` and `Commands` sections in `doc.go`
|
||||
- Run `go generate` to update the documentation
|
||||
- Commit your changes and send a pull request
|
||||
|
||||
## Platform specific code
|
||||
|
||||
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 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.
|
||||
@@ -2,17 +2,14 @@
|
||||
|
||||
[Google Groups](https://groups.google.com/forum/#!forum/lf-fm)
|
||||
| [Wiki](https://github.com/gokcehan/lf/wiki)
|
||||
| [#lf](https://webchat.freenode.net/?channels=lf) (on Freenode)
|
||||
| [#lf](https://web.libera.chat/#lf) (on Libera.Chat)
|
||||
| [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org) (with IRC bridge)
|
||||
|
||||
[](https://github.com/gokcehan/lf/actions/workflows/go.yml)
|
||||
[](https://goreportcard.com/report/github.com/gokcehan/lf)
|
||||
[](https://pkg.go.dev/github.com/gokcehan/lf)
|
||||
|
||||
> This is a work in progress. Use at your own risk.
|
||||
|
||||
`lf` (as in "list files") is a terminal file manager written in Go.
|
||||
It is heavily inspired by ranger with some missing and extra features.
|
||||
Some of the missing features are deliberately omitted since they are better handled by external tools.
|
||||
`lf` (as in "list files") is a terminal file manager written in Go with a heavy inspiration from 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.
|
||||
|
||||

|
||||
@@ -20,18 +17,20 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information and [tut
|
||||
|
||||
## Features
|
||||
|
||||
- Cross-platform (Linux, OSX, BSDs, Windows (partial))
|
||||
- Single binary without any runtime dependencies (except for terminfo database)
|
||||
- Fast startup and low memory footprint (due to native code and static binaries)
|
||||
- Server/client architecture to share file selection between multiple instances
|
||||
- Configuration with shell commands
|
||||
- Cross-platform (Linux, macOS, BSDs, Windows)
|
||||
- Single binary without any runtime dependencies
|
||||
- Fast startup and low memory footprint due to native code and static binaries
|
||||
- Asynchronous IO operations to avoid UI locking
|
||||
- Server/client architecture and remote commands to manage multiple instances
|
||||
- Extendable and configurable with shell commands
|
||||
- Customizable keybindings (vi and readline defaults)
|
||||
- Preview filtering (for source highlight, archives, pdfs/images as text etc.)
|
||||
- A reasonable set of other features (see the [documentation](https://pkg.go.dev/github.com/gokcehan/lf))
|
||||
|
||||
## Non-Features
|
||||
|
||||
- Tabs or windows (handled by window manager or terminal multiplexer)
|
||||
- Builtin pager/editor (handled by your pager/editor of choice)
|
||||
- Tabs or windows (better handled by window manager or terminal multiplexer)
|
||||
- Builtin pager/editor (better handled by your pager/editor of choice)
|
||||
- Builtin commands for file operations (better handled by the underlying shell tools including but not limited to `mkdir`, `touch`, `chmod`, `chown`, `chgrp`, and `ln`)
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -39,21 +38,27 @@ See [packages](https://github.com/gokcehan/lf/wiki/Packages) for community maint
|
||||
|
||||
See [releases](https://github.com/gokcehan/lf/releases) for pre-built binaries.
|
||||
|
||||
If you like to build from the source on unix:
|
||||
Building from the source requires [Go](https://go.dev/).
|
||||
|
||||
env CGO_ENABLED=0 GO111MODULE=on go get -u -ldflags="-s -w" github.com/gokcehan/lf
|
||||
On Unix:
|
||||
|
||||
On windows `cmd`:
|
||||
```bash
|
||||
env CGO_ENABLED=0 go install -ldflags="-s -w" github.com/gokcehan/lf@latest
|
||||
```
|
||||
|
||||
set CGO_ENABLED=0
|
||||
set GO111MODULE=on
|
||||
go get -u -ldflags="-s -w" github.com/gokcehan/lf
|
||||
On Windows `cmd`:
|
||||
|
||||
On windows `powershell`:
|
||||
```cmd
|
||||
set CGO_ENABLED=0
|
||||
go install -ldflags="-s -w" github.com/gokcehan/lf@latest
|
||||
```
|
||||
|
||||
$env:CGO_ENABLED = '0'
|
||||
$env:GO111MODULE = 'on'
|
||||
go get -u -ldflags="-s -w" github.com/gokcehan/lf
|
||||
On Windows `powershell`:
|
||||
|
||||
```powershell
|
||||
$env:CGO_ENABLED = '0'
|
||||
go install -ldflags="-s -w" github.com/gokcehan/lf@latest
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -63,8 +68,8 @@ Run `lf -help` to see command line options.
|
||||
|
||||
Run `lf -doc` to see the [documentation](https://pkg.go.dev/github.com/gokcehan/lf).
|
||||
|
||||
See [etc](etc) directory to integrate `lf` to your shell or editor.
|
||||
An example configuration file can also be found in this directory.
|
||||
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.
|
||||
|
||||
See [integrations](https://github.com/gokcehan/lf/wiki/Integrations) to integrate `lf` to other tools.
|
||||
|
||||
@@ -72,4 +77,4 @@ See [tips](https://github.com/gokcehan/lf/wiki/Tips) for more examples.
|
||||
|
||||
## Contributing
|
||||
|
||||
See [contributing](https://github.com/gokcehan/lf/wiki/Contributing) for guidelines.
|
||||
See [contributing](CONTRIBUTING.md) for guidelines.
|
||||
@@ -20,16 +20,20 @@ type cmdItem struct {
|
||||
}
|
||||
|
||||
type app struct {
|
||||
ui *ui
|
||||
nav *nav
|
||||
ticker *time.Ticker
|
||||
quitChan chan struct{}
|
||||
cmd *exec.Cmd
|
||||
cmdIn io.WriteCloser
|
||||
cmdOutBuf []byte
|
||||
cmdHistory []cmdItem
|
||||
cmdHistoryBeg int
|
||||
cmdHistoryInd int
|
||||
ui *ui
|
||||
nav *nav
|
||||
ticker *time.Ticker
|
||||
quitChan chan struct{}
|
||||
cmd *exec.Cmd
|
||||
cmdIn io.WriteCloser
|
||||
cmdOutBuf []byte
|
||||
cmdHistory []cmdItem
|
||||
cmdHistoryBeg int
|
||||
cmdHistoryInd int
|
||||
menuCompActive bool
|
||||
menuComps []string
|
||||
menuCompInd int
|
||||
selectionOut []string
|
||||
}
|
||||
|
||||
func newApp(ui *ui, nav *nav) *app {
|
||||
@@ -59,8 +63,10 @@ func newApp(ui *ui, nav *nav) *app {
|
||||
}
|
||||
|
||||
func (app *app) quit() {
|
||||
if err := app.writeHistory(); err != nil {
|
||||
log.Printf("writing history file: %s", err)
|
||||
if gOpts.history {
|
||||
if err := app.writeHistory(); err != nil {
|
||||
log.Printf("writing history file: %s", err)
|
||||
}
|
||||
}
|
||||
if !gSingleMode {
|
||||
if err := remote(fmt.Sprintf("drop %d", gClientID)); err != nil {
|
||||
@@ -72,7 +78,6 @@ func (app *app) quit() {
|
||||
}
|
||||
}
|
||||
}
|
||||
os.Remove(gLogPath)
|
||||
}
|
||||
|
||||
func (app *app) readFile(path string) {
|
||||
@@ -238,6 +243,7 @@ func (app *app) writeHistory() error {
|
||||
// separate goroutines and sent here for update.
|
||||
func (app *app) loop() {
|
||||
go app.nav.previewLoop(app.ui)
|
||||
go app.nav.dirPreviewLoop(app.ui)
|
||||
|
||||
var serverChan <-chan expr
|
||||
if !gSingleMode {
|
||||
@@ -246,19 +252,6 @@ func (app *app) loop() {
|
||||
|
||||
app.ui.readExpr()
|
||||
|
||||
if gSelect != "" {
|
||||
go func() {
|
||||
lstat, err := os.Lstat(gSelect)
|
||||
if err != nil {
|
||||
app.ui.exprChan <- &callExpr{"echoerr", []string{err.Error()}, 1}
|
||||
} else if lstat.IsDir() {
|
||||
app.ui.exprChan <- &callExpr{"cd", []string{gSelect}, 1}
|
||||
} else {
|
||||
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
if gConfigPath != "" {
|
||||
if _, err := os.Stat(gConfigPath); !os.IsNotExist(err) {
|
||||
app.readFile(gConfigPath)
|
||||
@@ -285,6 +278,28 @@ func (app *app) loop() {
|
||||
}
|
||||
}
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
}
|
||||
|
||||
app.nav.getDirs(wd)
|
||||
app.nav.addJumpList()
|
||||
app.nav.init = true
|
||||
|
||||
if gSelect != "" {
|
||||
go func() {
|
||||
lstat, err := os.Lstat(gSelect)
|
||||
if err != nil {
|
||||
app.ui.exprChan <- &callExpr{"echoerr", []string{err.Error()}, 1}
|
||||
} else if lstat.IsDir() {
|
||||
app.ui.exprChan <- &callExpr{"cd", []string{gSelect}, 1}
|
||||
} else {
|
||||
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-app.quitChan:
|
||||
@@ -303,25 +318,17 @@ func (app *app) loop() {
|
||||
continue
|
||||
}
|
||||
|
||||
if cmd, ok := gOpts.cmds["on-quit"]; ok {
|
||||
cmd.eval(app, nil)
|
||||
}
|
||||
|
||||
app.quit()
|
||||
|
||||
app.nav.previewChan <- ""
|
||||
app.nav.dirPreviewChan <- nil
|
||||
|
||||
log.Print("bye!")
|
||||
|
||||
if gLastDirPath != "" {
|
||||
f, err := os.Create(gLastDirPath)
|
||||
if err != nil {
|
||||
log.Printf("opening last dir file: %s", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, err = f.WriteString(app.nav.currDir().path)
|
||||
if err != nil {
|
||||
log.Printf("writing last dir file: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
case n := <-app.nav.copyBytesChan:
|
||||
app.nav.copyBytes += n
|
||||
@@ -370,12 +377,14 @@ func (app *app) loop() {
|
||||
}
|
||||
app.ui.draw(app.nav)
|
||||
case d := <-app.nav.dirChan:
|
||||
|
||||
app.nav.checkDir(d)
|
||||
|
||||
if gOpts.dircache {
|
||||
prev, ok := app.nav.dirCache[d.path]
|
||||
if ok {
|
||||
d.ind = prev.ind
|
||||
d.pos = prev.pos
|
||||
d.sel(prev.name(), app.nav.height)
|
||||
}
|
||||
|
||||
@@ -393,7 +402,10 @@ func (app *app) loop() {
|
||||
curr, err := app.nav.currFile()
|
||||
if err == nil {
|
||||
if d.path == app.nav.currDir().path {
|
||||
app.ui.loadFile(app.nav, true)
|
||||
app.ui.loadFile(app, true)
|
||||
if app.ui.msg == "" {
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
}
|
||||
if d.path == curr.path {
|
||||
app.ui.dirPrev = d
|
||||
@@ -415,7 +427,7 @@ func (app *app) loop() {
|
||||
|
||||
app.ui.draw(app.nav)
|
||||
case ev := <-app.ui.evChan:
|
||||
e := app.ui.readEvent(ev)
|
||||
e := app.ui.readEvent(ev, app.nav)
|
||||
if e == nil {
|
||||
continue
|
||||
}
|
||||
@@ -424,7 +436,7 @@ func (app *app) loop() {
|
||||
for {
|
||||
select {
|
||||
case ev := <-app.ui.evChan:
|
||||
e = app.ui.readEvent(ev)
|
||||
e = app.ui.readEvent(ev, app.nav)
|
||||
if e == nil {
|
||||
continue
|
||||
}
|
||||
@@ -442,34 +454,60 @@ func (app *app) loop() {
|
||||
app.ui.draw(app.nav)
|
||||
case <-app.ticker.C:
|
||||
app.nav.renew()
|
||||
app.ui.loadFile(app.nav, false)
|
||||
app.ui.loadFile(app, false)
|
||||
app.ui.draw(app.nav)
|
||||
case <-app.nav.previewTimer.C:
|
||||
app.nav.previewLoading = true
|
||||
app.ui.draw(app.nav)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (app *app) exportFiles() {
|
||||
var currFile string
|
||||
if curr, err := app.nav.currFile(); err == nil {
|
||||
currFile = curr.path
|
||||
func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
|
||||
app.nav.previewChan <- ""
|
||||
app.nav.dirPreviewChan <- nil
|
||||
|
||||
if err := app.ui.suspend(); err != nil {
|
||||
log.Printf("suspend: %s", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := app.ui.resume(); err != nil {
|
||||
app.quit()
|
||||
os.Exit(3)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
app.ui.echoerrf("running shell: %s", err)
|
||||
}
|
||||
if pause_after {
|
||||
anyKey()
|
||||
}
|
||||
|
||||
currSelections := app.nav.currSelections()
|
||||
|
||||
exportFiles(currFile, currSelections, app.nav.currDir().path)
|
||||
app.ui.loadFile(app, true)
|
||||
app.nav.renew()
|
||||
}
|
||||
|
||||
// This function is used to run a shell command. Modes are as follows:
|
||||
//
|
||||
// Prefix Wait Async Stdin Stdout Stderr UI action
|
||||
// $ No No Yes Yes Yes Pause and then resume
|
||||
// % No No Yes Yes Yes Statline for input/output
|
||||
// ! Yes No Yes Yes Yes Pause and then resume
|
||||
// & No Yes No No No Do nothing
|
||||
// Prefix Wait Async Stdin Stdout Stderr UI action
|
||||
// $ No No Yes Yes Yes Pause and then resume
|
||||
// % No No Yes Yes Yes Statline for input/output
|
||||
// ! Yes No Yes Yes Yes Pause and then resume
|
||||
// & No Yes No No No Do nothing
|
||||
func (app *app) runShell(s string, args []string, prefix string) {
|
||||
app.exportFiles()
|
||||
app.nav.exportFiles()
|
||||
app.ui.exportSizes()
|
||||
exportOpts()
|
||||
|
||||
gState.mutex.Lock()
|
||||
gState.data["maps"] = listBinds(gOpts.keys).String()
|
||||
gState.data["cmaps"] = listBinds(gOpts.cmdkeys).String()
|
||||
gState.data["cmds"] = listCmds().String()
|
||||
gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd).String()
|
||||
gState.data["history"] = listHistory(app.cmdHistory).String()
|
||||
gState.mutex.Unlock()
|
||||
|
||||
cmd := shellCommand(s, args)
|
||||
|
||||
var out io.Reader
|
||||
@@ -477,24 +515,15 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
switch prefix {
|
||||
case "$", "!":
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stdout = os.Stderr
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
app.nav.previewChan <- ""
|
||||
if err := app.ui.suspend(); err != nil {
|
||||
log.Printf("suspend: %s", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := app.ui.resume(); err != nil {
|
||||
app.quit()
|
||||
os.Exit(3)
|
||||
return
|
||||
}
|
||||
}()
|
||||
defer app.nav.renew()
|
||||
app.runCmdSync(cmd, prefix == "!")
|
||||
return
|
||||
}
|
||||
|
||||
err = cmd.Run()
|
||||
case "%":
|
||||
// We are running the command asynchronously
|
||||
if prefix == "%" {
|
||||
if app.ui.cmdPrefix == ">" {
|
||||
return
|
||||
}
|
||||
@@ -509,22 +538,13 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
}
|
||||
out = stdout
|
||||
cmd.Stderr = cmd.Stdout
|
||||
fallthrough
|
||||
case "&":
|
||||
err = cmd.Start()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
shellSetPG(cmd)
|
||||
if err = cmd.Start(); err != nil {
|
||||
app.ui.echoerrf("running shell: %s", err)
|
||||
}
|
||||
|
||||
switch prefix {
|
||||
case "!":
|
||||
anyKey()
|
||||
}
|
||||
|
||||
app.ui.loadFile(app.nav, true)
|
||||
|
||||
switch prefix {
|
||||
case "%":
|
||||
normal(app)
|
||||
@@ -567,6 +587,8 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
if err := cmd.Wait(); err != nil {
|
||||
log.Printf("running shell: %s", err)
|
||||
}
|
||||
app.ui.exprChan <- &callExpr{"load", nil, 1}
|
||||
}()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,11 +8,23 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
type State struct {
|
||||
mutex sync.Mutex
|
||||
data map[string]string
|
||||
}
|
||||
|
||||
var gState State
|
||||
|
||||
func init() {
|
||||
gState.data = make(map[string]string)
|
||||
}
|
||||
|
||||
func run() {
|
||||
var screen tcell.Screen
|
||||
var err error
|
||||
@@ -25,12 +37,16 @@ func run() {
|
||||
screen.EnableMouse()
|
||||
}
|
||||
|
||||
f, err := os.Create(gLogPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
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)
|
||||
}
|
||||
defer f.Close()
|
||||
log.SetOutput(f)
|
||||
|
||||
log.Print("hi!")
|
||||
|
||||
@@ -46,6 +62,10 @@ func run() {
|
||||
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 {
|
||||
app.ui.echoerrf("reading history file: %s", err)
|
||||
}
|
||||
@@ -53,6 +73,52 @@ func run() {
|
||||
app.loop()
|
||||
|
||||
app.ui.screen.Fini()
|
||||
|
||||
if gLastDirPath != "" {
|
||||
writeLastDir(gLastDirPath, app.nav.currDir().path)
|
||||
}
|
||||
|
||||
if gSelectionPath != "" && len(app.selectionOut) > 0 {
|
||||
writeSelection(gSelectionPath, app.selectionOut)
|
||||
}
|
||||
|
||||
if gPrintLastDir {
|
||||
fmt.Println(app.nav.currDir().path)
|
||||
}
|
||||
|
||||
if gPrintSelection && len(app.selectionOut) > 0 {
|
||||
for _, file := range app.selectionOut {
|
||||
fmt.Println(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func writeLastDir(filename string, lastDir string) {
|
||||
f, err := os.Create(filename)
|
||||
if err != nil {
|
||||
log.Printf("opening last dir file: %s", err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, err = f.WriteString(lastDir)
|
||||
if err != nil {
|
||||
log.Printf("writing last dir file: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func writeSelection(filename string, selection []string) {
|
||||
f, err := os.Create(filename)
|
||||
if err != nil {
|
||||
log.Printf("opening selection file: %s", err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, err = f.WriteString(strings.Join(selection, "\n"))
|
||||
if err != nil {
|
||||
log.Printf("writing selection file: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func readExpr() <-chan expr {
|
||||
@@ -76,9 +142,24 @@ func readExpr() <-chan expr {
|
||||
s := bufio.NewScanner(c)
|
||||
for s.Scan() {
|
||||
log.Printf("recv: %s", s.Text())
|
||||
p := newParser(strings.NewReader(s.Text()))
|
||||
if p.parse() {
|
||||
ch <- p.expr
|
||||
|
||||
// `query` has to be handled outside of the main thread, which is
|
||||
// blocked when running a synchronous shell command ("$" or "!").
|
||||
// This is important since `query` is often the result of the user
|
||||
// running `$lf -remote "query $id <something>"`.
|
||||
if word, rest := splitWord(s.Text()); word == "query" {
|
||||
gState.mutex.Lock()
|
||||
state, ok := gState.data[rest]
|
||||
gState.mutex.Unlock()
|
||||
if ok {
|
||||
fmt.Fprint(c, state)
|
||||
}
|
||||
fmt.Fprintln(c, "")
|
||||
} else {
|
||||
p := newParser(strings.NewReader(s.Text()))
|
||||
if p.parse() {
|
||||
ch <- p.expr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,9 +72,23 @@ func parseStyles() styleMap {
|
||||
sm.parseGNU(env)
|
||||
}
|
||||
|
||||
for _, path := range gColorsPaths {
|
||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||
sm.parseFile(path)
|
||||
}
|
||||
}
|
||||
|
||||
return sm
|
||||
}
|
||||
|
||||
func parseEscapeSequence(s string) tcell.Style {
|
||||
s = strings.TrimPrefix(s, "\033[")
|
||||
if i := strings.IndexByte(s, 'm'); i >= 0 {
|
||||
s = s[:i]
|
||||
}
|
||||
return applyAnsiCodes(s, tcell.StyleDefault)
|
||||
}
|
||||
|
||||
func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
|
||||
toks := strings.Split(s, ";")
|
||||
|
||||
@@ -104,6 +118,8 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
|
||||
st = st.Bold(true)
|
||||
case n == 2:
|
||||
st = st.Dim(true)
|
||||
case n == 3:
|
||||
st = st.Italic(true)
|
||||
case n == 4:
|
||||
st = st.Underline(true)
|
||||
case n == 5 || n == 6:
|
||||
@@ -158,6 +174,35 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
|
||||
return st
|
||||
}
|
||||
|
||||
func (sm styleMap) parseFile(path string) {
|
||||
log.Printf("reading file: %s", path)
|
||||
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Printf("opening colors file: %s", err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
pairs, err := readPairs(f)
|
||||
if err != nil {
|
||||
log.Printf("reading colors file: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, pair := range pairs {
|
||||
key, val := pair[0], pair[1]
|
||||
|
||||
key = replaceTilde(key)
|
||||
|
||||
if filepath.IsAbs(key) {
|
||||
key = filepath.Clean(key)
|
||||
}
|
||||
|
||||
sm[key] = applyAnsiCodes(val, tcell.StyleDefault)
|
||||
}
|
||||
}
|
||||
|
||||
// This function parses $LS_COLORS environment variable.
|
||||
func (sm styleMap) parseGNU(env string) {
|
||||
for _, entry := range strings.Split(env, ":") {
|
||||
@@ -276,11 +321,15 @@ func (sm styleMap) get(f *file) tcell.Style {
|
||||
return val
|
||||
}
|
||||
|
||||
if val, ok := sm["*"+f.Name()]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
if val, ok := sm[filepath.Base(f.Name())+".*"]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
if val, ok := sm["*"+f.ext]; ok {
|
||||
if val, ok := sm["*"+strings.ToLower(f.ext)]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ func TestApplyAnsiCodes(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
if stGot := applyAnsiCodes(test.s, test.st); stGot != test.stExp {
|
||||
t.Errorf("at input '%s' with '%d' expected '%d' but got '%d'",
|
||||
t.Errorf("at input '%s' with '%v' expected '%v' but got '%v'",
|
||||
test.s, test.st, test.stExp, stGot)
|
||||
}
|
||||
}
|
||||
|
||||
+175
-88
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -12,30 +11,55 @@ import (
|
||||
var (
|
||||
gCmdWords = []string{
|
||||
"set",
|
||||
"setlocal",
|
||||
"map",
|
||||
"cmap",
|
||||
"cmd",
|
||||
"quit",
|
||||
"up",
|
||||
"half-up",
|
||||
"page-up",
|
||||
"scroll-up",
|
||||
"down",
|
||||
"half-down",
|
||||
"page-down",
|
||||
"scroll-down",
|
||||
"updir",
|
||||
"open",
|
||||
"quit",
|
||||
"jump-next",
|
||||
"jump-prev",
|
||||
"top",
|
||||
"bottom",
|
||||
"high",
|
||||
"middle",
|
||||
"low",
|
||||
"toggle",
|
||||
"invert",
|
||||
"invert-below",
|
||||
"unselect",
|
||||
"glob-select",
|
||||
"glob-unselect",
|
||||
"calcdirsize",
|
||||
"clearmaps",
|
||||
"copy",
|
||||
"cut",
|
||||
"paste",
|
||||
"clear",
|
||||
"sync",
|
||||
"draw",
|
||||
"redraw",
|
||||
"load",
|
||||
"reload",
|
||||
"read",
|
||||
"echo",
|
||||
"echomsg",
|
||||
"echoerr",
|
||||
"cd",
|
||||
"select",
|
||||
"delete",
|
||||
"rename",
|
||||
"source",
|
||||
"push",
|
||||
"read",
|
||||
"shell",
|
||||
"shell-pipe",
|
||||
"shell-wait",
|
||||
@@ -51,21 +75,38 @@ var (
|
||||
"filter",
|
||||
"setfilter",
|
||||
"mark-save",
|
||||
"mark-remove",
|
||||
"mark-load",
|
||||
"draw",
|
||||
"load",
|
||||
"sync",
|
||||
"echo",
|
||||
"echomsg",
|
||||
"echoerr",
|
||||
"cd",
|
||||
"select",
|
||||
"glob-select",
|
||||
"glob-unselect",
|
||||
"source",
|
||||
"push",
|
||||
"delete",
|
||||
"mark-remove",
|
||||
"tag",
|
||||
"tag-toggle",
|
||||
"cmd-escape",
|
||||
"cmd-complete",
|
||||
"cmd-menu-complete",
|
||||
"cmd-menu-complete-back",
|
||||
"cmd-menu-accept",
|
||||
"cmd-enter",
|
||||
"cmd-interrupt",
|
||||
"cmd-history-next",
|
||||
"cmd-history-prev",
|
||||
"cmd-left",
|
||||
"cmd-right",
|
||||
"cmd-home",
|
||||
"cmd-end",
|
||||
"cmd-delete",
|
||||
"cmd-delete-back",
|
||||
"cmd-delete-home",
|
||||
"cmd-delete-end",
|
||||
"cmd-delete-unix-word",
|
||||
"cmd-yank",
|
||||
"cmd-transpose",
|
||||
"cmd-transpose-word",
|
||||
"cmd-word",
|
||||
"cmd-word-back",
|
||||
"cmd-delete-word",
|
||||
"cmd-delete-word-back",
|
||||
"cmd-capitalize-word",
|
||||
"cmd-uppercase-word",
|
||||
"cmd-lowercase-word",
|
||||
}
|
||||
|
||||
gOptWords = []string{
|
||||
@@ -75,6 +116,10 @@ var (
|
||||
"autoquit",
|
||||
"noautoquit",
|
||||
"autoquit!",
|
||||
"borderfmt",
|
||||
"cursoractivefmt",
|
||||
"cursorparentfmt",
|
||||
"cursorpreviewfmt",
|
||||
"dircache",
|
||||
"nodircache",
|
||||
"dircache!",
|
||||
@@ -87,9 +132,13 @@ var (
|
||||
"dironly",
|
||||
"nodironly",
|
||||
"dironly!",
|
||||
"dirpreviews",
|
||||
"nodirpreviews",
|
||||
"dirpreviews!",
|
||||
"drawbox",
|
||||
"nodrawbox",
|
||||
"drawbox!",
|
||||
"dupfilefmt",
|
||||
"globsearch",
|
||||
"noglobsearch",
|
||||
"globsearch!",
|
||||
@@ -126,6 +175,12 @@ var (
|
||||
"reverse",
|
||||
"noreverse",
|
||||
"reverse!",
|
||||
"ruler",
|
||||
"rulerfmt",
|
||||
"preserve",
|
||||
"sixel",
|
||||
"nosixel",
|
||||
"sixel!",
|
||||
"smartcase",
|
||||
"nosmartcase",
|
||||
"smartcase!",
|
||||
@@ -146,22 +201,48 @@ var (
|
||||
"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{
|
||||
"dirfirst",
|
||||
"nodirfirst",
|
||||
"dirfirst!",
|
||||
"dironly",
|
||||
"nodironly",
|
||||
"dironly!",
|
||||
"hidden",
|
||||
"nohidden",
|
||||
"hidden!",
|
||||
"info",
|
||||
"reverse",
|
||||
"noreverse",
|
||||
"reverse!",
|
||||
"sortby",
|
||||
}
|
||||
)
|
||||
|
||||
func matchLongest(s1, s2 string) string {
|
||||
func matchLongest(s1, s2 []rune) []rune {
|
||||
i := 0
|
||||
for ; i < len(s1) && i < len(s2); i++ {
|
||||
if s1[i] != s2[i] {
|
||||
@@ -171,28 +252,28 @@ func matchLongest(s1, s2 string) string {
|
||||
return s1[:i]
|
||||
}
|
||||
|
||||
func matchWord(s string, words []string) (matches []string, longest string) {
|
||||
func matchWord(s string, words []string) (matches []string, longest []rune) {
|
||||
for _, w := range words {
|
||||
if !strings.HasPrefix(w, s) {
|
||||
continue
|
||||
}
|
||||
|
||||
matches = append(matches, w)
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, w)
|
||||
if len(longest) != 0 {
|
||||
longest = matchLongest(longest, []rune(w))
|
||||
} else if s != "" {
|
||||
longest = w + " "
|
||||
longest = []rune(w + " ")
|
||||
}
|
||||
}
|
||||
|
||||
if longest == "" {
|
||||
longest = s
|
||||
if len(longest) == 0 {
|
||||
longest = []rune(s)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func matchExec(s string) (matches []string, longest string) {
|
||||
func matchExec(s string) (matches []string, longest []rune) {
|
||||
var words []string
|
||||
|
||||
paths := strings.Split(envPath, string(filepath.ListSeparator))
|
||||
@@ -202,7 +283,7 @@ func matchExec(s string) (matches []string, longest string) {
|
||||
continue
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(p)
|
||||
files, err := os.ReadDir(p)
|
||||
if err != nil {
|
||||
log.Printf("reading path: %s", err)
|
||||
}
|
||||
@@ -212,18 +293,17 @@ func matchExec(s string) (matches []string, longest string) {
|
||||
continue
|
||||
}
|
||||
|
||||
f, err = os.Stat(filepath.Join(p, f.Name()))
|
||||
finfo, err := f.Info()
|
||||
if err != nil {
|
||||
log.Printf("getting file information: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !f.Mode().IsRegular() || !isExecutable(f) {
|
||||
if !finfo.Mode().IsRegular() || !isExecutable(finfo) {
|
||||
continue
|
||||
}
|
||||
|
||||
log.Print(f.Name())
|
||||
words = append(words, f.Name())
|
||||
words = append(words, finfo.Name())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +322,7 @@ func matchExec(s string) (matches []string, longest string) {
|
||||
return matchWord(s, words)
|
||||
}
|
||||
|
||||
func matchFile(s string) (matches []string, longest string) {
|
||||
func matchFile(s string) (matches []string, longest []rune) {
|
||||
dir := replaceTilde(s)
|
||||
|
||||
if !filepath.IsAbs(dir) {
|
||||
@@ -254,28 +334,24 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
}
|
||||
}
|
||||
|
||||
dir = unescape(filepath.Dir(dir))
|
||||
dir = filepath.Dir(unescape(dir))
|
||||
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
log.Printf("reading directory: %s", err)
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
name := filepath.Join(dir, f.Name())
|
||||
f, err := os.Stat(name)
|
||||
f, err := os.Lstat(name)
|
||||
if err != nil {
|
||||
fl, err := os.Lstat(name)
|
||||
if err == nil && fl.Mode()&os.ModeSymlink != 0 {
|
||||
continue
|
||||
} else {
|
||||
log.Printf("getting file information: %s", err)
|
||||
return
|
||||
}
|
||||
log.Printf("getting file information: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
name = strings.ToLower(escape(f.Name()))
|
||||
_, last := filepath.Split(s)
|
||||
if !strings.HasPrefix(escape(f.Name()), last) {
|
||||
if !strings.HasPrefix(name, strings.ToLower(last)) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -283,7 +359,7 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
if isRoot(s) || filepath.Base(s) != s {
|
||||
name = filepath.Join(filepath.Dir(unescape(s)), f.Name())
|
||||
}
|
||||
name = escape(name)
|
||||
name = escape(replaceTilde(name))
|
||||
|
||||
item := f.Name()
|
||||
if f.Mode().IsDir() {
|
||||
@@ -291,66 +367,82 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
}
|
||||
matches = append(matches, item)
|
||||
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, name)
|
||||
} else if s != "" {
|
||||
if longest == nil {
|
||||
if f.Mode().IsRegular() {
|
||||
longest = name + " "
|
||||
longest = []rune(name + " ")
|
||||
} else {
|
||||
longest = name + escape(string(filepath.Separator))
|
||||
longest = []rune(name + escape(string(filepath.Separator)))
|
||||
}
|
||||
} else {
|
||||
longest = matchLongest(longest, []rune(name))
|
||||
}
|
||||
}
|
||||
|
||||
if longest == "" {
|
||||
longest = s
|
||||
if len(longest) < len([]rune(s)) {
|
||||
longest = []rune(s)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func matchCmd(s string) (matches []string, longest []rune) {
|
||||
words := gCmdWords
|
||||
for c := range gOpts.cmds {
|
||||
words = append(words, c)
|
||||
}
|
||||
sort.Strings(words)
|
||||
j := 0
|
||||
for i := 1; i < len(words); i++ {
|
||||
if words[j] == words[i] {
|
||||
continue
|
||||
}
|
||||
j++
|
||||
words[i], words[j] = words[j], words[i]
|
||||
}
|
||||
words = words[:j+1]
|
||||
matches, longest = matchWord(s, words)
|
||||
return
|
||||
}
|
||||
|
||||
func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||
s := string(acc)
|
||||
f := tokenize(s)
|
||||
|
||||
var longest string
|
||||
var longest []rune
|
||||
|
||||
switch len(f) {
|
||||
case 1:
|
||||
words := gCmdWords
|
||||
for c := range gOpts.cmds {
|
||||
words = append(words, c)
|
||||
}
|
||||
sort.Strings(words)
|
||||
j := 0
|
||||
for i := 1; i < len(words); i++ {
|
||||
if words[j] == words[i] {
|
||||
continue
|
||||
}
|
||||
j++
|
||||
words[i], words[j] = words[j], words[i]
|
||||
}
|
||||
words = words[:j+1]
|
||||
matches, longest = matchWord(s, words)
|
||||
longestAcc = []rune(longest)
|
||||
matches, longestAcc = matchCmd(s)
|
||||
case 2:
|
||||
switch f[0] {
|
||||
case "set":
|
||||
matches, longest = matchWord(f[1], gOptWords)
|
||||
longestAcc = append(acc[:len(acc)-len(f[len(f)-1])], []rune(longest)...)
|
||||
case "map", "cmd":
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
case "map", "cmap", "cmd":
|
||||
longestAcc = acc
|
||||
default:
|
||||
matches, longest = matchFile(f[len(f)-1])
|
||||
longestAcc = append(acc[:len(acc)-len(f[len(f)-1])], []rune(longest)...)
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
}
|
||||
case 3:
|
||||
switch f[0] {
|
||||
case "setlocal":
|
||||
matches, longest = matchWord(f[2], gLocalOptWords)
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
case "map", "cmap":
|
||||
matches, longest = matchCmd(f[2])
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
default:
|
||||
matches, longest = matchFile(f[len(f)-1])
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
}
|
||||
default:
|
||||
switch f[0] {
|
||||
case "set", "map", "cmd":
|
||||
case "set", "setlocal", "map", "cmap", "cmd":
|
||||
longestAcc = acc
|
||||
default:
|
||||
matches, longest = matchFile(f[len(f)-1])
|
||||
longestAcc = append(acc[:len(acc)-len(f[len(f)-1])], []rune(longest)...)
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,33 +457,29 @@ func completeFile(acc []rune) (matches []string, longestAcc []rune) {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(wd)
|
||||
files, err := os.ReadDir(wd)
|
||||
if err != nil {
|
||||
log.Printf("reading directory: %s", err)
|
||||
}
|
||||
|
||||
var longest string
|
||||
|
||||
for _, f := range files {
|
||||
if !strings.HasPrefix(f.Name(), s) {
|
||||
if !strings.HasPrefix(strings.ToLower(f.Name()), strings.ToLower(s)) {
|
||||
continue
|
||||
}
|
||||
|
||||
matches = append(matches, f.Name())
|
||||
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, f.Name())
|
||||
} else if s != "" {
|
||||
longest = f.Name()
|
||||
if longestAcc == nil {
|
||||
longestAcc = []rune(f.Name())
|
||||
} else {
|
||||
longestAcc = matchLongest(longestAcc, []rune(f.Name()))
|
||||
}
|
||||
}
|
||||
|
||||
if longest == "" {
|
||||
longest = s
|
||||
if len(longestAcc) < len(acc) {
|
||||
longestAcc = acc
|
||||
}
|
||||
|
||||
longestAcc = []rune(longest)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -399,15 +487,14 @@ func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
||||
s := string(acc)
|
||||
f := tokenize(s)
|
||||
|
||||
var longest string
|
||||
var longest []rune
|
||||
|
||||
switch len(f) {
|
||||
case 1:
|
||||
matches, longest = matchExec(s)
|
||||
longestAcc = []rune(longest)
|
||||
matches, longestAcc = matchExec(s)
|
||||
default:
|
||||
matches, longest = matchFile(f[len(f)-1])
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], []rune(longest)...)
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
+4
-3
@@ -18,10 +18,11 @@ func TestMatchLongest(t *testing.T) {
|
||||
{"foo", "foobar", "foo"},
|
||||
{"foo", "barfoo", ""},
|
||||
{"foobar", "foobaz", "fooba"},
|
||||
{"год", "гол", "го"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if got := matchLongest(test.s1, test.s2); got != test.exp {
|
||||
if got := string(matchLongest([]rune(test.s1), []rune(test.s2))); got != test.exp {
|
||||
t.Errorf("at input '%s' and '%s' expected '%s' but got '%s'", test.s1, test.s2, test.exp, got)
|
||||
}
|
||||
}
|
||||
@@ -48,8 +49,8 @@ func TestMatchWord(t *testing.T) {
|
||||
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.matches, m)
|
||||
}
|
||||
|
||||
if l != test.longest {
|
||||
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.longest, l)
|
||||
if ls := string(l); ls != test.longest {
|
||||
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.longest, ls)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,10 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/djherbis/times"
|
||||
)
|
||||
|
||||
func copySize(srcs []string) (int64, error) {
|
||||
@@ -33,6 +37,17 @@ func copySize(srcs []string) (int64, error) {
|
||||
}
|
||||
|
||||
func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
|
||||
var dst_mode os.FileMode = 0666
|
||||
preserve_timestamps := false
|
||||
for _, s := range gOpts.preserve {
|
||||
switch s {
|
||||
case "timestamps":
|
||||
preserve_timestamps = true
|
||||
case "mode":
|
||||
dst_mode = info.Mode()
|
||||
}
|
||||
}
|
||||
|
||||
buf := make([]byte, 4096)
|
||||
|
||||
r, err := os.Open(src)
|
||||
@@ -41,7 +56,7 @@ func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
w, err := os.Create(dst)
|
||||
w, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, dst_mode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -70,9 +85,14 @@ func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Chmod(dst, info.Mode()); err != nil {
|
||||
os.Remove(dst)
|
||||
return err
|
||||
if preserve_timestamps {
|
||||
ts := times.Get(info)
|
||||
mtime := info.ModTime()
|
||||
atime := ts.AccessTime()
|
||||
if err := os.Chtimes(dst, atime, mtime); err != nil {
|
||||
os.Remove(dst)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -84,13 +104,20 @@ func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
|
||||
|
||||
go func() {
|
||||
for _, src := range srcs {
|
||||
dst := filepath.Join(dstDir, filepath.Base(src))
|
||||
file := filepath.Base(src)
|
||||
dst := filepath.Join(dstDir, file)
|
||||
|
||||
_, err := os.Lstat(dst)
|
||||
if !os.IsNotExist(err) {
|
||||
ext := filepath.Ext(file)
|
||||
basename := filepath.Base(file[:len(file)-len(ext)])
|
||||
var newPath string
|
||||
for i := 1; !os.IsNotExist(err); i++ {
|
||||
newPath = fmt.Sprintf("%s.~%d~", dst, i)
|
||||
file = strings.ReplaceAll(gOpts.dupfilefmt, "%f", basename+ext)
|
||||
file = strings.ReplaceAll(file, "%b", basename)
|
||||
file = strings.ReplaceAll(file, "%e", ext)
|
||||
file = strings.ReplaceAll(file, "%n", strconv.Itoa(i))
|
||||
newPath = filepath.Join(dstDir, file)
|
||||
_, err = os.Lstat(newPath)
|
||||
}
|
||||
dst = newPath
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func diskFree(wd string) string {
|
||||
var stat unix.Statfs_t
|
||||
|
||||
if err := unix.Statfs(wd, &stat); err != nil {
|
||||
log.Printf("diskfree: %s", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
// Available blocks * size per block = available space in bytes
|
||||
return "df: " + humanize(int64(uint64(stat.F_bavail)*uint64(stat.F_bsize)))
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
//go:build darwin || dragonfly || freebsd || linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func diskFree(wd string) string {
|
||||
var stat unix.Statfs_t
|
||||
|
||||
if err := unix.Statfs(wd, &stat); err != nil {
|
||||
log.Printf("diskfree: %s", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
// Available blocks * size per block = available space in bytes
|
||||
return "df: " + humanize(int64(uint64(stat.Bavail)*uint64(stat.Bsize)))
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
//go:build illumos || netbsd || solaris
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func diskFree(wd string) string {
|
||||
var stat unix.Statvfs_t
|
||||
|
||||
if err := unix.Statvfs(wd, &stat); err != nil {
|
||||
log.Printf("diskfree: %s", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
// Available blocks * size per block = available space in bytes
|
||||
return "df: " + humanize(int64(uint64(stat.Bavail)*uint64(stat.Bsize)))
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func diskFree(wd string) string {
|
||||
var free uint64
|
||||
|
||||
pathPtr, err := windows.UTF16PtrFromString(wd)
|
||||
if err != nil {
|
||||
log.Printf("diskfree: %s", err)
|
||||
return ""
|
||||
}
|
||||
err = windows.GetDiskFreeSpaceEx(pathPtr, &free, nil, nil) // cwd, free, total, available
|
||||
if err != nil {
|
||||
log.Printf("diskfree: %s", err)
|
||||
return ""
|
||||
}
|
||||
return "df: " + humanize(int64(free))
|
||||
}
|
||||
+1045
-640
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,174 @@
|
||||
# vim:ft=dircolors
|
||||
# (This is not a dircolors file but it helps to highlight colors and comments)
|
||||
|
||||
# default values from dircolors
|
||||
# (entries with a leading # are not implemented in lf)
|
||||
# #no 00 # NORMAL
|
||||
# fi 00 # FILE
|
||||
# #rs 0 # RESET
|
||||
# di 01;34 # DIR
|
||||
# ln 01;36 # LINK
|
||||
# #mh 00 # MULTIHARDLINK
|
||||
# pi 40;33 # FIFO
|
||||
# so 01;35 # SOCK
|
||||
# #do 01;35 # DOOR
|
||||
# bd 40;33;01 # BLK
|
||||
# cd 40;33;01 # CHR
|
||||
# or 40;31;01 # ORPHAN
|
||||
# #mi 00 # MISSING
|
||||
# su 37;41 # SETUID
|
||||
# sg 30;43 # SETGID
|
||||
# #ca 30;41 # CAPABILITY
|
||||
# tw 30;42 # STICKY_OTHER_WRITABLE
|
||||
# ow 34;42 # OTHER_WRITABLE
|
||||
# st 37;44 # STICKY
|
||||
# ex 01;32 # EXEC
|
||||
|
||||
# default values from lf (with matching order)
|
||||
# ln 01;36 # LINK
|
||||
# or 31;01 # ORPHAN
|
||||
# tw 01;34 # STICKY_OTHER_WRITABLE
|
||||
# ow 01;34 # OTHER_WRITABLE
|
||||
# st 01;34 # STICKY
|
||||
# di 01;34 # DIR
|
||||
# pi 33 # FIFO
|
||||
# so 01;35 # SOCK
|
||||
# bd 33;01 # BLK
|
||||
# cd 33;01 # CHR
|
||||
# su 01;32 # SETUID
|
||||
# sg 01;32 # SETGID
|
||||
# ex 01;32 # EXEC
|
||||
# fi 00 # FILE
|
||||
|
||||
# file types (with matching order)
|
||||
ln 01;36 # LINK
|
||||
or 31;01 # ORPHAN
|
||||
tw 34 # STICKY_OTHER_WRITABLE
|
||||
ow 34 # OTHER_WRITABLE
|
||||
st 01;34 # STICKY
|
||||
di 01;34 # DIR
|
||||
pi 33 # FIFO
|
||||
so 01;35 # SOCK
|
||||
bd 33;01 # BLK
|
||||
cd 33;01 # CHR
|
||||
su 01;32 # SETUID
|
||||
sg 01;32 # SETGID
|
||||
ex 01;32 # EXEC
|
||||
fi 00 # FILE
|
||||
|
||||
# archives or compressed (dircolors defaults)
|
||||
*.tar 01;31
|
||||
*.tgz 01;31
|
||||
*.arc 01;31
|
||||
*.arj 01;31
|
||||
*.taz 01;31
|
||||
*.lha 01;31
|
||||
*.lz4 01;31
|
||||
*.lzh 01;31
|
||||
*.lzma 01;31
|
||||
*.tlz 01;31
|
||||
*.txz 01;31
|
||||
*.tzo 01;31
|
||||
*.t7z 01;31
|
||||
*.zip 01;31
|
||||
*.z 01;31
|
||||
*.dz 01;31
|
||||
*.gz 01;31
|
||||
*.lrz 01;31
|
||||
*.lz 01;31
|
||||
*.lzo 01;31
|
||||
*.xz 01;31
|
||||
*.zst 01;31
|
||||
*.tzst 01;31
|
||||
*.bz2 01;31
|
||||
*.bz 01;31
|
||||
*.tbz 01;31
|
||||
*.tbz2 01;31
|
||||
*.tz 01;31
|
||||
*.deb 01;31
|
||||
*.rpm 01;31
|
||||
*.jar 01;31
|
||||
*.war 01;31
|
||||
*.ear 01;31
|
||||
*.sar 01;31
|
||||
*.rar 01;31
|
||||
*.alz 01;31
|
||||
*.ace 01;31
|
||||
*.zoo 01;31
|
||||
*.cpio 01;31
|
||||
*.7z 01;31
|
||||
*.rz 01;31
|
||||
*.cab 01;31
|
||||
*.wim 01;31
|
||||
*.swm 01;31
|
||||
*.dwm 01;31
|
||||
*.esd 01;31
|
||||
|
||||
# image formats (dircolors defaults)
|
||||
*.jpg 01;35
|
||||
*.jpeg 01;35
|
||||
*.mjpg 01;35
|
||||
*.mjpeg 01;35
|
||||
*.gif 01;35
|
||||
*.bmp 01;35
|
||||
*.pbm 01;35
|
||||
*.pgm 01;35
|
||||
*.ppm 01;35
|
||||
*.tga 01;35
|
||||
*.xbm 01;35
|
||||
*.xpm 01;35
|
||||
*.tif 01;35
|
||||
*.tiff 01;35
|
||||
*.png 01;35
|
||||
*.svg 01;35
|
||||
*.svgz 01;35
|
||||
*.mng 01;35
|
||||
*.pcx 01;35
|
||||
*.mov 01;35
|
||||
*.mpg 01;35
|
||||
*.mpeg 01;35
|
||||
*.m2v 01;35
|
||||
*.mkv 01;35
|
||||
*.webm 01;35
|
||||
*.ogm 01;35
|
||||
*.mp4 01;35
|
||||
*.m4v 01;35
|
||||
*.mp4v 01;35
|
||||
*.vob 01;35
|
||||
*.qt 01;35
|
||||
*.nuv 01;35
|
||||
*.wmv 01;35
|
||||
*.asf 01;35
|
||||
*.rm 01;35
|
||||
*.rmvb 01;35
|
||||
*.flc 01;35
|
||||
*.avi 01;35
|
||||
*.fli 01;35
|
||||
*.flv 01;35
|
||||
*.gl 01;35
|
||||
*.dl 01;35
|
||||
*.xcf 01;35
|
||||
*.xwd 01;35
|
||||
*.yuv 01;35
|
||||
*.cgm 01;35
|
||||
*.emf 01;35
|
||||
*.ogv 01;35
|
||||
*.ogx 01;35
|
||||
|
||||
# audio formats (dircolors defaults)
|
||||
*.aac 00;36
|
||||
*.au 00;36
|
||||
*.flac 00;36
|
||||
*.m4a 00;36
|
||||
*.mid 00;36
|
||||
*.midi 00;36
|
||||
*.mka 00;36
|
||||
*.mp3 00;36
|
||||
*.mpc 00;36
|
||||
*.ogg 00;36
|
||||
*.ra 00;36
|
||||
*.wav 00;36
|
||||
*.oga 00;36
|
||||
*.opus 00;36
|
||||
*.spx 00;36
|
||||
*.xspf 00;36
|
||||
@@ -0,0 +1,357 @@
|
||||
# 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
|
||||
|
||||
# file extensions (vim-devicons)
|
||||
*.styl
|
||||
*.sass
|
||||
*.scss
|
||||
*.htm
|
||||
*.html
|
||||
*.slim
|
||||
*.haml
|
||||
*.ejs
|
||||
*.css
|
||||
*.less
|
||||
*.md
|
||||
*.mdx
|
||||
*.markdown
|
||||
*.rmd
|
||||
*.json
|
||||
*.webmanifest
|
||||
*.js
|
||||
*.mjs
|
||||
*.jsx
|
||||
*.rb
|
||||
*.gemspec
|
||||
*.rake
|
||||
*.php
|
||||
*.py
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
*.coffee
|
||||
*.mustache
|
||||
*.hbs
|
||||
*.conf
|
||||
*.ini
|
||||
*.yml
|
||||
*.yaml
|
||||
*.toml
|
||||
*.bat
|
||||
*.mk
|
||||
*.jpg
|
||||
*.jpeg
|
||||
*.bmp
|
||||
*.png
|
||||
*.webp
|
||||
*.gif
|
||||
*.ico
|
||||
*.twig
|
||||
*.cpp
|
||||
*.c++
|
||||
*.cxx
|
||||
*.cc
|
||||
*.cp
|
||||
*.c
|
||||
*.cs
|
||||
*.h
|
||||
*.hh
|
||||
*.hpp
|
||||
*.hxx
|
||||
*.hs
|
||||
*.lhs
|
||||
*.nix
|
||||
*.lua
|
||||
*.java
|
||||
*.sh
|
||||
*.fish
|
||||
*.bash
|
||||
*.zsh
|
||||
*.ksh
|
||||
*.csh
|
||||
*.awk
|
||||
*.ps1
|
||||
*.ml λ
|
||||
*.mli λ
|
||||
*.diff
|
||||
*.db
|
||||
*.sql
|
||||
*.dump
|
||||
*.clj
|
||||
*.cljc
|
||||
*.cljs
|
||||
*.edn
|
||||
*.scala
|
||||
*.go
|
||||
*.dart
|
||||
*.xul
|
||||
*.sln
|
||||
*.suo
|
||||
*.pl
|
||||
*.pm
|
||||
*.t
|
||||
*.rss
|
||||
'*.f#'
|
||||
*.fsscript
|
||||
*.fsx
|
||||
*.fs
|
||||
*.fsi
|
||||
*.rs
|
||||
*.rlib
|
||||
*.d
|
||||
*.erl
|
||||
*.hrl
|
||||
*.ex
|
||||
*.exs
|
||||
*.eex
|
||||
*.leex
|
||||
*.heex
|
||||
*.vim
|
||||
*.ai
|
||||
*.psd
|
||||
*.psb
|
||||
*.ts
|
||||
*.tsx
|
||||
*.jl
|
||||
*.pp
|
||||
*.vue
|
||||
*.elm
|
||||
*.swift
|
||||
*.xcplayground
|
||||
*.tex
|
||||
*.r
|
||||
*.rproj
|
||||
*.sol
|
||||
*.pem
|
||||
|
||||
# file names (vim-devicons) (case-insensitive not supported in lf)
|
||||
*gruntfile.coffee
|
||||
*gruntfile.js
|
||||
*gruntfile.ls
|
||||
*gulpfile.coffee
|
||||
*gulpfile.js
|
||||
*gulpfile.ls
|
||||
*mix.lock
|
||||
*dropbox
|
||||
*.ds_store
|
||||
*.gitconfig
|
||||
*.gitignore
|
||||
*.gitattributes
|
||||
*.gitlab-ci.yml
|
||||
*.bashrc
|
||||
*.zshrc
|
||||
*.zshenv
|
||||
*.zprofile
|
||||
*.vimrc
|
||||
*.gvimrc
|
||||
*_vimrc
|
||||
*_gvimrc
|
||||
*.bashprofile
|
||||
*favicon.ico
|
||||
*license
|
||||
*node_modules
|
||||
*react.jsx
|
||||
*procfile
|
||||
*dockerfile
|
||||
*docker-compose.yml
|
||||
*rakefile
|
||||
*config.ru
|
||||
*gemfile
|
||||
*makefile
|
||||
*cmakelists.txt
|
||||
*robots.txt
|
||||
|
||||
# file names (case-sensitive adaptations)
|
||||
*Gruntfile.coffee
|
||||
*Gruntfile.js
|
||||
*Gruntfile.ls
|
||||
*Gulpfile.coffee
|
||||
*Gulpfile.js
|
||||
*Gulpfile.ls
|
||||
*Dropbox
|
||||
*.DS_Store
|
||||
*LICENSE
|
||||
*React.jsx
|
||||
*Procfile
|
||||
*Dockerfile
|
||||
*Docker-compose.yml
|
||||
*Rakefile
|
||||
*Gemfile
|
||||
*Makefile
|
||||
*CMakeLists.txt
|
||||
|
||||
# file patterns (vim-devicons) (patterns not supported in lf)
|
||||
# .*jquery.*\.js$
|
||||
# .*angular.*\.js$
|
||||
# .*backbone.*\.js$
|
||||
# .*require.*\.js$
|
||||
# .*materialize.*\.js$
|
||||
# .*materialize.*\.css$
|
||||
# .*mootools.*\.js$
|
||||
# .*vimrc.*
|
||||
# Vagrantfile$
|
||||
|
||||
# file patterns (file name adaptations)
|
||||
*jquery.min.js
|
||||
*angular.min.js
|
||||
*backbone.min.js
|
||||
*require.min.js
|
||||
*materialize.min.js
|
||||
*materialize.min.css
|
||||
*mootools.min.js
|
||||
*vimrc
|
||||
Vagrantfile
|
||||
|
||||
# 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
|
||||
@@ -13,7 +13,10 @@ _lf () {
|
||||
-cpuprofile
|
||||
-doc
|
||||
-last-dir-path
|
||||
-log
|
||||
-memprofile
|
||||
-print-last-dir
|
||||
-print-selection
|
||||
-remote
|
||||
-selection-path
|
||||
-server
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
# endif
|
||||
#
|
||||
|
||||
set LF_ARGS = "-command -config -cpuprofile -doc -last-dir-path -memprofile -remote -selection-path -server -single -version -help "
|
||||
set LF_ARGS = "-command -config -cpuprofile -doc -last-dir-path -log -memprofile -print-last-dir -print-selection -remote -selection-path -server -single -version -help "
|
||||
|
||||
complete lf "C/-*/(${LF_ARGS})/"
|
||||
complete lfcd "C/-*/(${LF_ARGS})/"
|
||||
@@ -11,7 +11,10 @@ complete -c lf -o config -r -d 'path to the config file (instead of the usual pa
|
||||
complete -c lf -o cpuprofile -r -d 'path to the file to write the CPU profile'
|
||||
complete -c lf -o doc -d 'show documentation'
|
||||
complete -c lf -o last-dir-path -r -d 'path to the file to write the last dir on exit (to use for cd)'
|
||||
complete -c lf -o log -r -d 'path to the log file to write messages'
|
||||
complete -c lf -o memprofile -r -d 'path to the file to write the memory profile'
|
||||
complete -c lf -o print-last-dir -d 'print the last dir to stdout on exit (to use for cd)'
|
||||
complete -c lf -o print-selection -d 'print the selected files to stdout on open (to use as open file dialog)'
|
||||
complete -c lf -o remote -x -d 'send remote command to server'
|
||||
complete -c lf -o selection-path -r -d 'path to the file to write selected files on open (to use as open file dialog)'
|
||||
complete -c lf -o server -d 'start server (automatic)'
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# Autocompletion for nushell.
|
||||
#
|
||||
# Documentation: https://www.nushell.sh/book/externs.html
|
||||
|
||||
# To enable autocompletion you may put this file into a directory:
|
||||
#
|
||||
# mkdir -p ~/.config/nushell/completions
|
||||
# ln -s "/path/to/lf.nu" ~/.config/nushell/completions
|
||||
#
|
||||
# Then you need to source this file in your nu config (Open the config with the
|
||||
# command 'config nu' inside the nushell) by adding:
|
||||
#
|
||||
# source ~/.config/nushell/completions/lf.nu
|
||||
|
||||
export extern "lf" [
|
||||
--command # command to execute on client initialization
|
||||
--config: string # path to the config file (instead of the usual paths)
|
||||
--cpuprofile: string # path to the file to write the CPU profile
|
||||
--doc # show documentation
|
||||
--last-dir-path: string # path to the file to write the last dir on exit (to use for cd)
|
||||
--log: string # path to the log file to write messages
|
||||
--memprofile: string # path to the file to write the memory profile
|
||||
--print-last-dir # print the last dir to stdout on exit (to use for cd)
|
||||
--print-selection # print the selected files to stdout on open (to use as open file dialog)
|
||||
--remote: string # send remote command to server
|
||||
--selection-path: string # path to the file to write selected files on open (to use as open file dialog)
|
||||
--server # start server (automatic)
|
||||
--single # start a client without server
|
||||
--version # show version
|
||||
--help # show help
|
||||
]
|
||||
@@ -14,7 +14,10 @@ Register-ArgumentCompleter -Native -CommandName 'lf' -ScriptBlock {
|
||||
[CompletionResult]::new('-cpuprofile ', '-cpuprofile', [CompletionResultType]::ParameterName, 'path to the file to write the CPU profile')
|
||||
[CompletionResult]::new('-doc', '-doc', [CompletionResultType]::ParameterName, 'show documentation')
|
||||
[CompletionResult]::new('-last-dir-path ', '-last-dir-path', [CompletionResultType]::ParameterName, 'path to the file to write the last dir on exit (to use for cd)')
|
||||
[CompletionResult]::new('-log ', '-log', [CompletionResultType]::ParameterName, 'path to the log file to write messages')
|
||||
[CompletionResult]::new('-memprofile ', '-memprofile', [CompletionResultType]::ParameterName, 'path to the file to write the memory profile')
|
||||
[CompletionResult]::new('-print-last-dir', '-print-last-dir', [CompletionResultType]::ParameterName, 'print the last dir to stdout on exit (to use for cd)')
|
||||
[CompletionResult]::new('-print-selection', '-print-selection', [CompletionResultType]::ParameterName, 'print the selected files to stdout on open (to use as open file dialog)')
|
||||
[CompletionResult]::new('-remote ', '-remote', [CompletionResultType]::ParameterName, 'send remote command to server')
|
||||
[CompletionResult]::new('-selection-path ', '-selection-path', [CompletionResultType]::ParameterName, 'path to the file to write selected files on open (to use as open file dialog)')
|
||||
[CompletionResult]::new('-server', '-server', [CompletionResultType]::ParameterName, 'start server (automatic)')
|
||||
|
||||
@@ -18,7 +18,10 @@ arguments=(
|
||||
'-cpuprofile[path to the file to write the CPU profile]'
|
||||
'-doc[show documentation]'
|
||||
'-last-dir-path[path to the file to write the last dir on exit (to use for cd)]'
|
||||
'-log[path to the log file to write messages]'
|
||||
'-memprofile[path to the file to write the memory profile]'
|
||||
'-print-last-dir[print the last dir to stdout on exit (to use for cd)]'
|
||||
'-print-selection[print the selected files to stdout on open (to use as open file dialog)]'
|
||||
'-remote[send remote command to server]'
|
||||
'-selection-path[path to the file to write selected files on open (to use as open file dialog)]'
|
||||
'-server[start server (automatic)]'
|
||||
|
||||
+3
-2
@@ -5,7 +5,7 @@
|
||||
# mkdir -p ~/.config/fish/functions
|
||||
# ln -s "/path/to/lfcd.fish" ~/.config/fish/functions
|
||||
#
|
||||
# You may also like to assign a key to this command:
|
||||
# You may also like to assign a key (Ctrl-O) to this command:
|
||||
#
|
||||
# bind \co 'set old_tty (stty -g); stty sane; lfcd; stty $old_tty; commandline -f repaint'
|
||||
#
|
||||
@@ -13,7 +13,8 @@
|
||||
|
||||
function lfcd
|
||||
set tmp (mktemp)
|
||||
lf -last-dir-path=$tmp $argv
|
||||
# `command` is needed in case `lfcd` is aliased to `lf`
|
||||
command lf -last-dir-path=$tmp $argv
|
||||
if test -f "$tmp"
|
||||
set dir (cat $tmp)
|
||||
rm -f $tmp
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
# Change working dir in shell to last dir in lf on exit (adapted from ranger).
|
||||
#
|
||||
# You need to add this to your Nushell Enviroment Config File
|
||||
# (Execute 'config env' in the nushell to open it).
|
||||
|
||||
# You may also like to assign a key (Ctrl-O) to this command:
|
||||
# See the documentation: https://www.nushell.sh/book/line_editor.html#keybindings
|
||||
#
|
||||
# keybindings: [
|
||||
# {
|
||||
# name: lfcd
|
||||
# modifier: control
|
||||
# keycode: char_o
|
||||
# mode: [emacs, vi_normal, vi_insert]
|
||||
# event: {
|
||||
# send: executehostcommand
|
||||
# cmd: "lfcd"
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
|
||||
def-env lfcd [] {
|
||||
let tmp = (mktemp)
|
||||
lf -last-dir-path $tmp
|
||||
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)'
|
||||
}
|
||||
}
|
||||
+3
-12
@@ -8,22 +8,13 @@
|
||||
# source "$LFCD"
|
||||
# fi
|
||||
#
|
||||
# You may also like to assign a key to this command:
|
||||
# You may also like to assign a key (Ctrl-O) to this command:
|
||||
#
|
||||
# bind '"\C-o":"lfcd\C-m"' # bash
|
||||
# bindkey -s '^o' 'lfcd\n' # zsh
|
||||
#
|
||||
|
||||
lfcd () {
|
||||
tmp="$(mktemp)"
|
||||
lf -last-dir-path="$tmp" "$@"
|
||||
if [ -f "$tmp" ]; then
|
||||
dir="$(cat "$tmp")"
|
||||
rm -f "$tmp"
|
||||
if [ -d "$dir" ]; then
|
||||
if [ "$dir" != "$(pwd)" ]; then
|
||||
cd "$dir"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
# `command` is needed in case `lfcd` is aliased to `lf`
|
||||
cd "$(command lf -print-last-dir "$@")"
|
||||
}
|
||||
+14
-6
@@ -20,9 +20,15 @@ set ifs "\n"
|
||||
# leave some space at the top and the bottom of the screen
|
||||
set scrolloff 10
|
||||
|
||||
# Use the `dim` attribute instead of underline for the cursor in the preview pane
|
||||
set cursorpreviewfmt "\033[7;2m"
|
||||
|
||||
# use enter for shell commands
|
||||
map <enter> shell
|
||||
|
||||
# show the result of execution of previous commands
|
||||
map ` !true
|
||||
|
||||
# execute current file (must be executable)
|
||||
map x $$f
|
||||
map X !$f
|
||||
@@ -35,14 +41,16 @@ map O $mimeopen --ask $f
|
||||
# This command is called when current file is not a directory. You may want to
|
||||
# use either file extensions and/or mime types here. Below uses an editor for
|
||||
# text files and a file opener for the rest.
|
||||
cmd open ${{
|
||||
test -L $f && f=$(readlink -f $f)
|
||||
case $(file --mime-type $f -b) in
|
||||
text/*) $EDITOR $fx;;
|
||||
*) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;;
|
||||
cmd open &{{
|
||||
case $(file --mime-type -Lb $f) in
|
||||
text/*) lf -remote "send $id \$$EDITOR \$fx";;
|
||||
*) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;;
|
||||
esac
|
||||
}}
|
||||
|
||||
# mkdir command. See wiki if you want it to select created dir
|
||||
map a :push %mkdir<space>
|
||||
|
||||
# define a custom 'rename' command without prompt for overwrite
|
||||
# cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||
# map r push :rename<space>
|
||||
@@ -60,7 +68,7 @@ cmd trash %set -f; mv $fx ~/.trash
|
||||
# printf "$fx\n"
|
||||
# printf "delete?[y/n]"
|
||||
# read ans
|
||||
# [ $ans = "y" ] && rm -rf $fx
|
||||
# [ "$ans" = "y" ] && rm -rf $fx
|
||||
# }}
|
||||
|
||||
# use '<delete>' key for either 'trash' or 'delete' command
|
||||
|
||||
@@ -10,6 +10,9 @@ set shell powershell
|
||||
# which does not work with powershell. Therefore, you need to override these
|
||||
# keybindings with explicit choices accordingly.
|
||||
|
||||
# change the default open command to work in powerShell
|
||||
cmd open &start $Env:f
|
||||
|
||||
# change the editor used in default editor keybinding
|
||||
# There is no builtin terminal editor installed in Windows. The default editor
|
||||
# mapping uses 'notepad' which launches in a separate GUI window. You may
|
||||
|
||||
@@ -191,6 +191,84 @@ var gEvalTests = []struct {
|
||||
[]expr{&setExpr{"ratios", "1:2:3"}, &setExpr{"hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
"setlocal /foo/bar hidden # trailing comments are allowed",
|
||||
[]string{"setlocal", "/foo/bar", "hidden", "\n"},
|
||||
[]expr{&setLocalExpr{"/foo/bar", "hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
"setlocal /foo/bar hidden; setlocal /foo/bar reverse",
|
||||
[]string{"setlocal", "/foo/bar", "hidden", ";", "setlocal", "/foo/bar", "reverse", "\n"},
|
||||
[]expr{&setLocalExpr{"/foo/bar", "hidden", ""}, &setLocalExpr{"/foo/bar", "reverse", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
"setlocal /foo/bar hidden\nsetlocal /foo/bar reverse",
|
||||
[]string{"setlocal", "/foo/bar", "hidden", "\n", "setlocal", "/foo/bar", "reverse", "\n"},
|
||||
[]expr{&setLocalExpr{"/foo/bar", "hidden", ""}, &setLocalExpr{"/foo/bar", "reverse", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
`setlocal /foo/bar info ""`,
|
||||
[]string{"setlocal", "/foo/bar", "info", "", "\n"},
|
||||
[]expr{&setLocalExpr{"/foo/bar", "info", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
`setlocal /foo/bar info "size"`,
|
||||
[]string{"setlocal", "/foo/bar", "info", "size", "\n"},
|
||||
[]expr{&setLocalExpr{"/foo/bar", "info", "size"}},
|
||||
},
|
||||
|
||||
{
|
||||
"setlocal /foo/bar info size:time",
|
||||
[]string{"setlocal", "/foo/bar", "info", "size:time", "\n"},
|
||||
[]expr{&setLocalExpr{"/foo/bar", "info", "size:time"}},
|
||||
},
|
||||
|
||||
{
|
||||
"setlocal /foo/bar info size:time;",
|
||||
[]string{"setlocal", "/foo/bar", "info", "size:time", ";"},
|
||||
[]expr{&setLocalExpr{"/foo/bar", "info", "size:time"}},
|
||||
},
|
||||
|
||||
{
|
||||
":setlocal /foo/bar info size:time",
|
||||
[]string{":", "setlocal", "/foo/bar", "info", "size:time", "\n", "\n"},
|
||||
[]expr{&listExpr{[]expr{&setLocalExpr{"/foo/bar", "info", "size:time"}}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
":setlocal /foo/bar info size:time\nsetlocal /foo/bar hidden",
|
||||
[]string{":", "setlocal", "/foo/bar", "info", "size:time", "\n", "\n", "setlocal", "/foo/bar", "hidden", "\n"},
|
||||
[]expr{&listExpr{[]expr{&setLocalExpr{"/foo/bar", "info", "size:time"}}, 1}, &setLocalExpr{"/foo/bar", "hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
":setlocal /foo/bar info size:time;",
|
||||
[]string{":", "setlocal", "/foo/bar", "info", "size:time", ";", "\n"},
|
||||
[]expr{&listExpr{[]expr{&setLocalExpr{"/foo/bar", "info", "size:time"}}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
":setlocal /foo/bar info size:time;\nsetlocal /foo/bar hidden",
|
||||
[]string{":", "setlocal", "/foo/bar", "info", "size:time", ";", "\n", "setlocal", "/foo/bar", "hidden", "\n"},
|
||||
[]expr{&listExpr{[]expr{&setLocalExpr{"/foo/bar", "info", "size:time"}}, 1}, &setLocalExpr{"/foo/bar", "hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
"setlocal /foo/bar info size:time\n setlocal /foo/bar hidden",
|
||||
[]string{"setlocal", "/foo/bar", "info", "size:time", "\n", "setlocal", "/foo/bar", "hidden", "\n"},
|
||||
[]expr{&setLocalExpr{"/foo/bar", "info", "size:time"}, &setLocalExpr{"/foo/bar", "hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
"setlocal /foo/bar info size:time \nsetlocal /foo/bar hidden",
|
||||
[]string{"setlocal", "/foo/bar", "info", "size:time", "\n", "setlocal", "/foo/bar", "hidden", "\n"},
|
||||
[]expr{&setLocalExpr{"/foo/bar", "info", "size:time"}, &setLocalExpr{"/foo/bar", "hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
"map gh cd ~",
|
||||
[]string{"map", "gh", "cd", "~", "\n"},
|
||||
|
||||
+4
-2
@@ -28,6 +28,7 @@ lf \- terminal file manager
|
||||
.OP \-cpuprofile path
|
||||
.OP \-doc
|
||||
.OP \-last-dir-path path
|
||||
.OP \-log path
|
||||
.OP \-memprofile path
|
||||
.OP \-remote command
|
||||
.OP \-selection-path path
|
||||
@@ -35,7 +36,7 @@ lf \- terminal file manager
|
||||
.OP \-single
|
||||
.OP \-version
|
||||
.OP \-help
|
||||
.RI [ directory ]
|
||||
.RI [ cd-or-select-path ]
|
||||
.YS
|
||||
.SH DESCRIPTION
|
||||
END
|
||||
@@ -57,7 +58,8 @@ BEGIN {
|
||||
}
|
||||
|
||||
# heading
|
||||
/^[^[:punct:]]*$/ {
|
||||
/^# *[^[:punct:]]*$/ {
|
||||
gsub(/# */, "", $0)
|
||||
print ".SH", toupper($0)
|
||||
start = 1
|
||||
next
|
||||
|
||||
+76
-42
@@ -8,51 +8,85 @@
|
||||
# compressed in an archive form (`.zip` for windows and `.tar.gz` for the rest)
|
||||
# within a folder named `dist`.
|
||||
|
||||
set -o verbose
|
||||
[ -z "$version" ] && version=$(git describe --tags)
|
||||
|
||||
[ -z $version ] && version=$(git describe --tags)
|
||||
test -d dist && {
|
||||
echo "gen/xbuild.sh: WARNING: removing preexisting subdir 'dist'"
|
||||
rm -r dist || exit 5
|
||||
}
|
||||
mkdir dist || exit 5
|
||||
|
||||
mkdir -p dist
|
||||
ERRORS=
|
||||
|
||||
# https://golang.org/doc/install/source#environment
|
||||
build() {
|
||||
# https://golang.org/doc/install/source#environment
|
||||
echo "=== Building for GOOS=$1 and GOARCH=$2."
|
||||
CGO_ENABLED=0 GOOS="$1" GOARCH="$2" go build -o dist/ \
|
||||
-ldflags="-s -w -X main.gVersion=$version"
|
||||
if test "$?" != "0"; then
|
||||
ERRORS=1
|
||||
else
|
||||
package "$1" "$2" || exit 5
|
||||
fi
|
||||
}
|
||||
|
||||
CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-android-arm64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-darwin-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=dragonfly GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-dragonfly-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-freebsd-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-freebsd-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-freebsd-arm.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=illumos GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-illumos-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-arm.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-arm64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-ppc64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-ppc64le.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mips.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mipsle.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mips64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mips64le.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=s390x go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-s390x.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=netbsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-netbsd-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=netbsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-netbsd-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=netbsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-netbsd-arm.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=openbsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=openbsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-arm.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=openbsd GOARCH=arm64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-arm64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=solaris GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-solaris-amd64.tar.gz lf --remove-files
|
||||
package() (
|
||||
cd dist || return 1
|
||||
# Since the function is surrounded by (), the cd only affects a subshell
|
||||
OUTFILE=
|
||||
case "$1" in
|
||||
windows)
|
||||
OUTFILE="lf-$1-$2.zip"
|
||||
zip "$OUTFILE" lf.exe --move || return 1
|
||||
;;
|
||||
*)
|
||||
OUTFILE="lf-$1-$2.tar.gz"
|
||||
tar czf "$OUTFILE" lf --remove-files || return 1
|
||||
;;
|
||||
esac
|
||||
echo "dist/$OUTFILE successfully created."
|
||||
)
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && zip dist/lf-windows-386.zip lf.exe --move
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && zip dist/lf-windows-amd64.zip lf.exe --move
|
||||
build android arm64
|
||||
build darwin amd64
|
||||
build darwin arm64
|
||||
build dragonfly amd64
|
||||
build freebsd 386
|
||||
build freebsd amd64
|
||||
build freebsd arm
|
||||
build illumos amd64
|
||||
build linux 386
|
||||
build linux amd64
|
||||
build linux arm
|
||||
build linux arm64
|
||||
build linux ppc64
|
||||
build linux ppc64le
|
||||
build linux mips
|
||||
build linux mipsle
|
||||
build linux mips64
|
||||
build linux mips64le
|
||||
build linux s390x
|
||||
build netbsd 386
|
||||
build netbsd amd64
|
||||
build netbsd arm
|
||||
build openbsd 386
|
||||
build openbsd amd64
|
||||
build openbsd arm
|
||||
build openbsd arm64
|
||||
build solaris amd64
|
||||
build windows 386
|
||||
build windows amd64
|
||||
# Unsupported
|
||||
# build aix ppc64
|
||||
# build android 386
|
||||
# build android amd64
|
||||
# build android arm
|
||||
# build js wasm
|
||||
# build plan9 386
|
||||
# build plan9 amd64
|
||||
# build plan9 arm
|
||||
|
||||
# not supported
|
||||
# CGO_ENABLED=0 GOOS=aix GOARCH=ppc64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-aix-ppc64.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=android GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-android-386.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=android GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-android-amd64.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=android GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-android-arm.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-darwin-arm64.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=js GOARCH=wasm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-js-wasm.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=plan9 GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-plan9-386.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=plan9 GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-plan9-amd64.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=plan9 GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-plan9-arm.tar.gz lf --remove-files
|
||||
if test -n "$ERRORS"; then
|
||||
printf "\ngen/xbuild.sh: some targets failed to compile.\n"
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,10 +1,18 @@
|
||||
module github.com/gokcehan/lf
|
||||
|
||||
go 1.12
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gdamore/tcell/v2 v2.3.1
|
||||
github.com/mattn/go-runewidth v0.0.10
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d
|
||||
gopkg.in/djherbis/times.v1 v1.2.0
|
||||
github.com/djherbis/times v1.5.0
|
||||
github.com/gdamore/tcell/v2 v2.6.0
|
||||
github.com/mattn/go-runewidth v0.0.15
|
||||
golang.org/x/sys v0.12.0
|
||||
golang.org/x/term v0.12.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gdamore/encoding v1.0.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/rivo/uniseg v0.4.3 // indirect
|
||||
golang.org/x/text v0.7.0 // indirect
|
||||
)
|
||||
@@ -1,19 +1,45 @@
|
||||
github.com/djherbis/times v1.5.0 h1:79myA211VwPhFTqUk8xehWrsEO+zcIZj0zT8mXPVARU=
|
||||
github.com/djherbis/times v1.5.0/go.mod h1:5q7FDLvbNg1L/KaBmPcWlVR9NmoKo3+ucqUA3ijQhA0=
|
||||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||
github.com/gdamore/tcell/v2 v2.3.1 h1:htEXmKMzurgcnNH3VqQA7GYlCpdl9LCSNpzFpZOKhJE=
|
||||
github.com/gdamore/tcell/v2 v2.3.1/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
|
||||
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
|
||||
github.com/gdamore/tcell/v2 v2.6.0 h1:OKbluoP9VYmJwZwq/iLb4BxwKcwGthaa1YNBJIyCySg=
|
||||
github.com/gdamore/tcell/v2 v2.6.0/go.mod h1:be9omFATkdr0D9qewWW3d+MEvl5dha+Etb5y65J2H8Y=
|
||||
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/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
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.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
|
||||
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
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-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
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-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
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/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/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
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-20220722155257-8c9f86f7a55f/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.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
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.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
|
||||
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM=
|
||||
gopkg.in/djherbis/times.v1 v1.2.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8=
|
||||
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.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@@ -13,20 +13,20 @@ func parseIcons() iconMap {
|
||||
im := make(iconMap)
|
||||
|
||||
defaultIcons := []string{
|
||||
"fi=🗎",
|
||||
"di=🗀",
|
||||
"ln=🗎",
|
||||
"pi=🗎",
|
||||
"so=🗎",
|
||||
"bd=🗎",
|
||||
"cd=🗎",
|
||||
"or=🗎",
|
||||
"su=🗎",
|
||||
"sg=🗎",
|
||||
"tw=🗀",
|
||||
"ow=🗀",
|
||||
"st=🗀",
|
||||
"ex=🗎",
|
||||
"ln=l",
|
||||
"or=l",
|
||||
"tw=t",
|
||||
"ow=d",
|
||||
"st=t",
|
||||
"di=d",
|
||||
"pi=p",
|
||||
"so=s",
|
||||
"bd=b",
|
||||
"cd=c",
|
||||
"su=u",
|
||||
"sg=g",
|
||||
"ex=x",
|
||||
"fi=-",
|
||||
}
|
||||
|
||||
im.parseEnv(strings.Join(defaultIcons, ":"))
|
||||
@@ -35,9 +35,44 @@ func parseIcons() iconMap {
|
||||
im.parseEnv(env)
|
||||
}
|
||||
|
||||
for _, path := range gIconsPaths {
|
||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||
im.parseFile(path)
|
||||
}
|
||||
}
|
||||
|
||||
return im
|
||||
}
|
||||
|
||||
func (im iconMap) parseFile(path string) {
|
||||
log.Printf("reading file: %s", path)
|
||||
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Printf("opening icons file: %s", err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
pairs, err := readPairs(f)
|
||||
if err != nil {
|
||||
log.Printf("reading icons file: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, pair := range pairs {
|
||||
key, val := pair[0], pair[1]
|
||||
|
||||
key = replaceTilde(key)
|
||||
|
||||
if filepath.IsAbs(key) {
|
||||
key = filepath.Clean(key)
|
||||
}
|
||||
|
||||
im[key] = val
|
||||
}
|
||||
}
|
||||
|
||||
func (im iconMap) parseEnv(env string) {
|
||||
for _, entry := range strings.Split(env, ":") {
|
||||
if entry == "" {
|
||||
@@ -113,11 +148,15 @@ func (im iconMap) get(f *file) string {
|
||||
return val
|
||||
}
|
||||
|
||||
if val, ok := im["*"+f.Name()]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
if val, ok := im[filepath.Base(f.Name())+".*"]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
if val, ok := im["*"+f.ext]; ok {
|
||||
if val, ok := im["*"+strings.ToLower(f.ext)]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
|
||||
@@ -22,19 +22,20 @@ var (
|
||||
type arrayFlag []string
|
||||
|
||||
var (
|
||||
gSingleMode bool
|
||||
gClientID int
|
||||
gHostname string
|
||||
gLastDirPath string
|
||||
gSelectionPath string
|
||||
gSocketProt string
|
||||
gSocketPath string
|
||||
gLogPath string
|
||||
gServerLogPath string
|
||||
gSelect string
|
||||
gConfigPath string
|
||||
gCommands arrayFlag
|
||||
gVersion string
|
||||
gSingleMode bool
|
||||
gPrintLastDir bool
|
||||
gPrintSelection bool
|
||||
gClientID int
|
||||
gHostname string
|
||||
gLastDirPath string
|
||||
gSelectionPath string
|
||||
gSocketProt string
|
||||
gSocketPath string
|
||||
gLogPath string
|
||||
gSelect string
|
||||
gConfigPath string
|
||||
gCommands arrayFlag
|
||||
gVersion string
|
||||
)
|
||||
|
||||
func (a *arrayFlag) Set(v string) error {
|
||||
@@ -68,7 +69,7 @@ func exportEnvVars() {
|
||||
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
fmt.Fprintf(os.Stderr, "getting current directory: %s\n", err)
|
||||
}
|
||||
os.Setenv("OLDPWD", dir)
|
||||
|
||||
@@ -80,6 +81,13 @@ func exportEnvVars() {
|
||||
level++
|
||||
|
||||
os.Setenv("LF_LEVEL", strconv.Itoa(level))
|
||||
|
||||
lfPath, err := os.Executable()
|
||||
if err != nil {
|
||||
log.Printf("getting path to lf binary: %s", err)
|
||||
lfPath = "lf"
|
||||
}
|
||||
os.Setenv("lf", quoteString(lfPath))
|
||||
}
|
||||
|
||||
// used by exportOpts below
|
||||
@@ -109,13 +117,14 @@ func fieldToString(field reflect.Value) string {
|
||||
return value
|
||||
}
|
||||
|
||||
func exportOpts() {
|
||||
e := reflect.ValueOf(&gOpts).Elem()
|
||||
func getOptsMap() map[string]string {
|
||||
opts := make(map[string]string)
|
||||
v := reflect.ValueOf(gOpts)
|
||||
t := v.Type()
|
||||
|
||||
for i := 0; i < e.NumField(); i++ {
|
||||
// Get name and prefix it with lf_
|
||||
name := e.Type().Field(i).Name
|
||||
name = fmt.Sprintf("lf_%s", name)
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// Get field name and prefix it with lf_
|
||||
name := "lf_" + t.Field(i).Name
|
||||
|
||||
// Skip maps
|
||||
if name == "lf_keys" || name == "lf_cmdkeys" || name == "lf_cmds" {
|
||||
@@ -143,23 +152,27 @@ func exportOpts() {
|
||||
sortby = "ext"
|
||||
}
|
||||
|
||||
os.Setenv("lf_sortby", sortby)
|
||||
|
||||
reverse := strconv.FormatBool(gOpts.sortType.option&reverseSort != 0)
|
||||
os.Setenv("lf_reverse", reverse)
|
||||
|
||||
hidden := strconv.FormatBool(gOpts.sortType.option&hiddenSort != 0)
|
||||
os.Setenv("lf_hidden", hidden)
|
||||
|
||||
dirfirst := strconv.FormatBool(gOpts.sortType.option&dirfirstSort != 0)
|
||||
os.Setenv("lf_dirfirst", dirfirst)
|
||||
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
|
||||
for key, value := range gOpts.user {
|
||||
opts[name+"_"+key] = value
|
||||
}
|
||||
} else {
|
||||
field := e.Field(i)
|
||||
value := fieldToString(field)
|
||||
|
||||
os.Setenv(name, value)
|
||||
opts[name] = fieldToString(v.Field(i))
|
||||
}
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
func exportOpts() {
|
||||
for key, value := range getOptsMap() {
|
||||
os.Setenv(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
@@ -185,6 +198,18 @@ func checkServer() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = func() {
|
||||
f := flag.CommandLine.Output()
|
||||
fmt.Fprintln(f, "lf - Terminal file manager")
|
||||
fmt.Fprintln(f, "")
|
||||
fmt.Fprintf(f, "Usage: %s [options] [cd-or-select-path]\n\n", os.Args[0])
|
||||
fmt.Fprintln(f, " cd-or-select-path")
|
||||
fmt.Fprintln(f, " set the initial dir or file selection to the given argument")
|
||||
fmt.Fprintln(f, "")
|
||||
fmt.Fprintln(f, "Options:")
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
showDoc := flag.Bool(
|
||||
"doc",
|
||||
false,
|
||||
@@ -205,6 +230,16 @@ func main() {
|
||||
false,
|
||||
"start a client without server")
|
||||
|
||||
printLastDir := flag.Bool(
|
||||
"print-last-dir",
|
||||
false,
|
||||
"print the last dir to stdout on exit (to use for cd)")
|
||||
|
||||
printSelection := flag.Bool(
|
||||
"print-selection",
|
||||
false,
|
||||
"print the selected files to stdout on open (to use as open file dialog)")
|
||||
|
||||
remoteCmd := flag.String(
|
||||
"remote",
|
||||
"",
|
||||
@@ -239,6 +274,11 @@ func main() {
|
||||
"command",
|
||||
"command to execute on client initialization")
|
||||
|
||||
flag.StringVar(&gLogPath,
|
||||
"log",
|
||||
"",
|
||||
"path to the log file to write messages")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
gSocketProt = gDefaultSocketProt
|
||||
@@ -265,23 +305,32 @@ func main() {
|
||||
log.Fatalf("remote command: %s", err)
|
||||
}
|
||||
case *serverMode:
|
||||
if gLogPath != "" && !filepath.IsAbs(gLogPath) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatalf("getting current directory: %s", err)
|
||||
} else {
|
||||
gLogPath = filepath.Join(wd, gLogPath)
|
||||
}
|
||||
}
|
||||
os.Chdir(gUser.HomeDir)
|
||||
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
|
||||
serve()
|
||||
default:
|
||||
gSingleMode = *singleMode
|
||||
gPrintLastDir = *printLastDir
|
||||
gPrintSelection = *printSelection
|
||||
|
||||
if !gSingleMode {
|
||||
checkServer()
|
||||
}
|
||||
|
||||
gClientID = os.Getpid()
|
||||
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
|
||||
|
||||
switch flag.NArg() {
|
||||
case 0:
|
||||
_, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
fmt.Fprintf(os.Stderr, "getting current directory: %s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
case 1:
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -29,23 +31,39 @@ func runeSliceWidth(rs []rune) int {
|
||||
}
|
||||
|
||||
func runeSliceWidthRange(rs []rune, beg, end int) []rune {
|
||||
if beg == end {
|
||||
return []rune{}
|
||||
}
|
||||
|
||||
curr := 0
|
||||
b := 0
|
||||
foundb := false
|
||||
for i, r := range rs {
|
||||
w := runewidth.RuneWidth(r)
|
||||
switch {
|
||||
case curr == beg:
|
||||
if curr >= beg && !foundb {
|
||||
b = i
|
||||
case curr < beg && curr+w > beg:
|
||||
b = i + 1
|
||||
case curr == end:
|
||||
foundb = true
|
||||
}
|
||||
if curr == end || curr+w > end {
|
||||
return rs[b:i]
|
||||
case curr > end:
|
||||
return rs[b : i-1]
|
||||
}
|
||||
curr += w
|
||||
}
|
||||
return nil
|
||||
|
||||
return rs[b:]
|
||||
}
|
||||
|
||||
// Returns the last runes of `rs` that take up at most `maxWidth` space.
|
||||
func runeSliceWidthLastRange(rs []rune, maxWidth int) []rune {
|
||||
lastWidth := 0
|
||||
for i := len(rs) - 1; i >= 0; i-- {
|
||||
w := runewidth.RuneWidth(rs[i])
|
||||
if lastWidth+w > maxWidth {
|
||||
return rs[i+1:]
|
||||
}
|
||||
lastWidth += w
|
||||
}
|
||||
return rs
|
||||
}
|
||||
|
||||
// This function is used to escape whitespaces and special characters with
|
||||
@@ -89,7 +107,7 @@ func unescape(s string) string {
|
||||
}
|
||||
|
||||
// This function splits the given string by whitespaces. It is aware of escaped
|
||||
// whitespaces so that they are not splitted unintentionally.
|
||||
// whitespaces so that they are not split unintentionally.
|
||||
func tokenize(s string) []string {
|
||||
esc := false
|
||||
var buf []rune
|
||||
@@ -133,6 +151,72 @@ func splitWord(s string) (word, rest string) {
|
||||
return
|
||||
}
|
||||
|
||||
// This function reads whitespace separated string pairs at each line. Single
|
||||
// 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
|
||||
// trimmed. Empty lines are skipped.
|
||||
func readPairs(r io.Reader) ([][]string, error) {
|
||||
var pairs [][]string
|
||||
s := bufio.NewScanner(r)
|
||||
for s.Scan() {
|
||||
line := s.Text()
|
||||
|
||||
squote, dquote := false, false
|
||||
for i := 0; i < len(line); i++ {
|
||||
if line[i] == '\'' && !dquote {
|
||||
squote = !squote
|
||||
} else if line[i] == '"' && !squote {
|
||||
dquote = !dquote
|
||||
}
|
||||
if !squote && !dquote && line[i] == '#' {
|
||||
line = line[:i]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
line = strings.TrimSpace(line)
|
||||
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
squote, dquote = false, false
|
||||
pair := strings.FieldsFunc(line, func(r rune) bool {
|
||||
if r == '\'' && !dquote {
|
||||
squote = !squote
|
||||
} else if r == '"' && !squote {
|
||||
dquote = !dquote
|
||||
}
|
||||
return !squote && !dquote && unicode.IsSpace(r)
|
||||
})
|
||||
|
||||
if len(pair) != 2 {
|
||||
return nil, fmt.Errorf("expected pair but found: %s", s.Text())
|
||||
}
|
||||
|
||||
for i := 0; i < len(pair); i++ {
|
||||
squote, dquote = false, false
|
||||
buf := make([]rune, 0, len(pair[i]))
|
||||
for _, r := range pair[i] {
|
||||
if r == '\'' && !dquote {
|
||||
squote = !squote
|
||||
continue
|
||||
}
|
||||
if r == '"' && !squote {
|
||||
dquote = !dquote
|
||||
continue
|
||||
}
|
||||
buf = append(buf, r)
|
||||
}
|
||||
pair[i] = string(buf)
|
||||
}
|
||||
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// This function converts a size in bytes to a human readable form using metric
|
||||
// suffixes (e.g. 1K = 1000). For values less than 10 the first significant
|
||||
// digit is shown, otherwise it is hidden. Numbers are always rounded down.
|
||||
@@ -207,7 +291,8 @@ func naturalLess(s1, s2 string) bool {
|
||||
}
|
||||
}
|
||||
|
||||
var reAltKey = regexp.MustCompile(`<a-(.)>`)
|
||||
var reModKey = regexp.MustCompile(`<(c|s|a)-(.+)>`)
|
||||
var reRulerSub = regexp.MustCompile(`%[apmcsfithd]|%\{[^}]+\}`)
|
||||
|
||||
var reWord = regexp.MustCompile(`(\pL|\pN)+`)
|
||||
var reWordBeg = regexp.MustCompile(`([^\pL\pN]|^)(\pL|\pN)`)
|
||||
@@ -227,10 +312,6 @@ func max(a, b int) int {
|
||||
return b
|
||||
}
|
||||
|
||||
func mod(a, b int) int {
|
||||
return (a%b + b) % b
|
||||
}
|
||||
|
||||
// We don't need no generic code
|
||||
// We don't need no type control
|
||||
// No dark templates in compiler
|
||||
|
||||
+78
-3
@@ -1,13 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsRoot(t *testing.T) {
|
||||
if !isRoot("/") {
|
||||
t.Errorf(`"/" is root`)
|
||||
sep := string(os.PathSeparator)
|
||||
if !isRoot(sep) {
|
||||
t.Errorf(`"%s" is root`, sep)
|
||||
}
|
||||
|
||||
paths := []string{
|
||||
@@ -52,21 +55,71 @@ func TestRuneSliceWidthRange(t *testing.T) {
|
||||
end int
|
||||
exp []rune
|
||||
}{
|
||||
{[]rune{}, 0, 0, []rune{}},
|
||||
{[]rune{'a', 'b', 'c', 'd'}, 1, 3, []rune{'b', 'c'}},
|
||||
{[]rune{'a', 'ı', 'b', 'ş'}, 1, 3, []rune{'ı', 'b'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 2, 6, []rune{'界', '世'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 3, 6, []rune{'世'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 2, 5, []rune{'界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 3, 5, []rune{}},
|
||||
{[]rune{'世', '界', '世', '界'}, 4, 4, []rune{}},
|
||||
{[]rune{'世', '界', '世', '界'}, 5, 5, []rune{}},
|
||||
{[]rune{'世', '界', '世', '界'}, 4, 7, []rune{'世'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 4, 8, []rune{'世', '界'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 2, 5, []rune{'a', '界'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 2, 4, []rune{'a'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 3, 5, []rune{'界'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 3, 4, []rune{}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 3, 3, []rune{}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 4, 4, []rune{}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 4, 6, []rune{'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 5, 6, []rune{'ı'}},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if got := runeSliceWidthRange(test.rs, test.beg, test.end); !reflect.DeepEqual(got, test.exp) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", test.rs, test.rs, got)
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", test.rs, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuneSliceWidthLastRange(t *testing.T) {
|
||||
tests := []struct {
|
||||
rs []rune
|
||||
maxWidth int
|
||||
exp []rune
|
||||
}{
|
||||
{[]rune{}, 0, []rune{}},
|
||||
{[]rune{}, 1, []rune{}},
|
||||
{[]rune{'a', 'ı', 'b', ' '}, 0, []rune{}},
|
||||
{[]rune{'a', 'ı', 'b', ' '}, 1, []rune{' '}},
|
||||
{[]rune{'a', 'ı', 'b', ' '}, 2, []rune{'b', ' '}},
|
||||
{[]rune{'a', 'ı', 'b', ' '}, 3, []rune{'ı', 'b', ' '}},
|
||||
{[]rune{'a', 'ı', 'b', ' '}, 4, []rune{'a', 'ı', 'b', ' '}},
|
||||
{[]rune{'a', 'ı', 'b', ' '}, 5, []rune{'a', 'ı', 'b', ' '}},
|
||||
{[]rune{'世', '界', '世', '界'}, 0, []rune{}},
|
||||
{[]rune{'世', '界', '世', '界'}, 1, []rune{}},
|
||||
{[]rune{'世', '界', '世', '界'}, 2, []rune{'界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 3, []rune{'界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 4, []rune{'世', '界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 5, []rune{'世', '界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 6, []rune{'界', '世', '界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 7, []rune{'界', '世', '界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 8, []rune{'世', '界', '世', '界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 9, []rune{'世', '界', '世', '界'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 0, []rune{}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 1, []rune{'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 2, []rune{'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 3, []rune{'界', 'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 4, []rune{'a', '界', 'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 5, []rune{'a', '界', 'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 6, []rune{'世', 'a', '界', 'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 7, []rune{'世', 'a', '界', 'ı'}},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if got := runeSliceWidthLastRange(test.rs, test.maxWidth); !reflect.DeepEqual(got, test.exp) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", test.rs, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,6 +216,28 @@ func TestSplitWord(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadPairs(t *testing.T) {
|
||||
tests := []struct {
|
||||
s string
|
||||
exp [][]string
|
||||
}{
|
||||
{"foo bar", [][]string{{"foo", "bar"}}},
|
||||
{"foo bar ", [][]string{{"foo", "bar"}}},
|
||||
{" foo bar", [][]string{{"foo", "bar"}}},
|
||||
{" foo bar ", [][]string{{"foo", "bar"}}},
|
||||
{"foo bar#baz", [][]string{{"foo", "bar"}}},
|
||||
{"foo bar #baz", [][]string{{"foo", "bar"}}},
|
||||
{`'foo#baz' bar`, [][]string{{"foo#baz", "bar"}}},
|
||||
{`"foo#baz" bar`, [][]string{{"foo#baz", "bar"}}},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if got, _ := readPairs(strings.NewReader(test.s)); !reflect.DeepEqual(got, test.exp) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHumanize(t *testing.T) {
|
||||
tests := []struct {
|
||||
i int64
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
type sortMethod byte
|
||||
|
||||
@@ -28,49 +31,154 @@ type sortType struct {
|
||||
}
|
||||
|
||||
var gOpts struct {
|
||||
anchorfind bool
|
||||
autoquit bool
|
||||
dircache bool
|
||||
dircounts bool
|
||||
dironly bool
|
||||
drawbox bool
|
||||
globsearch bool
|
||||
icons bool
|
||||
ignorecase bool
|
||||
ignoredia bool
|
||||
incfilter bool
|
||||
incsearch bool
|
||||
mouse bool
|
||||
number bool
|
||||
preview bool
|
||||
relativenumber bool
|
||||
smartcase bool
|
||||
smartdia bool
|
||||
waitmsg string
|
||||
wrapscan bool
|
||||
wrapscroll bool
|
||||
findlen int
|
||||
period int
|
||||
scrolloff int
|
||||
tabstop int
|
||||
errorfmt string
|
||||
filesep string
|
||||
ifs string
|
||||
previewer string
|
||||
cleaner string
|
||||
promptfmt string
|
||||
shell string
|
||||
shellflag string
|
||||
timefmt string
|
||||
truncatechar string
|
||||
ratios []int
|
||||
hiddenfiles []string
|
||||
info []string
|
||||
shellopts []string
|
||||
keys map[string]expr
|
||||
cmdkeys map[string]expr
|
||||
cmds map[string]expr
|
||||
sortType sortType
|
||||
anchorfind bool
|
||||
autoquit bool
|
||||
borderfmt string
|
||||
cursoractivefmt string
|
||||
cursorparentfmt string
|
||||
cursorpreviewfmt string
|
||||
dircache bool
|
||||
dircounts bool
|
||||
dironly bool
|
||||
dirpreviews bool
|
||||
drawbox bool
|
||||
dupfilefmt string
|
||||
globsearch bool
|
||||
icons bool
|
||||
ignorecase bool
|
||||
ignoredia bool
|
||||
incfilter bool
|
||||
incsearch bool
|
||||
mouse bool
|
||||
number bool
|
||||
preview bool
|
||||
sixel bool
|
||||
relativenumber bool
|
||||
smartcase bool
|
||||
smartdia bool
|
||||
waitmsg string
|
||||
wrapscan bool
|
||||
wrapscroll bool
|
||||
findlen int
|
||||
period int
|
||||
scrolloff int
|
||||
tabstop int
|
||||
errorfmt string
|
||||
filesep string
|
||||
ifs string
|
||||
previewer string
|
||||
cleaner string
|
||||
promptfmt string
|
||||
selmode string
|
||||
shell string
|
||||
shellflag string
|
||||
statfmt string
|
||||
timefmt string
|
||||
infotimefmtnew string
|
||||
infotimefmtold string
|
||||
truncatechar string
|
||||
truncatepct int
|
||||
ratios []int
|
||||
hiddenfiles []string
|
||||
history bool
|
||||
info []string
|
||||
ruler []string
|
||||
rulerfmt string
|
||||
preserve []string
|
||||
shellopts []string
|
||||
keys map[string]expr
|
||||
cmdkeys map[string]expr
|
||||
cmds map[string]expr
|
||||
user map[string]string
|
||||
sortType sortType
|
||||
tempmarks string
|
||||
numberfmt string
|
||||
tagfmt string
|
||||
}
|
||||
|
||||
var gLocalOpts struct {
|
||||
sortMethods map[string]sortMethod
|
||||
dirfirsts map[string]bool
|
||||
dironlys map[string]bool
|
||||
hiddens map[string]bool
|
||||
reverses map[string]bool
|
||||
infos map[string][]string
|
||||
}
|
||||
|
||||
func localOptPaths(path string) []string {
|
||||
var list []string
|
||||
list = append(list, path)
|
||||
for curr := path; !isRoot(curr); curr = filepath.Dir(curr) {
|
||||
list = append(list, curr+string(filepath.Separator))
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func getSortMethod(path string) sortMethod {
|
||||
for _, key := range localOptPaths(path) {
|
||||
if val, ok := gLocalOpts.sortMethods[key]; ok {
|
||||
return val
|
||||
}
|
||||
}
|
||||
return gOpts.sortType.method
|
||||
}
|
||||
|
||||
func getSortType(path string) sortType {
|
||||
method := getSortMethod(path)
|
||||
option := gOpts.sortType.option
|
||||
for _, key := range localOptPaths(path) {
|
||||
if val, ok := gLocalOpts.dirfirsts[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
|
||||
}
|
||||
|
||||
func getDirOnly(path string) bool {
|
||||
for _, key := range localOptPaths(path) {
|
||||
if val, ok := gLocalOpts.dironlys[key]; ok {
|
||||
return val
|
||||
}
|
||||
}
|
||||
return gOpts.dironly
|
||||
}
|
||||
|
||||
func getInfo(path string) []string {
|
||||
for _, key := range localOptPaths(path) {
|
||||
if val, ok := gLocalOpts.infos[key]; ok {
|
||||
return val
|
||||
}
|
||||
}
|
||||
return gOpts.info
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -79,7 +187,13 @@ func init() {
|
||||
gOpts.dircache = true
|
||||
gOpts.dircounts = false
|
||||
gOpts.dironly = false
|
||||
gOpts.dirpreviews = false
|
||||
gOpts.drawbox = false
|
||||
gOpts.dupfilefmt = "%f.~%n~"
|
||||
gOpts.borderfmt = "\033[0m"
|
||||
gOpts.cursoractivefmt = "\033[7m"
|
||||
gOpts.cursorparentfmt = "\033[7m"
|
||||
gOpts.cursorpreviewfmt = "\033[4m"
|
||||
gOpts.globsearch = false
|
||||
gOpts.icons = false
|
||||
gOpts.ignorecase = true
|
||||
@@ -89,6 +203,7 @@ func init() {
|
||||
gOpts.mouse = false
|
||||
gOpts.number = false
|
||||
gOpts.preview = true
|
||||
gOpts.sixel = false
|
||||
gOpts.relativenumber = false
|
||||
gOpts.smartcase = true
|
||||
gOpts.smartdia = false
|
||||
@@ -99,34 +214,52 @@ func init() {
|
||||
gOpts.period = 0
|
||||
gOpts.scrolloff = 0
|
||||
gOpts.tabstop = 8
|
||||
gOpts.errorfmt = "\033[7;31;47m%s\033[0m"
|
||||
gOpts.errorfmt = "\033[7;31;47m"
|
||||
gOpts.filesep = "\n"
|
||||
gOpts.ifs = ""
|
||||
gOpts.previewer = ""
|
||||
gOpts.cleaner = ""
|
||||
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"
|
||||
gOpts.selmode = "all"
|
||||
gOpts.shell = gDefaultShell
|
||||
gOpts.shellflag = gDefaultShellFlag
|
||||
gOpts.statfmt = "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l"
|
||||
gOpts.timefmt = time.ANSIC
|
||||
gOpts.infotimefmtnew = "Jan _2 15:04"
|
||||
gOpts.infotimefmtold = "Jan _2 2006"
|
||||
gOpts.truncatechar = "~"
|
||||
gOpts.truncatepct = 100
|
||||
gOpts.ratios = []int{1, 2, 3}
|
||||
gOpts.hiddenfiles = []string{".*"}
|
||||
gOpts.history = true
|
||||
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.preserve = []string{"mode"}
|
||||
gOpts.shellopts = nil
|
||||
gOpts.sortType = sortType{naturalSort, dirfirstSort}
|
||||
gOpts.tempmarks = "'"
|
||||
gOpts.numberfmt = "\033[33m"
|
||||
gOpts.tagfmt = "\033[31m"
|
||||
|
||||
gOpts.keys = make(map[string]expr)
|
||||
|
||||
gOpts.keys["k"] = &callExpr{"up", nil, 1}
|
||||
gOpts.keys["<up>"] = &callExpr{"up", nil, 1}
|
||||
gOpts.keys["<m-up>"] = &callExpr{"up", nil, 1}
|
||||
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil, 1}
|
||||
gOpts.keys["<c-b>"] = &callExpr{"page-up", nil, 1}
|
||||
gOpts.keys["<pgup>"] = &callExpr{"page-up", nil, 1}
|
||||
gOpts.keys["<c-y>"] = &callExpr{"scroll-up", nil, 1}
|
||||
gOpts.keys["<c-m-up>"] = &callExpr{"scroll-up", nil, 1}
|
||||
gOpts.keys["j"] = &callExpr{"down", nil, 1}
|
||||
gOpts.keys["<down>"] = &callExpr{"down", nil, 1}
|
||||
gOpts.keys["<m-down>"] = &callExpr{"down", nil, 1}
|
||||
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil, 1}
|
||||
gOpts.keys["<c-f>"] = &callExpr{"page-down", nil, 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}
|
||||
@@ -136,7 +269,13 @@ func init() {
|
||||
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}
|
||||
@@ -186,7 +325,9 @@ func init() {
|
||||
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-complete", nil, 1}
|
||||
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil, 1}
|
||||
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil, 1}
|
||||
gOpts.cmdkeys["<down>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||
gOpts.cmdkeys["<up>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil, 1}
|
||||
gOpts.cmdkeys["<c-d>"] = &callExpr{"cmd-delete", nil, 1}
|
||||
@@ -210,11 +351,21 @@ func init() {
|
||||
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.user = make(map[string]string)
|
||||
|
||||
gLocalOpts.sortMethods = make(map[string]sortMethod)
|
||||
gLocalOpts.dirfirsts = make(map[string]bool)
|
||||
gLocalOpts.dironlys = make(map[string]bool)
|
||||
gLocalOpts.hiddens = make(map[string]bool)
|
||||
gLocalOpts.reverses = make(map[string]bool)
|
||||
gLocalOpts.infos = make(map[string][]string)
|
||||
|
||||
setDefaults()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build !windows
|
||||
//go:build !windows
|
||||
|
||||
package main
|
||||
|
||||
@@ -12,11 +12,13 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var (
|
||||
envOpener = os.Getenv("OPENER")
|
||||
envEditor = os.Getenv("EDITOR")
|
||||
envEditor = os.Getenv("VISUAL")
|
||||
envPager = os.Getenv("PAGER")
|
||||
envShell = os.Getenv("SHELL")
|
||||
)
|
||||
@@ -31,8 +33,11 @@ var (
|
||||
var (
|
||||
gUser *user.User
|
||||
gConfigPaths []string
|
||||
gColorsPaths []string
|
||||
gIconsPaths []string
|
||||
gFilesPath string
|
||||
gMarksPath string
|
||||
gTagsPath string
|
||||
gHistoryPath string
|
||||
)
|
||||
|
||||
@@ -46,7 +51,10 @@ func init() {
|
||||
}
|
||||
|
||||
if envEditor == "" {
|
||||
envEditor = "vi"
|
||||
envEditor = os.Getenv("EDITOR")
|
||||
if envEditor == "" {
|
||||
envEditor = "vi"
|
||||
}
|
||||
}
|
||||
|
||||
if envPager == "" {
|
||||
@@ -59,17 +67,27 @@ func init() {
|
||||
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
// When the user is not in /etc/passwd (for e.g. LDAP) and CGO_ENABLED=1 in go env,
|
||||
// the cgo implementation of user.Current() fails even when HOME and USER are set.
|
||||
|
||||
log.Printf("user: %s", err)
|
||||
if os.Getenv("HOME") == "" {
|
||||
log.Print("$HOME variable is empty or not set")
|
||||
panic("$HOME variable is empty or not set")
|
||||
}
|
||||
if os.Getenv("USER") == "" {
|
||||
log.Print("$USER variable is empty or not set")
|
||||
panic("$USER variable is empty or not set")
|
||||
}
|
||||
u = &user.User{
|
||||
Username: os.Getenv("USER"),
|
||||
HomeDir: os.Getenv("HOME"),
|
||||
}
|
||||
}
|
||||
gUser = u
|
||||
|
||||
config := os.Getenv("XDG_CONFIG_HOME")
|
||||
config := os.Getenv("LF_CONFIG_HOME")
|
||||
if config == "" {
|
||||
config = os.Getenv("XDG_CONFIG_HOME")
|
||||
}
|
||||
if config == "" {
|
||||
config = filepath.Join(gUser.HomeDir, ".config")
|
||||
}
|
||||
@@ -79,21 +97,40 @@ func init() {
|
||||
filepath.Join(config, "lf", "lfrc"),
|
||||
}
|
||||
|
||||
data := os.Getenv("XDG_DATA_HOME")
|
||||
gColorsPaths = []string{
|
||||
filepath.Join("/etc", "lf", "colors"),
|
||||
filepath.Join(config, "lf", "colors"),
|
||||
}
|
||||
|
||||
gIconsPaths = []string{
|
||||
filepath.Join("/etc", "lf", "icons"),
|
||||
filepath.Join(config, "lf", "icons"),
|
||||
}
|
||||
|
||||
data := os.Getenv("LF_DATA_HOME")
|
||||
if data == "" {
|
||||
data = os.Getenv("XDG_DATA_HOME")
|
||||
}
|
||||
if data == "" {
|
||||
data = filepath.Join(gUser.HomeDir, ".local", "share")
|
||||
}
|
||||
|
||||
gFilesPath = filepath.Join(data, "lf", "files")
|
||||
gMarksPath = filepath.Join(data, "lf", "marks")
|
||||
gTagsPath = filepath.Join(data, "lf", "tags")
|
||||
gHistoryPath = filepath.Join(data, "lf", "history")
|
||||
|
||||
gDefaultSocketPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.sock", gUser.Username))
|
||||
runtime := os.Getenv("XDG_RUNTIME_DIR")
|
||||
if runtime == "" {
|
||||
runtime = os.TempDir()
|
||||
}
|
||||
|
||||
gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username))
|
||||
}
|
||||
|
||||
func detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||
cmd := exec.Command(name, arg...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
||||
cmd.SysProcAttr = &unix.SysProcAttr{Setsid: true}
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -109,14 +146,38 @@ func shellCommand(s string, args []string) *exec.Cmd {
|
||||
return exec.Command(gOpts.shell, args...)
|
||||
}
|
||||
|
||||
func shellSetPG(cmd *exec.Cmd) {
|
||||
cmd.SysProcAttr = &unix.SysProcAttr{Setpgid: true}
|
||||
}
|
||||
|
||||
func shellKill(cmd *exec.Cmd) error {
|
||||
pgid, err := unix.Getpgid(cmd.Process.Pid)
|
||||
if err == nil && cmd.Process.Pid == pgid {
|
||||
// kill the process group
|
||||
err = unix.Kill(-pgid, 15)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return cmd.Process.Kill()
|
||||
}
|
||||
|
||||
func setDefaults() {
|
||||
gOpts.cmds["open"] = &execExpr{"&", `$OPENER "$f"`}
|
||||
gOpts.keys["e"] = &execExpr{"$", `$EDITOR "$f"`}
|
||||
gOpts.keys["i"] = &execExpr{"$", `$PAGER "$f"`}
|
||||
gOpts.keys["w"] = &execExpr{"$", "$SHELL"}
|
||||
|
||||
gOpts.cmds["doc"] = &execExpr{"$", "lf -doc | $PAGER"}
|
||||
gOpts.cmds["doc"] = &execExpr{"$", `"$lf" -doc | $PAGER`}
|
||||
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||
|
||||
gOpts.cmds["maps"] = &execExpr{"$", `"$lf" -remote "query $id maps" | $PAGER`}
|
||||
gOpts.cmds["cmaps"] = &execExpr{"$", `"$lf" -remote "query $id cmaps" | $PAGER`}
|
||||
gOpts.cmds["cmds"] = &execExpr{"$", `"$lf" -remote "query $id cmds" | $PAGER`}
|
||||
}
|
||||
|
||||
func setUserUmask() {
|
||||
unix.Umask(0077)
|
||||
}
|
||||
|
||||
func isExecutable(f os.FileInfo) bool {
|
||||
@@ -139,7 +200,7 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
|
||||
func userName(f os.FileInfo) string {
|
||||
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
||||
if u, err := user.LookupId(fmt.Sprint(stat.Uid)); err == nil {
|
||||
return fmt.Sprintf("%v ", u.Username)
|
||||
return u.Username
|
||||
}
|
||||
}
|
||||
return ""
|
||||
@@ -148,7 +209,7 @@ func userName(f os.FileInfo) string {
|
||||
func groupName(f os.FileInfo) string {
|
||||
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
||||
if g, err := user.LookupGroupId(fmt.Sprint(stat.Gid)); err == nil {
|
||||
return fmt.Sprintf("%v ", g.Name)
|
||||
return g.Name
|
||||
}
|
||||
}
|
||||
return ""
|
||||
@@ -156,41 +217,15 @@ func groupName(f os.FileInfo) string {
|
||||
|
||||
func linkCount(f os.FileInfo) string {
|
||||
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
||||
return fmt.Sprintf("%v ", stat.Nlink)
|
||||
return fmt.Sprint(stat.Nlink)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func matchPattern(pattern, name, path string) bool {
|
||||
s := name
|
||||
|
||||
pattern = replaceTilde(pattern)
|
||||
|
||||
if filepath.IsAbs(pattern) {
|
||||
s = filepath.Join(path, name)
|
||||
}
|
||||
|
||||
// pattern errors are checked when 'hiddenfiles' option is set
|
||||
matched, _ := filepath.Match(pattern, s)
|
||||
|
||||
return matched
|
||||
}
|
||||
|
||||
func errCrossDevice(err error) bool {
|
||||
return err.(*os.LinkError).Err.(syscall.Errno) == syscall.EXDEV
|
||||
return err.(*os.LinkError).Err.(unix.Errno) == unix.EXDEV
|
||||
}
|
||||
|
||||
func exportFiles(f string, fs []string, pwd string) {
|
||||
envFile := f
|
||||
envFiles := strings.Join(fs, gOpts.filesep)
|
||||
|
||||
os.Setenv("f", envFile)
|
||||
os.Setenv("fs", envFiles)
|
||||
os.Setenv("PWD", pwd)
|
||||
|
||||
if len(fs) == 0 {
|
||||
os.Setenv("fx", envFile)
|
||||
} else {
|
||||
os.Setenv("fx", envFiles)
|
||||
}
|
||||
func quoteString(s string) string {
|
||||
return s
|
||||
}
|
||||
+64
-29
@@ -8,12 +8,13 @@ import (
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var (
|
||||
envOpener = os.Getenv("OPENER")
|
||||
envEditor = os.Getenv("EDITOR")
|
||||
envEditor = os.Getenv("VISUAL")
|
||||
envPager = os.Getenv("PAGER")
|
||||
envShell = os.Getenv("SHELL")
|
||||
)
|
||||
@@ -30,7 +31,10 @@ var (
|
||||
var (
|
||||
gUser *user.User
|
||||
gConfigPaths []string
|
||||
gColorsPaths []string
|
||||
gIconsPaths []string
|
||||
gFilesPath string
|
||||
gTagsPath string
|
||||
gMarksPath string
|
||||
gHistoryPath string
|
||||
)
|
||||
@@ -41,7 +45,10 @@ func init() {
|
||||
}
|
||||
|
||||
if envEditor == "" {
|
||||
envEditor = "notepad"
|
||||
envEditor = os.Getenv("EDITOR")
|
||||
if envEditor == "" {
|
||||
envEditor = "notepad"
|
||||
}
|
||||
}
|
||||
|
||||
if envPager == "" {
|
||||
@@ -61,42 +68,82 @@ func init() {
|
||||
// remove domain prefix
|
||||
gUser.Username = strings.Split(gUser.Username, `\`)[1]
|
||||
|
||||
data := os.Getenv("LOCALAPPDATA")
|
||||
data := os.Getenv("LF_CONFIG_HOME")
|
||||
if data == "" {
|
||||
data = os.Getenv("LOCALAPPDATA")
|
||||
}
|
||||
|
||||
gConfigPaths = []string{
|
||||
filepath.Join(os.Getenv("ProgramData"), "lf", "lfrc"),
|
||||
filepath.Join(data, "lf", "lfrc"),
|
||||
}
|
||||
|
||||
gColorsPaths = []string{
|
||||
filepath.Join(os.Getenv("ProgramData"), "lf", "colors"),
|
||||
filepath.Join(data, "lf", "colors"),
|
||||
}
|
||||
|
||||
gIconsPaths = []string{
|
||||
filepath.Join(os.Getenv("ProgramData"), "lf", "icons"),
|
||||
filepath.Join(data, "lf", "icons"),
|
||||
}
|
||||
|
||||
gFilesPath = filepath.Join(data, "lf", "files")
|
||||
gMarksPath = filepath.Join(data, "lf", "marks")
|
||||
gTagsPath = filepath.Join(data, "lf", "tags")
|
||||
gHistoryPath = filepath.Join(data, "lf", "history")
|
||||
}
|
||||
|
||||
func detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||
cmd := exec.Command(name, arg...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: 8}
|
||||
cmd.SysProcAttr = &windows.SysProcAttr{CreationFlags: 8}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func shellCommand(s string, args []string) *exec.Cmd {
|
||||
// Windows CMD requires special handling to deal with quoted arguments
|
||||
if strings.ToLower(gOpts.shell) == "cmd" {
|
||||
var builder strings.Builder
|
||||
builder.WriteString(s)
|
||||
for _, arg := range args {
|
||||
fmt.Fprintf(&builder, ` "%s"`, arg)
|
||||
}
|
||||
shellOpts := strings.Join(gOpts.shellopts, " ")
|
||||
cmdline := fmt.Sprintf(`%s %s %s "%s"`, gOpts.shell, shellOpts, gOpts.shellflag, builder.String())
|
||||
|
||||
cmd := exec.Command(gOpts.shell)
|
||||
cmd.SysProcAttr = &windows.SysProcAttr{CmdLine: cmdline}
|
||||
return cmd
|
||||
}
|
||||
|
||||
args = append([]string{gOpts.shellflag, s}, args...)
|
||||
|
||||
args = append(gOpts.shellopts, args...)
|
||||
|
||||
return exec.Command(gOpts.shell, args...)
|
||||
}
|
||||
|
||||
func shellSetPG(cmd *exec.Cmd) {
|
||||
}
|
||||
|
||||
func shellKill(cmd *exec.Cmd) error {
|
||||
return cmd.Process.Kill()
|
||||
}
|
||||
|
||||
func setDefaults() {
|
||||
gOpts.cmds["open"] = &execExpr{"&", "%OPENER% %f%"}
|
||||
gOpts.keys["e"] = &execExpr{"$", "%EDITOR% %f%"}
|
||||
gOpts.keys["i"] = &execExpr{"!", "%PAGER% %f%"}
|
||||
gOpts.keys["w"] = &execExpr{"$", "%SHELL%"}
|
||||
|
||||
gOpts.cmds["doc"] = &execExpr{"!", "lf -doc | %PAGER%"}
|
||||
gOpts.cmds["doc"] = &execExpr{"!", "%lf% -doc | %PAGER%"}
|
||||
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||
|
||||
gOpts.cmds["maps"] = &execExpr{"!", `%lf% -remote "query %id% maps" | %PAGER%`}
|
||||
gOpts.cmds["cmaps"] = &execExpr{"!", `%lf% -remote "query %id% cmaps" | %PAGER%`}
|
||||
gOpts.cmds["cmds"] = &execExpr{"!", `%lf% -remote "query %id% cmds" | %PAGER%`}
|
||||
}
|
||||
|
||||
func setUserUmask() {}
|
||||
|
||||
func isExecutable(f os.FileInfo) bool {
|
||||
exts := strings.Split(envPathExt, string(filepath.ListSeparator))
|
||||
for _, e := range exts {
|
||||
@@ -109,15 +156,15 @@ func isExecutable(f os.FileInfo) bool {
|
||||
}
|
||||
|
||||
func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
|
||||
ptr, err := syscall.UTF16PtrFromString(filepath.Join(path, f.Name()))
|
||||
ptr, err := windows.UTF16PtrFromString(filepath.Join(path, f.Name()))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
attrs, err := syscall.GetFileAttributes(ptr)
|
||||
attrs, err := windows.GetFileAttributes(ptr)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return attrs&syscall.FILE_ATTRIBUTE_HIDDEN != 0
|
||||
return attrs&windows.FILE_ATTRIBUTE_HIDDEN != 0
|
||||
}
|
||||
|
||||
func userName(f os.FileInfo) string {
|
||||
@@ -133,25 +180,13 @@ func linkCount(f os.FileInfo) string {
|
||||
}
|
||||
|
||||
func errCrossDevice(err error) bool {
|
||||
return err.(*os.LinkError).Err.(syscall.Errno) == 17
|
||||
return err.(*os.LinkError).Err.(windows.Errno) == 17
|
||||
}
|
||||
|
||||
func exportFiles(f string, fs []string, pwd string) {
|
||||
envFile := fmt.Sprintf(`"%s"`, f)
|
||||
|
||||
var quotedFiles []string
|
||||
for _, f := range fs {
|
||||
quotedFiles = append(quotedFiles, fmt.Sprintf(`"%s"`, f))
|
||||
}
|
||||
envFiles := strings.Join(quotedFiles, gOpts.filesep)
|
||||
|
||||
os.Setenv("f", envFile)
|
||||
os.Setenv("fs", envFiles)
|
||||
os.Setenv("PWD", pwd)
|
||||
|
||||
if len(fs) == 0 {
|
||||
os.Setenv("fx", envFile)
|
||||
} else {
|
||||
os.Setenv("fx", envFiles)
|
||||
func quoteString(s string) string {
|
||||
// Windows CMD requires special handling to deal with quoted arguments
|
||||
if strings.ToLower(gOpts.shell) == "cmd" {
|
||||
return fmt.Sprintf(`"%s"`, s)
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -2,34 +2,37 @@ package main
|
||||
|
||||
// Grammar of the language used in the evaluator
|
||||
//
|
||||
// Expr = SetExpr
|
||||
// | MapExpr
|
||||
// | CMapExpr
|
||||
// | CmdExpr
|
||||
// | CallExpr
|
||||
// | ExecExpr
|
||||
// | ListExpr
|
||||
// Expr = SetExpr
|
||||
// | SetLocalExpr
|
||||
// | MapExpr
|
||||
// | CMapExpr
|
||||
// | CmdExpr
|
||||
// | CallExpr
|
||||
// | ExecExpr
|
||||
// | ListExpr
|
||||
//
|
||||
// SetExpr = 'set' <opt> <val> ';'
|
||||
// SetExpr = 'set' <opt> <val> ';'
|
||||
//
|
||||
// MapExpr = 'map' <keys> Expr
|
||||
// SetLocalExpr = 'setlocal' <dir> <opt> <val> ';'
|
||||
//
|
||||
// CMapExpr = 'cmap' <key> Expr
|
||||
// MapExpr = 'map' <keys> Expr
|
||||
//
|
||||
// CmdExpr = 'cmd' <name> Expr
|
||||
// CMapExpr = 'cmap' <key> Expr
|
||||
//
|
||||
// CallExpr = <name> <args> ';'
|
||||
// CmdExpr = 'cmd' <name> Expr
|
||||
//
|
||||
// ExecExpr = Prefix <value> '\n'
|
||||
// | Prefix '{{' <value> '}}' ';'
|
||||
// CallExpr = <name> <args> ';'
|
||||
//
|
||||
// Prefix = '$' | '%' | '!' | '&'
|
||||
// ExecExpr = Prefix <value> '\n'
|
||||
// | Prefix '{{' <value> '}}' ';'
|
||||
//
|
||||
// ListExpr = ':' Expr ListRest '\n'
|
||||
// | ':' '{{' Expr ListRest '}}' ';'
|
||||
// Prefix = '$' | '%' | '!' | '&'
|
||||
//
|
||||
// ListRest = Nil
|
||||
// | Expr ListExpr
|
||||
// ListExpr = ':' Expr ListRest '\n'
|
||||
// | ':' '{{' Expr ListRest '}}' ';'
|
||||
//
|
||||
// ListRest = Nil
|
||||
// | Expr ListExpr
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -50,6 +53,14 @@ type setExpr struct {
|
||||
|
||||
func (e *setExpr) String() string { return fmt.Sprintf("set %s %s", e.opt, e.val) }
|
||||
|
||||
type setLocalExpr struct {
|
||||
path string
|
||||
opt string
|
||||
val string
|
||||
}
|
||||
|
||||
func (e *setLocalExpr) String() string { return fmt.Sprintf("setlocal %s %s %s", e.path, e.opt, e.val) }
|
||||
|
||||
type mapExpr struct {
|
||||
keys string
|
||||
expr expr
|
||||
@@ -176,6 +187,30 @@ func (p *parser) parseExpr() expr {
|
||||
s.scan()
|
||||
|
||||
result = &setExpr{opt, val}
|
||||
case "setlocal":
|
||||
var val string
|
||||
|
||||
s.scan()
|
||||
if s.typ != tokenIdent {
|
||||
p.err = fmt.Errorf("expected directory: %s", s.tok)
|
||||
}
|
||||
dir := s.tok
|
||||
|
||||
s.scan()
|
||||
if s.typ != tokenIdent {
|
||||
p.err = fmt.Errorf("expected identifier: %s", s.tok)
|
||||
}
|
||||
opt := s.tok
|
||||
|
||||
s.scan()
|
||||
if s.typ != tokenSemicolon {
|
||||
val = s.tok
|
||||
s.scan()
|
||||
}
|
||||
|
||||
s.scan()
|
||||
|
||||
result = &setLocalExpr{dir, opt, val}
|
||||
case "map":
|
||||
var expr expr
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strconv"
|
||||
)
|
||||
@@ -38,7 +37,7 @@ type scanner struct {
|
||||
}
|
||||
|
||||
func newScanner(r io.Reader) *scanner {
|
||||
buf, err := ioutil.ReadAll(r)
|
||||
buf, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
log.Printf("scanning: %s", err)
|
||||
}
|
||||
|
||||
@@ -16,15 +16,21 @@ var (
|
||||
)
|
||||
|
||||
func serve() {
|
||||
f, err := os.Create(gServerLogPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
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)
|
||||
}
|
||||
defer f.Close()
|
||||
log.SetOutput(f)
|
||||
|
||||
log.Print("hi!")
|
||||
|
||||
if gSocketProt == "unix" {
|
||||
setUserUmask()
|
||||
}
|
||||
|
||||
l, err := net.Listen(gSocketProt, gSocketPath)
|
||||
if err != nil {
|
||||
log.Printf("listening socket: %s", err)
|
||||
@@ -55,7 +61,7 @@ func listen(l net.Listener) {
|
||||
|
||||
func echoerr(c net.Conn, msg string) {
|
||||
fmt.Fprintln(c, msg)
|
||||
log.Printf(msg)
|
||||
log.Print(msg)
|
||||
}
|
||||
|
||||
func echoerrf(c net.Conn, format string, a ...interface{}) {
|
||||
@@ -77,7 +83,10 @@ Loop:
|
||||
if err != nil {
|
||||
echoerr(c, "listen: conn: client id should be a number")
|
||||
} else {
|
||||
// lifetime of the connection is managed by the server and
|
||||
// will be cleaned up via the `drop` command
|
||||
gConnList[id] = c
|
||||
return
|
||||
}
|
||||
} else {
|
||||
echoerr(c, "listen: conn: requires a client id")
|
||||
@@ -89,6 +98,9 @@ Loop:
|
||||
if err != nil {
|
||||
echoerr(c, "listen: drop: client id should be a number")
|
||||
} else {
|
||||
if c2, ok := gConnList[id]; ok {
|
||||
c2.Close()
|
||||
}
|
||||
delete(gConnList, id)
|
||||
}
|
||||
} else {
|
||||
@@ -110,6 +122,27 @@ Loop:
|
||||
}
|
||||
}
|
||||
}
|
||||
case "query":
|
||||
if rest == "" {
|
||||
echoerr(c, "listen: query: requires a client id")
|
||||
break
|
||||
}
|
||||
word2, rest2 := splitWord(rest)
|
||||
id, err := strconv.Atoi(word2)
|
||||
if err != nil {
|
||||
echoerr(c, "listen: query: client id should be a number")
|
||||
break
|
||||
}
|
||||
c2, ok := gConnList[id]
|
||||
if !ok {
|
||||
echoerr(c, "listen: query: no such client id is connected")
|
||||
break
|
||||
}
|
||||
fmt.Fprintln(c2, "query "+rest2)
|
||||
s2 := bufio.NewScanner(c2)
|
||||
for s2.Scan() && s2.Text() != "" {
|
||||
fmt.Fprintln(c, s2.Text())
|
||||
}
|
||||
case "quit":
|
||||
if len(gConnList) == 0 {
|
||||
gQuitChan <- struct{}{}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
gSixelBegin = "\033P"
|
||||
gSixelFiller = '\u2000'
|
||||
)
|
||||
|
||||
type sixelScreen struct {
|
||||
xprev, yprev int
|
||||
sixel *string
|
||||
altFill bool
|
||||
lastFile string // TODO maybe use hash of sixels instead to flip altFill
|
||||
}
|
||||
|
||||
func (sxs *sixelScreen) fillerStyle(filePath string) tcell.Style {
|
||||
if sxs.lastFile != filePath {
|
||||
sxs.altFill = !sxs.altFill
|
||||
}
|
||||
|
||||
if sxs.altFill {
|
||||
return tcell.StyleDefault.Bold(true)
|
||||
}
|
||||
return tcell.StyleDefault
|
||||
}
|
||||
|
||||
func (sxs *sixelScreen) showSixels() {
|
||||
if sxs.sixel == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// XXX: workaround for bug where quitting lf might leave the terminal in bold
|
||||
fmt.Print("\033[0m")
|
||||
|
||||
fmt.Print("\0337") // Save cursor position
|
||||
fmt.Printf("\033[%d;%dH", sxs.yprev, sxs.xprev) // Move cursor to position
|
||||
fmt.Print(*sxs.sixel) //
|
||||
fmt.Print("\0338") // Restore cursor position
|
||||
}
|
||||
|
||||
func (sxs *sixelScreen) printSixel(win *win, screen tcell.Screen, reg *reg) {
|
||||
if reg.sixel == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 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.
|
||||
st := sxs.fillerStyle(reg.path)
|
||||
for y := 0; y < win.h; y++ {
|
||||
st = win.print(screen, 0, y, st, strings.Repeat(string(gSixelFiller), win.w))
|
||||
}
|
||||
|
||||
sxs.xprev, sxs.yprev = win.x+1, win.y+1
|
||||
sxs.sixel = reg.sixel
|
||||
}
|
||||
Reference in new issue
Block a user