Compare commits

66 Commits
Author SHA1 Message Date
Gokcehan d26eb0108a update doc 2024-03-31 21:54:18 +02:00
Joe Lim ac016fee16 Skip drawing UI for period timer (#1666) 2024-03-31 21:19:16 +02:00
David Pedersen 702d67575e Ignore extension when renaming directory (#1664) 2024-03-31 21:19:08 +02:00
Joe Lim 1e10e95f4d Revert "Trigger update after copy/move (#1638)" (#1661)
This reverts commit ddcd308614.
2024-03-26 18:52:14 +11:00
dependabot[bot] c9d28f6e9d Bump dominikh/staticcheck-action from 1.3.0 to 1.3.1 (#1658)
Bumps [dominikh/staticcheck-action](https://github.com/dominikh/staticcheck-action) from 1.3.0 to 1.3.1.
- [Release notes](https://github.com/dominikh/staticcheck-action/releases)
- [Changelog](https://github.com/dominikh/staticcheck-action/blob/master/CHANGES.md)
- [Commits](https://github.com/dominikh/staticcheck-action/compare/v1.3.0...v1.3.1)

---
updated-dependencies:
- dependency-name: dominikh/staticcheck-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-25 15:22:44 +11:00
Joe Lim a1edda1f70 Clear only when cut succeeds (#1652) 2024-03-24 20:13:17 +01:00
valoq ddcd308614 Trigger update after copy/move (#1638)
* trigger update after copy/move

* trigger refresh after returnign from shell

* add renew after returning from shell

* move file update
2024-03-24 20:12:47 +01:00
Michael Gallo 951795c789 Directories added to dirChan no longer trigger checkDir (#1607)
* Directories added to dirChan no longer trigger checkDir

removed unneeded blank line

* removed possibly looping checkReg call
2024-03-24 20:12:35 +01:00
dependabot[bot] c19cc15079 Bump softprops/action-gh-release from 1 to 2 (#1633)
Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 1 to 2.
- [Release notes](https://github.com/softprops/action-gh-release/releases)
- [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md)
- [Commits](https://github.com/softprops/action-gh-release/compare/v1...v2)

---
updated-dependencies:
- dependency-name: softprops/action-gh-release
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-24 19:43:41 +01:00
Catalin Ancutei 4b076d199b Fixed tags on windows (#1646)
* Fixed tags on windows

* Use the variable text directly in error message
2024-03-18 10:01:00 +11:00
Joe Lim d2136df538 Clear cached sixels after horizontal resize (#1629) 2024-03-10 13:08:38 +11:00
Joe Lim 44c6aead23 Make documentation generating step optional (#1628) 2024-03-09 19:50:02 +01:00
Nuckle 43c2683ca8 Add more file extensions for docker icon (#1626) 2024-03-06 20:02:14 +01:00
dependabot[bot] d89afb8c7d Bump golang.org/x/term from 0.17.0 to 0.18.0 (#1624)
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.17.0 to 0.18.0.
- [Commits](https://github.com/golang/term/compare/v0.17.0...v0.18.0)

---
updated-dependencies:
- dependency-name: golang.org/x/term
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-05 17:39:36 +11:00
dependabot[bot] 853bcc524b Bump github.com/gdamore/tcell/v2 from 2.7.1 to 2.7.4 (#1621)
Bumps [github.com/gdamore/tcell/v2](https://github.com/gdamore/tcell) from 2.7.1 to 2.7.4.
- [Release notes](https://github.com/gdamore/tcell/releases)
- [Changelog](https://github.com/gdamore/tcell/blob/main/CHANGESv2.md)
- [Commits](https://github.com/gdamore/tcell/compare/v2.7.1...v2.7.4)

---
updated-dependencies:
- dependency-name: github.com/gdamore/tcell/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-04 17:37:37 +11:00
Joe Lim 055ce47224 Fix crash if tags/marks contains invalid entry (#1614)
* Fix crash if tags file contains invalid entry

* Fix crash if marks file contains invalid entry
2024-03-04 10:11:42 +11:00
Catalin Ancutei 8ee8592b91 avoid using the user.Current on windows to avoid slow startup (#1617)
* avoid using the user.Current on windows to avoid slow startup

* formated os_windows.go
2024-03-03 21:31:12 +01:00
dependabot[bot] 0c02239b17 Bump github.com/gdamore/tcell/v2 from 2.7.0 to 2.7.1 (#1608)
Bumps [github.com/gdamore/tcell/v2](https://github.com/gdamore/tcell) from 2.7.0 to 2.7.1.
- [Release notes](https://github.com/gdamore/tcell/releases)
- [Changelog](https://github.com/gdamore/tcell/blob/main/CHANGESv2.md)
- [Commits](https://github.com/gdamore/tcell/compare/v2.7.0...v2.7.1)

---
updated-dependencies:
- dependency-name: github.com/gdamore/tcell/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-20 13:24:29 +11:00
Joe Lim cf996263bb Export mode for use in scripting keybindings (#1594)
* Export mode

* Add pipe mode

* Add documentation
2024-02-12 10:27:57 +11:00
Joe Lim ab54329570 Dynamically generate list of completions (#1595)
* Dynamically generate list of completions

* Update contribution guide

* Add unit tests
2024-02-12 10:19:17 +11:00
Joe Lim ac32468629 Fix tilde expansion when using setlocal (#1596) 2024-02-12 10:13:13 +11:00
dependabot[bot] d654f09885 Bump golang.org/x/term from 0.16.0 to 0.17.0 (#1601)
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.16.0 to 0.17.0.
- [Commits](https://github.com/golang/term/compare/v0.16.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/term
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-08 14:29:23 +11:00
Joe Lim 8374080815 Refactor eval code (#1591)
* 1

* globsearch

* hidden

* some more options

* ignorecase and ignoredia

* fix ignorecase/ignoredia

turns out position and loadfile are required here too since the list of
files can change (similar to hidden option)

* incfilter/incsearch

* mouse

* some more options

* preview

* remaining bool options

* fix more options that can change list of files

* Add applyLocalBoolOpt

* Use applyLocalBoolOpt

* Add position and loadfile fixes
2024-02-05 10:29:19 +11:00
M Bakhtiyar Ali 8bbcbdd0ea Update lfcd.nu to support nushell >= 0.87.0 (#1575)
* Update lfcd.nu to support nushell >= 0.87.0 

Deprecated def-env in favor of def --env
https://www.nushell.sh/blog/2023-11-14-nushell_0_87_0.html#deprecated-commands-toc

* Update lfcd.nu using `-print-last-dir` introduced in #1402
2024-02-04 18:38:12 +01:00
Jan Tatje 2007ae51a1 Fallback to showing UID/GID if user/group lookup fails (#1590)
If you mount a filesystem from another computer then UID/GID might
not be mapped to any user. This changes it so that lf shows the UID
and GID instead of nothing if user/group lookup fails.
2024-02-04 18:34:02 +01:00
Joe Lim 8a14749154 Update generated documentation (#1580) 2024-01-18 14:51:04 +11:00
Joe Lim b401318046 Implement sort options as separate variables (#1577) 2024-01-18 11:15:06 +11:00
Joe Lim 6af25565d4 Simplify eval for tempmarks option (#1571) 2024-01-13 13:40:02 +01:00
Joe Lim ce32bc67b9 Add missing completions for nohistory and history! (#1570) 2024-01-13 13:39:26 +01:00
postsolar 27c71f8210 lf.zsh: make completions complete both lf and lfcd (#1564)
* Leave a note on how to add shell completions for `lfcd` in ZSH

* Revert "Leave a note on how to add shell completions for `lfcd` in ZSH"

@joelim-work suggested a better idea: to make `lf.zsh` complete both `lf` and `lfcd`

This reverts commit c28393dd43.

* Make `lf.zsh` complete both `lf` and `lfcd`
2024-01-08 00:00:25 +11:00
dependabot[bot] 43610eaf40 Bump golang.org/x/term from 0.15.0 to 0.16.0 (#1567)
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.15.0 to 0.16.0.
- [Commits](https://github.com/golang/term/compare/v0.15.0...v0.16.0)

---
updated-dependencies:
- dependency-name: golang.org/x/term
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-05 14:21:51 +11:00
Joe Lim c88b8eaa65 Update documentation contributing guidelines (#1565)
* Update documentation contributing guidelines

* intentional error

* Revert "intentional error"

This reverts commit f77d2466d6.
2024-01-02 10:02:49 +11:00
Joe Lim f8399eb6e0 Allow customization for cut/copy/select colors (#1540)
* Allow customization for cut/copy/select colors

* Add documentation
2024-01-01 06:35:54 +11:00
Christian Zangl 488294588e generate doc with pandoc in docker (#1555) 2023-12-26 16:16:52 +01:00
Joe Lim 27cbf9403c Reload file info after mark-save/mark-remove (#1544) 2023-12-26 15:58:33 +01:00
Joe Lim 12ce649681 Improve refreshing of file statinfo (#1536) 2023-12-26 15:56:20 +01:00
Michael GalloandJoe Lim e1ab72516d sortMethod simplification. (#1535)
* made sortMethod a string enum to reduce comparisons and repetition

* main uses sortmethod directly instead of converting it into a string

* updated sortmethod validity check to no longer require slices package

* Update opts.go

Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com>

---------

Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com>
2023-12-26 15:55:42 +01:00
Joe Lim f13325f78d Use string values for go-version (#1534) 2023-12-26 15:42:08 +01:00
David Pedersen a51462dcb9 Show git commit if version information is missing (#1517)
* Show git commit if version information is missing

* Update version command format
2023-12-26 15:41:15 +01:00
Christian Zangl 075caac3a9 Add hidecursorinactive option to indicate status when terminal loses focus (#965)
* Enable focus events through configuration by using focus (option) and on-ui-enter/on-ui-exit events.

* Revert doc

This reverts commit 77f113639f.

* Revert rune evt

This reverts commit 77f113639f.

* hidecursorinactive with tcell

* cleanup

* cleanup
2023-12-26 15:37:11 +01:00
Matthew Toohey 2a4adb323f continue responding to signals after initial sigint (#1549) 2023-12-16 19:26:16 +11:00
Michael Gallo d8b7df87cb normalize now properly uses boolean parameters (#1526) 2023-12-11 15:51:33 +11:00
Joe Lim ec9bdad90d Fix low/high crash for big scrolloff values (#1504) 2023-12-11 15:41:27 +11:00
hankertrix 03b7321938 Update doc.md (#1518)
* Update doc.md

Make the icon and colour configuration file more clear, as the names and locations of both files were not explicitly stated.

* Used a reference to the configuration section instead

Also edited the English for spelling and grammar mistakes.
2023-12-11 15:26:18 +11:00
postsolar e9571ab1d7 Enable completions and add description for lfcd.fish and simplify the code (#1503)
* Enable completions and add description for lfcd.fish

A simple addition of `--wraps=lf` to the function definition will enable the standard lf completions to be used for `lfcd` function as well.

* Simplify lfcd.fish

* lfcd.fish: unquote $argv

* lfcd.fish: further simplify

* lfcd.fish: cd only on clean exit

* lfcd.fish: further simplify and add a coment on quoting semantics

* lfcd.fish: amend comment style
2023-12-11 15:12:30 +11:00
Joshua Li 31f4a4e16f fix basename being . when it is empty (#1525)
* fix basename being `.` when it is empty

* remove unnecessary call of `filepath.Base`
2023-12-11 15:02:07 +11:00
dependabot[bot] cbdae8e7f3 Bump github.com/gdamore/tcell/v2 from 2.6.0 to 2.7.0 (#1533)
Bumps [github.com/gdamore/tcell/v2](https://github.com/gdamore/tcell) from 2.6.0 to 2.7.0.
- [Release notes](https://github.com/gdamore/tcell/releases)
- [Changelog](https://github.com/gdamore/tcell/blob/main/CHANGESv2.md)
- [Commits](https://github.com/gdamore/tcell/compare/v2.6.0...v2.7.0)

---
updated-dependencies:
- dependency-name: github.com/gdamore/tcell/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-11 14:22:15 +11:00
dependabot[bot] ff0ca39a4c Bump actions/setup-go from 4 to 5 (#1527)
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 4 to 5.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-11 14:02:12 +11:00
dependabot[bot] 6abce04855 Bump golang.org/x/term from 0.14.0 to 0.15.0 (#1511)
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.14.0 to 0.15.0.
- [Commits](https://github.com/golang/term/compare/v0.14.0...v0.15.0)

---
updated-dependencies:
- dependency-name: golang.org/x/term
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-28 17:37:44 +11:00
dependabot[bot] 7bd5756330 Bump golang.org/x/sys from 0.14.0 to 0.15.0 (#1510)
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.14.0 to 0.15.0.
- [Commits](https://github.com/golang/sys/compare/v0.14.0...v0.15.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-28 17:33:03 +11:00
Gökçehan Kara 9698ecddf1 use markdown for the documentation (#1474)
* add doc.md

* use h2 for doc sections

* use h3 for doc commands/options/vars

* use backticks instead of quotes in the doc

* merge multiple commands/options in the doc

* change header levels in the doc

* add man page sections to the doc

* remove extra spaces in headers in the doc

* add man and plain conversions of the doc

* update doc

* add missing flags to the doc

* replace the old documentation with the new one

* remove old doc files

* remove the doc instructions from CONTRIBUTING.md

* change the links to the doc

* shorten long links in the readme
2023-11-12 15:43:06 +01:00
Alexander LunegovandJoe Lim ade9e986e5 Use -print-last-dir option for lfcd.ps1 (#1491)
* Use `-print-last-dir` option for `lfcd.ps1`

* chore(etc/lfcd.ps1): use `Set-Location` instead of `cd`

Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com>

---------

Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com>
2023-11-08 23:16:01 +11:00
dependabot[bot] ae678f7102 Bump golang.org/x/term from 0.13.0 to 0.14.0 (#1492)
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.13.0 to 0.14.0.
- [Commits](https://github.com/golang/term/compare/v0.13.0...v0.14.0)

---
updated-dependencies:
- dependency-name: golang.org/x/term
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-08 18:00:04 +11:00
dependabot[bot] f6e7d0fd0e Bump golang.org/x/sys from 0.13.0 to 0.14.0 (#1486)
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.13.0 to 0.14.0.
- [Commits](https://github.com/golang/sys/compare/v0.13.0...v0.14.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-06 14:12:15 +11:00
Joe Lim dcd2ea8164 Preserve attributes when moving across devices (#1482) 2023-11-06 13:57:11 +11:00
Joe Lim f52fffbff6 Force sync when writing to cut/copy buffer file (#1480) 2023-10-30 09:40:39 +11:00
Joe Lim b3cb2dc2b4 Add on-redraw hook command (#1479)
* Add `on-redraw` hook command

* Add documentation
2023-10-30 09:40:24 +11:00
Joe Lim 7c23c27c59 Refactor sixel peek in previewer code (#1477) 2023-10-30 09:40:02 +11:00
dependabot[bot] 838fee6f13 Bump github.com/djherbis/times from 1.5.0 to 1.6.0 (#1478)
Bumps [github.com/djherbis/times](https://github.com/djherbis/times) from 1.5.0 to 1.6.0.
- [Release notes](https://github.com/djherbis/times/releases)
- [Commits](https://github.com/djherbis/times/compare/v1.5.0...v1.6.0)

---
updated-dependencies:
- dependency-name: github.com/djherbis/times
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-29 19:55:30 +01:00
Joe Lim b420dee145 Fix detection of character vs block devices (#1469) 2023-10-22 21:42:12 +02:00
Joe Lim 9ab2c2ec6f Print sixel data to stderr instead of stdout (#1451) 2023-10-22 21:06:19 +02:00
Abderrahmane TAHRI JOUTI 1a3bcb28a1 Use -print-last-dir option for lfcd.cmd (#1444)
* exit lf not the cmd

* exit successfully

* use -print-last-dir
2023-10-22 20:43:03 +02:00
Joe Lim 154d7182c0 Fix preview for files containing long lines (#1447)
* Fix preview for files containing long lines

* Limit lines read to preview window height

* Refactor

* Make comment more clear
2023-10-22 20:37:40 +02:00
Ching Pei Yang b4af8f47c8 doc: Add comments about sixel filler (#1443) 2023-10-22 20:33:19 +02:00
dependabot[bot] beedda2d67 Bump golang.org/x/term from 0.12.0 to 0.13.0 (#1461)
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.12.0 to 0.13.0.
- [Commits](https://github.com/golang/term/compare/v0.12.0...v0.13.0)

---
updated-dependencies:
- dependency-name: golang.org/x/term
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-06 15:12:47 +11:00
Joe Lim dddf437c42 Add spaces to rulerfmt to separate from statinfo (#1437) 2023-09-23 11:32:19 +10:00
36 changed files with 5366 additions and 5377 deletions

No files matched your search

+10 -10
View File
@@ -19,9 +19,9 @@ jobs:
fetch-depth: 1 fetch-depth: 1
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v4 uses: actions/setup-go@v5
with: with:
go-version: 1.18 go-version: "1.18"
- name: Build - name: Build
run: go build -v ./... run: go build -v ./...
@@ -29,7 +29,7 @@ jobs:
- name: Test - name: Test
run: go test -v ./... run: go test -v ./...
- uses: dominikh/staticcheck-action@v1.3.0 - uses: dominikh/staticcheck-action@v1.3.1
with: with:
version: "2022.1.3" version: "2022.1.3"
install-go: false install-go: false
@@ -42,14 +42,14 @@ jobs:
fetch-depth: 1 fetch-depth: 1
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v4 uses: actions/setup-go@v5
with: with:
go-version: 1.18 go-version: "1.18"
- name: Cross-compile on all supported platforms - name: Cross-compile on all supported platforms
run: gen/xbuild.sh run: gen/xbuild.sh
generate: formatting:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@@ -57,10 +57,10 @@ jobs:
fetch-depth: 1 fetch-depth: 1
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v4 uses: actions/setup-go@v5
with: with:
go-version: 1.19 go-version: "1.18"
- name: Test `go fmt && go generate` on Go 1.19 creates no diffs - name: Test `go fmt` creates no diffs
run: go fmt && go generate && git diff --exit-code run: go fmt && git diff --exit-code
+3 -3
View File
@@ -13,15 +13,15 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v4 uses: actions/setup-go@v5
with: with:
go-version: 1.18 go-version: "1.18"
- name: Build - name: Build
run: gen/xbuild.sh run: gen/xbuild.sh
- name: Release - name: Release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v2
with: with:
files: dist/* files: dist/*
env: env:
+5 -17
View File
@@ -15,7 +15,7 @@ Global variable names are prefixed with `g` as in `gFooBar`.
Exceptions are variables holding values of environmental variables which are prefixed with `env` as in `envFooBar` and regular expressions which are prefixed with `re` as in `reFooBar` when they are global. Exceptions are variables holding values of environmental variables which are prefixed with `env` as in `envFooBar` and regular expressions which are prefixed with `re` as in `reFooBar` when they are global.
- Type and function names are small case as in `fooBar` since we don't use exporting. - Type and function names are small case as in `fooBar` since we don't use exporting.
- For file name variables, `name`, `fname`, or `filename` should refer to the base name of the file as in `baz.txt`, and `path`, `fpath`, or `filepath` should refer to the full path of the file as in `/foo/bar/baz.txt`. - For file name variables, `name`, `fname`, or `filename` should refer to the base name of the file as in `baz.txt`, and `path`, `fpath`, or `filepath` should refer to the full path of the file as in `/foo/bar/baz.txt`.
- Run `go fmt && go generate` using Go 1.19+. On earlier versions of Go, `go generate` creates needless whitespace differences. - Run `go fmt` to ensure that files are formatted correctly.
Use the surrounding code as reference when in doubt as usual. Use the surrounding code as reference when in doubt as usual.
@@ -27,9 +27,8 @@ Adding a new option usually requires the following steps:
- Add default option value to `init` function in `opts.go` - Add default option value to `init` function in `opts.go`
- Add option evaluation logic to `setExpr.eval` in `eval.go` - Add option evaluation logic to `setExpr.eval` in `eval.go`
- Implement the option somewhere in the code - Implement the option somewhere in the code
- Add option name to `gOptWords` in `complete.go` for tab completion - Add option name and its default value to `Quick Reference` and `Options` sections in `doc.md`
- Add option name and its default value to `Quick Reference` and `Options` sections in `doc.go` - Run `gen/doc-with-docker.sh` to update the documentation
- Run `go generate` to update the documentation
- Commit your changes and send a pull request - Commit your changes and send a pull request
## Adding a new builtin command ## Adding a new builtin command
@@ -40,8 +39,8 @@ Adding a new command usually requires the following steps:
- Add command evaluation logic to `callExpr.eval` in `eval.go` - Add command evaluation logic to `callExpr.eval` in `eval.go`
- Implement the command somewhere in the code - Implement the command somewhere in the code
- Add command name to `gCmdWords` in `complete.go` for tab completion - Add command name to `gCmdWords` in `complete.go` for tab completion
- Add command name to `Quick Reference` and `Commands` sections in `doc.go` - Add command name to `Quick Reference` and `Commands` sections in `doc.md`
- Run `go generate` to update the documentation - Optionally, run `gen/doc-with-docker.sh` to update the documentation
- Commit your changes and send a pull request - Commit your changes and send a pull request
## Platform specific code ## Platform specific code
@@ -49,14 +48,3 @@ Adding a new command usually requires the following steps:
There are two files named `os.go` and `os_windows.go` for unix and windows specific code respectively. There are two files named `os.go` and `os_windows.go` for unix and windows specific code respectively.
If you add something to either of these files but not the other, you probably break the build for the other platform. If you add something to either of these files but not the other, you probably break the build for the other platform.
If your addition works the same in both platforms, your addition probably belongs to `main.go` instead. If your addition works the same in both platforms, your addition probably belongs to `main.go` instead.
## Make changes to the documentation
There are three files that contain the documentation in various formats:
- `doc.go` is the source of the [online documentation](https://pkg.go.dev/github.com/gokcehan/lf)
- `docstring.go` is used when running `lf -doc`
- `lf.1` is a man page which is commonly available on Unix-like operating systems (`man lf`)
You should only make changes to `doc.go`, the other files are automatically generated **and should not be edited manually**.
Run `go fmt && go generate` to ensure that the code is formatted and files are generated correctly.
+3 -3
View File
@@ -1,13 +1,13 @@
# LF # LF
[Google Groups](https://groups.google.com/forum/#!forum/lf-fm) [Google Groups](https://groups.google.com/forum/#!forum/lf-fm)
| [Doc](doc.md)
| [Wiki](https://github.com/gokcehan/lf/wiki) | [Wiki](https://github.com/gokcehan/lf/wiki)
| [#lf](https://web.libera.chat/#lf) (on Libera.Chat) | [#lf](https://web.libera.chat/#lf) (on Libera.Chat)
| [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org) (with IRC bridge) | [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org) (with IRC bridge)
[![Go Build](https://github.com/gokcehan/lf/actions/workflows/go.yml/badge.svg)](https://github.com/gokcehan/lf/actions/workflows/go.yml) [![Go Build](https://github.com/gokcehan/lf/actions/workflows/go.yml/badge.svg)](https://github.com/gokcehan/lf/actions/workflows/go.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/gokcehan/lf)](https://goreportcard.com/report/github.com/gokcehan/lf) [![Go Report Card](https://goreportcard.com/badge/github.com/gokcehan/lf)](https://goreportcard.com/report/github.com/gokcehan/lf)
[![Go Reference](https://pkg.go.dev/badge/github.com/gokcehan/lf.svg)](https://pkg.go.dev/github.com/gokcehan/lf)
`lf` (as in "list files") is a terminal file manager written in Go with a heavy inspiration from ranger file manager. `lf` (as in "list files") is a terminal file manager written in Go with a heavy inspiration from ranger file manager.
See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information and [tutorial](https://github.com/gokcehan/lf/wiki/Tutorial) for a gentle introduction with screencasts. See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information and [tutorial](https://github.com/gokcehan/lf/wiki/Tutorial) for a gentle introduction with screencasts.
@@ -24,7 +24,7 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information and [tut
- Server/client architecture and remote commands to manage multiple instances - Server/client architecture and remote commands to manage multiple instances
- Extendable and configurable with shell commands - Extendable and configurable with shell commands
- Customizable keybindings (vi and readline defaults) - Customizable keybindings (vi and readline defaults)
- A reasonable set of other features (see the [documentation](https://pkg.go.dev/github.com/gokcehan/lf)) - A reasonable set of other features (see the [documentation](doc.md))
## Non-Features ## Non-Features
@@ -66,7 +66,7 @@ After the installation `lf` command should start the application in the current
Run `lf -help` to see command line options. Run `lf -help` to see command line options.
Run `lf -doc` to see the [documentation](https://pkg.go.dev/github.com/gokcehan/lf). Run `lf -doc` to see the [documentation](doc.md).
See [etc](etc) directory to integrate `lf` to your shell and/or editor. See [etc](etc) directory to integrate `lf` to your shell and/or editor.
Example configuration files along with example colors and icons files can also be found in this directory. Example configuration files along with example colors and icons files can also be found in this directory.
+5 -8
View File
@@ -49,14 +49,15 @@ func newApp(ui *ui, nav *nav) *app {
sigChan := make(chan os.Signal, 1) sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM) signal.Notify(sigChan, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM)
go func() { go func() {
for {
switch <-sigChan { switch <-sigChan {
case os.Interrupt: case os.Interrupt:
return
case syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM: case syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM:
app.quit() app.quit()
os.Exit(3) os.Exit(3)
return return
} }
}
}() }()
return app return app
@@ -164,6 +165,7 @@ func saveFiles(list []string, cp bool) error {
fmt.Fprintln(files, f) fmt.Fprintln(files, f)
} }
files.Sync()
return nil return nil
} }
@@ -377,9 +379,6 @@ func (app *app) loop() {
} }
app.ui.draw(app.nav) app.ui.draw(app.nav)
case d := <-app.nav.dirChan: case d := <-app.nav.dirChan:
app.nav.checkDir(d)
if gOpts.dircache { if gOpts.dircache {
prev, ok := app.nav.dirCache[d.path] prev, ok := app.nav.dirCache[d.path]
if ok { if ok {
@@ -403,7 +402,7 @@ func (app *app) loop() {
if err == nil { if err == nil {
if d.path == app.nav.currDir().path { if d.path == app.nav.currDir().path {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
if app.ui.msg == "" { if app.ui.msgIsStat {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
} }
@@ -414,8 +413,6 @@ func (app *app) loop() {
app.ui.draw(app.nav) app.ui.draw(app.nav)
case r := <-app.nav.regChan: case r := <-app.nav.regChan:
app.nav.checkReg(r)
app.nav.regCache[r.path] = r app.nav.regCache[r.path] = r
curr, err := app.nav.currFile() curr, err := app.nav.currFile()
@@ -455,7 +452,6 @@ func (app *app) loop() {
case <-app.ticker.C: case <-app.ticker.C:
app.nav.renew() app.nav.renew()
app.ui.loadFile(app, false) app.ui.loadFile(app, false)
app.ui.draw(app.nav)
case <-app.nav.previewTimer.C: case <-app.nav.previewTimer.C:
app.nav.previewLoading = true app.nav.previewLoading = true
app.ui.draw(app.nav) app.ui.draw(app.nav)
@@ -498,6 +494,7 @@ func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
func (app *app) runShell(s string, args []string, prefix string) { func (app *app) runShell(s string, args []string, prefix string) {
app.nav.exportFiles() app.nav.exportFiles()
app.ui.exportSizes() app.ui.exportSizes()
app.ui.exportMode()
exportOpts() exportOpts()
gState.mutex.Lock() gState.mutex.Lock()
+1
View File
@@ -36,6 +36,7 @@ func run() {
if gOpts.mouse { if gOpts.mouse {
screen.EnableMouse() screen.EnableMouse()
} }
screen.EnableFocus()
if gLogPath != "" { if gLogPath != "" {
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
+2 -2
View File
@@ -301,10 +301,10 @@ func (sm styleMap) get(f *file) tcell.Style {
key = "pi" key = "pi"
case f.Mode()&os.ModeSocket != 0: case f.Mode()&os.ModeSocket != 0:
key = "so" key = "so"
case f.Mode()&os.ModeDevice != 0:
key = "bd"
case f.Mode()&os.ModeCharDevice != 0: case f.Mode()&os.ModeCharDevice != 0:
key = "cd" key = "cd"
case f.Mode()&os.ModeDevice != 0:
key = "bd"
case f.Mode()&os.ModeSetuid != 0: case f.Mode()&os.ModeSetuid != 0:
key = "su" key = "su"
case f.Mode()&os.ModeSetgid != 0: case f.Mode()&os.ModeSetgid != 0:
+39 -131
View File
@@ -4,6 +4,7 @@ import (
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"sort" "sort"
"strings" "strings"
) )
@@ -109,139 +110,46 @@ var (
"cmd-lowercase-word", "cmd-lowercase-word",
} }
gOptWords = []string{ gOptWords = getOptWords(gOpts)
"anchorfind", gLocalOptWords = getLocalOptWords(gLocalOpts)
"noanchorfind",
"anchorfind!",
"autoquit",
"noautoquit",
"autoquit!",
"borderfmt",
"cursoractivefmt",
"cursorparentfmt",
"cursorpreviewfmt",
"dircache",
"nodircache",
"dircache!",
"dircounts",
"nodircounts",
"dircounts!",
"dirfirst",
"nodirfirst",
"dirfirst!",
"dironly",
"nodironly",
"dironly!",
"dirpreviews",
"nodirpreviews",
"dirpreviews!",
"drawbox",
"nodrawbox",
"drawbox!",
"dupfilefmt",
"globsearch",
"noglobsearch",
"globsearch!",
"hidden",
"nohidden",
"hidden!",
"icons",
"noicons",
"icons!",
"ignorecase",
"noignorecase",
"ignorecase!",
"ignoredia",
"noignoredia",
"ignoredia!",
"incsearch",
"noincsearch",
"incsearch!",
"incfilter",
"noincfilter",
"incfilter!",
"mouse",
"nomouse",
"mouse!",
"number",
"nonumber",
"number!",
"preview",
"nopreview",
"preview!",
"relativenumber",
"norelativenumber",
"relativenumber!",
"reverse",
"noreverse",
"reverse!",
"ruler",
"rulerfmt",
"preserve",
"sixel",
"nosixel",
"sixel!",
"smartcase",
"nosmartcase",
"smartcase!",
"smartdia",
"nosmartdia",
"smartdia!",
"waitmsg",
"wrapscan",
"nowrapscan",
"wrapscan!",
"wrapscroll",
"nowrapscroll",
"wrapscroll!",
"findlen",
"period",
"scrolloff",
"tabstop",
"errorfmt",
"filesep",
"hiddenfiles",
"history",
"ifs",
"info",
"numberfmt",
"previewer",
"cleaner",
"promptfmt",
"ratios",
"selmode",
"shell",
"shellflag",
"shellopts",
"sortby",
"statfmt",
"timefmt",
"tempmarks",
"tagfmt",
"infotimefmtnew",
"infotimefmtold",
"truncatechar",
"truncatepct",
}
gLocalOptWords = []string{
"dirfirst",
"nodirfirst",
"dirfirst!",
"dironly",
"nodironly",
"dironly!",
"hidden",
"nohidden",
"hidden!",
"info",
"reverse",
"noreverse",
"reverse!",
"sortby",
}
) )
func getOptWords(opts any) (optWords []string) {
t := reflect.TypeOf(opts)
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
switch field.Type.Kind() {
case reflect.Map:
continue
case reflect.Bool:
name := field.Name
optWords = append(optWords, name, "no"+name, name+"!")
default:
optWords = append(optWords, field.Name)
}
}
sort.Strings(optWords)
return
}
func getLocalOptWords(localOpts any) (localOptWords []string) {
t := reflect.TypeOf(localOpts)
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
name := strings.TrimSuffix(field.Name, "s")
if field.Type.Kind() != reflect.Map {
continue
}
if field.Type.Elem().Kind() == reflect.Bool {
localOptWords = append(localOptWords, name, "no"+name, name+"!")
} else {
localOptWords = append(localOptWords, name)
}
}
sort.Strings(localOptWords)
return
}
func matchLongest(s1, s2 []rune) []rune { func matchLongest(s1, s2 []rune) []rune {
i := 0 i := 0
for ; i < len(s1) && i < len(s2); i++ { for ; i < len(s1) && i < len(s2); i++ {
+38
View File
@@ -54,3 +54,41 @@ func TestMatchWord(t *testing.T) {
} }
} }
} }
func TestGetOptWords(t *testing.T) {
tests := []struct {
opts any
exp []string
}{
{struct{ feature bool }{}, []string{"feature", "feature!", "nofeature"}},
{struct{ feature int }{}, []string{"feature"}},
{struct{ feature string }{}, []string{"feature"}},
{struct{ feature []string }{}, []string{"feature"}},
}
for _, test := range tests {
result := getOptWords(test.opts)
if !reflect.DeepEqual(result, test.exp) {
t.Errorf("at input '%#v' expected '%s' but got '%s'", test.opts, test.exp, result)
}
}
}
func TestGetLocalOptWords(t *testing.T) {
tests := []struct {
localOpts any
exp []string
}{
{struct{ features map[string]bool }{}, []string{"feature", "feature!", "nofeature"}},
{struct{ features map[string]int }{}, []string{"feature"}},
{struct{ features map[string]string }{}, []string{"feature"}},
{struct{ features map[string][]string }{}, []string{"feature"}},
}
for _, test := range tests {
result := getLocalOptWords(test.localOpts)
if !reflect.DeepEqual(result, test.exp) {
t.Errorf("at input '%#v' expected '%s' but got '%s'", test.localOpts, test.exp, result)
}
}
}
+5 -5
View File
@@ -36,10 +36,10 @@ func copySize(srcs []string) (int64, error) {
return total, nil return total, nil
} }
func copyFile(src, dst string, info os.FileInfo, nums chan int64) error { func copyFile(src, dst string, preserve []string, info os.FileInfo, nums chan int64) error {
var dst_mode os.FileMode = 0666 var dst_mode os.FileMode = 0666
preserve_timestamps := false preserve_timestamps := false
for _, s := range gOpts.preserve { for _, s := range preserve {
switch s { switch s {
case "timestamps": case "timestamps":
preserve_timestamps = true preserve_timestamps = true
@@ -98,7 +98,7 @@ func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
return nil return nil
} }
func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) { func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64, errs chan error) {
nums = make(chan int64, 1024) nums = make(chan int64, 1024)
errs = make(chan error, 1024) errs = make(chan error, 1024)
@@ -110,7 +110,7 @@ func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
_, err := os.Lstat(dst) _, err := os.Lstat(dst)
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
ext := filepath.Ext(file) ext := filepath.Ext(file)
basename := filepath.Base(file[:len(file)-len(ext)]) basename := file[:len(file)-len(ext)]
var newPath string var newPath string
for i := 1; !os.IsNotExist(err); i++ { for i := 1; !os.IsNotExist(err); i++ {
file = strings.ReplaceAll(gOpts.dupfilefmt, "%f", basename+ext) file = strings.ReplaceAll(gOpts.dupfilefmt, "%f", basename+ext)
@@ -149,7 +149,7 @@ func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
} }
nums <- info.Size() nums <- info.Size()
} else { } else {
if err := copyFile(path, newPath, info, nums); err != nil { if err := copyFile(path, newPath, preserve, info, nums); err != nil {
errs <- fmt.Errorf("copy: %s", err) errs <- fmt.Errorf("copy: %s", err)
} }
} }
+506 -485
View File
File diff suppressed because it is too large. Load diff
+2063
View File
File diff suppressed because it is too large. Load diff
-1983
View File
File diff suppressed because it is too large. Load diff
+4
View File
@@ -188,6 +188,9 @@ fi  # FILE
*procfile  *procfile 
*dockerfile  *dockerfile 
*docker-compose.yml  *docker-compose.yml 
*docker-compose.yaml 
*compose.yml 
*compose.yaml 
*rakefile  *rakefile 
*config.ru  *config.ru 
*gemfile  *gemfile 
@@ -209,6 +212,7 @@ fi  # FILE
*Procfile  *Procfile 
*Dockerfile  *Dockerfile 
*Docker-compose.yml  *Docker-compose.yml 
*Docker-compose.yaml 
*Rakefile  *Rakefile 
*Gemfile  *Gemfile 
*Makefile  *Makefile 
+1 -1
View File
@@ -1,4 +1,4 @@
#compdef lf #compdef lf lfcd
# Autocompletion for zsh shell. # Autocompletion for zsh shell.
# #
+1 -10
View File
@@ -3,13 +3,4 @@ rem Change working dir in cmd.exe to last dir in lf on exit.
rem rem
rem You need to put this file to a folder in %PATH% variable. rem You need to put this file to a folder in %PATH% variable.
:tmploop for /f "usebackq tokens=*" %%d in (`lf -print-last-dir %*`) do cd %%d
set tmpfile="%tmp%\lf.%random%.tmp"
if exist %tmpfile% goto:tmploop
lf -last-dir-path=%tmpfile% %*
if not exist %tmpfile% exit
set /p dir=<%tmpfile%
del /f %tmpfile%
if not exist "%dir%" exit
if "%dir%" == "%cd%" exit
cd /d "%dir%"
+4 -13
View File
@@ -11,17 +11,8 @@
# #
# You may put this in a function called fish_user_key_bindings. # You may put this in a function called fish_user_key_bindings.
function lfcd function lfcd --wraps="lf" --description="lf - Terminal file manager (changing directory on exit)"
set tmp (mktemp) # `command` is needed in case `lfcd` is aliased to `lf`.
# `command` is needed in case `lfcd` is aliased to `lf` # Quotes will cause `cd` to not change directory if `lf` prints nothing to stdout due to an error.
command lf -last-dir-path=$tmp $argv cd "$(command lf -print-last-dir $argv)"
if test -f "$tmp"
set dir (cat $tmp)
rm -f $tmp
if test -d "$dir"
if test "$dir" != (pwd)
cd $dir
end
end
end
end end
+3 -12
View File
@@ -19,16 +19,7 @@
# } # }
# ] # ]
def-env lfcd [] { # For nushell version >= 0.87.0
let tmp = (mktemp) def --env --wrapped lfcd [...args: string] {
lf -last-dir-path $tmp cd (lf -print-last-dir $args)
try {
let target_dir = (open --raw $tmp)
rm -f $tmp
try {
if ($target_dir != $env.PWD) { cd $target_dir }
} catch { |e| print -e $'lfcd: Can not change to ($target_dir): ($e | get debug)' }
} catch {
|e| print -e $'lfcd: Reading ($tmp) returned an error: ($e | get debug)'
}
} }
+1 -11
View File
@@ -13,14 +13,4 @@
# You may put this in one of the profiles found in $PROFILE. # You may put this in one of the profiles found in $PROFILE.
# #
$tmp = [System.IO.Path]::GetTempFileName() lf -print-last-dir $args | Set-Location
lf -last-dir-path="$tmp" $args
if (Test-Path -PathType Leaf "$tmp") {
$dir = Get-Content "$tmp"
Remove-Item -Force "$tmp"
if (Test-Path -PathType Container "$dir") {
if ("$dir" -ne "$pwd") {
cd "$dir"
}
}
}
+244 -821
View File
File diff suppressed because it is too large. Load diff
+71
View File
@@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@@ -537,3 +538,73 @@ func TestSplitKeys(t *testing.T) {
} }
} }
} }
func TestApplyBoolOpt(t *testing.T) {
tests := []struct {
opt bool
e setExpr
exp bool
}{
{true, setExpr{"feature", ""}, true},
{true, setExpr{"feature", "true"}, true},
{true, setExpr{"feature", "false"}, false},
{false, setExpr{"feature", ""}, true},
{false, setExpr{"feature", "true"}, true},
{false, setExpr{"feature", "false"}, false},
{true, setExpr{"nofeature", ""}, false},
{false, setExpr{"nofeature", ""}, false},
{true, setExpr{"feature!", ""}, false},
{false, setExpr{"feature!", ""}, true},
}
for _, test := range tests {
testStr := fmt.Sprintf("%v", test)
if err := applyBoolOpt(&test.opt, &test.e); err != nil {
t.Errorf("at test '%s' expected '%t' but got an error '%s'", testStr, test.exp, err)
continue
}
if test.opt != test.exp {
t.Errorf("at test '%s' expected '%t' but got '%t'", testStr, test.exp, test.opt)
}
}
}
func TestApplyLocalBoolOpt(t *testing.T) {
tests := []struct {
localOpt map[string]bool
globalOpt bool
e setLocalExpr
exp bool
}{
{map[string]bool{}, false, setLocalExpr{"/", "feature", ""}, true},
{map[string]bool{}, false, setLocalExpr{"/", "feature", "true"}, true},
{map[string]bool{}, false, setLocalExpr{"/", "feature", "false"}, false},
{map[string]bool{}, false, setLocalExpr{"/", "nofeature", ""}, false},
{map[string]bool{}, true, setLocalExpr{"/", "feature!", ""}, false},
{map[string]bool{}, false, setLocalExpr{"/", "feature!", ""}, true},
{map[string]bool{"/": true}, false, setLocalExpr{"/", "feature", ""}, true},
{map[string]bool{"/": true}, false, setLocalExpr{"/", "feature", "true"}, true},
{map[string]bool{"/": true}, false, setLocalExpr{"/", "feature", "false"}, false},
{map[string]bool{"/": true}, false, setLocalExpr{"/", "nofeature", ""}, false},
{map[string]bool{"/": true}, true, setLocalExpr{"/", "feature!", ""}, false},
{map[string]bool{"/": true}, false, setLocalExpr{"/", "feature!", ""}, false},
{map[string]bool{"/": false}, false, setLocalExpr{"/", "feature", ""}, true},
{map[string]bool{"/": false}, false, setLocalExpr{"/", "feature", "true"}, true},
{map[string]bool{"/": false}, false, setLocalExpr{"/", "feature", "false"}, false},
{map[string]bool{"/": false}, false, setLocalExpr{"/", "nofeature", ""}, false},
{map[string]bool{"/": false}, true, setLocalExpr{"/", "feature!", ""}, true},
{map[string]bool{"/": false}, false, setLocalExpr{"/", "feature!", ""}, true},
}
for _, test := range tests {
testStr := fmt.Sprintf("%v", test)
if err := applyLocalBoolOpt(test.localOpt, test.globalOpt, &test.e); err != nil {
t.Errorf("at test '%s' expected '%t' but got an error '%s'", testStr, test.exp, err)
continue
}
result := test.localOpt[test.e.path]
if result != test.exp {
t.Errorf("at test '%s' expected '%t' but got '%t'", testStr, test.exp, result)
}
}
}
+32
View File
@@ -0,0 +1,32 @@
#!/bin/sh
# Generates `lf.1` and `doc.txt` from the `doc.md` file.
#
# This script is used to generate a man page and a plain text conversion of the
# markdown documentation using pandoc (https://pandoc.org/). GitHub Flavored
# Markdown (GFM) (https://github.github.com/gfm/) is used for the markdown
# input format. The markdown file is automatically rendered in the GitHub
# repository (https://github.com/gokcehan/lf/blob/master/doc.md). The man page
# file `lf.1` is meant to be used for installations on Unix systems. The plain
# text file `doc.txt` is embedded in the binary to be displayed on request with
# the `-doc` command line flag. Thus the same documentation is used for online
# and terminal display.
[ -z $version ] && version=$(git describe --tags)
[ -z $date ] && date=$(date +%F)
PANDOC_IMAGE=pandoc/minimal:2.11
docker run --rm -v "$PWD:/data" --user "$(id -u):$(id -g)" $PANDOC_IMAGE \
--standalone \
--from gfm --to man \
--metadata=title:"LF" \
--metadata=section:"1" \
--metadata=date:"$date" \
--metadata=footer:"$version" \
--metadata=header:"DOCUMENTATION" \
doc.md -o lf.1
docker run --rm -v "$PWD:/data" --user "$(id -u):$(id -g)" $PANDOC_IMAGE \
--standalone \
--from gfm --to plain \
doc.md -o doc.txt
Executable
+30
View File
@@ -0,0 +1,30 @@
#!/bin/sh
# Generates `lf.1` and `doc.txt` from the `doc.md` file.
#
# This script is used to generate a man page and a plain text conversion of the
# markdown documentation using pandoc (https://pandoc.org/). GitHub Flavored
# Markdown (GFM) (https://github.github.com/gfm/) is used for the markdown
# input format. The markdown file is automatically rendered in the GitHub
# repository (https://github.com/gokcehan/lf/blob/master/doc.md). The man page
# file `lf.1` is meant to be used for installations on Unix systems. The plain
# text file `doc.txt` is embedded in the binary to be displayed on request with
# the `-doc` command line flag. Thus the same documentation is used for online
# and terminal display.
[ -z $version ] && version=$(git describe --tags)
[ -z $date ] && date=$(date +%F)
pandoc \
--standalone \
--from gfm --to man \
--metadata=title:"LF" \
--metadata=section:"1" \
--metadata=date:"$date" \
--metadata=footer:"$version" \
--metadata=header:"DOCUMENTATION" \
doc.md -o lf.1
pandoc \
--standalone \
--from gfm --to plain \
doc.md -o doc.txt
-19
View File
@@ -1,19 +0,0 @@
#!/bin/sh
# Generates `docstring.go` having `genDocString` variable with `go doc` output.
#
# This script is called in `doc.go` using `go generate` to embed the
# documentation inside the binary in order to show it on request with `-doc`
# command line flag. Thus the same documentation is used for online and
# terminal display.
tmp=gen/docstring.go
echo "// Code generated by gen/docstring.sh DO NOT EDIT." >> $tmp
echo >> $tmp
echo "package main" >> $tmp
echo >> $tmp
echo "var genDocString = \`" >> $tmp
go doc | tr "\`" "'" >> $tmp
echo "\`" >> $tmp
mv $tmp docstring.go
-75
View File
@@ -1,75 +0,0 @@
#!/bin/sh
# Generates `lf.1` man page using man macros with `go doc` output.
#
# This script is called in `doc.go` using `go generate` to generate a man page
# formatted with man macros from the documentation. A few additional sections
# such as `NAME` and `SYNOPSIS` are added to comply with man page conventions.
#
# Conversion logic implemented here from godoc output to man macros should not
# be considered compliant, as such it has inexact assumptions such as the use
# of spaces over tabs along with various corner cases that are not handled
# properly like character escaping. The intention here is to come up with
# something that can convert the current content in the documentation. For this
# reason, it is recommended to check the output after generation especially
# when the documentation is changed in a significant way.
out=lf.1
echo '.\" Code generated by gen/man.sh DO NOT EDIT.' > $out
cat << END >> $out
.TH LF 1
.SH NAME
lf \- terminal file manager
.SH SYNOPSIS
.SY lf
.OP \-command command
.OP \-config path
.OP \-cpuprofile path
.OP \-doc
.OP \-last-dir-path path
.OP \-log path
.OP \-memprofile path
.OP \-remote command
.OP \-selection-path path
.OP \-server
.OP \-single
.OP \-version
.OP \-help
.RI [ cd-or-select-path ]
.YS
.SH DESCRIPTION
END
go doc | awk '
BEGIN {
RS = ""
start = 1
}
# preformatted
/^ / {
gsub("\\\\", "\\e", $0)
print ".PP"
print ".EX"
print $0
print ".EE"
next
}
# heading
/^# *[^[:punct:]]*$/ {
gsub(/# */, "", $0)
print ".SH", toupper($0)
start = 1
next
}
# paragraph
{
gsub("\n", " ", $0)
gsub("\\\\", "\\e", $0)
if (start) { start = 0 } else { print ".PP" }
print $0
}
' >> $out
+5 -5
View File
@@ -3,16 +3,16 @@ module github.com/gokcehan/lf
go 1.18 go 1.18
require ( require (
github.com/djherbis/times v1.5.0 github.com/djherbis/times v1.6.0
github.com/gdamore/tcell/v2 v2.6.0 github.com/gdamore/tcell/v2 v2.7.4
github.com/mattn/go-runewidth v0.0.15 github.com/mattn/go-runewidth v0.0.15
golang.org/x/sys v0.12.0 golang.org/x/sys v0.18.0
golang.org/x/term v0.12.0 golang.org/x/term v0.18.0
) )
require ( require (
github.com/gdamore/encoding v1.0.0 // indirect github.com/gdamore/encoding v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/rivo/uniseg v0.4.3 // indirect github.com/rivo/uniseg v0.4.3 // indirect
golang.org/x/text v0.7.0 // indirect golang.org/x/text v0.14.0 // indirect
) )
+17 -10
View File
@@ -1,12 +1,11 @@
github.com/djherbis/times v1.5.0 h1:79myA211VwPhFTqUk8xehWrsEO+zcIZj0zT8mXPVARU= github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
github.com/djherbis/times v1.5.0/go.mod h1:5q7FDLvbNg1L/KaBmPcWlVR9NmoKo3+ucqUA3ijQhA0= github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= 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/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell/v2 v2.6.0 h1:OKbluoP9VYmJwZwq/iLb4BxwKcwGthaa1YNBJIyCySg= github.com/gdamore/tcell/v2 v2.7.4 h1:sg6/UnTM9jGpZU+oFYAsDahfchWAFW8Xx2yFinNSAYU=
github.com/gdamore/tcell/v2 v2.6.0/go.mod h1:be9omFATkdr0D9qewWW3d+MEvl5dha+Etb5y65J2H8Y= github.com/gdamore/tcell/v2 v2.7.4/go.mod h1:dSXtXTSK0VsW1biw65DZLZ2NKr7j0qP/0J7ONmsraWg=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= 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/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
@@ -16,30 +15,38 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+2 -2
View File
@@ -128,10 +128,10 @@ func (im iconMap) get(f *file) string {
key = "pi" key = "pi"
case f.Mode()&os.ModeSocket != 0: case f.Mode()&os.ModeSocket != 0:
key = "so" key = "so"
case f.Mode()&os.ModeDevice != 0:
key = "bd"
case f.Mode()&os.ModeCharDevice != 0: case f.Mode()&os.ModeCharDevice != 0:
key = "cd" key = "cd"
case f.Mode()&os.ModeDevice != 0:
key = "bd"
case f.Mode()&os.ModeSetuid != 0: case f.Mode()&os.ModeSetuid != 0:
key = "su" key = "su"
case f.Mode()&os.ModeSetgid != 0: case f.Mode()&os.ModeSetgid != 0:
+1988 -1561
View File
File diff suppressed because it is too large. Load diff
+39 -27
View File
@@ -9,11 +9,17 @@ import (
"path/filepath" "path/filepath"
"reflect" "reflect"
"runtime" "runtime"
"runtime/debug"
"runtime/pprof" "runtime/pprof"
"strconv" "strconv"
"strings" "strings"
_ "embed"
) )
//go:embed doc.txt
var genDocString string
var ( var (
envPath = os.Getenv("PATH") envPath = os.Getenv("PATH")
envLevel = os.Getenv("LF_LEVEL") envLevel = os.Getenv("LF_LEVEL")
@@ -131,32 +137,7 @@ func getOptsMap() map[string]string {
continue continue
} }
// Get string representation of the value if name == "lf_user" {
if name == "lf_sortType" {
var sortby string
switch gOpts.sortType.method {
case naturalSort:
sortby = "natural"
case nameSort:
sortby = "name"
case sizeSort:
sortby = "size"
case timeSort:
sortby = "time"
case ctimeSort:
sortby = "ctime"
case atimeSort:
sortby = "atime"
case extSort:
sortby = "ext"
}
opts["lf_sortby"] = sortby
opts["lf_reverse"] = strconv.FormatBool(gOpts.sortType.option&reverseSort != 0)
opts["lf_hidden"] = strconv.FormatBool(gOpts.sortType.option&hiddenSort != 0)
opts["lf_dirfirst"] = strconv.FormatBool(gOpts.sortType.option&dirfirstSort != 0)
} else if name == "lf_user" {
// set each user option // set each user option
for key, value := range gOpts.user { for key, value := range gOpts.user {
opts[name+"_"+key] = value opts[name+"_"+key] = value
@@ -197,6 +178,37 @@ func checkServer() {
} }
} }
func printVersion() {
if gVersion != "" {
fmt.Println(gVersion)
return
}
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return
}
var vcsRevision, vcsTime, vcsModified string
for _, setting := range buildInfo.Settings {
switch setting.Key {
case "vcs.revision":
vcsRevision = setting.Value
case "vcs.time":
vcsTime = setting.Value
case "vcs.modified":
if setting.Value == "true" {
vcsModified = " (dirty)"
}
}
}
if vcsRevision != "" {
fmt.Printf("Built at commit: %s%s %s\n", vcsRevision, vcsModified, vcsTime)
}
fmt.Printf("Go version: %s\n", buildInfo.GoVersion)
}
func main() { func main() {
flag.Usage = func() { flag.Usage = func() {
f := flag.CommandLine.Output() f := flag.CommandLine.Output()
@@ -299,7 +311,7 @@ func main() {
case *showDoc: case *showDoc:
fmt.Print(genDocString) fmt.Print(genDocString)
case *showVersion: case *showVersion:
fmt.Println(gVersion) printVersion()
case *remoteCmd != "": case *remoteCmd != "":
if err := remote(*remoteCmd); err != nil { if err := remote(*remoteCmd); err != nil {
log.Fatalf("remote command: %s", err) log.Fatalf("remote command: %s", err)
+72 -55
View File
@@ -2,7 +2,6 @@ package main
import ( import (
"bufio" "bufio"
"bytes"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@@ -169,8 +168,11 @@ type dir struct {
path string // full path of directory path string // full path of directory
files []*file // displayed files in directory including or excluding hidden ones files []*file // displayed files in directory including or excluding hidden ones
allFiles []*file // all files in directory including hidden ones (same array as files) allFiles []*file // all files in directory including hidden ones (same array as files)
sortType sortType // sort method and options from last sort sortby sortMethod // sortby value from last sort
dirfirst bool // dirfirst value from last sort
dironly bool // dironly value from last sort dironly bool // dironly value from last sort
hidden bool // hidden value from last sort
reverse bool // reverse value from last sort
hiddenfiles []string // hiddenfiles value from last sort hiddenfiles []string // hiddenfiles value from last sort
filter []string // last filter for this directory filter []string // last filter for this directory
ignorecase bool // ignorecase value from last sort ignorecase bool // ignorecase value from last sort
@@ -198,11 +200,11 @@ func newDir(path string) *dir {
} }
func normalize(s1, s2 string, ignorecase, ignoredia bool) (string, string) { func normalize(s1, s2 string, ignorecase, ignoredia bool) (string, string) {
if gOpts.ignorecase { if ignorecase {
s1 = strings.ToLower(s1) s1 = strings.ToLower(s1)
s2 = strings.ToLower(s2) s2 = strings.ToLower(s2)
} }
if gOpts.ignoredia { if ignoredia {
s1 = removeDiacritics(s1) s1 = removeDiacritics(s1)
s2 = removeDiacritics(s2) s2 = removeDiacritics(s2)
} }
@@ -210,8 +212,11 @@ func normalize(s1, s2 string, ignorecase, ignoredia bool) (string, string) {
} }
func (dir *dir) sort() { func (dir *dir) sort() {
dir.sortType = getSortType(dir.path) dir.sortby = getSortBy(dir.path)
dir.dirfirst = getDirFirst(dir.path)
dir.dironly = getDirOnly(dir.path) dir.dironly = getDirOnly(dir.path)
dir.hidden = getHidden(dir.path)
dir.reverse = getReverse(dir.path)
dir.hiddenfiles = gOpts.hiddenfiles dir.hiddenfiles = gOpts.hiddenfiles
dir.ignorecase = gOpts.ignorecase dir.ignorecase = gOpts.ignorecase
dir.ignoredia = gOpts.ignoredia dir.ignoredia = gOpts.ignoredia
@@ -220,13 +225,11 @@ func (dir *dir) sort() {
// reverse order cannot be applied after stable sorting, otherwise the order // reverse order cannot be applied after stable sorting, otherwise the order
// of equivalent elements will be reversed // of equivalent elements will be reversed
reverse := dir.sortType.option&reverseSort != 0 switch dir.sortby {
switch dir.sortType.method {
case naturalSort: case naturalSort:
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia) s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
if !reverse { if !dir.reverse {
return naturalLess(s1, s2) return naturalLess(s1, s2)
} else { } else {
return naturalLess(s2, s1) return naturalLess(s2, s1)
@@ -235,7 +238,7 @@ func (dir *dir) sort() {
case nameSort: case nameSort:
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia) s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
if !reverse { if !dir.reverse {
return s1 < s2 return s1 < s2
} else { } else {
return s2 < s1 return s2 < s1
@@ -243,7 +246,7 @@ func (dir *dir) sort() {
}) })
case sizeSort: case sizeSort:
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
if !reverse { if !dir.reverse {
return dir.files[i].TotalSize() < dir.files[j].TotalSize() return dir.files[i].TotalSize() < dir.files[j].TotalSize()
} else { } else {
return dir.files[j].TotalSize() < dir.files[i].TotalSize() return dir.files[j].TotalSize() < dir.files[i].TotalSize()
@@ -251,7 +254,7 @@ func (dir *dir) sort() {
}) })
case timeSort: case timeSort:
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
if !reverse { if !dir.reverse {
return dir.files[i].ModTime().Before(dir.files[j].ModTime()) return dir.files[i].ModTime().Before(dir.files[j].ModTime())
} else { } else {
return dir.files[j].ModTime().Before(dir.files[i].ModTime()) return dir.files[j].ModTime().Before(dir.files[i].ModTime())
@@ -259,7 +262,7 @@ func (dir *dir) sort() {
}) })
case atimeSort: case atimeSort:
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
if !reverse { if !dir.reverse {
return dir.files[i].accessTime.Before(dir.files[j].accessTime) return dir.files[i].accessTime.Before(dir.files[j].accessTime)
} else { } else {
return dir.files[j].accessTime.Before(dir.files[i].accessTime) return dir.files[j].accessTime.Before(dir.files[i].accessTime)
@@ -267,7 +270,7 @@ func (dir *dir) sort() {
}) })
case ctimeSort: case ctimeSort:
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
if !reverse { if !dir.reverse {
return dir.files[i].changeTime.Before(dir.files[j].changeTime) return dir.files[i].changeTime.Before(dir.files[j].changeTime)
} else { } else {
return dir.files[j].changeTime.Before(dir.files[i].changeTime) return dir.files[j].changeTime.Before(dir.files[i].changeTime)
@@ -290,7 +293,7 @@ func (dir *dir) sort() {
// in order to also have natural sorting with the filenames // in order to also have natural sorting with the filenames
// combine the name with the ext but have the ext at the front // combine the name with the ext but have the ext at the front
if !reverse { if !dir.reverse {
return ext1 < ext2 || ext1 == ext2 && name1 < name2 return ext1 < ext2 || ext1 == ext2 && name1 < name2
} else { } else {
return ext2 < ext1 || ext2 == ext1 && name2 < name1 return ext2 < ext1 || ext2 == ext1 && name2 < name1
@@ -298,7 +301,7 @@ func (dir *dir) sort() {
}) })
} }
if dir.sortType.option&dirfirstSort != 0 { if dir.dirfirst {
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
if dir.files[i].IsDir() == dir.files[j].IsDir() { if dir.files[i].IsDir() == dir.files[j].IsDir() {
return i < j return i < j
@@ -330,7 +333,7 @@ func (dir *dir) sort() {
// when hidden option is disabled, we move hidden files to the // when hidden option is disabled, we move hidden files to the
// beginning of our file list and then set the beginning of displayed // beginning of our file list and then set the beginning of displayed
// files to the first non-hidden file in the list // files to the first non-hidden file in the list
if dir.sortType.option&hiddenSort == 0 { if !dir.hidden {
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
if isHidden(dir.files[i], dir.path, dir.hiddenfiles) && isHidden(dir.files[j], dir.path, dir.hiddenfiles) { if isHidden(dir.files[i], dir.path, dir.hiddenfiles) && isHidden(dir.files[j], dir.path, dir.hiddenfiles) {
return i < j return i < j
@@ -472,7 +475,11 @@ func (nav *nav) loadDirInternal(path string) *dir {
loading: true, loading: true,
loadTime: time.Now(), loadTime: time.Now(),
path: path, path: path,
sortType: getSortType(path), sortby: getSortBy(path),
dirfirst: getDirFirst(path),
dironly: getDirOnly(path),
hidden: getHidden(path),
reverse: getReverse(path),
hiddenfiles: gOpts.hiddenfiles, hiddenfiles: gOpts.hiddenfiles,
ignorecase: gOpts.ignorecase, ignorecase: gOpts.ignorecase,
ignoredia: gOpts.ignoredia, ignoredia: gOpts.ignoredia,
@@ -535,8 +542,11 @@ func (nav *nav) checkDir(dir *dir) {
} }
nav.dirChan <- nd nav.dirChan <- nd
}() }()
case dir.sortType != getSortType(dir.path) || case dir.sortby != getSortBy(dir.path) ||
dir.dirfirst != getDirFirst(dir.path) ||
dir.dironly != getDirOnly(dir.path) || dir.dironly != getDirOnly(dir.path) ||
dir.hidden != getHidden(dir.path) ||
dir.reverse != getReverse(dir.path) ||
!reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) || !reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) ||
dir.ignorecase != gOpts.ignorecase || dir.ignorecase != gOpts.ignorecase ||
dir.ignoredia != gOpts.ignoredia: dir.ignoredia != gOpts.ignoredia:
@@ -827,7 +837,7 @@ func (nav *nav) preview(path string, win *win) {
reg := &reg{loadTime: time.Now(), path: path} reg := &reg{loadTime: time.Now(), path: path}
defer func() { nav.regChan <- reg }() defer func() { nav.regChan <- reg }()
var reader io.Reader var reader *bufio.Reader
if len(gOpts.previewer) != 0 { if len(gOpts.previewer) != 0 {
cmd := exec.Command(gOpts.previewer, path, cmd := exec.Command(gOpts.previewer, path,
@@ -861,7 +871,7 @@ func (nav *nav) preview(path string, win *win) {
} }
}() }()
defer out.Close() defer out.Close()
reader = out reader = bufio.NewReader(out)
} else { } else {
f, err := os.Open(path) f, err := os.Open(path)
if err != nil { if err != nil {
@@ -870,14 +880,11 @@ func (nav *nav) preview(path string, win *win) {
} }
defer f.Close() defer f.Close()
reader = f reader = bufio.NewReader(f)
} }
prefix := make([]byte, 2)
if gOpts.sixel { if gOpts.sixel {
n, err := reader.Read(prefix) prefix, err := reader.Peek(2)
reader = io.MultiReader(bytes.NewReader(prefix[:n]), reader)
if err == nil && string(prefix) == gSixelBegin { if err == nil && string(prefix) == gSixelBegin {
b, err := io.ReadAll(reader) b, err := io.ReadAll(reader)
if err != nil { if err != nil {
@@ -889,20 +896,27 @@ func (nav *nav) preview(path string, win *win) {
} }
} }
buf := bufio.NewScanner(reader) // bufio.Scanner can't handle files containing long lines if they exceed the
// size of its internal buffer
addLine := true
for len(reg.lines) < win.h {
line, isPrefix, err := reader.ReadLine()
if err != nil {
break
}
for i := 0; i < win.h && buf.Scan(); i++ { for _, r := range line {
for _, r := range buf.Text() {
if r == 0 { if r == 0 {
reg.lines = []string{"\033[7mbinary\033[0m"} reg.lines = []string{"\033[7mbinary\033[0m"}
return return
} }
} }
reg.lines = append(reg.lines, buf.Text())
if addLine {
reg.lines = append(reg.lines, string(line))
} }
if buf.Err() != nil { addLine = !isPrefix
log.Printf("loading file: %s", buf.Err())
} }
} }
@@ -1141,7 +1155,7 @@ func (nav *nav) high() bool {
old := dir.ind old := dir.ind
beg := max(dir.ind-dir.pos, 0) beg := max(dir.ind-dir.pos, 0)
offs := gOpts.scrolloff offs := min(nav.height/2, gOpts.scrolloff)
if beg == 0 { if beg == 0 {
offs = 0 offs = 0
} }
@@ -1172,7 +1186,14 @@ func (nav *nav) low() bool {
old := dir.ind old := dir.ind
beg := max(dir.ind-dir.pos, 0) beg := max(dir.ind-dir.pos, 0)
end := min(beg+nav.height, len(dir.files)) end := min(beg+nav.height, len(dir.files))
offs := gOpts.scrolloff
offs := min(nav.height/2, gOpts.scrolloff)
// use a smaller value for half when the height is even and scrolloff is
// maxed in order to stay at the same row when using both high and low
if nav.height%2 == 0 {
offs = min(nav.height/2-1, gOpts.scrolloff)
}
if end == len(dir.files) { if end == len(dir.files) {
offs = 0 offs = 0
} }
@@ -1317,7 +1338,7 @@ func (nav *nav) copyAsync(app *app, srcs []string, dstDir string) {
nav.copyTotalChan <- total nav.copyTotalChan <- total
nums, errs := copyAll(srcs, dstDir) nums, errs := copyAll(srcs, dstDir, gOpts.preserve)
errCount := 0 errCount := 0
loop: loop:
@@ -1388,7 +1409,7 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
continue continue
} else if !os.IsNotExist(err) { } else if !os.IsNotExist(err) {
ext := filepath.Ext(file) ext := filepath.Ext(file)
basename := filepath.Base(file[:len(file)-len(ext)]) basename := file[:len(file)-len(ext)]
var newPath string var newPath string
for i := 1; !os.IsNotExist(err); i++ { for i := 1; !os.IsNotExist(err); i++ {
file = strings.ReplaceAll(gOpts.dupfilefmt, "%f", basename+ext) file = strings.ReplaceAll(gOpts.dupfilefmt, "%f", basename+ext)
@@ -1412,7 +1433,7 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
nav.copyTotalChan <- total nav.copyTotalChan <- total
nums, errs := copyAll([]string{src}, dstDir) nums, errs := copyAll([]string{src}, dstDir, []string{"mode", "timestamps"})
oldCount := errCount oldCount := errCount
loop: loop:
@@ -1461,6 +1482,7 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
} }
if errCount == 0 { if errCount == 0 {
app.ui.exprChan <- &callExpr{"clear", nil, 1}
app.ui.exprChan <- &callExpr{"echo", []string{"\033[0;32mMoved successfully\033[0m"}, 1} app.ui.exprChan <- &callExpr{"echo", []string{"\033[0;32mMoved successfully\033[0m"}, 1}
} }
} }
@@ -1481,19 +1503,6 @@ func (nav *nav) paste(app *app) error {
go nav.copyAsync(app, srcs, dstDir) go nav.copyAsync(app, srcs, dstDir)
} else { } else {
go nav.moveAsync(app, srcs, dstDir) go nav.moveAsync(app, srcs, dstDir)
if err := saveFiles(nil, false); err != nil {
return fmt.Errorf("clearing copy/cut buffer: %s", err)
}
if gSingleMode {
if err := nav.sync(); err != nil {
return fmt.Errorf("paste: %s", err)
}
} else {
if err := remote("send sync"); err != nil {
return fmt.Errorf("paste: %s", err)
}
}
} }
return nil return nil
@@ -1847,9 +1856,12 @@ func (nav *nav) readMarks() error {
scanner := bufio.NewScanner(f) scanner := bufio.NewScanner(f)
for scanner.Scan() { for scanner.Scan() {
toks := strings.SplitN(scanner.Text(), ":", 2) mark, path, found := strings.Cut(scanner.Text(), ":")
if _, ok := nav.marks[toks[0]]; !ok { if !found {
nav.marks[toks[0]] = toks[1] return fmt.Errorf("invalid marks file entry: %s", scanner.Text())
}
if _, ok := nav.marks[mark]; !ok {
nav.marks[mark] = path
} }
} }
@@ -1903,11 +1915,16 @@ func (nav *nav) readTags() error {
scanner := bufio.NewScanner(f) scanner := bufio.NewScanner(f)
for scanner.Scan() { for scanner.Scan() {
text := scanner.Text() text := scanner.Text()
ind := strings.LastIndex(text, ":") ind := strings.LastIndex(text, ":")
if ind == -1 {
return fmt.Errorf("invalid tags file entry: %s", text)
}
path := text[0:ind] path := text[0:ind]
mark := text[ind+1:] tag := text[ind+1:]
if _, ok := nav.tags[path]; !ok { if _, ok := nav.tags[path]; !ok {
nav.tags[path] = mark nav.tags[path] = tag
} }
} }
+70 -70
View File
@@ -5,45 +5,49 @@ import (
"time" "time"
) )
type sortMethod byte // String values match the sortby string sent by the user at startup
type sortMethod string
const ( const (
naturalSort sortMethod = iota naturalSort sortMethod = "natural"
nameSort nameSort sortMethod = "name"
sizeSort sizeSort sortMethod = "size"
timeSort timeSort sortMethod = "time"
atimeSort atimeSort sortMethod = "atime"
ctimeSort ctimeSort sortMethod = "ctime"
extSort extSort sortMethod = "ext"
) )
type sortOption byte func isValidSortMethod(method sortMethod) bool {
for _, validMethod := range []sortMethod{naturalSort, nameSort, sizeSort, timeSort, atimeSort, ctimeSort, extSort} {
const ( if method == validMethod {
dirfirstSort sortOption = 1 << iota return true
hiddenSort }
reverseSort }
) return false
type sortType struct {
method sortMethod
option sortOption
} }
const invalidSortErrorMessage = `sortby: value should either be 'natural', 'name', 'size', 'time', 'atime', 'ctime' or 'ext'`
var gOpts struct { var gOpts struct {
anchorfind bool anchorfind bool
autoquit bool autoquit bool
borderfmt string borderfmt string
copyfmt string
cursoractivefmt string cursoractivefmt string
cursorparentfmt string cursorparentfmt string
cursorpreviewfmt string cursorpreviewfmt string
cutfmt string
hidecursorinactive bool
dircache bool dircache bool
dircounts bool dircounts bool
dirfirst bool
dironly bool dironly bool
dirpreviews bool dirpreviews bool
drawbox bool drawbox bool
dupfilefmt string dupfilefmt string
globsearch bool globsearch bool
hidden bool
icons bool icons bool
ignorecase bool ignorecase bool
ignoredia bool ignoredia bool
@@ -52,8 +56,11 @@ var gOpts struct {
mouse bool mouse bool
number bool number bool
preview bool preview bool
sixel bool
relativenumber bool relativenumber bool
reverse bool
selectfmt string
sixel bool
sortby sortMethod
smartcase bool smartcase bool
smartdia bool smartdia bool
waitmsg string waitmsg string
@@ -90,14 +97,13 @@ var gOpts struct {
cmdkeys map[string]expr cmdkeys map[string]expr
cmds map[string]expr cmds map[string]expr
user map[string]string user map[string]string
sortType sortType
tempmarks string tempmarks string
numberfmt string numberfmt string
tagfmt string tagfmt string
} }
var gLocalOpts struct { var gLocalOpts struct {
sortMethods map[string]sortMethod sortbys map[string]sortMethod
dirfirsts map[string]bool dirfirsts map[string]bool
dironlys map[string]bool dironlys map[string]bool
hiddens map[string]bool hiddens map[string]bool
@@ -114,53 +120,13 @@ func localOptPaths(path string) []string {
return list return list
} }
func getSortMethod(path string) sortMethod { func getDirFirst(path string) bool {
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) { for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.dirfirsts[key]; ok { 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 return val
}
}
return gOpts.dirfirst
} }
func getDirOnly(path string) bool { func getDirOnly(path string) bool {
@@ -172,6 +138,15 @@ func getDirOnly(path string) bool {
return gOpts.dironly return gOpts.dironly
} }
func getHidden(path string) bool {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.hiddens[key]; ok {
return val
}
}
return gOpts.hidden
}
func getInfo(path string) []string { func getInfo(path string) []string {
for _, key := range localOptPaths(path) { for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.infos[key]; ok { if val, ok := gLocalOpts.infos[key]; ok {
@@ -181,20 +156,43 @@ func getInfo(path string) []string {
return gOpts.info return gOpts.info
} }
func getReverse(path string) bool {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.reverses[key]; ok {
return val
}
}
return gOpts.reverse
}
func getSortBy(path string) sortMethod {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.sortbys[key]; ok {
return val
}
}
return gOpts.sortby
}
func init() { func init() {
gOpts.anchorfind = true gOpts.anchorfind = true
gOpts.autoquit = false gOpts.autoquit = false
gOpts.dircache = true gOpts.dircache = true
gOpts.dircounts = false gOpts.dircounts = false
gOpts.dirfirst = true
gOpts.dironly = false gOpts.dironly = false
gOpts.dirpreviews = false gOpts.dirpreviews = false
gOpts.drawbox = false gOpts.drawbox = false
gOpts.dupfilefmt = "%f.~%n~" gOpts.dupfilefmt = "%f.~%n~"
gOpts.borderfmt = "\033[0m" gOpts.borderfmt = "\033[0m"
gOpts.copyfmt = "\033[7;33m"
gOpts.cursoractivefmt = "\033[7m" gOpts.cursoractivefmt = "\033[7m"
gOpts.cursorparentfmt = "\033[7m" gOpts.cursorparentfmt = "\033[7m"
gOpts.cursorpreviewfmt = "\033[4m" gOpts.cursorpreviewfmt = "\033[4m"
gOpts.cutfmt = "\033[7;31m"
gOpts.hidecursorinactive = false
gOpts.globsearch = false gOpts.globsearch = false
gOpts.hidden = false
gOpts.icons = false gOpts.icons = false
gOpts.ignorecase = true gOpts.ignorecase = true
gOpts.ignoredia = true gOpts.ignoredia = true
@@ -203,8 +201,11 @@ func init() {
gOpts.mouse = false gOpts.mouse = false
gOpts.number = false gOpts.number = false
gOpts.preview = true gOpts.preview = true
gOpts.sixel = false
gOpts.relativenumber = false gOpts.relativenumber = false
gOpts.reverse = false
gOpts.selectfmt = "\033[7;35m"
gOpts.sixel = false
gOpts.sortby = naturalSort
gOpts.smartcase = true gOpts.smartcase = true
gOpts.smartdia = false gOpts.smartdia = false
gOpts.waitmsg = "Press any key to continue" gOpts.waitmsg = "Press any key to continue"
@@ -234,10 +235,9 @@ func init() {
gOpts.history = true gOpts.history = true
gOpts.info = nil gOpts.info = nil
gOpts.ruler = nil gOpts.ruler = nil
gOpts.rulerfmt = "%a |%p |\033[7;31m %m \033[0m |\033[7;33m %c \033[0m |\033[7;35m %s \033[0m |\033[7;34m %f \033[0m |%i/%t" gOpts.rulerfmt = " %a| %p| \033[7;31m %m \033[0m| \033[7;33m %c \033[0m| \033[7;35m %s \033[0m| \033[7;34m %f \033[0m| %i/%t"
gOpts.preserve = []string{"mode"} gOpts.preserve = []string{"mode"}
gOpts.shellopts = nil gOpts.shellopts = nil
gOpts.sortType = sortType{naturalSort, dirfirstSort}
gOpts.tempmarks = "'" gOpts.tempmarks = "'"
gOpts.numberfmt = "\033[33m" gOpts.numberfmt = "\033[33m"
gOpts.tagfmt = "\033[31m" gOpts.tagfmt = "\033[31m"
@@ -360,7 +360,7 @@ func init() {
gOpts.cmds = make(map[string]expr) gOpts.cmds = make(map[string]expr)
gOpts.user = make(map[string]string) gOpts.user = make(map[string]string)
gLocalOpts.sortMethods = make(map[string]sortMethod) gLocalOpts.sortbys = make(map[string]sortMethod)
gLocalOpts.dirfirsts = make(map[string]bool) gLocalOpts.dirfirsts = make(map[string]bool)
gLocalOpts.dironlys = make(map[string]bool) gLocalOpts.dironlys = make(map[string]bool)
gLocalOpts.hiddens = make(map[string]bool) gLocalOpts.hiddens = make(map[string]bool)
+8 -2
View File
@@ -199,8 +199,11 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
func userName(f os.FileInfo) string { func userName(f os.FileInfo) string {
if stat, ok := f.Sys().(*syscall.Stat_t); ok { if stat, ok := f.Sys().(*syscall.Stat_t); ok {
if u, err := user.LookupId(fmt.Sprint(stat.Uid)); err == nil { uid := fmt.Sprint(stat.Uid)
if u, err := user.LookupId(uid); err == nil {
return u.Username return u.Username
} else {
return uid
} }
} }
return "" return ""
@@ -208,8 +211,11 @@ func userName(f os.FileInfo) string {
func groupName(f os.FileInfo) string { func groupName(f os.FileInfo) string {
if stat, ok := f.Sys().(*syscall.Stat_t); ok { if stat, ok := f.Sys().(*syscall.Stat_t); ok {
if g, err := user.LookupGroupId(fmt.Sprint(stat.Gid)); err == nil { gid := fmt.Sprint(stat.Gid)
if g, err := user.LookupGroupId(gid); err == nil {
return g.Name return g.Name
} else {
return gid
} }
} }
return "" return ""
+11 -5
View File
@@ -59,14 +59,20 @@ func init() {
envShell = "cmd" envShell = "cmd"
} }
u, err := user.Current() homeDir, err := os.UserHomeDir()
if err != nil { if err != nil {
log.Printf("user: %s", err) panic(err)
} }
gUser = u
// remove domain prefix username := os.Getenv("USERNAME")
gUser.Username = strings.Split(gUser.Username, `\`)[1] if username == "" {
panic("$USERNAME variable is empty or not set")
}
gUser = &user.User{
HomeDir: homeDir,
Username: username,
}
data := os.Getenv("LF_CONFIG_HOME") data := os.Getenv("LF_CONFIG_HOME")
if data == "" { if data == "" {
+13 -5
View File
@@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"os"
"strings" "strings"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
@@ -9,6 +10,13 @@ import (
const ( const (
gSixelBegin = "\033P" gSixelBegin = "\033P"
// The filler character should be:
// - rarely used: the filler is used to trick tcell into redrawing, if the
// filler character appears in the user's preview, that cell might not
// be cleaned up properly
// - ideally renders as empty space: the filler alternates between bold
// and regular, using a non-space would look weird to the user.
gSixelFiller = '\u2000' gSixelFiller = '\u2000'
) )
@@ -36,12 +44,12 @@ func (sxs *sixelScreen) showSixels() {
} }
// XXX: workaround for bug where quitting lf might leave the terminal in bold // XXX: workaround for bug where quitting lf might leave the terminal in bold
fmt.Print("\033[0m") fmt.Fprint(os.Stderr, "\033[0m")
fmt.Print("\0337") // Save cursor position fmt.Fprint(os.Stderr, "\0337") // Save cursor position
fmt.Printf("\033[%d;%dH", sxs.yprev, sxs.xprev) // Move cursor to position fmt.Fprintf(os.Stderr, "\033[%d;%dH", sxs.yprev, sxs.xprev) // Move cursor to position
fmt.Print(*sxs.sixel) // fmt.Fprint(os.Stderr, *sxs.sixel) //
fmt.Print("\0338") // Restore cursor position fmt.Fprint(os.Stderr, "\0338") // Restore cursor position
} }
func (sxs *sixelScreen) printSixel(win *win, screen tcell.Screen, reg *reg) { func (sxs *sixelScreen) printSixel(win *win, screen tcell.Screen, reg *reg) {
+70 -26
View File
@@ -348,12 +348,7 @@ type dirStyle struct {
role dirRole role dirRole
} }
// These colors are not currently customizeable func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirStyle, previewLoading bool) {
const SelectionColor = tcell.ColorPurple
const YankColor = tcell.ColorOlive
const CutColor = tcell.ColorMaroon
func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dirStyle *dirStyle, previewLoading bool) {
if win.w < 5 || dir == nil { if win.w < 5 || dir == nil {
return return
} }
@@ -361,12 +356,12 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
messageStyle := tcell.StyleDefault.Reverse(true) messageStyle := tcell.StyleDefault.Reverse(true)
if dir.noPerm { if dir.noPerm {
win.print(screen, 2, 0, messageStyle, "permission denied") win.print(ui.screen, 2, 0, messageStyle, "permission denied")
return return
} }
if (dir.loading && len(dir.files) == 0) || (dirStyle.role == Preview && dir.loading && gOpts.dirpreviews) { if (dir.loading && len(dir.files) == 0) || (dirStyle.role == Preview && dir.loading && gOpts.dirpreviews) {
if dirStyle.role != Preview || previewLoading { if dirStyle.role != Preview || previewLoading {
win.print(screen, 2, 0, messageStyle, "loading...") win.print(ui.screen, 2, 0, messageStyle, "loading...")
} }
return return
} }
@@ -379,12 +374,12 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
break break
} }
st = win.print(screen, 2, i, st, l) st = win.print(ui.screen, 2, i, st, l)
} }
return return
} }
if len(dir.files) == 0 { if len(dir.files) == 0 {
win.print(screen, 2, 0, messageStyle, "empty") win.print(ui.screen, 2, 0, messageStyle, "empty")
return return
} }
@@ -428,18 +423,18 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
} }
} }
win.print(screen, 0, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.numberfmt), ln)) win.print(ui.screen, 0, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.numberfmt), ln))
} }
path := filepath.Join(dir.path, f.Name()) path := filepath.Join(dir.path, f.Name())
if _, ok := context.selections[path]; ok { if _, ok := context.selections[path]; ok {
win.print(screen, lnwidth, i, st.Background(SelectionColor), " ") win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.selectfmt), " ")
} else if cp, ok := context.saves[path]; ok { } else if cp, ok := context.saves[path]; ok {
if cp { if cp {
win.print(screen, lnwidth, i, st.Background(YankColor), " ") win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.copyfmt), " ")
} else { } else {
win.print(screen, lnwidth, i, st.Background(CutColor), " ") win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.cutfmt), " ")
} }
} }
@@ -486,7 +481,7 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
} }
ce := "" ce := ""
if i == dir.pos { if i == dir.pos && (ui.focused || !gOpts.hidecursorinactive) {
switch dirStyle.role { switch dirStyle.role {
case Active: case Active:
ce = gOpts.cursoractivefmt ce = gOpts.cursoractivefmt
@@ -500,14 +495,14 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
s = append(s, ' ') s = append(s, ' ')
styledFilename := fmt.Sprintf(cursorescapefmt, string(s)) styledFilename := fmt.Sprintf(cursorescapefmt, string(s))
win.print(screen, lnwidth+1, i, st, styledFilename) win.print(ui.screen, lnwidth+1, i, st, styledFilename)
tag, ok := context.tags[path] tag, ok := context.tags[path]
if ok { if ok {
if i == dir.pos { if i == dir.pos {
win.print(screen, lnwidth+1, i, st, fmt.Sprintf(cursorescapefmt, tag)) win.print(ui.screen, lnwidth+1, i, st, fmt.Sprintf(cursorescapefmt, tag))
} else { } else {
win.print(screen, lnwidth+1, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), tag)) win.print(ui.screen, lnwidth+1, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), tag))
} }
} }
} }
@@ -562,11 +557,13 @@ type ui struct {
screen tcell.Screen screen tcell.Screen
sxScreen sixelScreen sxScreen sixelScreen
polling bool polling bool
focused bool
wins []*win wins []*win
promptWin *win promptWin *win
msgWin *win msgWin *win
menuWin *win menuWin *win
msg string msg string
msgIsStat bool
regPrev *reg regPrev *reg
dirPrev *dir dirPrev *dir
exprChan chan expr exprChan chan expr
@@ -592,10 +589,12 @@ func newUI(screen tcell.Screen) *ui {
ui := &ui{ ui := &ui{
screen: screen, screen: screen,
polling: true, polling: true,
focused: true,
wins: getWins(screen), wins: getWins(screen),
promptWin: newWin(wtot, 1, 0, 0), promptWin: newWin(wtot, 1, 0, 0),
msgWin: newWin(wtot, 1, 0, htot-1), msgWin: newWin(wtot, 1, 0, htot-1),
menuWin: newWin(wtot, 1, 0, htot-2), menuWin: newWin(wtot, 1, 0, htot-2),
msgIsStat: true,
exprChan: make(chan expr, 1000), exprChan: make(chan expr, 1000),
keyChan: make(chan string, 1000), keyChan: make(chan string, 1000),
tevChan: make(chan tcell.Event, 1000), tevChan: make(chan tcell.Event, 1000),
@@ -653,10 +652,11 @@ func (ui *ui) sort() {
func (ui *ui) echo(msg string) { func (ui *ui) echo(msg string) {
ui.msg = msg ui.msg = msg
ui.msgIsStat = false
} }
func (ui *ui) echomsg(msg string) { func (ui *ui) echomsg(msg string) {
ui.msg = msg ui.echo(msg)
log.Print(msg) log.Print(msg)
} }
@@ -669,7 +669,7 @@ func optionToFmtstr(optstr string) string {
} }
func (ui *ui) echoerr(msg string) { func (ui *ui) echoerr(msg string) {
ui.msg = fmt.Sprintf(optionToFmtstr(gOpts.errorfmt), msg) ui.echo(fmt.Sprintf(optionToFmtstr(gOpts.errorfmt), msg))
log.Printf("error: %s", msg) log.Printf("error: %s", msg)
} }
@@ -754,7 +754,8 @@ func (ui *ui) loadFileInfo(nav *nav) {
} }
} }
ui.echo(fileInfo) ui.msg = fileInfo
ui.msgIsStat = true
} }
func (ui *ui) drawPromptLine(nav *nav) { func (ui *ui) drawPromptLine(nav *nav) {
@@ -855,16 +856,19 @@ func (ui *ui) drawRuler(nav *nav) {
} }
} }
if copy > 0 { if copy > 0 {
selection = append(selection, fmt.Sprintf("\033[33;7m %d \033[0m", copy)) copyStr := fmt.Sprintf(optionToFmtstr(gOpts.copyfmt), fmt.Sprintf(" %d ", copy))
selection = append(selection, copyStr)
} }
if move > 0 { if move > 0 {
selection = append(selection, fmt.Sprintf("\033[31;7m %d \033[0m", move)) moveStr := fmt.Sprintf(optionToFmtstr(gOpts.cutfmt), fmt.Sprintf(" %d ", move))
selection = append(selection, moveStr)
} }
} }
currSelections := nav.currSelections() currSelections := nav.currSelections()
if len(currSelections) > 0 { if len(currSelections) > 0 {
selection = append(selection, fmt.Sprintf("\033[35;7m %d \033[0m", len(currSelections))) selectStr := fmt.Sprintf(optionToFmtstr(gOpts.selectfmt), fmt.Sprintf(" %d ", len(currSelections)))
selection = append(selection, selectStr)
} }
progress := []string{} progress := []string{}
@@ -1029,7 +1033,7 @@ func (ui *ui) draw(nav *nav) {
role = Active role = Active
} }
if dir := ui.dirOfWin(nav, i); dir != nil { if dir := ui.dirOfWin(nav, i); dir != nil {
ui.wins[i].printDir(ui.screen, dir, &context, ui.wins[i].printDir(ui, dir, &context,
&dirStyle{colors: ui.styles, icons: ui.icons, role: role}, &dirStyle{colors: ui.styles, icons: ui.icons, role: role},
nav.previewLoading) nav.previewLoading)
} }
@@ -1060,7 +1064,7 @@ func (ui *ui) draw(nav *nav) {
preview := ui.wins[len(ui.wins)-1] preview := ui.wins[len(ui.wins)-1]
if curr.IsDir() { if curr.IsDir() {
preview.printDir(ui.screen, ui.dirPrev, &context, preview.printDir(ui, ui.dirPrev, &context,
&dirStyle{colors: ui.styles, icons: ui.icons, role: Preview}, &dirStyle{colors: ui.styles, icons: ui.icons, role: Preview},
nav.previewLoading) nav.previewLoading)
} else if curr.Mode().IsRegular() { } else if curr.Mode().IsRegular() {
@@ -1445,6 +1449,9 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
log.Printf("Got EventError: '%s' at %s", tev.Error(), tev.When()) log.Printf("Got EventError: '%s' at %s", tev.Error(), tev.When())
case *tcell.EventInterrupt: case *tcell.EventInterrupt:
log.Printf("Got EventInterrupt: at %s", tev.When()) log.Printf("Got EventInterrupt: at %s", tev.When())
case *tcell.EventFocus:
ui.focused = tev.Focused
return draw
} }
return nil return nil
} }
@@ -1505,6 +1512,43 @@ func (ui *ui) resume() error {
return err return err
} }
func (ui *ui) exportMode() {
getMode := func() string {
if strings.HasPrefix(ui.cmdPrefix, "delete") {
return "delete"
}
if strings.HasPrefix(ui.cmdPrefix, "replace") || strings.HasPrefix(ui.cmdPrefix, "create") {
return "rename"
}
switch ui.cmdPrefix {
case "filter: ":
return "filter"
case "find: ", "find-back: ":
return "find"
case "mark-save: ", "mark-load: ", "mark-remove: ":
return "mark"
case "rename: ":
return "rename"
case "/", "?":
return "search"
case ":":
return "command"
case "$", "%", "!", "&":
return "shell"
case ">":
return "pipe"
case "":
return "normal"
default:
return "unknown"
}
}
os.Setenv("lf_mode", getMode())
}
func (ui *ui) exportSizes() { func (ui *ui) exportSizes() {
w, h := ui.screen.Size() w, h := ui.screen.Size()
os.Setenv("lf_width", strconv.Itoa(w)) os.Setenv("lf_width", strconv.Itoa(w))