Showing preview only (749K chars total). Download the full file or copy to clipboard to get everything.
Repository: gokcehan/lf
Branch: master
Commit: 551f9d3418c0
Files: 73
Total size: 721.6 KB
Directory structure:
gitextract_3_ndz1ve/
├── .github/
│ ├── dependabot.yml
│ └── workflows/
│ ├── go.yml
│ └── release.yml
├── .gitignore
├── .golangci.yaml
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── app.go
├── client.go
├── colors.go
├── colors_test.go
├── complete.go
├── complete_test.go
├── copy.go
├── df_openbsd.go
├── df_statfs.go
├── df_statvfs.go
├── df_windows.go
├── diacritics.go
├── diacritics_test.go
├── doc.md
├── doc.txt
├── etc/
│ ├── colors.example
│ ├── icons.example
│ ├── icons_colored.example
│ ├── lf.bash
│ ├── lf.csh
│ ├── lf.fish
│ ├── lf.nu
│ ├── lf.ps1
│ ├── lf.vim
│ ├── lf.zsh
│ ├── lfcd.cmd
│ ├── lfcd.csh
│ ├── lfcd.fish
│ ├── lfcd.nu
│ ├── lfcd.ps1
│ ├── lfcd.sh
│ ├── lfrc.cmd.example
│ ├── lfrc.example
│ ├── lfrc.ps1.example
│ └── ruler.default
├── eval.go
├── eval_test.go
├── gen/
│ ├── build.sh
│ ├── deflist.lua
│ ├── doc.sh
│ └── package.sh
├── go.mod
├── go.sum
├── icons.go
├── key.go
├── key_test.go
├── lf.1
├── lf.desktop
├── main.go
├── misc.go
├── misc_test.go
├── nav.go
├── opts.go
├── os.go
├── os_windows.go
├── parse.go
├── ruler.go
├── scan.go
├── server.go
├── sixel.go
├── termseq.go
├── termseq_test.go
├── ui.go
└── watch.go
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/dependabot.yml
================================================
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
commit-message:
prefix: chore
include: scope
- package-ecosystem: gomod
directory: /
schedule:
interval: daily
commit-message:
prefix: chore
include: scope
================================================
FILE: .github/workflows/go.yml
================================================
name: Go
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Check formatting
run: go fmt && git diff --exit-code
tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.5.0
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- { os: android, arch: arm64 }
- { os: darwin, arch: amd64 }
- { os: darwin, arch: arm64 }
- { os: dragonfly, arch: amd64 }
- { os: freebsd, arch: "386" }
- { os: freebsd, arch: amd64 }
- { os: freebsd, arch: arm }
- { os: illumos, arch: amd64 }
- { os: linux, arch: "386" }
- { os: linux, arch: amd64 }
- { os: linux, arch: arm }
- { os: linux, arch: arm64 }
- { os: linux, arch: ppc64 }
- { os: linux, arch: ppc64le }
- { os: linux, arch: mips }
- { os: linux, arch: mipsle }
- { os: linux, arch: mips64 }
- { os: linux, arch: mips64le }
- { os: linux, arch: s390x }
- { os: netbsd, arch: "386" }
- { os: netbsd, arch: amd64 }
- { os: netbsd, arch: arm }
- { os: openbsd, arch: "386" }
- { os: openbsd, arch: amd64 }
- { os: openbsd, arch: arm }
- { os: openbsd, arch: arm64 }
- { os: solaris, arch: amd64 }
- { os: windows, arch: "386" }
- { os: windows, arch: amd64 }
# Unsupported
# - { os: aix, arch: ppc64 }
# - { os: android, arch: "386" }
# - { os: android, arch: amd64 }
# - { os: android, arch: arm }
# - { os: js, arch: wasm }
# - { os: plan9, arch: "386" }
# - { os: plan9, arch: amd64 }
# - { os: plan9, arch: arm }
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # https://github.com/actions/checkout/issues/2199
fetch-tags: true
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Build
run: gen/build.sh
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
================================================
FILE: .github/workflows/release.yml
================================================
name: Release
on:
push:
tags:
- "*"
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- { os: android, arch: arm64 }
- { os: darwin, arch: amd64 }
- { os: darwin, arch: arm64 }
- { os: dragonfly, arch: amd64 }
- { os: freebsd, arch: "386" }
- { os: freebsd, arch: amd64 }
- { os: freebsd, arch: arm }
- { os: illumos, arch: amd64 }
- { os: linux, arch: "386" }
- { os: linux, arch: amd64 }
- { os: linux, arch: arm }
- { os: linux, arch: arm64 }
- { os: linux, arch: ppc64 }
- { os: linux, arch: ppc64le }
- { os: linux, arch: mips }
- { os: linux, arch: mipsle }
- { os: linux, arch: mips64 }
- { os: linux, arch: mips64le }
- { os: linux, arch: s390x }
- { os: netbsd, arch: "386" }
- { os: netbsd, arch: amd64 }
- { os: netbsd, arch: arm }
- { os: openbsd, arch: "386" }
- { os: openbsd, arch: amd64 }
- { os: openbsd, arch: arm }
- { os: openbsd, arch: arm64 }
- { os: solaris, arch: amd64 }
- { os: windows, arch: "386" }
- { os: windows, arch: amd64 }
# Unsupported
# - { os: aix, arch: ppc64 }
# - { os: android, arch: "386" }
# - { os: android, arch: amd64 }
# - { os: android, arch: arm }
# - { os: js, arch: wasm }
# - { os: plan9, arch: "386" }
# - { os: plan9, arch: amd64 }
# - { os: plan9, arch: arm }
steps:
- uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Build
run: gen/build.sh
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
- name: Package
run: gen/package.sh
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: lf-${{ matrix.os }}-${{ matrix.arch }}
path: dist/*
release:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download artifacts
uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true
- name: Release
uses: softprops/action-gh-release@v2
with:
files: dist/*
winget:
runs-on: ubuntu-latest
needs: build
steps:
- uses: vedantmgoyal2009/winget-releaser@v2
with:
identifier: gokcehan.lf
version: ${{ github.ref_name }}
installers-regex: '-windows-\w+\.zip$'
token: ${{ secrets.WINGET_TOKEN }}
================================================
FILE: .gitignore
================================================
lf
lf.exe
tags
dist/
vendor/
================================================
FILE: .golangci.yaml
================================================
version: "2"
linters:
settings:
errcheck:
exclude-functions:
- (*github.com/fsnotify/fsnotify.Watcher).Close
- (*net.TCPConn).CloseWrite
- (*net.UnixConn).CloseWrite
- (*os.File).Close
- (*os.File).Write
- (*text/tabwriter.Writer).Flush
- (io.Closer).Close
- (io.Writer).Write
- (net.Conn).Close
- (net.Listener).Close
- fmt.Fprintf
- fmt.Fprintln
- io.WriteString
- os.Setenv
- syscall.Close
issues:
max-issues-per-linter: 0 # no limit
max-same-issues: 0 # no limit
================================================
FILE: CHANGELOG.md
================================================
# Changelog
All changes observable to end users should be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and should contain the following sections for each release:
- `Changed`
- `Added`
- `Fixed`
## Unreleased
### Changed
- The key `<backspace2>` has been renamed to `<backspace>` for `map` keybindings (#2286).
- `.Stat.DirSize` and `.Stat.DirCount` in the ruler file no longer have a pointer type, and will be set to `-1` instead of `nil` if the corresponding value cannot be determined (#2397).
- `setlocal` commands no longer support the ability to specify recursive directories (#2415). For use cases where `setlocal` should apply to a directory based on some condition, it is recommended to script this inside the `on-load` hook command.
### Added
- Emoji sequences containing Zero Width Joiner characters are now displayed as a single combined glyph (#2286).
- A new field `.All` is added to the `ruler` file to display the number of all files (i.e. visible + hidden) in the current working directory (#2376).
- A new option `numbercursorfmt` is added to further customize the appearance of line numbers (#2395).
- A new option `terminalcursor` is added to customize the appearance of the terminal cursor (#2441).
- A new option `borderstyle` is added to control whether `drawbox` draws an outline, separators, or both (#2445).
- The `loading...` message delay of 100 milliseconds for file previews is now applied to directories as well (#2410).
- `lf` will now automatically change to the parent directory if the current directory no longer exists and the `watch` option is enabled (#2424).
### Fixed
- Previews are now cleaned when changing to an empty directory (#2369).
- Previews are now correctly updated on `visual-change` (#2373).
- The `dircounts` indicator for errors is changed back to `!` instead of `?` (#2372).
- The `select` command can now select files immediately after creation as part of a script (#2377).
- The `on-load` hook command now ignores `.git` directories to reduce flicker and repeated `on-load` triggers (#2382).
- Preview messages like `empty` or `loading...` have their alignment improved (#2400).
- A bug where the `loading...` message was not displayed for volatile previews after the first time is now fixed (#2410).
- The `cmd-transpose` command now advances the cursor correctly after swapping characters (#2413).
- Symbolic links are no longer followed when changing directories (#2423).
- Using the `select` command with a blank string as the argument now properly raises an error instead of changing to the parent directory (#2429).
- Executable files on Windows are now correctly recognized for icon and color lookup based on `PATHEXT` (#2448).
## [r41](https://github.com/gokcehan/lf/releases/tag/r41)
### Changed
- The `previewer` script no longer skips non-regular files (#2327).
- Line numbers now take up less space when both `number` and `relativenumber` are enabled (#2331).
- Changes have been made to ruler configuration (#2338):
- The ruler file is no longer experimental.
- The ruler file will be used by default unless `rulerfmt` (now a blank string by default) is specified.
- The ruler file is no longer read from fixed locations like `~/.config/lf/ruler`, and instead the `rulerfile` option has been repurposed to specify the path of the ruler file.
### Added
- A new server command `list` is added to print the IDs of all currently connected clients (#2314).
- The `previewer` and `cleaner` scripts now have their `stderr` output logged (#2316).
- The `ruler` file now supports `.Stat.Extension`, `.Stat.AccessTime`, `.Stat.BirthTime`, `.Stat.ChangeTime` and `.Stat.CustomInfo` (#2329), as well as `.Stat.DirSize` and `.Stat.DirCount` (#2343).
- A new option `mergeindicators` is added to reduce the gap before filenames, by merging tag and selection indicators into a single column (#2330).
### Fixed
- A bug where sixel images fail to display when scrolling back and forth is now fixed (#2301).
- Newline characters are now ignored when drawing the ruler with the `ruler` file configured (#2319).
- A potential crash when using the `scroll-up`/`scroll-down` commands is now fixed (#2320).
- Case-insensitive command-line completions no longer cause user input to be displayed in lowercase (#2336).
- Calculation of window widths for the `ratios` option is now more accurate (#2347).
## [r40](https://github.com/gokcehan/lf/releases/tag/r40)
### Fixed
- Error messages from the server are no longer written to the terminal which causes the UI to break (#2290).
- A bug where file previews fail to load properly when scrolling quickly is now fixed (#2292).
## [r39](https://github.com/gokcehan/lf/releases/tag/r39)
### Changed
- File extensions are now shown for long filenames even if they are truncated (#2159).
- The history file will no longer contain a space between the prefix and the actual command (e.g. `:quit` instead of `: quit`) for each line (#2161). The command `sed -i -E 's/^(.) /\1/' ~/.local/share/lf/history` can be run to make an existing history file compatible with the new format.
- The `cmd-history-next` and `cmd-history-prev` commands will now select only matching entries if part of the command is typed beforehand (#2161). Consecutive duplicate entries will also be skipped for convenience.
- The string representation of commands shown when displaying keybindings is simplified (e.g. `cd ~` instead of `cd -- [~]`) (#2165).
- `yes-no-prompts` now use the same design everywhere (#2212).
- Logs generated by `-log <path>` now get appended to `<path>` instead of overwriting it (#2215).
- The `showbinds` menu now hides the redundant `mode` column (#2226) (#2228) and omits already typed keys (#2249).
- The `setlocal` command no longer requires absolute paths (#2253).
- The string representation of file permissions now matches the traditional `Unix` format instead of the one used by `Go` (#2270).
### Added
- A new command `cmd-menu-discard` is added to allow exiting the completion menu with completions discarded (#2146).
- The `lf_mode` environment variable will now be set to `compmenu` if the completion menu is active (#2146).
- A `ruler` config file is added as an alternate method for customizing the ruler (#2186). This is intended to eventually replace the existing `rulerfmt`/`statfmt` options and must be enabled using the new `rulerfile` option. **This feature is currently experimental.**
- A new option `preload` is added to enable calling the `previewer` to generate previews in advance (#2206). **This feature is currently experimental.**
- `OSC 8` escape codes to render clickable hyperlinks are now supported (#2243).
### Fixed
- `shell-pipe` commands no longer wait for output if kept open after the command has finished running (#2155).
- Natural sorting now compares string lengths when dealing with equivalent numbers (e.g. `0` is ordered before `00`) (#2177).
- A bug where the copy progress indicator only displayed the first time a file was copied is now fixed (#2181).
- A bug where the `source` command does not show an error message upon failure is now fixed (#2189).
- The `addcustominfo` (#2198) and `setlocal` (#2254) (#2259) commands, as well as the `cleaner` and `previewer` options (#2211) now support filename completions.
- A bug where an empty `custom` info property would still take up space is now fixed (#2208).
- A bug where setting `drawbox` could lead to scrolling outside the view is now fixed (#2210) (#2218).
- The preview cache is now not cleared when setting `ratios` to its current value (#2218).
- Filtering is fixed when using special characters in the search pattern if the `filtermethod` is `text` (#2231).
- Custom commands that output messages (e.g. `cmd greet echo 'hello world'`) now display properly (#2245).
- Errors in config files are now displayed properly (#2246).
## [r38](https://github.com/gokcehan/lf/releases/tag/r38)
### Changed
- The deprecated `globfilter` and `globsearch` options are now removed (#2108).
- Sixel image support is now enabled by default, and the `sixel` option has been removed as it is no longer required (#2109).
- The `dircache` option has now been removed (#2110). This was previously used as a workaround to disable the directory cache since at the time changes to files were not detected reliably, but this is no longer the case.
- The experimental `locale` option has been removed in favor of the recommendation to use `addcustominfo`/`set sortby custom` for custom sorting (#2111).
- The existing `doc` command has been renamed to `help` so that it is more natural for users (#2125).
- Text previews are no longer displayed with a padding of two spaces by default (#2131). Instead, a custom padding can be added in the `previewer` script, for example by piping to `sed 's/^/ /'`.
### Added
- Sixel image previews can now display multiple images as well as text (#2109).
- A new option `sizeunits` is added to allow displaying file sizes in either binary or decimal units (#2118).
- `XDG_CONFIG_HOME` and `XDG_DATA_HOME` are now taken into account when looking up config/data files on Windows (#2119).
- Three new options `menufmt`, `menuheaderfmt`, and `menuselectfmt` are added to customize the appearance of the menu (#2123).
### Fixed
- Error messages are now cleared after running interactive commands such as `invert`/`unselect`/`tag-toggle` (#2117).
- The menu is now drawn over sixel images instead of being hidden behind it if they overlap (#2122).
- A bug which prevents the user from quitting when copying files with a size of 0 has been fixed (#2130).
- `lf -remote` should no longer busy wait and cause high CPU usage if its output is not being read (#2138).
- The parameter types for command line options shown by `lf -help` now match the synopsis in the documentation (#2153).
## [r37](https://github.com/gokcehan/lf/releases/tag/r37)
### Changed
- The default paths of files read by `lf` is changed on Windows, to separate configuration files from data files (#2051).
- Configuration files (`lfrc`/`colors`/`icons`) are now stored in `%APPDATA%`, which can be overridden by `%LF_CONFIG_HOME%`.
- Data files (`files`/`marks`/`tags`/`history`) are now stored in `%LOCALAPPDATA%`, which can be overridden by `%LF_DATA_HOME%`.
- The change for following symbolic links when tagging files from the previous release has been reverted (#2055). The previous change made it impossible to tag symbolic links separately from their targets, and also caused `lf` to run slowly in some cases.
- The existing `globfilter` and `globsearch` options are now deprecated in favor of the new `filtermethod` and `searchmethod` options, which support regex patterns (#2058).
- `set globfilter true` should be replaced by `set filtermethod glob`.
- `set globsearch true` should be replaced by `set searchmethod glob`.
- File sizes are now displayed using binary units (e.g. `1.0K` means 1024 bytes, not 1000 bytes) (#2062). The maximum width for displaying the file size has been increased from four to five characters.
### Added
- `dircounts` are now respected when sorting by size (#2025).
- The `info` and `sortby` options now support `btime` (file creation time) (#2042). This depends on support for file creation times from the underlying system.
- The selection in Visual mode now follows wrapping when `wrapscan`/`wrapscroll` is enabled (#2056).
- Input pasted from the terminal is now ignored while in Normal mode (#2059). This prevents pasted content from being treated as keybindings, which can result in dangerous unintended behavior.
- The Command-line mode completion now supports keywords for the `selmode` and `sortby` options (#2061), as well as the `info` and `preserve` options (#2071).
- Command line options are now exported as environment variables in the form `lf_flag_{flag}` (#2079).
- Support is added for terminal escape sequences that disable text styles (#2101).
### Fixed
- `dircounts` are now automatically populated after enabling it (#2049).
- A bug where directories are unsorted after reloading when `dircache` is disabled is now fixed (#2050).
- Filenames are now escaped when completing shell commands (#2071).
- A bug where completion menu entries are misaligned when containing fullwidth characters is now fixed (#2071).
- The `on-load` command now passes all files in the directory as arguments, not just files visible to the user (#2077).
- Failure to move files across different filesystems is now shown as an error instead of a success in the UI (#2085).
- Errors are now logged correctly when there are multiple errors during move/copy operations (#2089).
- The progress for copy operations is now displayed immediately in the UI, even if it takes time to calculate the total size of files to be copied (#2093).
## [r36](https://github.com/gokcehan/lf/releases/tag/r36)
### Changed
- Tagging symbolic links now affects the target instead of the symbolic link itself. This mimics the behavior in `ranger` (#1997).
- The experimental command `invert-below` has been removed in favor of the newly added support for Visual mode (#2021).
### Added
- A new placeholder `%P` representing the scroll percentage is added to the `rulerfmt` option (#1985).
- A new `on-load` hook command is added, which is triggered when files in a directory are loaded in `lf` (#2010).
- The `info` option now supports `custom`, allowing users to display custom information for each file (#2012). The custom information should be added by the user via the `addcustominfo` command. Sorting by the custom information is also supported (#2019).
- Support for `visual-mode` has now been added (#2021) (#2035). This includes the following changes:
- A new command `visual` (default `V`) can be used to enter Visual mode.
- A new command `visual-change` (default `o` in Visual mode) can be used to swap the positions of the cursor and anchor (start of the visual selection).
- A new command `visual-accept` (default `V` in Visual mode) can be used to exit Visual mode, adding the visual selection to the selection list.
- A new command `visual-discard` (default `<esc>` in Visual mode) can be used to exit Visual mode, without adding the visual selection to the selection list.
- A new command `visual-unselect` can be used to exit Visual mode, removing the visual selection from the selection list.
- The existing `map` command now adds keybindings for both Normal and Visual modes. Two new commands `nmap` and `vmap` are added which can be used to add keybindings for only Normal or Visual mode respectively.
- Two new commands `nmaps` and `vmaps` are added to display the list of keybindings in Normal and Visual mode respectively. These, along with the existing `maps` and `cmaps` commands, now display an extra column indicating the mode for which the keybindings apply to.
- A new option `visualfmt` is added to customize the appearance of the visual selection.
- Two new placeholders `%m` and `%M` are added to `statfmt` to display the mode in the status line. Both will display `VISUAL` when in Visual mode, however in Normal mode `%m` will display as a blank string while `%M` will display `NORMAL`.
- A new placeholder `%v` is added to `rulerfmt` which displays the number of files in the Visual selection. This is included in the default setting for `rulerfmt`.
- The `lf_mode` environment variable will now be set to `visual` while in Visual mode.
- The environment variable `$fv` is now exported to shell commands, which lists the files in the visual selection.
- A `CHANGELOG.md` file has been added to the repo (#2027). This will be updated to describe `Changed`, `Added` and `Fixed` functionality for each new release.
### Fixed
- Displaying sixel images now uses the screen locking API in Tcell, which reduces flickering in the UI (#1943).
- The `cmd-history` command is now ignored outside of Normal or Command-line mode, to prevent accidentally escaping out of other modes (#1971).
- A potential crash when using the `cmd-delete-word-back` command is fixed (#1976).
- The `preserve` option now applies to directories in addition to files when copying. This includes preserving `timestamps` (#1979) and `mode` (#1981).
- The `lfrc.ps1.example` example config file is updated to include PowerShell equivalents for the default commands and keybindings (#1989).
- Quoting for the `lf` environment variable is fixed for PowerShell users (#1990).
- `tempmarks` are no longer cleared after the `sync` command is called (#1996).
- The file stat information is no longer displayed during the execution of a `shell-pipe` command even if the file is updated (#2002).
- Directories are now reloaded properly if any component in the current path is renamed (#2005).
- Write updates for the log file are now ignored when `watch` is enabled. This helps to reduce notification spam and potential of infinite loops (#2015).
- Attempting to `cut`/`copy` files into a directory without execute permissions no longer causes `lf` to crash, and an error message will be displayed instead (#2024).
## [r35](https://github.com/gokcehan/lf/releases/tag/r35)
### Added
- Support is added for displaying underline styles (#1896).
- Support is added for displaying underline colors (#1933).
- A new subcommand `files` is added to the `query` server command to list the files in the current directory as displayed in `lf` (#1949).
- A new `tty-write` command is added for sending escape sequences to the terminal (#1961). **Writing directly to `/dev/tty` is not recommended as it not synchronized and can interfere with drawing the UI.**
### Fixed
- The `trash` command in `lfrc.example` now verifies if the trash directory exists before moving files there (#1918).
- `lf` should no longer crash if it fails to open the log file (#1937).
- Arrow keys are now handled properly when waiting for a key press after executing a `shell-wait` (`!`) command (#1956).
- The `previewer` script is now only invoked for the current directory (instead of all directories), when starting `lf` with `dirpreviews` enabled (#1958).
## [r34](https://github.com/gokcehan/lf/releases/tag/r34)
### Changed
- The `autoquit` option is now enabled by default (#1839).
### Added
- A new option `locale` is added to sort files based on the collation rules of the provided locale (#1818). **This feature is currently experimental.**
- A new `on-init` hook command is added to allow triggering custom actions when `lf` has finished initializing and connecting to the server (#1838).
### Fixed
- The background color now renders properly when displaying filenames (#1849).
- A bug where the `on-quit` hook command causes an infinite loop has been fixed (#1856).
- File sizes now display correctly after being copied when `watch` is enabled (#1881).
- Files are now automatically unselected when removed by an external process, when `watch` is enabled (#1901).
## [r33](https://github.com/gokcehan/lf/releases/tag/r33)
### Changed
- The `globsearch` option, which previously affected both searching and filtering, now affects only searching. A new `globfilter` option is introduced to enable globs when filtering, and acts independently from `globsearch` (#1650).
- The `hidecursorinactive` option is replaced by the `on-focus-gained` and `on-focus-lost` hook commands. These commands can be used to invoke custom behavior when the terminal gains or loses focus (#1763).
- The `ruler` option (deprecated in favor of `rulerfmt`) is now removed (#1766).
- Line numbers from the `number` and `relativenumber` options are displayed in the main window only, instead of all windows (#1789).
### Added
- Support for Unix domain sockets (for communicating with the `lf` server) is added for Windows (#1637).
- Color and icon configurations now support the `target` keyword for symbolic links (#1644).
- A new option `roundbox` is added to use rounded corners when `drawbox` is enabled (#1653).
- A new option `watch` is added to allow using filesystem notifications to detect and display changes to files. This is an alternative to the `period` option, which polls the filesystem periodically for changes (#1667).
- Icons can now be colored independently of the filename (#1674).
- The `info` option now supports `perm`, `user` and `group` to display the permissions, user and group respectively for each file (#1799).
- A new option `showbinds` is added to toggle whether the keybinding hints are shown when a keybinding is partially typed (#1815).
### Fixed
- Sorting by extension is fixed for hidden files (#1670).
- The `on-quit` hook command is now triggered when the terminal is closed (#1681).
- Previews no longer flicker when deleting files (#1691).
- Previews no longer flicker when directories are being reloaded (#1697).
- `lfcd.nu` now runs properly without raising errors (#1728).
- Image previews (composed of ASCII art) containing long lines should now display properly (#1737).
- The performance is improved when copying files (#1749).
- `lfcd.cmd` now handles directories with special characters (#1772).
- Icon colors are no longer clipped when displaying in Windows Terminal (#1777).
- The file stat info is now cleared when changing to an empty directory (#1808).
- Error messages are cleared when opening files (#1809).
## [r32](https://github.com/gokcehan/lf/releases/tag/r32)
### Changed
- The example script `etc/lfcd.cmd` is updated to use the `-print-last-dir` option instead of `-last-dir-path` (#1444). Similar changes have been made for `etc/lfcd.ps1` (#1491), `etc/lfcd.fish` (#1503), and `etc/lfcd.nu` (#1575).
- The documentation from `lf -doc` and the `doc` command is now generated from Markdown using `pandoc` (#1474).
### Added
- A new option `hidecursorinactive` is added to hide the cursor when the terminal is not focused (#965).
- A new special command `on-redraw` is added to be able to run a command when the screen is redrawn or when the terminal is resized (#1479).
- Options `cutfmt`, `copyfmt` and `selectfmt` are added to configure the indicator color for cut/copied/selected files respectively (#1540).
- `zsh` completion is added for the `lfcd` command (#1564).
- The file stat information now falls back to displaying user/group ID if looking up the user/group name fails (#1590).
- A new environment variable `lf_mode` is now exported to indicate which mode `lf` is currently running in (#1594).
- Default icons are added for Docker Compose files (#1626).
### Fixed
- Default value of `rulerfmt` option is now left-padded with spaces to visually separate it from the file stat information (#1437).
- Previews should now work for files containing lines with 65536 characters or more (#1447).
- Sixel previews should now work when using `lfcd` scripts (#1451).
- Colors and icons should now display properly for character device files (#1469).
- The selection file is now immediately synced to physical storage after writing to it (#1480).
- Timestamps are preserved when moving files across devices (#1482).
- Fix crash for `high` and `low` commands when `scrolloff` is set to a large value (#1504).
- Documentation is updated with various spelling and grammar fixes (#1518).
- Files beginning with a dot (e.g. `.gitignore`) are named correctly after `paste` if another file with the same name already exists (#1525).
- Prevent potential race condition when sorting directory contents (#1526).
- Signals are now handled properly even after receiving and ignoring `SIGINT` (#1549).
- The file stat information should now update properly after using the `cd` command to change to a directory for the first time (#1536).
- Previous error messages should now be cleared after a `mark-save`/`mark-remove` operation (#1544).
- Fix high CPU usage issue when viewing CryFS filesystems (#1607).
- Invalid entries in the `marks` and `tags` files now raise an error message instead of crashing (#1614).
- Startup time is improved on Windows (#1617).
- Sixel previews are now resized properly when the horizontal size of the preview window changes (#1629).
- The cut buffer is only cleared if the `paste` operation succeeds (#1652).
- The extension after `.` is ignored to set the cursor position when renaming a directory (#1664).
- The option `period` should not cause flickers in sixel previews anymore (#1666).
## [r31](https://github.com/gokcehan/lf/releases/tag/r31)
### Changed
- There has been some changes in the server protocol. Make sure to kill the old server process when you update to avoid errors (i.e. `lf -remote 'quit!'`).
- A new server command `query` is added to expose internal state to users (#1384). A new builtin command `cmds` is added to display the commands. The old builtin command `jumps` is now removed. The builtin commands `maps` and `cmaps` now use the new server command.
- Environment variable exporting for files and options are not performed anymore while previewing and cleaning to avoid various issues with race conditions (#1354). Cleaning program should now instead receive an additional sixth argument for the next file path to be previewed to allow comparisons with the previous file path. User options (i.e. `user_{option}`) are now exported whenever they are changed (#1418).
- Command outputs are now exclusively attached to `stderr` to allow printing the last directory or selection to `stdout` (#1399) (#1402). Two new command line options `-print-last-dir` and `-print-selection` are added to print the last directory and selection to `stdout`. The example script `etc/lfcd.sh` is updated to use `-print-last-dir` instead. Other `lfcd` scripts are also likely to be updated in the future to use the new method (patches are welcome).
- The option `ruler` is now deprecated in favor of its replacement `rulerfmt` (#1386). The new `rulerfmt` option is more capable (i.e. displays option values, supports colors and attributes, and supports optional fields) and more consistent with the rest of our options. See the documentation for more information.
### Added
- Modifier keys (i.e. control, shift, alt) with special keys (e.g. arrows, enter) are now supported for most combinations (#1248).
- A new option `borderfmt` is added to configure colors for pane borders (#1251).
- New `lf` specific environment variables, `LF_CONFIG_HOME` on Windows and `LF_CONFIG/DATA_HOME` on Unix, are now supported to set the configuration directory (#1253).
- Tilde (i.e. `~`) expansion is performed during completion to be able to use expanded tilde paths as command arguments (#1246).
- A new option `preserve` is added to preserve attributes (i.e. mode and timestamps) while copying (#1026).
- The file `etc/icons.example` is updated for nerd-fonts v3.0.0 (#1271).
- A new builtin command `clearmaps` is added to clear all default keybindings except for `read` (i.e. `:`) and `cmap` keybindings to be able to `:quit` (#1286).
- A new option `statfmt` is added to configure the status line at the bottom (#1288).
- A new option `truncatepct` is added to determine the location of truncation from the beginning in terms of percentage (#1029).
- A new option `dupfilefmt` is added to configure the names of duplicate files while copying (#1315).
- Shell scripts `etc/lf.nu` and `etc/lfcd.nu` are added to the repository to allow completion and directory change with Nushell (#1341).
- Sixels are now supported for previewing (#1211). A new option `sixel` is added to enable this behavior.
- A new configuration keyword `setlocal` is added to configure directory specific options (#1381).
- A new command line command `cmd-delete-word-back` (default `a-backspace` and `a-backspace2`) is added to use word boundaries when deleting a word backwards (#1409).
### Fixed
- Cursor positions in the directory should now be preserved after file operations that changes the directory (e.g. create or delete) (#1247).
- Option `reverse` should now respect to sort stability requirements (#1261).
- Backspace should not exit `filter` mode anymore (#1269).
- Truncated double width characters should not cause misalignment for the file information (#1272).
- Piping shell commands should not refresh the preview anymore (#1281).
- Cursor position should now update properly after a terminal resize (#1290).
- Directories should now be reloaded properly after a `delete` operation (#1292).
- Executable file completion should not add entries to the log file anymore (#1307).
- Blank input lines are now allowed in piping shell commands (#1308).
- Shell commands arguments on Windows should now be quoted properly to fix various issues (#1309).
- Reloading in a symlink directory should not follow the symlink anymore (#1327).
- Command `load` should not flicker image previews anymore (#1335).
- Asynchronous shell commands should now trigger `load` automatically when they are finished (#1345).
- Changing the value of `preview` option should now clear image previews (#1350).
- Cursor position in the status line at the bottom should now consider double width characters properly (#1348).
- Filenames should only be quoted for `cmd` on Windows to avoid quoting issues for PowerShell (#1371).
- Inaccessible files should now be included in the directory list and display their `lstat` errors in the status line at the bottom (#1382).
- Command line command `cmd-delete-word` should now add the deleted text to the yank buffer (#1409).
## [r30](https://github.com/gokcehan/lf/releases/tag/r30)
### Added
- A new builtin command `jumps` is added to display the jump list (#1233).
- A new possible field `filter` is added to `ruler` option to display the filter indicator (#1223).
### Fixed
- Broken mappings for `bottom` command due to recent changes are fixed (#1240).
- Selecting a file does not scroll to bottom anymore (#1222).
- Broken builds on some platforms due to recent changes are fixed (#1168).
## [r29](https://github.com/gokcehan/lf/releases/tag/r29)
### Changed
- Three new options `cursoractivefmt`, `cursorparentfmt` and `cursorpreviewfmt` have been added (#1086) (#1106). The default style for the preview cursor is changed to underline. You can revert back to the old style with `set cursorpreviewfmt "\033[7m"`.
- An alternative boolean option syntax `set option true/false` is added in addition to the previous syntax `set option/nooption` (#758). If you have `set option true` in your configuration, then there is no need for any changes as it was already working as expected accidentally. If you have `set option false` in your configuration, then previously it was enabling the option instead accidentally but now it is disabling the option as intended. Any other syntax including `set option on/off` are now considered errors and result in error messages. Boolean option toggling `set option!` remains unchanged with no new alternative syntax added.
- Cursor is now placed at the file extension by default in rename prompts (#1162).
- The environment variable `VISUAL` is checked before `EDITOR` for the default editor choice (#1197).
### Added
- Mouse wheel events with the Control modifier have been bound to scrolling by default (#1051).
- Option values for `tagfmt` and `errorfmt` have been simplified to be able to avoid the reset sequence (#1086).
- Two default command line bindings for `<down>` and `<up>` have been added for `cmd-history-next` and `cmd-history-prev` respectively (#1112).
- A new command `invert-below` is added to invert all selections below the cursor (#1101). **This feature is currently experimental.**
- Two new commands `maps` and `cmaps` have been added to display the current list of bindings (#1146) (#1201).
- A new option `numberfmt` is added to customize line numbers (#1177).
- A new environment variable `lf_count` is now exported to use the count in shell commands (#1187).
- A new environment variable `lf` is now exported to be used as the executable path (#1176).
- An example `mkdir` binding is added to the example configuration (#1188).
- An example binding to show execution results is added to the example configuration (#1188).
- Commands `top` and `bottom` now accepts counts to move to a specific line (#1196).
- A new option `ruler` is added to customize the ruler information with a new addition for free disk space (#1168) (#1205).
### Fixed
- Example `lfcd` files have been made safer to be able to alias the commands as `lf` (#1049).
- Backspace should not exit from `rename:` mode anymore (#1060).
- Preview is now refreshed even if the selection does not change (#1074).
- Stale directory cache entry is now deleted during rename (#1138).
- File information is now updated properly after reloading (#1149).
- Window widths are now calculated properly when `drawbox` is enabled (#1150).
- Line number widths are now calculated properly when there are exactly 10 entries (#1151).
- Preview is not redrawn in async shell commands (#1164).
- A small delay is added before showing loading text in preview pane to avoid flickering (#1154).
- Hard-coded box drawing characters are replaced with Tcell constants to enable the fallback mechanism (#1170).
- Option `relativenumber` now shows zero in the current line (#1171).
- Completion is not stuck in an infinite loop anymore when a match is longer than the window width (#1183).
- Completion now inserts the longest match even if there is no word before the cursor (#1184).
- Command `doc` should now work even if `lf` is not in the `PATH` variable (#1176).
- Directory option changes should not crash the program anymore (#1204).
- Option `selmode` is now validated for the accepted values (#1206).
## [r28](https://github.com/gokcehan/lf/releases/tag/r28)
### Changed
- Extension matching for colors and icons are now case insensitive (#908).
### Added
- Three new commands `high`, `middle`, and `low` are added to move the current selection relative to the screen (#824).
- Backspace on empty prompt now switches to Normal mode (#836).
- A new `history` option is now added to be able to disable history (#866).
- A new special expansion `%S` spacer is added for `promptfmt` to be able to right align parts (#867).
- A new command-line command `cmd-menu-accept` is now added to accept the currently selected match (#934).
- Command-line commands should now be shown in completion for `map` and `cmap` (#934).
- Italic escape codes should now be working in previews (#936).
- Position and size information are now also passed to the `cleaner` script as arguments (#945).
- A new option `dirpreviews` is now added to also pass directories to the `previewer` script (#842).
- A new option `selmode` is now added to be able to limit the selection to the current directory (#849).
- User defined options with `user_` prefix are now supported (#865).
- Adding or removing `$`/`%`/`!`/`&` characters in `:` mode should now change the mode accordingly (#960).
- A new special command `on-select` is now added to be able to run a command after the selection changes (#864).
- Mouse support is extended to be able to click filenames for selection and opening (#963).
- Two new environment variables `lf_width` and `lf_height` are now exported for shell commands.
### Fixed
- Option `tagfmt` can now be changed properly.
- User name, group name, and link count should now be displayed as before where available (#829).
- Tagging files with colons in their names should now work as expected (#857).
- Some multibyte characters should now be handled properly for completion (#934).
- Menu completion for a file in a subdirectory should now be working properly (#934).
- File completion should now be escaped properly in menu completion (#934).
- First use of `cmd-menu-complete-back` should now select the last completion as expected (#934).
- Broken symlinks should now be working properly in completion (#934).
- Files with stat errors should now be skipped properly in completion (#934).
- Empty search with `incsearch` option should now be handled properly (#944).
- History position is now also reset when leaving the command line (#953).
- Mouse drag events are now ignored properly to avoid command repetition (#962).
- Environment variables `HOME` and `USER` should now be used as fallback for locations on some systems (#972).
- File information is now displayed in the status line at first launch when there are no errors in the configuration file (#994).
## [r27](https://github.com/gokcehan/lf/releases/tag/r27)
### Changed
- Creation of log files are now disabled by default. Instead, a new command line option `-log` is provided.
- `copy` selections are now kept after `paste` (#745). You can use `map p :paste; clear` to get the old behavior.
- The socket file is now created in `XDG_RUNTIME_DIR` when set, with a fallback to the temporary directory otherwise.
- Directory counting with `dircounts` option is moved from UI drawing to directory reading to be run asynchronously without locking the UI. With this change, manual `reload` commands might be necessary when `dircounts` is changed at runtime. Indicators for errors are changed to `!` instead of `?` to distinguish them from missing values.
- The default icons are now replaced with ASCII characters to avoid font issues.
### Added
- Files and options are now exported for `previewer` and `cleaner` scripts. For `cleaner` scripts, this can be used to detect if the file selection is changed or not (e.g. `$1 == $f`) and act accordingly (e.g. skip cleaning).
- A new `tempmarks` option is added to set some marks as temporary (#744).
- The pattern `*filename` is added for colors and icons.
- A new `calcdirsize` command is added to calculate directory sizes (#750).
- Two new options `infotimefmtnew` and `infotimefmtold` are added to configure the time format used in `info` (#751).
- Two new commands `jump-next` (default `]`) and `jump-prev` (default `[`) are added to navigate the jumplist (#755).
- Colors and icons file support is now added to be able to configure without environment variables. Example colors and icons files are added to the repository under `etc` directory. See the documentation for more information.
- For Windows, an example `open` command is now provided in the PowerShell example configuration (#765).
- Two new commands `scroll-up` (default `<c-y>`) and `scroll-down` (default `<c-e>`) are added to be able to scroll the file list without moving (#764).
- A new special command `on-quit` is added to be able to run a command before quitting.
- Two new commands `tag` and `tag-toggle` (default `t`) are now added to be able to tag files (#791).
### Fixed
- `Chmod` calls in the codebase are now removed to avoid TOC/TOU exploits. Instead, file permissions are now set at file creation.
- Socket and log files are now created with only user permissions.
- On Windows, `PWD` variable is now quoted properly.
- Shell commands `%` and `&` are now run in a separate process group (#753).
- Navigation initialization is now delayed after the evaluation of configuration files to avoid startup races and redundant loadings (#759).
- The error message shown when the current working directory does not exist at startup is made more clear.
- Trailing slashes in `PWD` variable are now handled properly.
- Files with `stat` errors are now skipped while reading directories.
## [r26](https://github.com/gokcehan/lf/releases/tag/r26)
### Fixed
- On Windows, input handling is properly resumed after shell commands.
## [r25](https://github.com/gokcehan/lf/releases/tag/r25)
### Added
- A new `dironly` option is added to only show directories and hide regular files (#669).
- A new `dircache` option is added to disable caching of directories (#673).
- Two new commands `filter` and `setfilter` is added along with a new option `incfilter` and a `promptfmt` expansion `%F` to implement directory filtering feature (#667).
- A new special command `pre-cd` is added to run a command before a directory is changed (#685).
- `cmap` command now accepts all expressions similar to `map` (#686).
### Fixed
- Marking a symlink directory should now save the symlink path instead of the target path (#659).
- A number of crashes have been fixed when the `hidden` option is changed.
## [r24](https://github.com/gokcehan/lf/releases/tag/r24)
### Fixed
- Data directory is automatically created before the selection file is written.
- An error is returned for remote commands when the given ID is not connected to the server.
- Prompts longer than the width should not crash the program anymore.
## [r23](https://github.com/gokcehan/lf/releases/tag/r23)
### Changed
- There has been some changes in the server protocol. Make sure to kill the old server process when you update to avoid errors.
- Server `load` and `save` commands are now removed. Instead a local file is used to record file selections (e.g. `~/.local/share/lf/files`). See the documentation for more information.
- Clients are now disconnected from server on quit. The old server `quit` command is renamed to `quit!` to act as a force quit by closing connected client connections first. A new `quit` command is added to only quit when there are no connected clients left.
### Added
- A new `autoquit` option is added to automatically quit the server when there are no connected clients left. This option is disabled by default to keep the old behavior. This is added as an option to avoid respawning server repeatedly when there is often a single client involved but more clients are spawned from time to time.
- A new `-single` command line flag is added to avoid spawning and/or connecting to server on startup. Remote commands would not work in this case as the client does not connect to a server. Local versions of internal `load` and `sync` commands are implemented properly.
- Errors for remote commands are now also shown in the output in addition to the server log file.
- Bright ANSI color escape codes (i.e. 90-97 and 100-107) are now supported.
### Fixed
- Lookahead size for escape codes are increased to recognize longer escape codes used in some image previewers.
- The file preview cache is invalidated when the terminal height changes to fill the screen properly.
- The file preview cache is invalidated when the `drawbox` option changes and true image previews should be triggered to be drawn at updated positions.
- A crash scenario is fixed when `hidden` option is changed.
- Pane widths should now be calculated properly when big numbers are used in `ratios` (#622).
- The special bookmark `'` is now preserved properly after `sync` commands (#624).
- On some platforms, a bug has been fixed on the Tcell side to avoid an extra key press after terminal suspend/resume and the Tcell version used in `lf` is bumped accordingly to include the fix.
- The prompt line should now scroll accordingly when the text is wider than the screen.
- Text width in the prompt line should now be calculated properly when non-ASCII characters are involved.
- Erase line escape codes (i.e. `\033[K`) used in some command outputs should now be ignored properly.
## [r22](https://github.com/gokcehan/lf/releases/tag/r22)
### Added
- A new `-config` command line flag is added to use a custom config file path (#587).
- The current working directory is now exported as `PWD` environment variable (#591). Subshells in symlink directories should now start in their own paths properly.
- The initial working directory is now exported as `OLDPWD` environment variable.
- A new `shellflag` option is added to customize the shell flag used for passing commands (i.e. default `-c` for Unix and `/c` for Windows).
- Using the command `cmd-enter` during `find` and `find-back` now jumps to the first match (#605).
- A new `waitmsg` option is added to customize the prompt message after `shell-wait` commands (i.e. default `Press any key to continue`) (#604).
### Fixed
- A regression bug is fixed to print a newline in the prompt message properly after `shell-wait` commands.
- A regression bug is fixed to avoid CPU stuck at 100% when the terminal is closed unexpectedly.
- A regression bug is fixed to make shell commands use the alternate screen properly and keep the terminal history after quitting.
- Enter keypad terminfo sequence is now sent on startup so the `delete` key should be recognized properly in `st` terminal.
## [r21](https://github.com/gokcehan/lf/releases/tag/r21)
### Changed
- `cut` and `copy` do not follow symlinks anymore. Broken symlinks can now be selected for the `cut` and `copy` commands (#581).
### Added
- User name, group name, and hard link counts are now shown in the status line at the bottom when available.
- Number of selected, copied, and cut files are now shown in the ruler at the bottom when they are non-zero.
- Hard-coded shell commands with `stty` (Unix) and `pause` (Windows) to implement the `Press any key to continue` behavior are now implemented properly with a Go terminal handling library. With this change, the requirement for a POSIX compatible shell for `shell` option is now dropped and other shells can be used.
### Fixed
- A longstanding issue regarding UI suspend/resume for shell commands in macOS is now fixed in Tcell.
- Renaming a symlink to its target or a symlink to another with the same target should now be handled properly (#581).
- Autocompletion in a directory containing a broken symlink should now work as intended (#581).
- Setting `shellopts` to empty in the configuration file should not pass an extra empty argument to shell commands anymore.
- Previously given tip to trap `SIGPIPE` in the preview script to enable caching is now updated in the documentation. Trapping the signal in the preview script avoids sending the signal to the program when enough lines are read. This may result in reading redundant lines especially for big files. The recommended method is now to add a trailing `|| true` to each command exiting with a non-zero return code after a `SIGPIPE`.
## [r20](https://github.com/gokcehan/lf/releases/tag/r20)
### Added
- A new `mouse` option is added to enable mouse events. This option is disabled by default to leave mouse events to the terminal. Also unbound mouse events when `mouse` is enabled should now show an `unknown mapping` error in the message line.
### Fixed
- Newline characters in the output of `%` commands should no longer shift the content up which was a bug introduced in the previous release due to a fix to handle combining characters in texts.
- Redundant preview loadings for the `search` and `find` commands are now avoided (#569).
- Scanner now only considers ASCII characters for spaces and digits which should avoid unexpected splits in some non-ASCII inputs.
## [r19](https://github.com/gokcehan/lf/releases/tag/r19)
### Changed
- Changes have been made to enable the use of true image previews. See the documentation and the previews wiki page for more information.
- Non-zero exit codes should now make the preview volatile to avoid caching. Programs that may not behave well to `SIGPIPE` may trigger this behavior unintentionally. You may trap `SIGPIPE` in your preview script to get the old behavior.
- Preview scripts should now get as arguments the current file path, width, height, horizontal position, and vertical position. Note that height is still passed as an argument but its order is changed.
- A new `cleaner` option is added to set the path to a file to be executed when the preview is changed.
- Redundant preview loadings for movement commands are now avoided.
- Expansion `%w` in `promptfmt` is changed back to its old behavior without a trailing separator. Instead, a new expansion `%d` is added with a trailing separator (#545). Expansion `%w` is meant to be used to display the current working directory, whereas `%d%f` is meant to be used to display the current file.
- A new `LF_COLORS` environment variable is now checked to be able to make `lf` specific configurations. Also, environment variables for colors are now read cumulatively starting from the default behavior (i.e. default, `LSCOLORS`, `LS_COLORS`, `LF_COLORS`).
### Added
- Full path, dir name, file name, and base name matching patterns are added to colors and icons. See the updated documentation for more information.
- PowerShell keybinding example has been added to `etc/lfcd.ps1` (#532).
- PowerShell autocompletion script has been added as `etc/lf.ps1` (#535).
- Multiple `-command` flags can now be given (#552).
- Basic mouse support has been added. Mouse buttons (e.g. `<m-1>` for primary button, `<m-2>` for secondary button, `<m-3>` for middle button etc.) and mouse wheels (e.g. `<m-up>` for wheel up, `<m-down>` for wheel down etc.) can be used in bindings.
- Commands `top` and `bottom` are now allowed in `cmap` mappings in addition to movement commands.
### Fixed
- Extension sorting should now handle extensions with different lengths properly (#539).
- Heuristic used to show `info` should now take into account the `number` and `icons` options properly.
- The environment variable `id` is now set to the process ID instead to avoid two clients getting the same ID when launched at the same time (#550).
- Unicode combining characters in texts should now be displayed properly.
## [r18](https://github.com/gokcehan/lf/releases/tag/r18)
### Changed
- The `ignorecase` and `ignoredia` options should now also apply to sorting in addition to searching.
- The `ignoredia` option is now enabled by default to be consistent with `ignorecase`.
- The terminal UI library Tcell has been updated to version 2. This version highlights adding 24-bit true colors on Windows and better support for colors on Unix. The environment variable `TCELL_TRUECOLOR` is not required anymore so that terminal themes and true colors can be used at the same time.
- The deprecated option `color256` is now removed.
### Added
- Two new command line commands `cmd-menu-complete` and `cmd-menu-complete-back` are added for completion menu cycling (#482).
- Simple configuration files for Windows `etc/lfrc.cmd.example` and `etc/lfrc.ps1.example` are now added to the repository.
- Bash completion script `etc/lf.bash` is now added to the repository.
- Time formats in `info` option should now show the year instead of `hh:mm` for times older than the current year.
### Fixed
- Signals `SIGHUP`, `SIGQUIT`, and `SIGTERM` should now quit the program properly.
- Setting `info` to an empty value should not print errors to the log file anymore.
- Natural sorting is optimized to work faster using less memory.
- Files and directories that incorrectly show modification times in the future (e.g. Linux builtin exFAT driver) should not cause CPU hogging anymore.
- The keybinding example in `etc/lfcd.fish` is now updated to avoid hanging in shell commands.
- Using the `bottom` command immediately after startup should not crash the program anymore.
- Changing sorting options during sorting operations should not crash the program anymore.
- Output in `shell-pipe` commands now uses lazy redrawing so that verbose commands should not block the program anymore.
- The server is now daemonized properly on Unix so that it is not killed anymore when the controlling terminal is killed (#517).
## [r17](https://github.com/gokcehan/lf/releases/tag/r17)
### Changed
- The terminal UI library has been changed from Termbox to Tcell as the former has been unmaintained for a while (#439). Some of the changes are listed below, though the list may not be complete as this is a relatively big change.
- Some special key names are changed to be consistent with the Tcell documentation (e.g. `<bs>` renamed to `<backspace>`). On the other hand, there are also additional keybindings that were not available before (e.g. `<backtab>` for <kbd>Shift+Tab</kbd>). You can either check the Tcell documentation for the list of keys or hit the key combination in `lf` to read the name of the key from the `unknown mapping` error message.
- 24-bit true colors are now supported on Unix systems. See the updated documentation for more information. There is an ongoing version 2.0 of Tcell in development that we plan to switch to once it becomes stable and it is expected to add support for true colors in Windows consoles as well.
- Additional platforms are now supported and the list of pre-built binaries provided are updated accordingly.
- Wide characters are now displayed properly in Windows consoles.
### Added
- Descriptions of commands and options are now added to the documentation. Undocumented behaviors should now be considered documentation bugs and they can be reported.
- Keys are now evaluated with a lazy drawing approach so `push` commands to set the prompt and pasting something to the command line should feel instantaneous.
### Fixed
- Corrupted history files should no longer crash the program.
- The server now only listens connections from `localhost` on Windows so firewall permissions are not required anymore.
- `push` commands that change the operation mode should now work consistently as expected.
- Loading directories should now display the previous file list if any, which was a regression due to a bug fix in a previous release.
- `shell-pipe` commands should now automatically update previews when necessary.
- Errors from failed shell commands should not be overwritten by file information anymore.
- The server can now also be started automatically when the program is called with a relative path, which was a regression due to a bug fix in a previous release (#463).
- Environment variables are now exported automatically for preview scripts without having to call a shell command first (#468).
- The `<esc>` key can now be bound to be used on its own, instead of escaping a keybinding combination, which was a regression due to a bug fix in a previous release (#475).
- Changing the `hiddenfiles` option should now automatically trigger directory updates when necessary.
## [r16](https://github.com/gokcehan/lf/releases/tag/r16)
### Added
- Option values are now available in shell commands as environment variables with a prefix of `lf_` (e.g. `$lf_hidden`, `$lf_ratios`) (#448).
### Fixed
- Directories containing internal Windows links that show permission denied errors should now display properly.
## [r15](https://github.com/gokcehan/lf/releases/tag/r15)
### Changed
- The `toggle` command does not move the selection down anymore. The default binding for `<space>` is now assigned to `:toggle; down` instead to keep the default behavior same as before.
- The expansion `%w` in option `promptfmt` should now have a trailing slash. The default value of `promptfmt` is now changed accordingly, and should not display double slashes in the root directory anymore.
- The key `<esc>` is now used as the escape key. It should not display an error message when used to cancel a keybinding menu as before. However, it is not possible to bind `<esc>` key to another command anymore.
### Added
- Symbolic link destinations are now shown in the bottom status line (#374).
- A new `hiddenfiles` option which takes a list of globs is implemented to customize which files should be `hidden` (#372).
- Expressions consisting of multiple commands can now use counts (#394).
- Moving operations now fall back to copy and then delete strategy automatically for cross-device linking.
- The `hidden` option now works in Windows.
- The `toggle` command can now take optional arguments to toggle given names instead of the current file (#409).
- A new option `truncatechar` is implemented to customize the truncate character used in long filenames (#417).
- Copy and move operations now display a success message when they are finished (#427).
### Fixed
- `SIGHUP` and `SIGTERM` signals are now properly handled. Log files should not remain when terminals are directly closed (#305).
- The `info` option should now align properly when used with the `number` and `relativenumber` options (#373).
- Tilde (`~`) is now only expanded at the beginning of the path for the `cd` and `select` commands (#373).
- The `rename` command should now work properly with names differing only cases on case-insensitive filesystems.
- Tab characters are now expanded to spaces in Windows.
- The `incsearch` option now respects the search direction accordingly.
- The server is now started in the home folder and will not hold mounted filesystems busy.
- Trailing spaces in configuration files do not confuse the parser anymore.
- Termbox version is updated to fix a keyboard problem in FreeBSD (#404).
- Async commands do not leave zombie processes anymore (#407).
- The `hidden` option now works consistently as expected when set at the initial launch.
- The `rename` command should now select the new file after the operation.
- The `rename` command should now handle absolute paths properly.
- The `select` command should now work properly on loading directories. Custom commands that select a file after an operation should now work properly without an explicit `load` operation beforehand.
- Previous errors in the bottom message line should not persist through the prompt usage anymore.
- The `push` command should not fail with non-ASCII characters anymore.
- The `select` command should not fail with broken links anymore.
- The `load` command should not clear toggled broken links anymore.
- Copy and move operations do not overwrite broken links anymore.
## [r14](https://github.com/gokcehan/lf/releases/tag/r14)
### Added
- The `delete` command now shows a prompt with the current filename or the number of selected files (#206).
- Backslash can now be escaped with a backslash even without quotes.
- A new desktop entry file `lf.desktop` is added (#222).
- Three new `sortby` types are added, access time (i.e. `atime`), change time (i.e. `ctime`) (#226), and extension (i.e. `ext`) (#230). New default keybindings are added for these sorts correspondingly (i.e. `sa`, `sc`, and `se`). The `info` option can now also contain `atime` and `ctime` values accordingly.
- A new shell completion for `zsh` is added to `etc/lf.zsh` (#239).
- The `delete` command now works asynchronously and shows the progress (#238).
- Completion and directory change scripts are added for `csh` and `tcsh` as `etc/lf.csh` and `etc/lfcd.csh` respectively (#264).
- A new special command `on-cd` is added to run a shell command when the directory is changed. See the documentation for more information (#291).
### Fixed
- Some directories with special permissions that previously show a file icon now shows a directory icon properly.
- The `etc/lfcd.cmd` script can now also change to a different volume drive (#221).
- The proper use of `setsid` for opening files is now added to the example configuration and the documentation.
- The home directory abbreviation `~` is now only applied properly to paths starting with the home directory (#241).
- The `rename` command now cancels the operation if the old and new paths are the same (#266).
- Autocompletion and word movements should now work properly with all Unicode characters.
- The `shell-pipe` command which was broken some time ago should now work as expected.
- The `$TERM` environment variable can now work with values containing `tmux` with custom `$TERMINFO` values. @doronbehar now maintains a Termbox fork for `lf` (https://github.com/doronbehar/termbox-go).
## [r13](https://github.com/gokcehan/lf/releases/tag/r13)
### Added
- A new `wrapscroll` option is added to wrap top and bottom while scrolling (#166).
- The `up`, `down` movement commands and their variants, `updir`, and `open` are now allowed in `cmap` mappings.
- Two new `glob-select` and `glob-unselect` commands are added to use globbing for toggling files (#184).
- A new `mark-remove` (default `"`) command is added to allow removing marks (#190).
- Icon support is added with the `icon` option. See the wiki page for more details.
- A new builtin `rename` command is added (#197).
### Fixed
- The `cmd-history-next` command now remains in Command-line mode after the last item (#168).
- The `select` command does not change directories anymore when used on a directory.
- The working directory is now changed to the first argument when it is a directory.
- The `ratios` option is now checked before `preview` to avoid crashes (#174).
- Previous error messages are now cleared after successful commands (#192).
- Symlink to directories are now colored as symlinks (#195).
- Permission errors for directories are now displayed properly instead of showing as empty (#203).
## [r12](https://github.com/gokcehan/lf/releases/tag/r12)
### Added
- Go modules replaced `godep` for dependency management. Package maintainers may need to update accordingly.
- A new `errorfmt` option is added to customize the colors and attributes of error messages.
### Fixed
- Autocompletion for searches now complete filenames instead of commands.
- Permanent environment variables (e.g. `$id`, `$EDITOR`, `$LF_LEVEL`) are now exported on startup so they can be used in preview scripts without running a shell command first.
- On Windows, quotes are added to the exported values `$f`, `$fs`, and `$fx` to handle filenames with spaces properly.
- On Windows, filenames starting with `.` characters are now shown to avoid crashes when filenames show up as empty.
## [r11](https://github.com/gokcehan/lf/releases/tag/r11)
### Changed
- Copy and move operations are now implemented as builtins instead of using the underlying shell primitives (i.e. `cp` and `mv`). Users who want the old behavior can define a custom `paste` command. See the updated documentation for more information. Please report bugs regarding this change.
- Preview messages (i.e. `empty`, `binary`, and `loading...`) are now shown with the reverse attribute.
### Added
- Copy and move operations now run asynchronously and the progress is shown in the bottom ruler.
- Two new commands `echomsg` and `echoerr` are added to print a message to the message line and to the log file at the same time.
### Fixed
- Terminal initialization errors are now shown in the terminal instead of the log file.
## [r10](https://github.com/gokcehan/lf/releases/tag/r10)
### Changed
- The ability to map Normal mode commands in `cmap` is removed. This has caused a number of bugs in the previous release. A different mechanism for a similar functionality is planned.
### Added
- A new command line flag `-command` has been added to execute a command on client initialization (#135).
- A `select` command is now executed after initialization if the first command line argument is a file.
- A prompting mechanism has been added to the builtin `delete` command.
### Fixed
- Input and output in `shell-pipe` commands were broken with the `cmap` patch. This should now work as before.
- Some `push` commands were broken with the `cmap` patch and sometimes ignored Command-line mode for some keys to execute as in Normal mode. This should now work as before.
- `read` and shell commands should now also work when typed manually (e.g. typing `:shell` should switch the prefix to `$`).
- Configuration files are now read after initialization.
- Background colors are removed from defaults to avoid confusion with selection highlighting.
## [r9](https://github.com/gokcehan/lf/releases/tag/r9)
### Changed
- The default number of colors is set to 8 to have better defaults in some terminals. A new option `color256` is added to use 256 colors instead. Users who want the old behavior should enable this option in their configuration files.
### Added
- A new `incsearch` option is added to enable incremental matching while searching.
- Two new options `ignoredia` and `smartdia` are added to ignore diacritics in Latin letters for `search` and `find` (#118).
- A new builtin `delete` command is added for file deletion (#121). This command is not assigned to a key by default to prevent accidental deletions. In the future, a prompting mechanism may be added to this command for more safety.
- Normal mode commands can now be used in `cmap` which can be used to immediately finish Command-line mode and execute a Normal mode command afterwards.
- A new `fish` completion script is added to the `etc` folder (#131).
- Two new options `number` and `relativenumber` are added to enable line numbers in directories (#133).
### Fixed
- Autocompletion should now show only a single match for redefined builtin commands.
## [r8](https://github.com/gokcehan/lf/releases/tag/r8)
### Added
- Four new commands `find`, `find-back`, `find-next`, and `find-prev` are added to implement file finding. Two options `anchorfind` and `findlen` are added to customize the behavior of these commands.
- A new `quit` command is added to the server protocol to quit the server.
- A new `$LF_LEVEL` environment variable is added to show the nesting level.
### Fixed
- The `load` and `reload` commands now work properly when the current directory is deleted. Also `lf` does not start in deleted directories anymore.
- The server is now started as a detached process in Windows so its lifetime is not tied to the command line window anymore.
- Clients now try to reconnect to the server at startup with exponentially increasing intervals when they fail. This is to avoid connection failures due to the server not being ready for the first client that automatically starts the server.
- The old index is now kept when the current selection is deleted.
- The `shell-pipe` command now triggers `load` instead of `reload`.
- Error messages are now more informative when `lf` fails to start due to either `$HOME` or `$USER` variables being empty or not set.
- Searching for the next/previous item is now based on the direction of the initial search.
## [r7](https://github.com/gokcehan/lf/releases/tag/r7)
### Changed
- The system-wide configuration path on Unix is changed from `/etc/lfrc` to `/etc/lf/lfrc`.
### Added
- A man page is now automatically generated from the documentation which can be installed to make the documentation available with the `man` command. On a related note, there is now a packaging guide section in packages wiki page.
- A new `doc` command (default `<f-1>`) is added to view the documentation in a pager.
- Commands `mark-save` (default `m`) and `mark-load` (default `'`) are added to implement builtin bookmarks. Marks are saved in a file in the data folder which can be found in the documentation.
- The history is now saved in a file in the data folder which can be found in the documentation.
## [r6](https://github.com/gokcehan/lf/releases/tag/r6)
### Changed
- The `yank`, `delete`, and `put` commands are renamed to `copy`, `cut`, and `paste` respectively. In the example configuration, the `remove` command is renamed to `delete`.
- The special command `open-file` to configure file opening is renamed to `open`.
### Added
- A new option `shellopts` is added to be able to pass command line arguments to the shell interpreter (i.e. `<shell> <shellopts> -c <cmd> -- <args>`) which is useful to set safety options for all shell commands (i.e. `sh -eu ...`). See the example configuration file for more information.
- The special keys `<home>`, `<end>`, `<pgup>`, and `<pgdn>` are mapped to the `top`, `bottom`, `page-up`, and `page-down` commands respectively by default.
- A new command `source` is added to read a configuration file.
- Support is added to read a system-wide configuration file on startup located in `/etc/lfrc` on Unix and `C:\ProgramData\lf\lfrc` on Windows. The documentation is updated to show the locations of all configuration files.
- Environment variables used for configuration (i.e. `$EDITOR`, `$PAGER`, `$SHELL`) are set to their default values when they are not set or empty and they are exported to shell commands.
- A new environment variable `$OPENER` is added to configure the default file opener using the previous default values and it is exported to shell commands.
### Fixed
- Executable completion now works on Windows as well.
## [r5](https://github.com/gokcehan/lf/releases/tag/r5)
### Added
- The server is automatically restarted on startup if it does not work anymore.
- A new option `period` is added to set time duration in seconds for periodic refreshes. Setting the value of this option to zero disables periodic refreshes which is the default behavior.
- A new command `load` is added to refresh only modified files and directories which is more efficient than `reload` command.
### Fixed
- `cmd-word-back` does not change the command line anymore.
- Modified files and directories are automatically detected and refreshed when they are loaded from cache.
- All clients are now refreshed when the `put` command is used.
- The correct hidden parent is selected when the `hidden` option is changed.
- The preview is properly updated when the `hidden` option is changed.
## [r4](https://github.com/gokcehan/lf/releases/tag/r4)
### Changed
- The following commands are renamed for clarity and consistency:
- `bot` is renamed to `bottom`
- `cmd-delete-word` is renamed to `cmd-delete-unix-word`
- `cmd-beg` is renamed to `cmd-home`
- `cmd-delete-beg` is renamed to `cmd-delete-home`
- `cmd-comp` is renamed to `cmd-complete`
- `cmd-hist-next` is renamed to `cmd-history-next`
- `cmd-hist-prev` is renamed to `cmd-history-prev`
- `cmd-put` is renamed to `cmd-yank`
### Added
- Support for alt key bindings have been added using the commonly used escape delaying mechanism. The delay value is set to 100ms which is also used for other escape codes in Termbox. Keys are named with an `a` prefix, as in `<a-f>` for the `alt` and `f` keys. Also note that the old mechanism for alt keybindings on 8-bit terminals still works as before.
- The following command line commands and their default alt keybindings have been added:
- `cmd-word` with `<a-f>`
- `cmd-word-back` with `<a-b>`
- `cmd-capitalize-word` with `<a-c>`
- `cmd-delete-word` with `<a-d>`
- `cmd-uppercase-word` with `<a-u>`
- `cmd-lowercase-word` with `<a-l>`
- `cmd-transpose-word` with `<a-t>`
### Fixed
- The default editor, pager, and opener commands should now work in Windows. Opener still only works with paths without spaces though.
- 8-bit color codes and attributes are not confused anymore.
- History selection is disabled when a `shell-pipe` command is running.
- Searches are now excluded from the history.
## [r3](https://github.com/gokcehan/lf/releases/tag/r3)
### Changed
- Command counts are now only applied for the `up`/`down` (and variants), `updir`, `toggle`, `search-next`, and `search-prev` commands. These commands are now handled more efficiently when used with counts.
### Added
- Pressed keys are now shown in the ruler when they are not matched yet.
- A new builtin `draw` command has been added which is more efficient than the `redraw` command. The latter is replaced with the former in many places to prevent flickers on the screen.
- Support for the `$LS_COLORS` and `$LSCOLORS` environment variables are added for color customization (#96). See the updated documentation for more information.
- A new option `drawbox` is added to draw a box around panes.
### Fixed
- Resize events that change the height are now handled properly.
- Changes in sorting methods and options are checked for cached directories and these directories are sorted again if necessary while loading.
- A `~` character is added as a suffix to file names when they do not fit in the window.
## [r2](https://github.com/gokcehan/lf/releases/tag/r2)
### Changed
- Shell command names are shortened (e.g. `read-shell-wait` is renamed to `shell-wait`).
### Added
- A new shell command type named `shell-pipe` is introduced that runs with the UI. See the updated documentation for the motivation and some example use cases.
- A new command named `cmd-interrupt` (default `<c-c>`) is introduced to interrupt the current `shell-pipe` command.
- A new command named `select` is introduced that changes the current file selection to its argument.
### Fixed
- Running `cmd-hist-prev` in Normal mode now always starts with the last item to avoid confusion. Running `cmd-hist-next` in Normal mode now has no effect for consistency.
## [r1](https://github.com/gokcehan/lf/releases/tag/r1)
### Added
- Initial release
================================================
FILE: CONTRIBUTING.md
================================================
# Contributing
Code contributions are always welcomed in lf.
If you are going to introduce a new feature, it is best to open an issue first for discussion. If your feature can be implemented as a configuration option **please add it to the [wiki](https://github.com/gokcehan/lf/wiki)**.
For bug fixes, you can simply send a pull request.
## Code conventions
In addition to `gofmt` and friends (e.g. [go vet](https://pkg.go.dev/cmd/vet), [staticcheck](https://staticcheck.dev/), [golangci-lint](https://golangci-lint.run/)), we have a few conventions:
- Global variables are best avoided except when they are not.
Global variable names are prefixed with `g` as in `gFooBar`.
Exceptions are variables holding values of environmental variables which are prefixed with `env` as in `envFooBar` and regular expressions which are prefixed with `re` as in `reFooBar` when they are global.
- Type and function names are small case as in `fooBar` since we don't use exporting.
- For file name variables, `name`, `fname`, or `filename` should refer to the base name of the file as in `baz.txt`, and `path`, `fpath`, or `filepath` should refer to the full path of the file as in `/foo/bar/baz.txt`.
- Run `go fmt` to ensure that files are formatted correctly.
- Consider using [conventional](https://www.conventionalcommits.org/) commit messages.
Use the surrounding code as reference when in doubt as usual.
## Adding a new option
Adding a new option usually requires the following steps:
- Add option name/type to `gOpts` struct in `opts.go`
- Add default option value to `init` function in `opts.go`
- Add option evaluation logic to `setExpr.eval` in `eval.go`
- Implement the option somewhere in the code
- Add option name and its default value to `Quick Reference` and `Options` sections in `doc.md`
- Run `gen/doc.sh` to update the documentation (optional as it requires `docker`/`podman`, but appreciated)
- Commit your changes and send a pull request
Options should be defined in alphabetical order, but note that boolean options are defined first in `eval.go` as they require special handling.
## Adding a new builtin command
Adding a new command usually requires the following steps:
- Add default key if any to `init` function in `opts.go`
- Add command evaluation logic to `callExpr.eval` in `eval.go`
- Implement the command somewhere in the code
- Add command name to `gCmdWords` in `complete.go` for tab completion
- Add command name to `Quick Reference` and `Commands` sections in `doc.md`
- Run `gen/doc.sh` to update the documentation (optional as it requires `docker`/`podman`, but appreciated)
- Commit your changes and send a pull request
Commands should be defined in alphabetical order, but note that commands are first organized roughly into the following sections in `eval.go` for clarity:
- Navigation
- Selection
- File-related operations
- Shell commands
- Finding and searching
- Filtering
- Marks
- Tags
- Echoing
- Miscellaneous commands
- Visual mode
- Command-line mode commands
- Hook commands
## Platform specific code
There are two files named `os.go` and `os_windows.go` for Unix and Windows specific code respectively.
If you add something to either of these files but not the other, you probably break the build for the other platform.
If your addition works the same in both platforms, your addition probably belongs to `main.go` instead.
There are also different variants of the `df` functionality provided by `df_openbsd.go`, `df_statfs.go`, `df_statvfs.go` and `df_windows.go`.
Where applicable, ensure that any changes you make are reflected across all of these files for consistency.
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2016 Gökçehan Kara
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# LF
[Doc](doc.md)
| [Wiki](https://github.com/gokcehan/lf/wiki)
| [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org) (with IRC bridge)
[](https://github.com/gokcehan/lf/actions/workflows/go.yml)
[](https://goreportcard.com/report/github.com/gokcehan/lf)
`lf` (as in "list files") is a terminal file manager written in Go with a heavy inspiration from [`ranger`](https://github.com/ranger/ranger) file manager.
See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information and [tutorial](https://github.com/gokcehan/lf/wiki/Tutorial) for a gentle introduction with screencasts.



## Features
- Cross-platform (Linux, macOS, BSDs, Windows)
- Single binary without any runtime dependencies
- Fast startup and low memory footprint due to native code and static binaries
- Asynchronous IO operations to avoid UI locking
- Server/client architecture and remote commands to manage multiple instances
- Extendable and configurable with shell commands
- Customizable keybindings (vi and readline defaults)
- A reasonable set of other features (see the [documentation](doc.md))
## Non-Features
- Tabs or windows (better handled by window manager or terminal multiplexer)
- Builtin pager/editor (better handled by your pager/editor of choice)
- Builtin commands for file operations (better handled by the underlying shell tools including but not limited to `mkdir`, `touch`, `chmod`, `chown`, `chgrp`, and `ln`)
## Installation
See [packages](https://github.com/gokcehan/lf/wiki/Packages) for community maintained packages.
See [releases](https://github.com/gokcehan/lf/releases) for pre-built binaries.
Building from the source requires [Go](https://go.dev/).
On Unix:
```bash
env CGO_ENABLED=0 go install -ldflags="-s -w" github.com/gokcehan/lf@latest
```
On Windows `cmd`:
```cmd
set CGO_ENABLED=0
go install -ldflags="-s -w" github.com/gokcehan/lf@latest
```
On Windows `PowerShell`:
```powershell
$env:CGO_ENABLED = '0'
go install -ldflags="-s -w" github.com/gokcehan/lf@latest
```
## Usage
After the installation `lf` command should start the application in the current directory.
Run `lf -help` to see [command line options](doc.md#options).
Run `lf -doc` to see the [documentation](doc.md).
See [etc](etc) directory to integrate `lf` to your shell and/or editor.
Example configuration files along with example colors and icons files can also be found in this directory.
See [integrations](https://github.com/gokcehan/lf/wiki/Integrations) to integrate `lf` to other tools.
See [tips](https://github.com/gokcehan/lf/wiki/Tips) for more examples.
## Contributing
See [contributing](CONTRIBUTING.md) for guidelines.
================================================
FILE: app.go
================================================
package main
import (
"bufio"
"cmp"
"errors"
"fmt"
"io"
"io/fs"
"log"
"os"
"os/exec"
"os/signal"
"path/filepath"
"slices"
"strings"
"syscall"
"time"
)
type app struct {
ui *ui // ui state (screen, windows, input)
nav *nav // navigation state (dirs, cursor, selections, preview, caches)
ticker *time.Ticker // refresh ticker if `period` > 0
quitChan chan struct{} // signals main loop to exit
cmd *exec.Cmd // currently running % (shell-pipe) command
cmdIn io.WriteCloser // stdin writer for running % command
cmdOutBuf []byte // output of running % command
cmdHistory []string // command history entries
cmdHistoryBeg int // index where commands from this session start in cmdHistory
cmdHistoryInd int // history navigation offset from most recent
cmdHistoryInput *string // initial input used as prefix filter while browsing history
menuCompActive bool // whether completion cycling is active
menuCompTmp []string // token snapshot taken when completion cycling starts, used for `cmd-menu-discard`
menuComps []compMatch // completion candidates for active prompt
menuCompInd int // index of selected completion candidate (-1: none selected)
selectionOut []string // paths to output on exit, used for `-print-selection` and `-selection-path`
watch *watch // fs watcher if `watch` is enabled
quitting bool // guard to prevent re-entering quit logic
}
func newApp(ui *ui, nav *nav) *app {
quitChan := make(chan struct{}, 1)
app := &app{
ui: ui,
nav: nav,
ticker: new(time.Ticker),
quitChan: quitChan,
watch: newWatch(nav.dirChan, nav.fileChan, nav.delChan),
}
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM)
go func() {
for {
switch <-sigChan {
case os.Interrupt:
case syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM:
app.quit()
os.Exit(3)
return
}
}
}()
return app
}
func (app *app) quit() {
// Using synchronous shell commands for `on-quit` can cause this to be
// called again, so a guard variable is introduced here to prevent an
// infinite loop.
if app.quitting {
return
}
app.quitting = true
onQuit(app)
if gOpts.history {
if err := app.writeHistory(); err != nil {
log.Printf("writing history file: %s", err)
}
}
if !gSingleMode {
if _, err := remote(fmt.Sprintf("drop %d", gClientID)); err != nil {
log.Printf("dropping connection: %s", err)
}
if gOpts.autoquit {
if _, err := remote("quit"); err != nil {
log.Printf("auto quitting server: %s", err)
}
}
}
}
func (app *app) readFile(path string) {
log.Printf("reading file: %s", path)
f, err := os.Open(path)
if err != nil {
app.ui.echoerrf("opening file: %s", err)
return
}
defer f.Close()
p := newParser(f)
for p.parse() {
p.expr.eval(app, nil)
}
if p.err != nil {
app.ui.echoerrf("%s", p.err)
}
}
func loadFiles() (clipboard clipboard, err error) {
files, err := os.Open(gFilesPath)
if os.IsNotExist(err) {
err = nil
return
}
if err != nil {
err = fmt.Errorf("opening file selections file: %w", err)
return
}
defer files.Close()
s := bufio.NewScanner(files)
if !s.Scan() {
err = fmt.Errorf("scanning file list: %w", cmp.Or(s.Err(), io.EOF))
return
}
switch s.Text() {
case "copy":
clipboard.mode = clipboardCopy
case "move":
clipboard.mode = clipboardCut
default:
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
return
}
for s.Scan() && s.Text() != "" {
clipboard.paths = append(clipboard.paths, s.Text())
}
if s.Err() != nil {
err = fmt.Errorf("scanning file list: %w", s.Err())
return
}
log.Printf("loading clipboard: %v", clipboard.paths)
return
}
func saveFiles(clipboard clipboard) error {
if err := os.MkdirAll(filepath.Dir(gFilesPath), os.ModePerm); err != nil {
return fmt.Errorf("creating data directory: %w", err)
}
files, err := os.Create(gFilesPath)
if err != nil {
return fmt.Errorf("opening file selections file: %w", err)
}
defer files.Close()
log.Printf("saving files: %v", clipboard.paths)
var clipboardModeStr string
if clipboard.mode == clipboardCopy {
clipboardModeStr = "copy"
} else {
clipboardModeStr = "move"
}
if _, err := fmt.Fprintln(files, clipboardModeStr); err != nil {
return fmt.Errorf("write clipboard mode to file: %w", err)
}
for _, path := range clipboard.paths {
if _, err := fmt.Fprintln(files, path); err != nil {
return fmt.Errorf("write path to file: %w", err)
}
}
return files.Sync()
}
func (app *app) readHistory() error {
f, err := os.Open(gHistoryPath)
if os.IsNotExist(err) {
return nil
}
if err != nil {
return fmt.Errorf("opening history file: %w", err)
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
cmd := scanner.Text()
if len(cmd) < 1 || !slices.Contains([]string{":", "$", "!", "%", "&"}, cmd[:1]) {
continue
}
app.cmdHistory = append(app.cmdHistory, cmd)
}
app.cmdHistoryBeg = len(app.cmdHistory)
if err := scanner.Err(); err != nil {
return fmt.Errorf("reading history file: %w", err)
}
return nil
}
func (app *app) writeHistory() error {
if len(app.cmdHistory) == 0 {
return nil
}
local := slices.Clone(app.cmdHistory[app.cmdHistoryBeg:])
app.cmdHistory = nil
if err := app.readHistory(); err != nil {
return fmt.Errorf("reading history file: %w", err)
}
app.cmdHistory = append(app.cmdHistory, local...)
if len(app.cmdHistory) > 1000 {
app.cmdHistory = app.cmdHistory[len(app.cmdHistory)-1000:]
}
if err := os.MkdirAll(filepath.Dir(gHistoryPath), os.ModePerm); err != nil {
return fmt.Errorf("creating data directory: %w", err)
}
f, err := os.Create(gHistoryPath)
if err != nil {
return fmt.Errorf("creating history file: %w", err)
}
defer f.Close()
for _, cmd := range app.cmdHistory {
if _, err = fmt.Fprintln(f, cmd); err != nil {
return fmt.Errorf("writing history file: %w", err)
}
}
return nil
}
// loop is the main event loop of the application. Expressions are read from
// the client and the server on separate goroutines and sent here over channels
// for evaluation. Similarly directories and regular files are also read in
// separate goroutines and sent here for update.
func (app *app) loop() {
go app.nav.preloadLoop(app.ui)
go app.nav.previewLoop(app.ui)
var serverChan <-chan expr
if !gSingleMode {
serverChan = readExpr()
}
go app.ui.readEvents()
if gConfigPath != "" {
if _, err := os.Stat(gConfigPath); !os.IsNotExist(err) {
app.readFile(gConfigPath)
} else {
log.Printf("config file does not exist: %s", err)
}
} else {
for _, path := range gConfigPaths {
if _, err := os.Stat(path); !os.IsNotExist(err) {
app.readFile(path)
}
}
}
for _, cmd := range gCommands {
p := newParser(strings.NewReader(cmd))
for p.parse() {
p.expr.eval(app, nil)
}
if p.err != nil {
app.ui.echoerrf("%s", p.err)
}
}
app.nav.addJumpList()
if gSelect != "" {
go func() {
lstat, err := os.Lstat(gSelect)
if err != nil {
app.ui.exprChan <- &callExpr{"echoerr", []string{err.Error()}, 1}
} else if lstat.IsDir() {
app.ui.exprChan <- &callExpr{"cd", []string{gSelect}, 1}
} else {
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
}
}()
}
for {
select {
case <-app.quitChan:
if app.nav.copyJobs > 0 {
app.ui.echoerr("quit: copy operation in progress")
continue
}
if app.nav.moveTotal > 0 {
app.ui.echoerr("quit: move operation in progress")
continue
}
if app.nav.deleteTotal > 0 {
app.ui.echoerr("quit: delete operation in progress")
continue
}
app.quit()
app.nav.previewChan <- ""
log.Printf("*************** closing client, PID: %d ***************", gClientID)
return
case n := <-app.nav.copyJobsChan:
app.nav.copyJobs += n
app.ui.draw(app.nav)
case n := <-app.nav.copyBytesChan:
app.nav.copyBytes += n
// n is usually 32*1024B (default io.Copy() buffer) so update roughly per 32KB x 128 = 4MB copied
if app.nav.copyUpdate++; app.nav.copyUpdate >= 128 {
app.nav.copyUpdate = 0
app.ui.draw(app.nav)
}
case n := <-app.nav.copyTotalChan:
app.nav.copyTotal += n
if n < 0 {
app.nav.copyBytes += n
}
if app.nav.copyTotal == 0 {
app.nav.copyUpdate = 0
}
app.ui.draw(app.nav)
case n := <-app.nav.moveCountChan:
app.nav.moveCount += n
if app.nav.moveUpdate++; app.nav.moveUpdate >= 1000 {
app.nav.moveUpdate = 0
app.ui.draw(app.nav)
}
case n := <-app.nav.moveTotalChan:
app.nav.moveTotal += n
if n < 0 {
app.nav.moveCount += n
}
if app.nav.moveTotal == 0 {
app.nav.moveUpdate = 0
}
app.ui.draw(app.nav)
case n := <-app.nav.deleteCountChan:
app.nav.deleteCount += n
if app.nav.deleteUpdate++; app.nav.deleteUpdate >= 1000 {
app.nav.deleteUpdate = 0
app.ui.draw(app.nav)
}
case n := <-app.nav.deleteTotalChan:
app.nav.deleteTotal += n
if n < 0 {
app.nav.deleteCount += n
}
if app.nav.deleteTotal == 0 {
app.nav.deleteUpdate = 0
}
app.ui.draw(app.nav)
case d := <-app.nav.dirChan:
var oldCurrPath string
if curr := app.nav.currFile(); curr != nil {
oldCurrPath = curr.path
}
prev, ok := app.nav.dirCache[d.path]
if ok {
d.ind = prev.ind
d.pos = prev.pos
d.visualAnchor = min(prev.visualAnchor, len(d.files)-1)
d.visualWrap = prev.visualWrap
d.filter = prev.filter
d.sort()
d.sel(prev.name(), app.nav.height)
}
app.nav.dirCache[d.path] = d
app.nav.position()
if curr := app.nav.currFile(); curr != nil {
if curr.path != oldCurrPath {
app.ui.loadFile(app, true)
}
}
app.watchDir(d)
// Avoid flickering UI and multiple, unnecessary `on-load` calls
// triggered by Git commands executed inside the users `on-load`
// command (often used to add git symbols using `addcustominfo`).
// TODO: Should `watch` also ignore `.git` directories?
if filepath.Base(d.path) != ".git" {
paths := make([]string, len(d.allFiles))
for i, file := range d.allFiles {
paths[i] = file.path
}
onLoad(app, paths)
}
if d.path == app.nav.currDir().path {
app.nav.preload()
}
app.ui.draw(app.nav)
case r := <-app.nav.regChan:
app.nav.regCache[r.path] = r
if curr := app.nav.currFile(); curr != nil {
if r.path == curr.path {
app.ui.sxScreen.forceClear = true
if gOpts.preload && r.volatile {
app.ui.loadFile(app, true)
}
}
}
app.ui.draw(app.nav)
case f := <-app.nav.fileChan:
for _, dir := range app.nav.dirCache {
if dir.path != filepath.Dir(f.path) {
continue
}
for i := range dir.allFiles {
if dir.allFiles[i].path == f.path {
dir.allFiles[i] = f
break
}
}
name := dir.name()
dir.sort()
dir.sel(name, app.nav.height)
}
delete(app.nav.regCache, f.path)
app.ui.loadFile(app, false)
onLoad(app, []string{f.path})
app.ui.draw(app.nav)
case path := <-app.nav.delChan:
deletePathRecursive(app.nav.selections, path)
if len(app.nav.selections) == 0 {
app.nav.selectionInd = 0
}
deletePathRecursive(app.nav.regCache, path)
deletePathRecursive(app.nav.dirCache, path)
for _, dirPath := range app.nav.dirPaths {
if dirPath == path {
if err := app.nav.cd(filepath.Dir(path)); err != nil {
log.Print(err)
}
break
}
}
case ev := <-app.ui.evChan:
e := app.ui.readEvent(ev, app.nav)
if e == nil {
continue
}
e.eval(app, nil)
loop:
for {
select {
case ev := <-app.ui.evChan:
e = app.ui.readEvent(ev, app.nav)
if e == nil {
continue
}
e.eval(app, nil)
default:
break loop
}
}
app.ui.draw(app.nav)
case e := <-app.ui.exprChan:
e.eval(app, nil)
app.ui.draw(app.nav)
case e := <-serverChan:
e.eval(app, nil)
app.ui.draw(app.nav)
case <-app.ticker.C:
app.nav.renew()
app.ui.loadFile(app, false)
case <-app.nav.previewTimer.C:
app.ui.draw(app.nav)
case <-app.nav.preloadTimer.C:
app.nav.preload()
}
}
}
func (app *app) runCmdSync(cmd *exec.Cmd, pauseAfter bool) {
app.nav.previewChan <- ""
if err := app.ui.suspend(); err != nil {
log.Printf("suspend: %s", err)
}
defer func() {
if err := app.ui.resume(); err != nil {
app.quit()
os.Exit(3)
}
}()
if err := cmd.Run(); err != nil {
app.ui.echoerrf("running shell: %s", err)
}
if pauseAfter {
anyKey()
}
app.ui.loadFile(app, true)
app.nav.renew()
}
// runShell is used to run a shell command. Modes are as follows:
//
// Prefix Wait Async Stdin Stdout Stderr UI action
// $ No No Yes Yes Yes Pause and then resume
// % No No Yes Yes Yes Statline for input/output
// ! Yes No Yes Yes Yes Pause and then resume
// & No Yes No No No Do nothing
func (app *app) runShell(s string, args []string, prefix string) {
app.nav.exportFiles()
app.ui.exportSizes()
app.exportMode()
exportLfPath()
exportOpts()
gState.mutex.Lock()
gState.data["maps"] = listBinds(map[string]map[string]expr{
"n": gOpts.nkeys,
"v": gOpts.vkeys,
})
gState.data["nmaps"] = listBinds(map[string]map[string]expr{
"n": gOpts.nkeys,
})
gState.data["vmaps"] = listBinds(map[string]map[string]expr{
"v": gOpts.vkeys,
})
gState.data["cmaps"] = listBinds(map[string]map[string]expr{
"c": gOpts.cmdkeys,
})
gState.data["cmds"] = listCmds(gOpts.cmds)
gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd)
gState.data["history"] = listHistory(app.cmdHistory)
gState.data["files"] = listFilesInCurrDir(app.nav)
gState.mutex.Unlock()
cmd := shellCommand(s, args)
switch prefix {
case "$", "!":
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr
app.runCmdSync(cmd, prefix == "!")
return
}
// We are running the command asynchronously
var inReader, inWriter, outReader, outWriter *os.File
if prefix == "%" {
if app.ui.cmdPrefix == ">" {
return
}
// [exec.Cmd.StdoutPipe] cannot be used as it requires the output to be fully
// read before calling [exec.Cmd.Wait], however in this case Cmd.Wait should
// only wait for the command to finish executing regardless of whether the
// output has been fully read or not.
inReader, inWriter, err := os.Pipe()
if err != nil {
log.Printf("creating input pipe: %s", err)
return
}
cmd.Stdin = inReader
app.cmdIn = inWriter
outReader, outWriter, err = os.Pipe()
if err != nil {
log.Printf("creating output pipe: %s", err)
return
}
cmd.Stdout = outWriter
cmd.Stderr = outWriter
}
shellSetPG(cmd)
if err := cmd.Start(); err != nil {
app.ui.echoerrf("running shell: %s", err)
}
switch prefix {
case "%":
normal(app)
app.cmd = cmd
app.cmdOutBuf = nil
app.ui.cmdPrefix = ">"
app.ui.echo("")
go func() {
reader := bufio.NewReader(outReader)
for {
b, err := reader.ReadByte()
if err != nil {
if !errors.Is(err, io.EOF) && !errors.Is(err, fs.ErrClosed) {
log.Printf("reading command output: %s", err)
}
break
}
app.cmdOutBuf = append(app.cmdOutBuf, b)
if reader.Buffered() == 0 {
app.ui.exprChan <- &callExpr{"echo", []string{string(app.cmdOutBuf)}, 1}
}
if b == '\n' || b == '\r' {
app.cmdOutBuf = nil
}
}
}()
go func() {
if err := cmd.Wait(); err != nil {
log.Printf("running shell: %s", err)
}
inReader.Close()
inWriter.Close()
outReader.Close()
outWriter.Close()
app.cmd = nil
app.ui.cmdPrefix = ""
app.ui.exprChan <- &callExpr{"load", nil, 1}
}()
case "&":
go func() {
if err := cmd.Wait(); err != nil {
log.Printf("running shell: %s", err)
}
app.ui.exprChan <- &callExpr{"load", nil, 1}
}()
}
}
func (app *app) doComplete() (matches []compMatch) {
var longest string
switch app.ui.cmdPrefix {
case ":":
matches, longest = completeCmd(app.ui.cmdAccLeft)
case "$", "%", "!", "&":
matches, longest = completeShell(app.ui.cmdAccLeft)
case "/", "?":
matches, longest = completeSearch(app.ui.cmdAccLeft)
}
app.ui.cmdAccLeft = longest
app.ui.menu, app.ui.menuSelect = listMatches(app.ui.screen, matches, -1)
return
}
func (app *app) menuComplete(direction int) {
if !app.menuCompActive {
app.menuCompTmp = tokenize(app.ui.cmdAccLeft)
app.menuComps = app.doComplete()
if len(app.menuComps) > 1 {
app.menuCompInd = -1
app.menuCompActive = true
}
} else {
app.menuCompInd += direction
if app.menuCompInd == len(app.menuComps) {
app.menuCompInd = 0
} else if app.menuCompInd < 0 {
app.menuCompInd = len(app.menuComps) - 1
}
toks := slices.Clone(app.menuCompTmp)
toks[len(toks)-1] = app.menuComps[app.menuCompInd].result
app.ui.cmdAccLeft = strings.Join(toks, " ")
}
app.ui.menu, app.ui.menuSelect = listMatches(app.ui.screen, app.menuComps, app.menuCompInd)
}
func (app *app) watchDir(dir *dir) {
if !gOpts.watch {
return
}
app.watch.add(dir.path)
// ensure dircounts are updated for child directories
for _, file := range dir.allFiles {
if file.IsDir() {
app.watch.add(file.path)
}
}
}
func (app *app) exportMode() {
getMode := func() string {
if app.menuCompActive {
return "compmenu"
}
if strings.HasPrefix(app.ui.cmdPrefix, "delete") {
return "delete"
}
if strings.HasPrefix(app.ui.cmdPrefix, "replace") || strings.HasPrefix(app.ui.cmdPrefix, "create") {
return "rename"
}
switch app.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 "":
if app.nav.isVisualMode() {
return "visual"
}
return "normal"
default:
return "unknown"
}
}
os.Setenv("lf_mode", getMode())
}
================================================
FILE: client.go
================================================
package main
import (
"bufio"
"fmt"
"io"
"log"
"net"
"os"
"strings"
"sync"
"time"
"github.com/gdamore/tcell/v3"
)
type State struct {
mutex sync.Mutex
data map[string]string
}
var gState State
func init() {
gState.data = make(map[string]string)
}
func run() {
if gLogPath != "" {
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600)
if err != nil {
log.Fatalf("failed to open log file: %s", err)
}
defer f.Close()
log.SetOutput(f)
} else {
log.SetOutput(io.Discard)
}
log.Printf("*************** starting client, PID: %d ***************", gClientID)
var screen tcell.Screen
var err error
if screen, err = tcell.NewScreen(); err != nil {
log.Fatalf("creating screen: %s", err)
} else if err = screen.Init(); err != nil {
log.Fatalf("initializing screen: %s", err)
}
if gOpts.mouse {
screen.EnableMouse()
}
screen.EnablePaste()
ui := newUI(screen)
nav := newNav(ui)
app := newApp(ui, nav)
if err := nav.sync(); err != nil {
app.ui.echoerrf("sync: %s", err)
}
if err := app.readHistory(); err != nil {
app.ui.echoerrf("reading history file: %s", err)
}
app.loop()
app.ui.screen.Fini()
if gLastDirPath != "" {
writeLastDir(gLastDirPath, app.nav.currDir().path)
}
if gSelectionPath != "" && len(app.selectionOut) > 0 {
writeSelection(gSelectionPath, app.selectionOut)
}
if gPrintLastDir {
fmt.Println(app.nav.currDir().path)
}
if gPrintSelection && len(app.selectionOut) > 0 {
for _, file := range app.selectionOut {
fmt.Println(file)
}
}
}
func writeLastDir(filename, lastDir string) {
f, err := os.Create(filename)
if err != nil {
log.Printf("opening last dir file: %s", err)
return
}
defer f.Close()
_, err = f.WriteString(lastDir)
if err != nil {
log.Printf("writing last dir file: %s", err)
}
}
func writeSelection(filename string, selection []string) {
f, err := os.Create(filename)
if err != nil {
log.Printf("opening selection file: %s", err)
return
}
defer f.Close()
_, err = f.WriteString(strings.Join(selection, "\n"))
if err != nil {
log.Printf("writing selection file: %s", err)
}
}
func readExpr() <-chan expr {
ch := make(chan expr)
go func() {
duration := 100 * time.Millisecond
c, err := net.Dial(gSocketProt, gSocketPath)
for err != nil {
log.Printf("connecting server: %s", err)
time.Sleep(duration)
duration *= 2
c, err = net.Dial(gSocketProt, gSocketPath)
}
if _, err := fmt.Fprintf(c, "conn %d\n", gClientID); err != nil {
log.Fatalf("registering with server: %s", err)
}
ch <- &callExpr{"sync", nil, 1}
ch <- &callExpr{"on-init", nil, 1}
s := bufio.NewScanner(c)
for s.Scan() {
log.Printf("recv: %s", s.Text())
// `query` has to be handled outside of the main thread, which is
// blocked when running a synchronous shell command ("$" or "!").
// This is important since `query` is often the result of the user
// running `$lf -remote "query $id <something>"`.
if word, rest := splitWord(s.Text()); word == "query" {
gState.mutex.Lock()
state := gState.data[rest]
gState.mutex.Unlock()
if _, err := fmt.Fprintln(c, state); err != nil {
log.Fatalf("sending response to server: %s", err)
}
} else {
p := newParser(strings.NewReader(s.Text()))
if p.parse() {
ch <- p.expr
}
}
}
if err := s.Err(); err != nil {
log.Printf("reading from server: %s", err)
}
c.Close()
}()
return ch
}
func remote(req string) (string, error) {
c, err := net.Dial(gSocketProt, gSocketPath)
if err != nil {
return "", fmt.Errorf("connecting to server: %w", err)
}
defer c.Close()
if _, err := fmt.Fprintln(c, req); err != nil {
return "", fmt.Errorf("sending command to server: %w", err)
}
// XXX: Standard net.Conn interface does not include a CloseWrite method
// but net.UnixConn and net.TCPConn implement it so the following should be
// safe as long as we do not use other types of connections. We need
// CloseWrite to notify the server that this is not a persistent connection
// and it should be closed after the response.
switch c := c.(type) {
case *net.TCPConn:
c.CloseWrite()
case *net.UnixConn:
c.CloseWrite()
}
resp, err := io.ReadAll(c)
if err != nil {
return "", fmt.Errorf("reading response from server: %w", err)
}
return string(resp), nil
}
================================================
FILE: colors.go
================================================
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/gdamore/tcell/v3"
)
type styleMap struct {
styles map[string]tcell.Style
useLinkTarget bool
}
func parseStyles() styleMap {
sm := styleMap{
styles: make(map[string]tcell.Style),
useLinkTarget: false,
}
// Default values from dircolors
//
// no* NORMAL 00
// fi FILE 00
// rs* RESET 0
// di DIR 01;34
// ln LINK 01;36
// mh* MULTIHARDLINK 00
// pi FIFO 40;33
// so SOCK 01;35
// do* DOOR 01;35
// bd BLK 40;33;01
// cd CHR 40;33;01
// or ORPHAN 40;31;01
// mi* MISSING 00
// su SETUID 37;41
// sg SETGID 30;43
// ca* CAPABILITY 30;41
// tw STICKY_OTHER_WRITABLE 30;42
// ow OTHER_WRITABLE 34;42
// st STICKY 37;44
// ex EXEC 01;32
//
// (Entries marked with * are not implemented in lf)
// default values from dircolors with background colors removed
defaultColors := []string{
"fi=00",
"di=01;34",
"ln=01;36",
"pi=33",
"so=01;35",
"bd=33;01",
"cd=33;01",
"or=31;01",
"su=01;32",
"sg=01;32",
"tw=01;34",
"ow=01;34",
"st=01;34",
"ex=01;32",
}
sm.parseGNU(strings.Join(defaultColors, ":"))
if env := os.Getenv("LSCOLORS"); env != "" {
sm.parseBSD(env)
}
if env := os.Getenv("LS_COLORS"); env != "" {
sm.parseGNU(env)
}
if env := os.Getenv("LF_COLORS"); env != "" {
sm.parseGNU(env)
}
for _, path := range gColorsPaths {
if _, err := os.Stat(path); !os.IsNotExist(err) {
sm.parseFile(path)
}
}
return sm
}
func parseColor(toks []string) (tcell.Color, int, error) {
if len(toks) == 0 {
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
}
if toks[0] == "5" && len(toks) >= 2 {
n, err := strconv.Atoi(toks[1])
if err != nil {
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
}
return tcell.PaletteColor(n), 2, nil
}
if toks[0] == "2" && len(toks) >= 4 {
r, err := strconv.Atoi(toks[1])
if err != nil {
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
}
g, err := strconv.Atoi(toks[2])
if err != nil {
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
}
b, err := strconv.Atoi(toks[3])
if err != nil {
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
}
return tcell.NewRGBColor(int32(r), int32(g), int32(b)), 4, nil
}
return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
}
func (sm styleMap) parseFile(path string) {
log.Printf("reading file: %s", path)
f, err := os.Open(path)
if err != nil {
log.Printf("opening colors file: %s", err)
return
}
defer f.Close()
pairs, err := readPairs(f)
if err != nil {
log.Printf("reading colors file: %s", err)
return
}
for _, pair := range pairs {
sm.parsePair(pair)
}
}
// parseGNU parses the $LS_COLORS environment variable.
func (sm *styleMap) parseGNU(env string) {
for entry := range strings.SplitSeq(env, ":") {
if entry == "" {
continue
}
pair := strings.Split(entry, "=")
if len(pair) != 2 {
log.Printf("invalid $LS_COLORS entry: %s", entry)
return
}
sm.parsePair(pair)
}
}
func (sm *styleMap) parsePair(pair []string) {
key, val := pair[0], pair[1]
key = replaceTilde(key)
if filepath.IsAbs(key) {
key = filepath.Clean(key)
}
if key == "ln" && val == "target" {
sm.useLinkTarget = true
}
sm.styles[key] = applySGR(val, tcell.StyleDefault)
}
// parseBSD parses the $LSCOLORS environment variable.
func (sm styleMap) parseBSD(env string) {
if len(env) != 22 {
log.Printf("invalid $LSCOLORS variable: %s", env)
return
}
colorNames := []string{"di", "ln", "so", "pi", "ex", "bd", "cd", "su", "sg", "tw", "ow"}
getStyle := func(r1, r2 byte) tcell.Style {
st := tcell.StyleDefault
switch {
case r1 == 'x':
st = st.Foreground(tcell.ColorDefault)
case 'A' <= r1 && r1 <= 'H':
st = st.Foreground(tcell.PaletteColor(int(r1 - 'A'))).Bold(true)
case 'a' <= r1 && r1 <= 'h':
st = st.Foreground(tcell.PaletteColor(int(r1 - 'a')))
default:
log.Printf("invalid $LSCOLORS entry: %c", r1)
return tcell.StyleDefault
}
switch {
case r2 == 'x':
st = st.Background(tcell.ColorDefault)
case 'a' <= r2 && r2 <= 'h':
st = st.Background(tcell.PaletteColor(int(r2 - 'a')))
default:
log.Printf("invalid $LSCOLORS entry: %c", r2)
return tcell.StyleDefault
}
return st
}
for i, key := range colorNames {
sm.styles[key] = getStyle(env[i*2], env[i*2+1])
}
}
func (sm styleMap) get(f *file) tcell.Style {
if val, ok := sm.styles[f.path]; ok {
return val
}
if f.IsDir() {
if val, ok := sm.styles[f.Name()+"/"]; ok {
return val
}
}
var key string
switch {
case f.linkState == working && !sm.useLinkTarget:
key = "ln"
case f.linkState == broken:
key = "or"
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0o002 != 0:
key = "tw"
case f.IsDir() && f.Mode()&0o002 != 0:
key = "ow"
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
key = "st"
case f.IsDir():
key = "di"
case f.Mode()&os.ModeNamedPipe != 0:
key = "pi"
case f.Mode()&os.ModeSocket != 0:
key = "so"
case f.Mode()&os.ModeCharDevice != 0:
key = "cd"
case f.Mode()&os.ModeDevice != 0:
key = "bd"
case f.Mode()&os.ModeSetuid != 0:
key = "su"
case f.Mode()&os.ModeSetgid != 0:
key = "sg"
case isExecutable(f.FileInfo):
key = "ex"
}
if val, ok := sm.styles[key]; ok {
return val
}
if val, ok := sm.styles[f.Name()+"*"]; ok {
return val
}
if val, ok := sm.styles["*"+f.Name()]; ok {
return val
}
if val, ok := sm.styles[filepath.Base(f.Name())+".*"]; ok {
return val
}
if val, ok := sm.styles["*"+strings.ToLower(f.ext)]; ok {
return val
}
if val, ok := sm.styles["fi"]; ok {
return val
}
return tcell.StyleDefault
}
================================================
FILE: colors_test.go
================================================
package main
import (
"testing"
"github.com/gdamore/tcell/v3"
)
func TestParseColor(t *testing.T) {
tests := []struct {
toks []string
color tcell.Color
offset int
success bool
}{
{[]string{}, tcell.ColorDefault, 0, false},
{[]string{"foo"}, tcell.ColorDefault, 0, false},
{[]string{"5"}, tcell.ColorDefault, 0, false},
{[]string{"5", "foo"}, tcell.ColorDefault, 0, false},
{[]string{"5", "42"}, tcell.PaletteColor(42), 2, true},
{[]string{"2"}, tcell.ColorDefault, 0, false},
{[]string{"2", "foo"}, tcell.ColorDefault, 0, false},
{[]string{"2", "42", "foo"}, tcell.ColorDefault, 0, false},
{[]string{"2", "42", "43", "foo"}, tcell.ColorDefault, 0, false},
{[]string{"2", "42", "43", "44"}, tcell.NewRGBColor(42, 43, 44), 4, true},
}
for _, test := range tests {
color, offset, err := parseColor(test.toks)
success := err == nil
if color != test.color || offset != test.offset || success != test.success {
t.Errorf("at input %v expected (%v, %v, %v) but got (%v, %v, %v)",
test.toks, test.color, test.offset, test.success, color, offset, success)
}
}
}
================================================
FILE: complete.go
================================================
package main
import (
"log"
"maps"
"os"
"path/filepath"
"reflect"
"slices"
"sort"
"strings"
)
var (
gCmdWords = []string{
"set",
"setlocal",
"map",
"nmap",
"vmap",
"cmap",
"cmd",
"addcustominfo",
"bottom",
"calcdirsize",
"cd",
"clear",
"clearmaps",
"copy",
"cut",
"down",
"delete",
"draw",
"echo",
"echoerr",
"echomsg",
"filter",
"find",
"find-back",
"find-next",
"find-prev",
"glob-select",
"glob-unselect",
"half-down",
"half-up",
"high",
"invert",
"jump-next",
"jump-prev",
"load",
"low",
"mark-load",
"mark-remove",
"mark-save",
"middle",
"open",
"page-down",
"page-up",
"paste",
"push",
"quit",
"read",
"redraw",
"reload",
"rename",
"scroll-down",
"scroll-up",
"search",
"search-back",
"search-next",
"search-prev",
"select",
"setfilter",
"shell",
"shell-async",
"shell-pipe",
"shell-wait",
"source",
"sync",
"tag",
"tag-toggle",
"toggle",
"top",
"tty-write",
"unselect",
"up",
"updir",
"visual",
"visual-accept",
"visual-change",
"visual-discard",
"visual-unselect",
"cmd-capitalize-word",
"cmd-complete",
"cmd-delete",
"cmd-delete-back",
"cmd-delete-end",
"cmd-delete-home",
"cmd-delete-unix-word",
"cmd-delete-word",
"cmd-delete-word-back",
"cmd-end",
"cmd-enter",
"cmd-escape",
"cmd-history-next",
"cmd-history-prev",
"cmd-home",
"cmd-interrupt",
"cmd-left",
"cmd-lowercase-word",
"cmd-menu-accept",
"cmd-menu-complete",
"cmd-menu-complete-back",
"cmd-menu-discard",
"cmd-right",
"cmd-transpose",
"cmd-transpose-word",
"cmd-uppercase-word",
"cmd-word",
"cmd-word-back",
"cmd-yank",
}
gOptWords = getOptWords(gOpts)
gLocalOptWords = getLocalOptWords(gLocalOpts)
)
func getOptWords(opts any) (optWords []string) {
t := reflect.TypeOf(opts)
for i := range t.NumField() {
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 := range t.NumField() {
field := t.Field(i)
name := field.Name
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 getLongest(s1, s2 string) string {
r1 := []rune(s1)
r2 := []rune(s2)
i := 0
for ; i < len(r1) && i < len(r2); i++ {
if r1[i] != r2[i] {
break
}
}
return string(r1[:i])
}
type compMatch struct {
name string // display name in completion menu
result string // result when cycling through completion menu
}
func matchWord(s string, words []string) (matches []compMatch, longest string) {
for _, w := range words {
if !strings.HasPrefix(w, s) {
continue
}
matches = append(matches, compMatch{w, w})
if len(matches) == 1 {
longest = w
} else {
longest = getLongest(longest, w)
}
}
switch len(matches) {
case 0:
longest = s
case 1:
longest += " "
}
return
}
func matchList(s string, words []string) (matches []compMatch, longest string) {
toks := strings.Split(s, ":")
for _, w := range words {
if slices.Contains(toks[:len(toks)-1], w) || !strings.HasPrefix(w, toks[len(toks)-1]) {
continue
}
matchResult := strings.Join(append(slices.Clone(toks[:len(toks)-1]), w), ":")
matches = append(matches, compMatch{w, matchResult})
if len(matches) == 1 {
longest = matchResult
} else {
longest = getLongest(longest, matchResult)
}
}
switch len(matches) {
case 0:
longest = s
case 1:
if longest == s {
longest += " "
}
}
return
}
func matchCmd(s string) (matches []compMatch, longest string) {
words := slices.Concat(gCmdWords, slices.Collect(maps.Keys(gOpts.cmds)))
slices.Sort(words)
matches, longest = matchWord(s, slices.Compact(words))
return
}
func matchFile(s string, dirOnly bool, escape, unescape func(string) string) (matches []compMatch, longest string) {
dir, file := filepath.Split(unescape(replaceTilde(s)))
d := dir
if dir == "" {
d = "."
}
files, err := os.ReadDir(d)
if err != nil {
log.Printf("reading directory: %s", err)
longest = s
return
}
var longestName string
for _, f := range files {
isDir := false
if f.IsDir() {
isDir = true
} else if f.Type()&os.ModeSymlink != 0 {
if stat, err := os.Stat(filepath.Join(d, f.Name())); err == nil && stat.IsDir() {
isDir = true
}
}
if !isDir && dirOnly {
continue
}
if !strings.HasPrefix(strings.ToLower(f.Name()), strings.ToLower(file)) {
continue
}
name := f.Name()
if isDir {
name += string(filepath.Separator)
}
matches = append(matches, compMatch{name, escape(dir + name)})
if len(matches) == 1 {
longestName = name
} else {
// Match case-insensitively without changing the prefix's case.
p := getLongest(strings.ToLower(longestName), strings.ToLower(name))
longestName = string([]rune(longestName)[:len([]rune(p))])
}
}
switch len(matches) {
case 0:
longest = s
case 1:
longest = escape(dir + longestName)
if !strings.HasSuffix(longestName, string(filepath.Separator)) {
longest += " "
}
default:
longest = escape(dir + longestName)
}
return
}
func matchCmdFile(s string, dirOnly bool) (matches []compMatch, longest string) {
matches, longest = matchFile(s, dirOnly, cmdEscape, cmdUnescape)
return
}
func matchShellFile(s string) (matches []compMatch, longest string) {
matches, longest = matchFile(s, false, shellEscape, shellUnescape)
return
}
func matchExec(s string) (matches []compMatch, longest string) {
var words []string
for p := range strings.SplitSeq(envPath, string(filepath.ListSeparator)) {
files, err := os.ReadDir(p)
if err != nil {
if !os.IsNotExist(err) {
log.Printf("reading path: %s", err)
}
continue
}
for _, f := range files {
if !strings.HasPrefix(f.Name(), s) {
continue
}
finfo, err := f.Info()
if err != nil {
log.Printf("getting file information: %s", err)
continue
}
if finfo.Mode().IsRegular() && isExecutable(finfo) {
words = append(words, f.Name())
}
}
}
slices.Sort(words)
matches, longest = matchWord(s, slices.Compact(words))
return
}
func matchSearch(s string) (matches []compMatch, longest string) {
files, err := os.ReadDir(".")
if err != nil {
log.Printf("reading directory: %s", err)
longest = s
return
}
for _, f := range files {
if !strings.HasPrefix(strings.ToLower(f.Name()), strings.ToLower(s)) {
continue
}
matches = append(matches, compMatch{f.Name(), f.Name()})
if len(matches) == 1 {
longest = f.Name()
} else {
p := getLongest(strings.ToLower(longest), strings.ToLower(f.Name()))
longest = string([]rune(longest)[:len([]rune(p))])
}
}
if len(matches) == 0 {
longest = s
}
return
}
func completeCmd(s string) (matches []compMatch, longest string) {
f := tokenize(s)
if len(f) == 1 {
matches, longest = matchCmd(s)
return
}
longest = f[len(f)-1]
switch f[0] {
case "set":
if len(f) == 2 {
matches, longest = matchWord(f[1], gOptWords)
break
}
if len(f) != 3 {
break
}
switch f[1] {
case "cleaner", "previewer", "rulerfile":
matches, longest = matchCmdFile(f[2], false)
case "borderstyle":
matches, longest = matchWord(f[2], []string{"box", "roundbox", "outline", "roundoutline", "separators"})
case "filtermethod", "searchmethod":
matches, longest = matchWord(f[2], []string{"glob", "regex", "text"})
case "info":
matches, longest = matchList(f[2], []string{"atime", "btime", "ctime", "custom", "group", "perm", "size", "time", "user"})
case "preserve":
matches, longest = matchList(f[2], []string{"mode", "timestamps"})
case "selmode":
matches, longest = matchWord(f[2], []string{"all", "dir"})
case "sizeunits":
matches, longest = matchWord(f[2], []string{"binary", "decimal"})
case "sortby":
matches, longest = matchWord(f[2], []string{"atime", "btime", "ctime", "custom", "ext", "name", "natural", "size", "time"})
case "terminalcursor":
matches, longest = matchWord(f[2], []string{"default", "block", "underline", "bar", "blinkblock", "blinkunderline", "blinkbar"})
default:
if slices.Contains(gOptWords, f[1]+"!") {
matches, longest = matchWord(f[2], []string{"false", "true"})
}
}
case "setlocal":
if len(f) == 2 {
matches, longest = matchCmdFile(f[1], true)
break
}
if len(f) == 3 {
matches, longest = matchWord(f[2], gLocalOptWords)
break
}
if len(f) != 4 {
break
}
switch f[2] {
case "info":
matches, longest = matchList(f[3], []string{"atime", "btime", "ctime", "custom", "group", "perm", "size", "time", "user"})
case "sortby":
matches, longest = matchWord(f[3], []string{"atime", "btime", "ctime", "custom", "ext", "name", "natural", "size", "time"})
default:
if slices.Contains(gLocalOptWords, f[2]+"!") {
matches, longest = matchWord(f[3], []string{"false", "true"})
}
}
case "map", "nmap", "vmap", "cmap":
if len(f) == 3 {
matches, longest = matchCmd(f[2])
}
case "cmd":
case "cd":
if len(f) == 2 {
matches, longest = matchCmdFile(f[1], true)
}
case "addcustominfo", "select", "source":
if len(f) == 2 {
matches, longest = matchCmdFile(f[1], false)
}
case "toggle":
matches, longest = matchCmdFile(f[len(f)-1], false)
default:
if !slices.Contains(gCmdWords, f[0]) {
matches, longest = matchCmdFile(f[len(f)-1], false)
}
}
f[len(f)-1] = longest
longest = strings.Join(f, " ")
return
}
func completeShell(s string) (matches []compMatch, longest string) {
f := tokenize(s)
switch len(f) {
case 1:
matches, longest = matchExec(f[0])
default:
matches, longest = matchShellFile(f[len(f)-1])
}
f[len(f)-1] = longest
longest = strings.Join(f, " ")
return
}
func completeSearch(s string) (matches []compMatch, longest string) {
matches, longest = matchSearch(s)
return
}
================================================
FILE: complete_test.go
================================================
package main
import (
"reflect"
"testing"
)
func TestGetOptWords(t *testing.T) {
tests := []struct {
opts any
exp []string
}{
{struct{ feature bool }{}, []string{"feature", "feature!", "nofeature"}},
{struct{ feature int }{}, []string{"feature"}},
{struct{ feature string }{}, []string{"feature"}},
{struct{ feature []string }{}, []string{"feature"}},
}
for _, test := range tests {
result := getOptWords(test.opts)
if !reflect.DeepEqual(result, test.exp) {
t.Errorf("at input '%#v' expected '%s' but got '%s'", test.opts, test.exp, result)
}
}
}
func TestGetLocalOptWords(t *testing.T) {
tests := []struct {
localOpts any
exp []string
}{
{struct{ feature map[string]bool }{}, []string{"feature", "feature!", "nofeature"}},
{struct{ feature map[string]int }{}, []string{"feature"}},
{struct{ feature map[string]string }{}, []string{"feature"}},
{struct{ feature map[string][]string }{}, []string{"feature"}},
}
for _, test := range tests {
result := getLocalOptWords(test.localOpts)
if !reflect.DeepEqual(result, test.exp) {
t.Errorf("at input '%#v' expected '%s' but got '%s'", test.localOpts, test.exp, result)
}
}
}
func TestGetLongest(t *testing.T) {
tests := []struct {
s1 string
s2 string
exp string
}{
{"", "", ""},
{"", "foo", ""},
{"foo", "", ""},
{"foo", "bar", ""},
{"foo", "foobar", "foo"},
{"foo", "barfoo", ""},
{"foobar", "foobaz", "fooba"},
{"год", "гол", "го"},
}
for _, test := range tests {
if got := getLongest(test.s1, test.s2); got != test.exp {
t.Errorf("at input '%s' and '%s' expected '%s' but got '%s'", test.s1, test.s2, test.exp, got)
}
}
}
func TestMatchWord(t *testing.T) {
tests := []struct {
s string
words []string
matches []compMatch
longest string
}{
{"", nil, nil, ""},
{"", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "foo"}, {"bar", "bar"}, {"baz", "baz"}}, ""},
{"f", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "foo"}}, "foo "},
{"b", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "bar"}, {"baz", "baz"}}, "ba"},
{"fo", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "foo"}}, "foo "},
{"ba", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "bar"}, {"baz", "baz"}}, "ba"},
{"fo", []string{"bar", "baz"}, nil, "fo"},
}
for _, test := range tests {
matches, longest := matchWord(test.s, test.words)
if !reflect.DeepEqual(matches, test.matches) {
t.Errorf("at input '%s' with '%s' expected '%v' but got '%v'", test.s, test.words, test.matches, matches)
}
if longest != test.longest {
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.longest, longest)
}
}
}
func TestMatchList(t *testing.T) {
tests := []struct {
s string
words []string
matches []compMatch
longest string
}{
{"", nil, nil, ""},
{"", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "foo"}, {"bar", "bar"}, {"baz", "baz"}}, ""},
{"f", []string{"bar", "baz"}, nil, "f"},
{"f", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "foo"}}, "foo"},
{"b", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "bar"}, {"baz", "baz"}}, "ba"},
{"ba", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "bar"}, {"baz", "baz"}}, "ba"},
{"foo", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "foo"}}, "foo "},
{"foo:", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "foo:bar"}, {"baz", "foo:baz"}}, "foo:ba"},
{"foo:f", []string{"foo", "bar", "baz"}, nil, "foo:f"},
{"foo:b", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "foo:bar"}, {"baz", "foo:baz"}}, "foo:ba"},
{"foo:ba", []string{"foo", "bar", "baz"}, []compMatch{{"bar", "foo:bar"}, {"baz", "foo:baz"}}, "foo:ba"},
{"bar:b", []string{"foo", "bar", "baz"}, []compMatch{{"baz", "bar:baz"}}, "bar:baz"},
{"bar:f", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "bar:foo"}}, "bar:foo"},
{"bar:foo", []string{"foo", "bar", "baz"}, []compMatch{{"foo", "bar:foo"}}, "bar:foo "},
}
for _, test := range tests {
matches, longest := matchList(test.s, test.words)
if !reflect.DeepEqual(matches, test.matches) {
t.Errorf("at input '%s' with '%s' expected '%v' but got '%v'", test.s, test.words, test.matches, matches)
}
if longest != test.longest {
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.longest, longest)
}
}
}
================================================
FILE: copy.go
================================================
package main
import (
"fmt"
"io"
"os"
"path/filepath"
"slices"
"strconv"
"strings"
"github.com/djherbis/times"
)
type ProgressWriter struct {
writer io.Writer
nums chan<- int64
}
func NewProgressWriter(writer io.Writer, nums chan<- int64) *ProgressWriter {
return &ProgressWriter{
writer: writer,
nums: nums,
}
}
func (progressWriter *ProgressWriter) Write(b []byte) (int, error) {
n, err := progressWriter.writer.Write(b)
progressWriter.nums <- int64(n)
return n, err
}
func copySize(srcs []string) (int64, error) {
var total int64
for _, src := range srcs {
_, err := os.Lstat(src)
if os.IsNotExist(err) {
return total, fmt.Errorf("src does not exist: %q", src)
}
err = filepath.Walk(src, func(_ string, info os.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("walk: %w", err)
}
total += info.Size()
return nil
})
if err != nil {
return total, err
}
}
return total, nil
}
func copyFile(src, dst string, preserve []string, info os.FileInfo, nums chan<- int64, errs chan<- error) {
r, err := os.Open(src)
if err != nil {
errs <- err
return
}
defer r.Close()
var dstMode os.FileMode = 0o666
if slices.Contains(preserve, "mode") {
dstMode = info.Mode()
}
w, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, dstMode)
if err != nil {
errs <- err
return
}
if _, err := io.Copy(NewProgressWriter(w, nums), r); err != nil {
errs <- err
w.Close()
if err = os.Remove(dst); err != nil {
errs <- err
}
return
}
if err := w.Close(); err != nil {
errs <- err
if err = os.Remove(dst); err != nil {
errs <- err
}
return
}
if slices.Contains(preserve, "timestamps") {
atime := times.Get(info).AccessTime()
mtime := info.ModTime()
if err := os.Chtimes(dst, atime, mtime); err != nil {
errs <- err
if err = os.Remove(dst); err != nil {
errs <- err
}
return
}
}
}
func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64, errs chan error) {
nums = make(chan int64, 1024)
errs = make(chan error, 1024)
go func() {
dirInfos := make(map[string]os.FileInfo)
for _, src := range srcs {
file := filepath.Base(src)
dst := filepath.Join(dstDir, file)
if lstat, err := os.Lstat(dst); err == nil {
ext := getFileExtension(lstat)
basename := file[:len(file)-len(ext)]
var newPath string
for i := 1; !os.IsNotExist(err); i++ {
file = strings.ReplaceAll(gOpts.dupfilefmt, "%f", basename+ext)
file = strings.ReplaceAll(file, "%b", basename)
file = strings.ReplaceAll(file, "%e", ext)
file = strings.ReplaceAll(file, "%n", strconv.Itoa(i))
newPath = filepath.Join(dstDir, file)
_, err = os.Lstat(newPath)
}
dst = newPath
}
err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil {
errs <- fmt.Errorf("walk: %w", err)
return nil
}
rel, err := filepath.Rel(src, path)
if err != nil {
errs <- fmt.Errorf("relative: %w", err)
return nil
}
newPath := filepath.Join(dst, rel)
switch {
case info.IsDir():
dstMode := os.ModePerm
if slices.Contains(preserve, "mode") {
dstMode = info.Mode()
}
if err := os.MkdirAll(newPath, dstMode); err != nil {
errs <- fmt.Errorf("mkdir: %w", err)
}
if slices.Contains(preserve, "timestamps") {
dirInfos[newPath] = info
}
nums <- info.Size()
case info.Mode()&os.ModeSymlink != 0:
if rlink, err := os.Readlink(path); err != nil {
errs <- fmt.Errorf("symlink: %w", err)
} else {
if err := os.Symlink(rlink, newPath); err != nil {
errs <- fmt.Errorf("symlink: %w", err)
}
}
nums <- info.Size()
default:
copyFile(path, newPath, preserve, info, nums, errs)
}
return nil
})
if err != nil {
errs <- fmt.Errorf("walk: %w", err)
}
}
for path, info := range dirInfos {
atime := times.Get(info).AccessTime()
mtime := info.ModTime()
if err := os.Chtimes(path, atime, mtime); err != nil {
errs <- fmt.Errorf("chtimes: %w", err)
}
}
close(errs)
}()
return nums, errs
}
================================================
FILE: df_openbsd.go
================================================
package main
import (
"log"
"golang.org/x/sys/unix"
)
func diskFree(wd string) string {
var stat unix.Statfs_t
if err := unix.Statfs(wd, &stat); err != nil {
log.Printf("diskfree: %s", err)
return ""
}
// Available blocks * size per block = available space in bytes
return "df: " + humanize(int64(stat.F_bavail)*int64(stat.F_bsize))
}
================================================
FILE: df_statfs.go
================================================
//go:build darwin || dragonfly || freebsd || linux
package main
import (
"log"
"golang.org/x/sys/unix"
)
func diskFree(wd string) string {
var stat unix.Statfs_t
if err := unix.Statfs(wd, &stat); err != nil {
log.Printf("diskfree: %s", err)
return ""
}
// Available blocks * size per block = available space in bytes
return "df: " + humanize(int64(stat.Bavail)*int64(stat.Bsize))
}
================================================
FILE: df_statvfs.go
================================================
//go:build illumos || netbsd || solaris
package main
import (
"log"
"golang.org/x/sys/unix"
)
func diskFree(wd string) string {
var stat unix.Statvfs_t
if err := unix.Statvfs(wd, &stat); err != nil {
log.Printf("diskfree: %s", err)
return ""
}
// Available blocks * size per block = available space in bytes
return "df: " + humanize(int64(stat.Bavail)*int64(stat.Bsize))
}
================================================
FILE: df_windows.go
================================================
package main
import (
"log"
"golang.org/x/sys/windows"
)
func diskFree(wd string) string {
var free uint64
pathPtr, err := windows.UTF16PtrFromString(wd)
if err != nil {
log.Printf("diskfree: %s", err)
return ""
}
err = windows.GetDiskFreeSpaceEx(pathPtr, &free, nil, nil) // cwd, free, total, available
if err != nil {
log.Printf("diskfree: %s", err)
return ""
}
return "df: " + humanize(int64(free))
}
================================================
FILE: diacritics.go
================================================
package main
var normMap = map[rune]rune{
// lowercase (not only) european
'ě': 'e', 'ř': 'r', 'ů': 'u', 'ø': 'o', 'ĉ': 'c', 'ĝ': 'g', 'ĥ': 'h', 'ĵ': 'j', 'ŝ': 's',
'ŭ': 'u', 'è': 'e', 'ù': 'u', 'ÿ': 'y', 'ė': 'e', 'į': 'i', 'ų': 'u', 'ā': 'a', 'ē': 'e',
'ī': 'i', 'ū': 'u', 'ļ': 'l', 'ķ': 'k', 'ņ': 'n', 'ģ': 'g', 'ő': 'o', 'ű': 'u', 'ë': 'e',
'ï': 'i', 'ą': 'a', 'ć': 'c', 'ę': 'e', 'ł': 'l', 'ń': 'n', 'ś': 's', 'ź': 'z', 'ż': 'z',
'õ': 'o', 'ș': 's', 'ț': 't', 'č': 'c', 'ď': 'd', 'ĺ': 'l', 'ľ': 'l', 'ň': 'n', 'ŕ': 'r',
'š': 's', 'ť': 't', 'ý': 'y', 'ž': 'z', 'é': 'e', 'í': 'i', 'ñ': 'n', 'ó': 'o', 'ú': 'u',
'ü': 'u', 'å': 'a', 'ä': 'a', 'ö': 'o', 'ç': 'c', 'î': 'i', 'ş': 's', 'û': 'u', 'ğ': 'g',
'ă': 'a', 'â': 'a', 'đ': 'd', 'ê': 'e', 'ô': 'o', 'ơ': 'o', 'ư': 'u', 'á': 'a', 'à': 'a',
'ã': 'a', 'ả': 'a', 'ạ': 'a',
// uppercase (not only) european
'Ě': 'E', 'Ř': 'R', 'Ů': 'U', 'Ø': 'O', 'Ĉ': 'C', 'Ĝ': 'G', 'Ĥ': 'H', 'Ĵ': 'J', 'Ŝ': 'S',
'Ŭ': 'U', 'È': 'E', 'Ù': 'U', 'Ÿ': 'Y', 'Ė': 'E', 'Į': 'I', 'Ų': 'U', 'Ā': 'A', 'Ē': 'E',
'Ī': 'I', 'Ū': 'U', 'Ļ': 'L', 'Ķ': 'K', 'Ņ': 'N', 'Ģ': 'G', 'Ő': 'O', 'Ű': 'U', 'Ë': 'E',
'Ï': 'I', 'Ą': 'A', 'Ć': 'C', 'Ę': 'E', 'Ł': 'L', 'Ń': 'N', 'Ś': 'S', 'Ź': 'Z', 'Ż': 'Z',
'Õ': 'O', 'Ș': 'S', 'Ț': 'T', 'Č': 'C', 'Ď': 'D', 'Ĺ': 'L', 'Ľ': 'L', 'Ň': 'N', 'Ŕ': 'R',
'Š': 'S', 'Ť': 'T', 'Ý': 'Y', 'Ž': 'Z', 'É': 'E', 'Í': 'I', 'Ñ': 'N', 'Ó': 'O', 'Ú': 'U',
'Ü': 'U', 'Å': 'A', 'Ä': 'A', 'Ö': 'O', 'Ç': 'C', 'Î': 'I', 'Ş': 'S', 'Û': 'U', 'Ğ': 'G',
'Ă': 'A', 'Â': 'A', 'Đ': 'D', 'Ê': 'E', 'Ô': 'O', 'Ơ': 'O', 'Ư': 'U', 'Á': 'A', 'À': 'A',
'Ã': 'A', 'Ả': 'A', 'Ạ': 'A',
// lowercase Vietnamese
'ắ': 'a', 'ặ': 'a', 'ằ': 'a', 'ẳ': 'a', 'ẵ': 'a', 'ấ': 'a', 'ậ': 'a', 'ầ': 'a', 'ẩ': 'a',
'ẫ': 'a', 'ẹ': 'e', 'ẻ': 'e', 'ẽ': 'e', 'ế': 'e', 'ệ': 'e', 'ề': 'e', 'ể': 'e', 'ễ': 'e',
'i': 'i', 'ị': 'i', 'ì': 'i', 'ỉ': 'i', 'ĩ': 'i', 'o': 'o', 'ọ': 'o', 'ò': 'o', 'ỏ': 'o',
'ố': 'o', 'ộ': 'o', 'ồ': 'o', 'ổ': 'o', 'ỗ': 'o', 'ớ': 'o', 'ợ': 'o', 'ờ': 'o', 'ở': 'o',
'ỡ': 'o', 'ụ': 'u', 'ủ': 'u', 'ũ': 'u', 'ứ': 'u', 'ự': 'u', 'ừ': 'u', 'ử': 'u', 'ữ': 'u',
'y': 'y', 'ỵ': 'y', 'ỳ': 'y', 'ỷ': 'y', 'ỹ': 'y',
// uppercase Vietnamese
'Ắ': 'A', 'Ặ': 'A', 'Ằ': 'A', 'Ẳ': 'A', 'Ẵ': 'A', 'Ấ': 'A', 'Ậ': 'A', 'Ầ': 'A', 'Ẩ': 'A',
'Ẫ': 'A', 'Ẹ': 'E', 'Ẻ': 'E', 'Ẽ': 'E', 'Ế': 'E', 'Ệ': 'E', 'Ề': 'E', 'Ể': 'E', 'Ễ': 'E',
'I': 'I', 'Ị': 'I', 'Ì': 'I', 'Ỉ': 'I', 'Ĩ': 'I', 'O': 'O', 'Ọ': 'O', 'Ò': 'O', 'Ỏ': 'O',
'Ố': 'O', 'Ộ': 'O', 'Ồ': 'O', 'Ổ': 'O', 'Ỗ': 'O', 'Ớ': 'O', 'Ợ': 'O', 'Ờ': 'O', 'Ở': 'O',
'Ỡ': 'O', 'Ụ': 'U', 'Ủ': 'U', 'Ũ': 'U', 'Ứ': 'U', 'Ự': 'U', 'Ừ': 'U', 'Ử': 'U', 'Ữ': 'U',
'Y': 'Y', 'Ỵ': 'Y', 'Ỳ': 'Y', 'Ỷ': 'Y', 'Ỹ': 'Y',
}
func removeDiacritics(baseString string) string {
normalizedRunes := make([]rune, 0, len(baseString))
for _, baseRune := range baseString {
if normRune, ok := normMap[baseRune]; ok {
normalizedRunes = append(normalizedRunes, normRune)
} else {
normalizedRunes = append(normalizedRunes, baseRune)
}
}
return string(normalizedRunes)
}
================================================
FILE: diacritics_test.go
================================================
package main
import (
"testing"
)
// typical czech test sentence ;-)
const baseTestString = "Příliš žluťoučký kůň příšerně úpěl ďábelské ódy"
func TestRemoveDiacritics(t *testing.T) {
testStr := baseTestString
expStr := "Prilis zlutoucky kun priserne upel dabelske ody"
checkRemoveDiacritics(testStr, expStr, t)
// other accents (non complete, but all I found)
testStr = "áéíóúýčďěňřšťžůåøĉĝĥĵŝŭšžõäöüàâçéèêëîïôùûüÿžščćđáéíóúąęėįųūčšžāēīūčšžļķņģáéíóúöüőűäöüëïąćęłńóśźżáàãâçéêíóõôăâîșțáäčďéíĺľňóôŕšťúýžáéíñóúüåäöâçîşûğăâđêôơưáàãảạ"
expStr = "aeiouycdenrstzuaocghjsuszoaouaaceeeeiiouuuyzsccdaeiouaeeiuucszaeiucszlkngaeiouououaoueiacelnoszzaaaaceeioooaaistaacdeillnoorstuyzaeinouuaaoacisugaadeoouaaaaa"
checkRemoveDiacritics(testStr, expStr, t)
testStr = "ÁÉÍÓÚÝČĎĚŇŘŠŤŽŮÅØĈĜĤĴŜŬŠŽÕÄÖÜÀÂÇÉÈÊËÎÏÔÙÛÜŸŽŠČĆĐÁÉÍÓÚĄĘĖĮŲŪČŠŽĀĒĪŪČŠŽĻĶŅĢÁÉÍÓÚÖÜŐŰÄÖÜËÏĄĆĘŁŃÓŚŹŻÁÀÃÂÇÉÊÍÓÕÔĂÂÎȘȚÁÄČĎÉÍĹĽŇÓÔŔŠŤÚÝŽÁÉÍÑÓÚÜÅÄÖÂÇÎŞÛĞĂÂĐÊÔƠƯÁÀÃẢẠ"
expStr = "AEIOUYCDENRSTZUAOCGHJSUSZOAOUAACEEEEIIOUUUYZSCCDAEIOUAEEIUUCSZAEIUCSZLKNGAEIOUOUOUAOUEIACELNOSZZAAAACEEIOOOAAISTAACDEILLNOORSTUYZAEINOUUAAOACISUGAADEOOUAAAAA"
checkRemoveDiacritics(testStr, expStr, t)
testStr = "áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ"
expStr = "aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd"
checkRemoveDiacritics(testStr, expStr, t)
testStr = "ÁẠÀẢÃĂẮẶẰẲẴÂẤẬẦẨẪÉẸÈẺẼÊẾỆỀỂỄÍỊÌỈĨÓỌÒỎÕÔỐỘỒỔỖƠỚỢỜỞỠÚỤÙỦŨƯỨỰỪỬỮÝỴỲỶỸĐ"
expStr = "AAAAAAAAAAAAAAAAAEEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYYD"
checkRemoveDiacritics(testStr, expStr, t)
}
func checkRemoveDiacritics(testStr, expStr string, t *testing.T) {
resultStr := removeDiacritics(testStr)
if resultStr != expStr {
t.Errorf("at input '%v' expected '%v' but got '%v'", testStr, expStr, resultStr)
}
}
func TestSearchSettings(t *testing.T) {
runSearch(t, true, false, true, true, "Veřejný", "vere", true)
runSearch(t, true, false, true, false, baseTestString, "Zlutoucky", true)
runSearch(t, true, false, true, false, baseTestString, "zlutoucky", true)
runSearch(t, true, true, true, false, baseTestString, "Zlutoucky", false)
runSearch(t, true, true, true, true, baseTestString, "zlutoucky", true)
runSearch(t, false, false, true, false, baseTestString, "žlutoucky", true)
runSearch(t, false, false, true, false, baseTestString, "Žlutoucky", false)
runSearch(t, false, false, true, true, baseTestString, "žluťoučký", true)
runSearch(t, false, false, true, false, baseTestString, "žluťoučký", true)
runSearch(t, false, false, false, false, baseTestString, "žluťoučký", true)
runSearch(t, false, false, false, false, baseTestString, "zlutoucky", false)
runSearch(t, false, false, true, true, baseTestString, "zlutoucky", true)
}
func runSearch(t *testing.T, ignorecase, smartcase, ignorediacritics, smartdiacritics bool, base, pattern string, expected bool) {
gOpts.ignorecase = ignorecase
gOpts.smartcase = smartcase
gOpts.ignoredia = ignorediacritics
gOpts.smartdia = smartdiacritics
matched, _ := searchMatch(base, pattern, textSearch)
if matched != expected {
t.Errorf("False search for ignorecase = %t, smartcase = %t, ignoredia = %t, smartdia = %t",
gOpts.ignorecase,
gOpts.smartcase,
gOpts.ignoredia,
gOpts.smartdia)
}
}
================================================
FILE: doc.md
================================================
# NAME
lf - terminal file manager
# SYNOPSIS
**lf**
[**-command** *command*]
[**-config** *path*]
[**-cpuprofile** *path*]
[**-doc**]
[**-help**]
[**-last-dir-path** *path*]
[**-log** *path*]
[**-memprofile** *path*]
[**-print-last-dir**]
[**-print-selection**]
[**-remote** *command*]
[**-selection-path** *path*]
[**-server**]
[**-single**]
[**-version**]
[*cd-or-select-path*]
# DESCRIPTION
lf is a terminal file manager.
The source code can be found in the repository at https://github.com/gokcehan/lf
This documentation can either be read from the terminal using `lf -doc` or online at https://github.com/gokcehan/lf/blob/master/doc.md
You can also use the `help` command (default `<f-1>`) inside lf to view the documentation in a pager.
A man page with the same content is also available in the repository at https://github.com/gokcehan/lf/blob/master/lf.1
# OPTIONS
## POSITIONAL ARGUMENTS
**cd-or-select-path**
Set the starting location. If *path* is a directory, start in there. If it's a file, start in the file's parent directory and select the file. When no *path* is supplied, lf uses the current directory. Only accepts one argument.
## META OPTIONS
**-doc**
Show lf's documentation (same content as this file) and exit.
**-help**
Show command-line usage and exit.
**-version**
Show version information and exit.
## STARTUP & CONFIGURATION
**-command** *command*
Execute *command* during client initialization (i.e. after reading configuration, before `on-init`). To execute more than one command, you can either use the **-command** flag multiple times or pass multiple commands at once by chaining them with ";".
**-config** *path*
Use the config file at *path* instead of the normal search locations. This only affects which `lfrc` is read at startup.
## SHELL INTEGRATION
**-print-last-dir**
Print the last directory to stdout when lf exits. This can be used to let lf change your shells working directory. See `CHANGING DIRECTORY` for more details.
**-last-dir-path** *path*
Same as **-print-last-dir**, but write the directory to *path* instead of stdout.
**-print-selection**
Print selected files to stdout when opening a file in lf. This can be used to use lf as an "open file" dialog. First, select the files you want to pass to another program. Then, confirm the selection by opening a file. This causes lf to quit and print out the selection. Quitting lf prematurely discards the selection.
**-selection-path** *path*
Same as **-print-selection**, but write the newline-separated list to *path* instead of stdout.
## SERVER
**-remote** *command*
Send *command* to the running server (i.e. `send`, `query`, `list`, `quit`, or `quit!`). See `REMOTE COMMANDS` for more details.
**-server**
Start the (headless) server process explicitly. Runs in the foreground and writes server logs to stderr (or the file set with **-log**). Clients auto-start a server if none is running unless **-single** is used.
**-single**
Start a stand-alone client without a server. Disables remote control.
## DIAGNOSTICS
**-log** *path*
Append runtime log messages to *path*.
**-cpuprofile** *path*
Write a CPU profile to *path*. The profile can be used by `go tool pprof`.
**-memprofile** *path*
Write a memory profile to *path*. The profile can be used by `go tool pprof`.
## EXAMPLES
Use `lf` to select files (while hiding certain file types):
lf -command 'set nohidden' -command 'set hiddenfiles "*mp4:*pdf:*txt"' -print-selection
Another sophisticated "open file" dialog focusing on design:
lf -command 'set nopreview; set ratios 1; set drawbox; set promptfmt "Select files [%w] %S q: cancel, l: confirm"' -print-selection
Open Downloads and set `sortby` and `info` to creation date:
lf -command 'set sortby btime; set info btime' ~/Downloads
Temporarily prevent `lf` from modifying the command history:
lf -command 'set nohistory'
Use default settings and log current session:
lf -config /dev/null -log /tmp/lf.log
Force-quit the server:
lf -remote 'quit!'
Inherit lf's working directory in your shell:
cd "$(lf -print-last-dir)"
# QUICK REFERENCE
The following commands are provided by lf:
quit (default 'q')
up (default 'k' and '<up>')
half-up (default '<c-u>')
page-up (default '<c-b>' and '<pgup>')
scroll-up (default '<c-y>')
down (default 'j' and '<down>')
half-down (default '<c-d>')
page-down (default '<c-f>' and '<pgdn>')
scroll-down (default '<c-e>')
updir (default 'h' and '<left>')
open (default 'l' and '<right>')
jump-next (default ']')
jump-prev (default '[')
top (default 'gg' and '<home>')
bottom (default 'G' and '<end>')
high (default 'H')
middle (default 'M')
low (default 'L')
toggle
invert (default 'v')
unselect (default 'u')
glob-select
glob-unselect
copy (default 'y')
cut (default 'd')
paste (default 'p')
clear (default 'c')
sync
draw
redraw (default '<c-l>')
load
reload (default '<c-r>')
delete (modal)
rename (modal) (default 'r')
read (modal) (default ':')
shell (modal) (default '$')
shell-pipe (modal) (default '%')
shell-wait (modal) (default '!')
shell-async (modal) (default '&')
find (modal) (default 'f')
find-back (modal) (default 'F')
find-next (default ';')
find-prev (default ',')
search (modal) (default '/')
search-back (modal) (default '?')
search-next (default 'n')
search-prev (default 'N')
filter (modal)
setfilter
mark-save (modal) (default 'm')
mark-load (modal) (default "'")
mark-remove (modal) (default '"')
tag
tag-toggle (default 't')
echo
echomsg
echoerr
cd
select
source
push
addcustominfo
calcdirsize
clearmaps
tty-write
visual (default 'V')
The following Visual mode commands are provided by lf:
visual-accept (default 'V')
visual-unselect
visual-discard (default '<esc>')
visual-change (default 'o')
The following Command-line mode commands are provided by lf:
cmd-insert
cmd-escape (default '<esc>')
cmd-complete (default '<tab>')
cmd-menu-complete
cmd-menu-complete-back
cmd-menu-accept
cmd-menu-discard
cmd-enter (default '<c-j>' and '<enter>')
cmd-interrupt (default '<c-c>')
cmd-history-next (default '<c-n>' and '<down>')
cmd-history-prev (default '<c-p>' and '<up>')
cmd-left (default '<c-b>' and '<left>')
cmd-right (default '<c-f>' and '<right>')
cmd-home (default '<c-a>' and '<home>')
cmd-end (default '<c-e>' and '<end>')
cmd-delete (default '<c-d>' and '<delete>')
cmd-delete-back (default '<backspace>')
cmd-delete-home (default '<c-u>')
cmd-delete-end (default '<c-k>')
cmd-delete-unix-word (default '<c-w>')
cmd-yank (default '<c-y>')
cmd-transpose (default '<c-t>')
cmd-transpose-word (default '<a-t>')
cmd-word (default '<a-f>')
cmd-word-back (default '<a-b>')
cmd-delete-word (default '<a-d>')
cmd-delete-word-back (default '<a-backspace>')
cmd-capitalize-word (default '<a-c>')
cmd-uppercase-word (default '<a-u>')
cmd-lowercase-word (default '<a-l>')
The following options can be used to customize the behavior of lf:
anchorfind bool (default true)
autoquit bool (default true)
borderfmt string (default "\033[0m")
borderstyle string (default 'box')
cleaner string (default '')
copyfmt string (default "\033[7;33m")
cursoractivefmt string (default "\033[7m")
cursorparentfmt string (default "\033[7m")
cursorpreviewfmt string (default "\033[4m")
cutfmt string (default "\033[7;31m")
dircounts bool (default false)
dirfirst bool (default true)
dironly bool (default false)
dirpreviews bool (default false)
drawbox bool (default false)
dupfilefmt string (default '%f.~%n~')
errorfmt string (default "\033[7;31;47m")
filesep string (default "\n")
filtermethod string (default 'text')
findlen int (default 1)
hidden bool (default false)
hiddenfiles []string (default '.*' for Unix and '' for Windows)
history bool (default true)
icons bool (default false)
ifs string (default '')
ignorecase bool (default true)
ignoredia bool (default true)
incfilter bool (default false)
incsearch bool (default false)
info []string (default '')
infotimefmtnew string (default 'Jan _2 15:04')
infotimefmtold string (default 'Jan _2 2006')
menufmt string (default "\033[0m")
menuheaderfmt string (default "\033[1m")
menuselectfmt string (default "\033[7m")
mergeindicators bool (default false)
mouse bool (default false)
number bool (default false)
numbercursorfmt string (default '')
numberfmt string (default "\033[33m")
period int (default 0)
preload bool (default false)
preserve []string (default "mode")
preview bool (default true)
previewer string (default '')
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m")
ratios []int (default '1:2:3')
relativenumber bool (default false)
reverse bool (default false)
rulerfile string (default "")
rulerfmt string (default "")
scrolloff int (default 0)
searchmethod string (default 'text')
selectfmt string (default "\033[7;35m")
selmode string (default 'all')
shell string (default 'sh' for Unix and 'cmd' for Windows)
shellflag string (default '-c' for Unix and '/c' for Windows)
shellopts []string (default '')
showbinds bool (default true)
sizeunits string (default 'binary')
smartcase bool (default true)
smartdia bool (default false)
sortby string (default 'natural')
statfmt string (default "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l")
tabstop int (default 8)
tagfmt string (default "\033[31m")
tempmarks string (default '')
terminalcursor string (default 'default')
timefmt string (default 'Mon Jan _2 15:04:05 2006')
truncatechar string (default '~')
truncatepct int (default 100)
visualfmt string (default "\033[7;36m")
waitmsg string (default 'Press any key to continue')
watch bool (default false)
wrapscan bool (default true)
wrapscroll bool (default false)
user_{option} string (default none)
The following environment variables are exported for shell commands:
f
fs
fv
fx
id
PWD
OLDPWD
LF_LEVEL
OPENER
VISUAL
EDITOR
PAGER
SHELL
lf
lf_{option}
lf_user_{option}
lf_flag_{flag}
lf_width
lf_height
lf_count
lf_mode
The following special shell commands are used to customize the behavior of lf when defined:
open
paste
rename
delete
pre-cd
on-cd
on-load
on-focus-gained
on-focus-lost
on-init
on-select
on-redraw
on-quit
The following commands/keybindings are provided by default:
Unix
cmd open &$OPENER "$f"
map e $$EDITOR "$f"
map i $$PAGER "$f"
map w $$SHELL
cmd help $$lf -doc | $PAGER
map <f-1> help
cmd maps $lf -remote "query $id maps" | $PAGER
cmd nmaps $lf -remote "query $id nmaps" | $PAGER
cmd vmaps $lf -remote "query $id vmaps" | $PAGER
cmd cmaps $lf -remote "query $id cmaps" | $PAGER
cmd cmds $lf -remote "query $id cmds" | $PAGER
Windows
cmd open &%OPENER% %f%
map e $%EDITOR% %f%
map i !%PAGER% %f%
map w $%SHELL%
cmd help !%lf% -doc | %PAGER%
map <f-1> help
cmd maps !%lf% -remote "query %id% maps" | %PAGER%
cmd nmaps !%lf% -remote "query %id% nmaps" | %PAGER%
cmd vmaps !%lf% -remote "query %id% vmaps" | %PAGER%
cmd cmaps !%lf% -remote "query %id% cmaps" | %PAGER%
cmd cmds !%lf% -remote "query %id% cmds" | %PAGER%
The defaults for Windows are using `cmd` syntax.
A `PowerShell` compatible configuration file can be found at
https://github.com/gokcehan/lf/blob/master/etc/lfrc.ps1.example
The following additional keybindings are provided by default:
map zh set hidden!
map zr set reverse!
map zn set info
map zs set info size
map zt set info time
map za set info size:time
map sn :set sortby natural; set info
map ss :set sortby size; set info size
map st :set sortby time; set info time
map sa :set sortby atime; set info atime
map sb :set sortby btime; set info btime
map sc :set sortby ctime; set info ctime
map se :set sortby ext; set info
map gh cd ~
nmap <space> :toggle; down
If the `mouse` option is enabled, mouse buttons have the following default effects:
Left mouse button
Click on a file or directory to select it.
Right mouse button
Enter a directory or open a file. Also works on the preview pane.
Scroll wheel
Move up or down. If Ctrl is pressed, scroll up or down.
# CONFIGURATION
Configuration files should be located at:
OS system-wide user-specific
Unix /etc/lf/lfrc ~/.config/lf/lfrc
Windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Roaming\lf\lfrc
The colors file should be located at:
OS system-wide user-specific
Unix /etc/lf/colors ~/.config/lf/colors
Windows C:\ProgramData\lf\colors C:\Users\<user>\AppData\Roaming\lf\colors
The icons file should be located at:
OS system-wide user-specific
Unix /etc/lf/icons ~/.config/lf/icons
Windows C:\ProgramData\lf\icons C:\Users\<user>\AppData\Roaming\lf\icons
The selection file should be located at:
Unix ~/.local/share/lf/files
Windows C:\Users\<user>\AppData\Local\lf\files
The marks file should be located at:
Unix ~/.local/share/lf/marks
Windows C:\Users\<user>\AppData\Local\lf\marks
The tags file should be located at:
Unix ~/.local/share/lf/tags
Windows C:\Users\<user>\AppData\Local\lf\tags
The history file should be located at:
Unix ~/.local/share/lf/history
Windows C:\Users\<user>\AppData\Local\lf\history
You can configure these locations with the following variables given with their order of precedences and their default values:
Unix
$LF_CONFIG_HOME
$XDG_CONFIG_HOME
~/.config
$LF_DATA_HOME
$XDG_DATA_HOME
~/.local/share
Windows
%LF_CONFIG_HOME%
%XDG_CONFIG_HOME%
%APPDATA%
%LF_DATA_HOME%
%XDG_DATA_HOME%
%LOCALAPPDATA%
A sample configuration file can be found at
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example
# COMMANDS
This section shows information about built-in commands.
Modal commands do not take any arguments, but instead change the operation mode to read their input conveniently, and so they are meant to be assigned to keybindings.
## quit (default `q`)
Quit lf and return to the shell.
## up (default `k` and `<up>`), half-up (default `<c-u>`), page-up (default `<c-b>` and `<pgup>`), scroll-up (default `<c-y>`), down (default `j` and `<down>`), half-down (default `<c-d>`), page-down (default `<c-f>` and `<pgdn>`), scroll-down (default `<c-e>`)
Move/scroll the current file selection upwards/downwards by one/half a page/full page.
## updir (default `h` and `<left>`)
Change the current working directory to the parent directory.
## open (default `l` and `<right>`)
If the current file is a directory, then change the current directory to it, otherwise, execute the `open` command.
A default `open` command is provided to call the default system opener asynchronously with the current file as the argument.
A custom `open` command can be defined to override this default.
## jump-next (default `]`), jump-prev (default `[`)
Change the current working directory to the next/previous jumplist item.
## top (default `gg` and `<home>`), bottom (default `G` and `<end>`)
Move the current file selection to the top/bottom of the directory.
A count can be specified to move to a specific line, for example, use `3G` to move to the third line.
## high (default `H`), middle (default `M`), low (default `L`)
Move the current file selection to the high/middle/low of the screen.
## toggle
Toggle the selection of the current file or files given as arguments.
## invert (default `v`)
Reverse the selection of all files in the current directory (i.e. `toggle` all files).
Selections in other directories are not affected by this command.
You can define a new command to select all files in the directory by combining `invert` with `unselect` (i.e. `cmd select-all :unselect; invert`), though this will also remove selections in other directories.
## unselect (default `u`)
Remove the selection of all files in all directories.
## glob-select, glob-unselect
Select/unselect files that match the given glob.
## copy (default `y`)
Save the paths of selected files to the clipboard as files to be copied.
If there are no selected files, the path of the current file is used instead.
## cut (default `d`)
Save the paths of selected files to the clipboard as files to be moved.
If there are no selected files, the path of the current file is used instead.
## paste (default `p`)
Copy/Move files in the clipboard to the current working directory.
A custom `paste` command can be defined to override this default.
## clear (default `c`)
Clear file paths in the clipboard.
## sync
Synchronize copied/cut files with the server.
This command is automatically called when required.
## draw
Draw the screen.
This command is automatically called when required.
## redraw (default `<c-l>`)
Synchronize the terminal and redraw the screen.
## load
Load modified files and directories.
This command is automatically called when required.
## reload (default `<c-r>`)
Flush the cache and reload all files and directories.
## delete (modal)
Remove the current file or selected file(s).
A custom `delete` command can be defined to override this default.
## rename (modal) (default `r`)
Rename the current file using the built-in method.
A custom `rename` command can be defined to override this default.
## read (modal) (default `:`)
Read a command to evaluate.
## shell (modal) (default `$`)
Read a shell command to execute.
## shell-pipe (modal) (default `%`)
Read a shell command to execute piping its standard I/O to the bottom statline.
## shell-wait (modal) (default `!`)
Read a shell command to execute and wait for a key press at the end.
## shell-async (modal) (default `&`)
Read a shell command to execute asynchronously without standard I/O.
## find (modal) (default `f`), find-back (modal) (default `F`), find-next (default `;`), find-prev (default `,`)
Read key(s) to find the appropriate filename match in the forward/backward direction and jump to the next/previous match.
## search (default `/`), search-back (default `?`), search-next (default `n`), search-prev (default `N`)
Read a pattern to search for a filename match in the forward/backward direction and jump to the next/previous match.
## filter (modal), setfilter
Command `filter` reads a pattern to filter out and only view files matching the pattern.
Command `setfilter` does the same but uses an argument to set the filter immediately.
You can supply an argument to `filter` to use as the starting prompt.
## mark-save (modal) (default `m`)
Save the current directory as a bookmark assigned to the given key.
## mark-load (modal) (default `'`)
Change the current directory to the bookmark assigned to the given key.
A special bookmark `'` holds the previous directory after a `mark-load`, `cd`, or `select` command.
## mark-remove (modal) (default `"`)
Remove a bookmark assigned to the given key.
## tag
Tag a file with `*` or a single-width character given in the argument.
You can define a new tag-clearing command by combining `tag` with `tag-toggle` (i.e. `cmd tag-clear :tag; tag-toggle`).
## tag-toggle (default `t`)
Tag a file with `*` or a single-width character given in the argument if the file is untagged, otherwise remove the tag.
## echo
Print the given arguments to the message line at the bottom.
## echomsg
Print the given arguments to the message line at the bottom and also to the log file.
## echoerr
Print given arguments to the message line at the bottom as `errorfmt` and also to the log file.
## cd
Change the working directory to the given argument.
## select
Change the current file selection to the given argument.
## source
Read the configuration file given in the argument.
## push
Simulate key pushes given in the argument.
## addcustominfo
Update the `custom` info and `.Stat.CustomInfo` field of the given file with the given string.
The info string may contain ANSI escape codes to further customize its appearance.
If no info is provided, clear the file's info instead.
## calcdirsize
Calculate the total size for each of the selected directories.
Option `info` should include `size` and option `dircounts` should be disabled to show this size.
If the total size of a directory is not calculated, it will be shown as `-`.
## clearmaps
Remove all keybindings associated with the `map`, `nmap` and `vmap` command.
This command can be used in the config file to remove the default keybindings.
For safety purposes, `:` is left mapped to the `read` command, and `cmap` keybindings are retained so that it is still possible to exit `lf` using `:quit`.
## tty-write
Write the given string to the tty.
This is useful for sending escape sequences to the terminal to control its behavior (e.g. OSC 0 to set the window title).
Using `tty-write` is preferred over directly writing to `/dev/tty` because the latter is not synchronized and can interfere with drawing the UI.
## visual (default `V`)
Switch to Visual mode.
If already in Visual mode, discard the visual selection and stay in Visual mode.
# VISUAL MODE COMMANDS
## visual-accept (default `V`)
Add the visual selection to the selection list, quit Visual mode and return to Normal mode.
## visual-unselect
Remove the visual selection from the selection list, quit Visual mode and return to Normal mode.
## visual-discard (default `<esc>`)
Discard the visual selection, quit Visual mode and return to Normal mode.
## visual-change (default `o`)
Go to the other end of the current Visual mode selection.
# COMMAND-LINE MODE COMMANDS
The prompt character specifies which of the several Command-line modes you are in.
For example, the `read` command takes you to the `:` mode.
When the cursor is at the first character in `:` mode, pressing one of the keys `!`, `$`, `%`, or `&` takes you to the corresponding mode.
You can go back with `cmd-delete-back` (`<backspace>` by default).
The command line commands should be mostly compatible with readline keybindings.
A character refers to a Unicode code point, a word consists of letters and digits, and a Unix word consists of any non-blank characters.
## cmd-insert
Insert the character given in the argument.
This command is automatically called when required.
## cmd-escape (default `<esc>`)
Quit Command-line mode and return to Normal mode.
## cmd-complete (default `<tab>`)
Autocomplete the current word.
## cmd-menu-complete, cmd-menu-complete-back
Autocomplete the current word with the menu selection.
You need to assign keys to these commands (e.g. `cmap <tab> cmd-menu-complete; cmap <backtab> cmd-menu-complete-back`).
You can use the assigned keys to display the menu and then cycle through completion options.
## cmd-menu-accept
Accept the currently selected match in menu completion and close the menu.
## cmd-menu-discard
Discard the currently selected match in menu completion and close the menu.
## cmd-enter (default `<c-j>` and `<enter>`)
Execute the current line.
## cmd-interrupt (default `<c-c>`)
Interrupt the current shell-pipe command and return to the Normal mode.
## cmd-history-next (default `<c-n>` and `<down>`), cmd-history-prev (default `<c-p>` and `<up>`)
Go to the next/previous entry in the command history.
If part of the command is already typed, then only matching entries will be considered, and consecutive duplicate entries are skipped.
## cmd-left (default `<c-b>` and `<left>`), cmd-right (default `<c-f>` and `<right>`)
Move the cursor to the left/right.
## cmd-home (default `<c-a>` and `<home>`), cmd-end (default `<c-e>` and `<end>`)
Move the cursor to the beginning/end of the line.
## cmd-delete (default `<c-d>` and `<delete>`)
Delete the next character.
## cmd-delete-back (default `<backspace>`)
Delete the previous character.
When at the beginning of a prompt, returns either to Normal mode or to `:` mode.
## cmd-delete-home (default `<c-u>`), cmd-delete-end (default `<c-k>`)
Delete everything up to the beginning/end of the line.
## cmd-delete-unix-word (default `<c-w>`)
Delete the previous Unix word.
## cmd-yank (default `<c-y>`)
Paste the buffer content containing the last deleted item.
## cmd-transpose (default `<c-t>`)
Swap the characters before and after the cursor, then move the cursor forward.
If there is no character after the cursor, swap the previous two characters instead.
## cmd-transpose-word (default `<a-t>`)
Swap the words before and after the cursor, then move the cursor forward.
If there is no word after the cursor, swap the previous two words instead.
## cmd-word (default `<a-f>`), cmd-word-back (default `<a-b>`)
Move the cursor by one word in the forward/backward direction.
## cmd-delete-word (default `<a-d>`)
Delete the next word in the forward direction.
## cmd-delete-word-back (default `<a-backspace>`)
Delete the previous word in the backward direction.
## cmd-capitalize-word (default `<a-c>`), cmd-uppercase-word (default `<a-u>`), cmd-lowercase-word (default `<a-l>`)
Capitalize/uppercase/lowercase the current word and jump to the next word.
# SETTINGS
This section shows information about options to customize the behavior.
Character `:` is used as the separator for list options `[]int` and `[]string`.
## anchorfind (bool) (default true)
When this option is enabled, the find command starts matching patterns from the beginning of filenames, otherwise, it can match at an arbitrary position.
## autoquit (bool) (default true)
Automatically quit the server when there are no clients left connected.
## borderfmt (string) (default `\033[0m`)
Format string of border characters.
## borderstyle (string) (default `box`)
Border style used by `drawbox`.
The following styles are supported:
box outline around all panes and separators between them
roundbox like `box`, but with rounded outer corners
outline outline around all panes
roundoutline like `outline`, but with rounded outer corners
separators separators between panes
## cleaner (string) (default ``) (not called if empty)
Set the path of a cleaner file.
The file should be executable.
This file is called if previewing is enabled, the previewer is set, and the previously selected file has its preview cache disabled.
The following arguments are passed to the file, (1) current filename, (2) width, (3) height, (4) horizontal position, (5) vertical position of preview pane and (6) next filename to be previewed respectively.
Preview cleaning is disabled when the value of this option is left empty.
## copyfmt (string) (default `\033[7;33m`)
Format string of the indicator for files to be copied.
## cursoractivefmt (string) (default `\033[7m`), cursorparentfmt (string) (default `\033[7m`), cursorpreviewfmt (string) (default `\033[4m`)
Format strings for highlighting the cursor.
`cursoractivefmt` applies in the current directory pane,
`cursorparentfmt` applies in panes that show parents of the current directory,
and `cursorpreviewfmt` applies in panes that preview directories.
The default is to make the active cursor and the parent directory cursor inverted. The preview cursor is underlined.
Some other possibilities to consider for the preview or parent cursors: an empty string for no cursor, `\033[7;2m` for dimmed inverted text (visibility varies by terminal), `\033[7;90m` for inverted text with grey (aka "brightblack") background.
If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence.
For example, `\033[4m%s\033[0m` has the same effect as `\033[4m`.
## cutfmt (string) (default `\033[7;31m`)
Format string of the indicator for files to be cut.
## dircounts (bool) (default false)
When this option is enabled, directory sizes show the number of items inside instead of the total size of the directory, which needs to be calculated for each directory using `calcdirsize`.
This information needs to be calculated by reading the directory and counting the items inside.
Therefore, this option is disabled by default for performance reasons.
This option only has an effect when `info` has a `size` field and the pane is wide enough to show the information.
999 items are counted per directory at most, and bigger directories are shown as `999+`.
## dirfirst (bool) (default true)
Show directories first above regular files.
With `dircounts` enabled, sorting by `size` always separates directories and files, regardless of `dirfirst`.
## dironly (bool) (default false)
Show only directories.
## dirpreviews (bool) (default false)
If enabled, directories will also be passed to the previewer script. This allows custom previews for directories.
## drawbox (bool) (default false)
Draw borders around panes using box drawing characters.
## dupfilefmt (string) (default `%f.~%n~`)
Format string of filename when creating duplicate files. With the default format, copying a file `abc.txt` to the same directory will result in a duplicate file called `abc.txt.~1~`.
Special expansions are provided, `%f` as the file name, `%b` for the base name (file name without extension), `%e` as the extension (including the dot) and `%n` as the number of duplicates.
## errorfmt (string) (default `\033[7;31;47m`)
Format string of error messages shown in the bottom message line.
If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence.
For example, `\033[4m%s\033[0m` has the same effect as `\033[4m`.
## filesep (string) (default `\n`)
File separator used in environment variables `fs`, `fv` and `fx`.
## filtermethod (string) (default `text`)
How filter command patterns are treated.
Currently supported methods are `text` (i.e. string literals), `glob` (i.e. shell globs) and `regex` (i.e. regular expressions).
See `SEARCHING FILES` for more details.
## findlen (int) (default 1)
Number of characters prompted for the find command.
When this value is set to 0, find command prompts until there is only a single match left.
## hidden (bool) (default false)
Show hidden files.
On Unix systems, hidden files are determined by the value of `hiddenfiles`.
On Windows, files with hidden attributes are also considered hidden files.
## hiddenfiles ([]string) (default `.*` for Unix and `` for Windows)
List of hidden file glob patterns.
Patterns can be given as relative or absolute paths.
Globbing supports the usual special characters, `*` to match any sequence, `?` to match any character, and `[...]` or `[^...]` to match character sets or ranges.
In addition, if a pattern starts with `!`, then its matches are excluded from hidden files. To add multiple patterns, use `:` as a separator. Example: `.*:lost+found:*.bak`
## history (bool) (default true)
Save command history.
## icons (bool) (default false)
Show icons before each item in the list.
## ifs (string) (default ``)
Sets `IFS` variable in shell commands.
It works by adding the assignment to the beginning of the command string as `IFS=...; ...`.
The reason is that `IFS` variable is not inherited by the shell for security reasons.
This method assumes a POSIX shell syntax so it can fail for non-POSIX shells.
This option has no effect when the value is left empty.
This option does not have any effect on Windows.
## ignorecase (bool) (default true)
Ignore case in sorting and search patterns.
## ignoredia (bool) (default true)
Ignore diacritics in sorting and search patterns.
## incfilter (bool) (default false)
Apply filter pattern after each keystroke during filtering.
## incsearch (bool) (default false)
Jump to the first match after each keystroke during searching.
## info ([]string) (default ``)
A list of information that is shown for directory items at the right side of the pane.
The following information types are supported:
perm file permission
user user name
group group name
size file size
time time of last data modification
atime time of last access
btime time of file birth
ctime time of last status (inode) change
custom property defined via `addcustominfo` (empty by default)
Information is only shown when the pane width is more than twice the width of information.
## infotimefmtnew (string) (default `Jan _2 15:04`)
Format string of the file time shown in the info column when it matches this year.
## infotimefmtold (string) (default `Jan _2 2006`)
Format string of the file time shown in the info column when it doesn't match this year.
## menufmt (string) (default `\033[0m`)
Format string of the menu.
## menuheaderfmt (string) (default `\033[1m`)
Format string of the header row in the menu.
## menuselectfmt (string) (default `\033[7m`)
Format string of the currently selected item in the menu.
## mergeindicators (bool) (default false)
When `mergeindicators` is enabled, tag and selection indicators are drawn in a single column to reduce the gap before filenames.
If a file is both tagged and selected, the tag uses the selection format (e.g. `copyfmt`) instead of `tagfmt`.
## mouse (bool) (default false)
Send mouse events as input.
## number (bool) (default false)
Show the position number for directory items on the left side of the pane.
When the `relativenumber` option is enabled, only the current line shows the absolute position and relative positions are shown for the rest.
## numberfmt (string) (default `\033[33m`), numbercursorfmt (string) (default ``)
Format strings for highlighting line numbers.
`numberfmt` applies to all lines.
`numbercursorfmt` applies to the cursor line and falls back to `numberfmt` when left empty.
## period (int) (default 0)
Set the interval in seconds for periodic checks of directory updates.
This works by periodically calling the `load` command.
Note that directories are already updated automatically in many cases.
This option can be useful when there is an external process changing the displayed directory and you are not doing anything in lf.
Periodic checks are disabled when the value of this option is set to zero.
## preload (bool) (default false)
Allow previews to be generated in advance using the `previewer` script as the user navigates through the filesystem.
## preserve ([]string) (default `mode`)
List of attributes that are preserved when copying files.
Currently supported attributes are `mode` (i.e. access mode) and `timestamps` (i.e. modification time and access time).
Note that preserving other attributes like ownership of change/birth timestamp is desirable, but not portably supported in Go.
## preview (bool) (default true)
Show previews of files and directories at the rightmost pane.
If the file has more lines than the preview pane, the rest of the lines are not read.
Files containing the null character (U+0000) in the read portion are considered binary files and displayed as `binary`.
## previewer (string) (default ``) (not filtered if empty)
Set the path of a previewer file to filter the content of regular files for previewing.
The file should be executable.
The following arguments are passed to the file, (1) current filename, (2) width, (3) height, (4) horizontal position, (5) vertical position, and (6) mode ("preview" or "preload").
SIGPIPE signal is sent when enough lines are read.
If the previewer returns a non-zero exit code, then the preview cache for the given file is disabled.
This means that if the file is selected in the future, the previewer is called once again.
Preview filtering is disabled and files are displayed as they are when the value of this option is left empty.
If the `preload` option is enabled, then this will be called with `preload` as the mode when preloading file previews.
Refer to the [PREVIEWING FILES section](https://github.com/gokcehan/lf/blob/master/doc.md#previewing-files) for more information about how to configure custom previews.
## promptfmt (string) (default `\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m`)
Format string of the prompt shown in the top line.
The following special expansions are supported:
%f file name
%h host name
%u user name
%w working directory
%d working directory (with trailing path separator)
%F current filter
%S spacer to right-align the following parts (can be used once)
The home folder is shown as `~` in the working directory expansion.
Directory names are automatically shortened to a single character starting from the leftmost parent when the prompt does not fit the screen.
## ratios ([]int) (default `1:2:3`)
List of ratios of pane widths.
Number of items in the list determines the number of panes in the UI.
When the `preview` option is enabled, the rightmost number is used for the width of the preview pane.
## relativenumber (bool) (default false)
Show the position number relative to the current line.
When `number` is enabled, the current line shows the absolute position, otherwise nothing is shown.
## reverse (bool) (default false)
Reverse the direction of sort.
## rulerfile (string) (default ``)
Set the path of the ruler file.
If not set, then a default template will be used for the ruler.
Refer to the [RULER section](https://github.com/gokcehan/lf/blob/master/doc.md#ruler) for more information about how the ruler file works.
## rulerfmt (string) (default ``)
Format string of the ruler shown in the bottom right corner.
When set, it will be used along with `statfmt` to draw the ruler, and `rulerfile` will be ignored.
However, using `rulerfile` is preferred and this option is provided for backwards compatibility.
The following special expansions are supported:
%a pressed keys
%p progress of file operations
%m number of files to be cut (moved)
%c number of files to be copied
%s number of selected files
%v number of visually selected files
%t number of shown files in the current directory
%h number of hidden files in the current directory
%f current filter
%i cursor position
%P scroll percentage
%d amount of free disk space
Additional expansions are provided for environment variables exported by lf, in the form `%{lf_<name>}` (e.g. `%{lf_selmode}`). This is useful for displaying the current settings.
Expansions are also provided for user-defined options, in the form `%{lf_user_<name>}` (e.g. `%{lf_user_foo}`).
The `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown.
## scrolloff (int) (default 0)
Minimum number of offset lines shown at all times at the top and bottom of the screen when scrolling.
The current line is kept in the middle when this option is set to a large value that is bigger than half the number of lines.
A smaller offset can be used when the current file is close to the beginning or end of the list to show the maximum number of items.
## searchmethod (string) (default `text`)
How search command patterns are treated.
Currently supported methods are `text` (i.e. string literals), `glob` (i.e. shell globs) and `regex` (i.e. regular expressions).
See `SEARCHING FILES` for more details.
## selectfmt (string) (default `\033[7;35m`)
Format string of the indicator for files that are selected.
## selmode (string) (default `all`)
Selection mode for commands.
When set to `all` it will use the selected files from all directories.
When set to `dir` it will only use the selected files in the current directory.
## shell (string) (default `sh` for Unix and `cmd` for Windows)
Shell executable to use for shell commands.
Shell commands are executed as `shell shellopts shellflag command -- arguments`.
## shellflag (string) (default `-c` for Unix and `/c` for Windows)
Command line flag used to pass shell commands.
## shellopts ([]string) (default ``)
List of shell options to pass to the shell executable.
## showbinds (bool) (default true)
Show bindings associated with pressed keys.
## sizeunits (string) (default `binary`)
Determines whether file sizes are displayed using binary units (`1K` is 1024 bytes) or decimal units (`1K` is 1000 bytes).
## smartcase (bool) (default true)
Override `ignorecase` option when the pattern contains an uppercase character.
This option has no effect when `ignorecase` is disabled.
## smartdia (bool) (default false)
Override `ignoredia` option when the pattern contains a character with diacritic.
This option has no effect when `ignoredia` is disabled.
## sortby (string) (default `natural`)
Sort type for directories.
The following sort types are supported:
natural file name (track_2.flac comes before track_10.flac)
name file name (track_10.flac comes before track_2.flac)
ext file extension
size file size
time time of last data modification
atime time of last access
btime time of file birth
ctime time of last status (inode) change
custom property defined via `addcustominfo` (empty by default)
## statfmt (string) (default `\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l`)
Format string of the file info shown in the bottom left corner.
This option has no effect unless `rulerfmt` is also set.
Using `rulerfile` is preferred and this option is provided for backwards compatibility.
The following special expansions are supported:
%p file permission
%c link count
%u user name
%g group name
%s file size
%S file size (left-padded with spaces to a fixed width of 5 characters)
%t time of last data modification
%l link target
%m current mode
%M current mode (displaying `NORMAL` instead of a blank string in Normal mode)
The `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown.
## tabstop (int) (default 8)
Number of space characters to show for horizontal tabulation (U+0009) character.
## tagfmt (string) (default `\033[31m`)
Format string of the tags.
If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence.
For example, `\033[4m%s\033[0m` has the same effect as `\033[4m`.
## tempmarks (string) (default ``)
Marks to be considered temporary (e.g. `abc` refers to marks `a`, `b`, and `c`).
These marks are not synced to other clients and they are not saved in the bookmarks file.
Note that the special bookmark `'` is always treated as temporary and it does not need to be specified.
## terminalcursor (string) (default `default`)
Set the appearance of the terminal cursor for prompts shown in the bottom line.
Currently supported values are `default`, `block`, `underline`, `bar`, `blinkblock`, `blinkunderline` and `blinkbar`.
## timefmt (string) (default `Mon Jan _2 15:04:05 2006`)
Format string of the file modification time shown in the bottom line.
## truncatechar (string) (default `~`)
The truncate character that is shown at the end when the filename does not fit into the pane.
## truncatepct (int) (default 100)
When a filename is too long to be shown completely, the available space will be partitioned into two parts.
`truncatepct` is a percentage value between 0 and 100 that determines the size of the first part, which will be shown at the beginning of the filename.
The second part uses the rest of the available space, and will be shown at the end of the filename.
Both parts are separated by the truncation character (`truncatechar`).
Truncation is not applied to the file extension.
For example, with the filename `very_long_filename.txt`:
- `set truncatepct 100` -> `very_long_filena~.txt` (default)
- `set truncatepct 50` -> `very_lon~filename.txt`
- `set truncatepct 0` -> `~ry_long_filename.txt`
## visualfmt (string) (default `\033[7;36m`)
Format string of the indicator for files that are visually selected.
## waitmsg (string) (default `Press any key to continue`)
String shown after commands of shell-wait type.
## watch (bool) (default false)
Watch the filesystem for changes using `fsnotify` to automatically refresh file information.
FUSE is currently not supported due to limitations in `fsnotify`.
## wrapscan (bool) (default true)
Searching can wrap around the file list.
## wrapscroll (bool) (default false)
Scrolling can wrap around the file list.
## user_{option} (string) (default none)
Any option that is prefixed with `user_` is a user-defined option and can be set to any string.
Inside a user-defined command, the value will be provided in the `lf_user_{option}` environment variable.
These options are not used by lf and are not persisted.
# ENVIRONMENT VARIABLES
The following variables are exported for shell commands:
These are referred to with a `$` prefix on POSIX shells (e.g. `$f`), between `%` characters on Windows cmd (e.g. `%f%`), and with a `$env:` prefix on Windows PowerShell (e.g. `$env:f`).
## f
Current file selection as a full path.
## fs
Selected file(s) separated with the value of `filesep` option as full path(s).
## fv
Visually selected file(s) separated with the value of `filesep` option as full path(s).
## fx
Selected file(s) (i.e. `fs`, never `fv`) if there are any selected files, otherwise current file selection (i.e. `f`).
## id
Id of the running client.
## PWD
Present working directory.
## OLDPWD
Initial working directory.
## LF_LEVEL
The value of this variable is set to the current nesting level when you run lf from a shell spawned inside lf.
You can add the value of this variable to your shell prompt to make it clear that your shell runs inside lf.
For example, with POSIX shells, you can use `[ -n "$LF_LEVEL" ] && PS1="$PS1""(lf level: $LF_LEVEL) "` in your shell configuration file (e.g. `~/.bashrc`).
## OPENER
If this variable is set in the environment, use the same value. Otherwise, this is set to `start` in Windows, `open` in macOS, `xdg-open` in others.
## EDITOR
If VISUAL is set in the environment, use its value. Otherwise, use the value of the environment variable EDITOR. If neither variable is set, this is set to `vi` on Unix, `notepad` in Windows.
## PAGER
If this variable is set in the environment, use the same value. Otherwise, this is set to `less` on Unix, `more` in Windows.
## SHELL
If this variable is set in the environment, use the same value. Otherwise, this is set to `sh` on Unix, `cmd` in Windows.
## lf
Absolute path to the currently running lf binary, if it can be found. Otherwise, this is set to the string `lf`.
## lf_{option}
Value of the {option}.
## lf_user_{option}
Value of the user_{option}.
## lf_flag_{flag}
Value of the command line {flag}.
## lf_width, lf_height
Width/Height of the terminal.
## lf_count
Value of the count associated with the current command.
## lf_mode
Current mode that `lf` is operating in.
This is useful for customizing keybindings depending on what the current mode is.
Possible values are `compmenu`, `delete`, `rename`, `filter`, `find`, `mark`, `search`, `command`, `shell`, `pipe` (when running a shell-pipe command), `normal`, `visual` and `unknown`.
# SPECIAL COMMANDS
This section shows information about special shell commands.
## open
This shell command can be defined to override the default `open` command when the current file is not a directory.
## paste
This shell command can be defined to override the default `paste` command.
## rename
This shell command can be defined to override the default `rename` command.
## delete
This shell command can be defined to override the default `delete` command.
## pre-cd
This shell command can be defined to be executed before changing a directory.
## on-cd
This shell command can be defined to be executed after changing a directory.
## on-load
This shell command can be defined to be executed after loading a directory.
It provides the files inside the directory as arguments.
## on-focus-gained
This shell command can be defined to be executed when the terminal gains focus.
## on-focus-lost
This shell command can be defined to be executed when the terminal loses focus.
## on-init
This shell command can be defined to be executed after initializing and connecting to the server.
## on-select
This shell command can be defined to be executed after the selection changes.
## on-redraw
This shell command can be defined to be executed after the screen is redrawn or if the terminal is resized.
## on-quit
This shell command can be defined to be executed before quitting.
# PREFIXES
The following command prefixes are used by lf:
: read (default) built-in/custom command
$ shell shell command
% shell-pipe shell command running with the UI
! shell-wait shell command waiting for a key press
& shell-async shell command running asynchronously
The same evaluator is used for the command line and the configuration file for reading shell commands.
The difference is that prefixes are not necessary in the command line.
Instead, different modes are provided to read corresponding commands.
These modes are mapped to the prefix keys above by default.
Visual mode mappings are defined the same way Normal mode mappings are defined.
# SYNTAX
Characters from `#` to newline are comments and ignored:
# comments start with `#`
The following commands (`set`, `setlocal`, `map`, `nmap`, `vmap`, `cmap`, and `cmd`) are used for configuration.
Command `set` is used to set an option which can be a boolean, integer, or string:
set hidden # boolean enable
set hidden true # boolean enable
set nohidden # boolean disable
set hidden false # boolean disable
set hidden! # boolean toggle
set scrolloff 10 # integer value
set sortby time # string value without quotes
set sortby 'time' # string value with single quotes (whitespace)
set sortby "time" # string value with double quotes (backslash escapes)
Command `setlocal` is used to set a local option for a directory which can be a boolean or string.
Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `reverse` and `sortby`.
setlocal /foo/bar hidden # boolean enable
setlocal /foo/bar hidden true # boolean enable
setlocal /foo/bar nohidden # boolean disable
setlocal /foo/bar hidden false # boolean disable
setlocal /foo/bar hidden! # boolean toggle
setlocal /foo/bar sortby time # string value without quotes
setlocal /foo/bar sortby 'time' # string value with single quotes (whitespace)
setlocal /foo/bar sortby "time" # string value with double quotes (backslash escapes)
Command `map` is used to bind a key in Normal and Visual mode to a command which can be a built-in command, custom command, or shell command:
map gh cd ~ # built-in command
map D trash # custom command
map i $less $f # shell command
map U !du -csh * # waiting shell command
Command `nmap` does the same but for Normal mode only.
Command `vmap` does the same but for Visual mode only.
Overview of which map command works in which mode:
map Normal, Visual
nmap Normal
vmap Visual
cmap Command-line
Command `cmap` is used to bind a key on the command line to a command line command or any other command:
cmap <c-g> cmd-escape
cmap <a-i> set incsearch!
You can delete an existing binding by leaving the expression empty:
map gh # deletes 'gh' mapping in Normal and Visual mode
nmap v # deletes 'v' mapping in Normal mode
vmap o # deletes 'o' mapping in Visual mode
cmap <c-g> # deletes '<c-g>' mapping
Command `cmd` is used to define a custom command:
cmd usage $du -h -d1 | less
You can delete an existing command by leaving the
gitextract_3_ndz1ve/ ├── .github/ │ ├── dependabot.yml │ └── workflows/ │ ├── go.yml │ └── release.yml ├── .gitignore ├── .golangci.yaml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── app.go ├── client.go ├── colors.go ├── colors_test.go ├── complete.go ├── complete_test.go ├── copy.go ├── df_openbsd.go ├── df_statfs.go ├── df_statvfs.go ├── df_windows.go ├── diacritics.go ├── diacritics_test.go ├── doc.md ├── doc.txt ├── etc/ │ ├── colors.example │ ├── icons.example │ ├── icons_colored.example │ ├── lf.bash │ ├── lf.csh │ ├── lf.fish │ ├── lf.nu │ ├── lf.ps1 │ ├── lf.vim │ ├── lf.zsh │ ├── lfcd.cmd │ ├── lfcd.csh │ ├── lfcd.fish │ ├── lfcd.nu │ ├── lfcd.ps1 │ ├── lfcd.sh │ ├── lfrc.cmd.example │ ├── lfrc.example │ ├── lfrc.ps1.example │ └── ruler.default ├── eval.go ├── eval_test.go ├── gen/ │ ├── build.sh │ ├── deflist.lua │ ├── doc.sh │ └── package.sh ├── go.mod ├── go.sum ├── icons.go ├── key.go ├── key_test.go ├── lf.1 ├── lf.desktop ├── main.go ├── misc.go ├── misc_test.go ├── nav.go ├── opts.go ├── os.go ├── os_windows.go ├── parse.go ├── ruler.go ├── scan.go ├── server.go ├── sixel.go ├── termseq.go ├── termseq_test.go ├── ui.go └── watch.go
SYMBOL INDEX (489 symbols across 34 files)
FILE: app.go
type app (line 21) | type app struct
method quit (line 70) | func (app *app) quit() {
method readFile (line 98) | func (app *app) readFile(path string) {
method readHistory (line 194) | func (app *app) readHistory() error {
method writeHistory (line 222) | func (app *app) writeHistory() error {
method loop (line 262) | func (app *app) loop() {
method runCmdSync (line 522) | func (app *app) runCmdSync(cmd *exec.Cmd, pauseAfter bool) {
method runShell (line 553) | func (app *app) runShell(s string, args []string, prefix string) {
method doComplete (line 678) | func (app *app) doComplete() (matches []compMatch) {
method menuComplete (line 695) | func (app *app) menuComplete(direction int) {
method watchDir (line 718) | func (app *app) watchDir(dir *dir) {
method exportMode (line 733) | func (app *app) exportMode() {
function newApp (line 42) | func newApp(ui *ui, nav *nav) *app {
function loadFiles (line 119) | func loadFiles() (clipboard clipboard, err error) {
function saveFiles (line 162) | func saveFiles(clipboard clipboard) error {
FILE: client.go
type State (line 17) | type State struct
function init (line 24) | func init() {
function run (line 28) | func run() {
function writeLastDir (line 89) | func writeLastDir(filename, lastDir string) {
function writeSelection (line 103) | func writeSelection(filename string, selection []string) {
function readExpr (line 117) | func readExpr() <-chan expr {
function remote (line 171) | func remote(req string) (string, error) {
FILE: colors.go
type styleMap (line 14) | type styleMap struct
method parseFile (line 127) | func (sm styleMap) parseFile(path string) {
method parseGNU (line 149) | func (sm *styleMap) parseGNU(env string) {
method parsePair (line 166) | func (sm *styleMap) parsePair(pair []string) {
method parseBSD (line 183) | func (sm styleMap) parseBSD(env string) {
method get (line 224) | func (sm styleMap) get(f *file) tcell.Style {
function parseStyles (line 19) | func parseStyles() styleMap {
function parseColor (line 91) | func parseColor(toks []string) (tcell.Color, int, error) {
FILE: colors_test.go
function TestParseColor (line 9) | func TestParseColor(t *testing.T) {
FILE: complete.go
function getOptWords (line 128) | func getOptWords(opts any) (optWords []string) {
function getLocalOptWords (line 146) | func getLocalOptWords(localOpts any) (localOptWords []string) {
function getLongest (line 164) | func getLongest(s1, s2 string) string {
type compMatch (line 178) | type compMatch struct
function matchWord (line 183) | func matchWord(s string, words []string) (matches []compMatch, longest s...
function matchList (line 206) | func matchList(s string, words []string) (matches []compMatch, longest s...
function matchCmd (line 235) | func matchCmd(s string) (matches []compMatch, longest string) {
function matchFile (line 242) | func matchFile(s string, dirOnly bool, escape, unescape func(string) str...
function matchCmdFile (line 305) | func matchCmdFile(s string, dirOnly bool) (matches []compMatch, longest ...
function matchShellFile (line 310) | func matchShellFile(s string) (matches []compMatch, longest string) {
function matchExec (line 315) | func matchExec(s string) (matches []compMatch, longest string) {
function matchSearch (line 348) | func matchSearch(s string) (matches []compMatch, longest string) {
function completeCmd (line 376) | func completeCmd(s string) (matches []compMatch, longest string) {
function completeShell (line 467) | func completeShell(s string) (matches []compMatch, longest string) {
function completeSearch (line 482) | func completeSearch(s string) (matches []compMatch, longest string) {
FILE: complete_test.go
function TestGetOptWords (line 8) | func TestGetOptWords(t *testing.T) {
function TestGetLocalOptWords (line 27) | func TestGetLocalOptWords(t *testing.T) {
function TestGetLongest (line 46) | func TestGetLongest(t *testing.T) {
function TestMatchWord (line 69) | func TestMatchWord(t *testing.T) {
function TestMatchList (line 98) | func TestMatchList(t *testing.T) {
FILE: copy.go
type ProgressWriter (line 15) | type ProgressWriter struct
method Write (line 27) | func (progressWriter *ProgressWriter) Write(b []byte) (int, error) {
function NewProgressWriter (line 20) | func NewProgressWriter(writer io.Writer, nums chan<- int64) *ProgressWri...
function copySize (line 33) | func copySize(srcs []string) (int64, error) {
function copyFile (line 57) | func copyFile(src, dst string, preserve []string, info os.FileInfo, nums...
function copyAll (line 105) | func copyAll(srcs []string, dstDir string, preserve []string) (nums chan...
FILE: df_openbsd.go
function diskFree (line 9) | func diskFree(wd string) string {
FILE: df_statfs.go
function diskFree (line 11) | func diskFree(wd string) string {
FILE: df_statvfs.go
function diskFree (line 11) | func diskFree(wd string) string {
FILE: df_windows.go
function diskFree (line 9) | func diskFree(wd string) string {
FILE: diacritics.go
function removeDiacritics (line 41) | func removeDiacritics(baseString string) string {
FILE: diacritics_test.go
constant baseTestString (line 8) | baseTestString = "Příliš žluťoučký kůň příšerně úpěl ďábelské ódy"
function TestRemoveDiacritics (line 10) | func TestRemoveDiacritics(t *testing.T) {
function checkRemoveDiacritics (line 33) | func checkRemoveDiacritics(testStr, expStr string, t *testing.T) {
function TestSearchSettings (line 40) | func TestSearchSettings(t *testing.T) {
function runSearch (line 58) | func runSearch(t *testing.T, ignorecase, smartcase, ignorediacritics, sm...
FILE: eval.go
function applyBoolOpt (line 21) | func applyBoolOpt(opt *bool, e *setExpr) error {
function applyLocalBoolOpt (line 47) | func applyLocalBoolOpt(localOpt map[string]bool, globalOpt bool, e *setL...
method eval (line 61) | func (e *setExpr) eval(app *app, _ []string) {
method eval (line 500) | func (e *setLocalExpr) eval(app *app, _ []string) {
method eval (line 567) | func (e *mapExpr) eval(app *app, _ []string) {
method eval (line 577) | func (e *nmapExpr) eval(app *app, _ []string) {
method eval (line 585) | func (e *vmapExpr) eval(app *app, _ []string) {
method eval (line 593) | func (e *cmapExpr) eval(app *app, _ []string) {
method eval (line 601) | func (e *cmdExpr) eval(app *app, _ []string) {
function preChdir (line 620) | func preChdir(app *app) {
function onChdir (line 626) | func onChdir(app *app) {
function onLoad (line 633) | func onLoad(app *app, files []string) {
function onFocusGained (line 639) | func onFocusGained(app *app) {
function onFocusLost (line 645) | func onFocusLost(app *app) {
function onInit (line 651) | func onInit(app *app) {
function onRedraw (line 657) | func onRedraw(app *app) {
function onSelect (line 663) | func onSelect(app *app) {
function onQuit (line 670) | func onQuit(app *app) {
function splitKeys (line 676) | func splitKeys(s string) (keys []string) {
function update (line 695) | func update(app *app) {
function restartIncCmd (line 745) | func restartIncCmd(app *app) {
function resetIncCmd (line 758) | func resetIncCmd(app *app) {
function normal (line 777) | func normal(app *app) {
function insert (line 789) | func insert(app *app, arg string) {
function cd (line 972) | func cd(app *app, path string) error {
function exitCompMenu (line 1000) | func exitCompMenu(app *app) {
method eval (line 1006) | func (e *callExpr) eval(app *app, _ []string) {
method eval (line 2170) | func (e *execExpr) eval(app *app, args []string) {
method eval (line 2189) | func (e *listExpr) eval(app *app, _ []string) {
FILE: eval_test.go
function TestScan (line 492) | func TestScan(t *testing.T) {
function TestParse (line 508) | func TestParse(t *testing.T) {
function TestExprString (line 524) | func TestExprString(t *testing.T) {
function TestSplitKeys (line 565) | func TestSplitKeys(t *testing.T) {
function TestApplyBoolOpt (line 595) | func TestApplyBoolOpt(t *testing.T) {
function TestApplyLocalBoolOpt (line 625) | func TestApplyLocalBoolOpt(t *testing.T) {
FILE: icons.go
type iconDef (line 12) | type iconDef struct
type iconMap (line 18) | type iconMap struct
method parseFile (line 69) | func (im *iconMap) parseFile(path string) {
method parseEnv (line 90) | func (im *iconMap) parseEnv(env string) {
method parseArray (line 107) | func (im *iconMap) parseArray(arr []string) {
method get (line 130) | func (im iconMap) get(f *file) iconDef {
function iconWithoutStyle (line 23) | func iconWithoutStyle(icon string) iconDef {
function iconWithStyle (line 27) | func iconWithStyle(icon string, style tcell.Style) iconDef {
function parseIcons (line 31) | func parseIcons() iconMap {
FILE: key.go
function init (line 128) | func init() {
function wrapModifier (line 138) | func wrapModifier(s string, mod string) string {
function addKeyModifier (line 144) | func addKeyModifier(s string, mod tcell.ModMask) string {
function readKey (line 161) | func readKey(ev *tcell.EventKey) string {
function parseKeyModifier (line 181) | func parseKeyModifier(s string) (tcell.ModMask, string) {
function parseKey (line 205) | func parseKey(s string) *tcell.EventKey {
FILE: key_test.go
function TestReadKey (line 28) | func TestReadKey(t *testing.T) {
function TestParseKey (line 36) | func TestParseKey(t *testing.T) {
FILE: main.go
type arrayFlag (line 28) | type arrayFlag
method Set (line 47) | func (a *arrayFlag) Set(v string) error {
method String (line 52) | func (a *arrayFlag) String() string {
function init (line 56) | func init() {
function exportEnvVars (line 68) | func exportEnvVars() {
function exportFlags (line 92) | func exportFlags() {
function fieldToString (line 103) | func fieldToString(field reflect.Value) string {
function getOptsMap (line 132) | func getOptsMap() map[string]string {
function exportLfPath (line 158) | func exportLfPath() {
function exportOpts (line 167) | func exportOpts() {
function startServer (line 173) | func startServer() {
function checkServer (line 180) | func checkServer() {
function printVersion (line 197) | func printVersion() {
function main (line 228) | func main() {
FILE: misc.go
function isRoot (line 33) | func isRoot(name string) bool { return filepath.Dir(name) == name }
function replaceTilde (line 35) | func replaceTilde(s string) string {
function firstGraphemeCluster (line 44) | func firstGraphemeCluster(s string) string {
function lastGraphemeCluster (line 52) | func lastGraphemeCluster(s string) string {
function truncateRight (line 63) | func truncateRight(s string, maxWidth int) string {
function truncateLeft (line 82) | func truncateLeft(s string, maxWidth int) string {
function cmdEscape (line 111) | func cmdEscape(s string) string {
function cmdUnescape (line 124) | func cmdUnescape(s string) string {
function tokenize (line 151) | func tokenize(s string) []string {
function splitWord (line 180) | func splitWord(s string) (word, rest string) {
function readArrays (line 198) | func readArrays(r io.Reader, minCols, maxCols int) ([][]string, error) {
function readPairs (line 264) | func readPairs(r io.Reader) ([][]string, error) {
function humanize (line 271) | func humanize(size int64) string {
function permString (line 317) | func permString(m os.FileMode) string {
function naturalCmp (line 367) | func naturalCmp(s1, s2 string) int {
function getFileExtension (line 417) | func getFileExtension(file fs.FileInfo) string {
function truncateFilename (line 433) | func truncateFilename(file fs.FileInfo, maxWidth, truncatePct int, trunc...
function deletePathRecursive (line 454) | func deletePathRecursive[T any](m map[string]T, path string) {
function readLines (line 469) | func readLines(reader io.ByteReader, maxLines int) (lines []string, bina...
function getWidths (line 535) | func getWidths(wtot int, ratios []int, drawbox bool, borderstyle borderS...
FILE: misc_test.go
function TestIsRoot (line 12) | func TestIsRoot(t *testing.T) {
function TestFirstGraphemeCluster (line 35) | func TestFirstGraphemeCluster(t *testing.T) {
function TestLastGraphemeCluster (line 53) | func TestLastGraphemeCluster(t *testing.T) {
function TestTruncateRight (line 71) | func TestTruncateRight(t *testing.T) {
function TestTruncateLeft (line 98) | func TestTruncateLeft(t *testing.T) {
function TestCmdEscape (line 125) | func TestCmdEscape(t *testing.T) {
function TestCmdUnescape (line 150) | func TestCmdUnescape(t *testing.T) {
function TestTokenize (line 175) | func TestTokenize(t *testing.T) {
function TestSplitWord (line 202) | func TestSplitWord(t *testing.T) {
function TestReadArrays (line 226) | func TestReadArrays(t *testing.T) {
function TestHumanize (line 252) | func TestHumanize(t *testing.T) {
function TestPermString (line 343) | func TestPermString(t *testing.T) {
function TestNaturalCmp (line 376) | func TestNaturalCmp(t *testing.T) {
type fakeFileInfo (line 415) | type fakeFileInfo struct
method Name (line 420) | func (fileinfo fakeFileInfo) Name() string { return fileinfo.name }
method Size (line 421) | func (fileinfo fakeFileInfo) Size() int64 { return 0 }
method Mode (line 422) | func (fileinfo fakeFileInfo) Mode() os.FileMode { return os.FileMode(...
method ModTime (line 423) | func (fileinfo fakeFileInfo) ModTime() time.Time { return time.Unix(0,...
method IsDir (line 424) | func (fileinfo fakeFileInfo) IsDir() bool { return fileinfo.isD...
method Sys (line 425) | func (fileinfo fakeFileInfo) Sys() any { return nil }
function TestGetFileExtension (line 427) | func TestGetFileExtension(t *testing.T) {
function TestTruncateFilename (line 452) | func TestTruncateFilename(t *testing.T) {
function TestReadLines (line 507) | func TestReadLines(t *testing.T) {
function TestGetWidths (line 559) | func TestGetWidths(t *testing.T) {
FILE: nav.go
type linkState (line 27) | type linkState
constant notLink (line 30) | notLink linkState = iota
constant working (line 31) | working
constant broken (line 32) | broken
type file (line 35) | type file struct
method isPreviewable (line 132) | func (file *file) isPreviewable() bool {
function newFile (line 50) | func newFile(path string) *file {
type fakeStat (line 136) | type fakeStat struct
method Name (line 140) | func (fs *fakeStat) Name() string { return fs.name }
method Size (line 141) | func (fs *fakeStat) Size() int64 { return 0 }
method Mode (line 142) | func (fs *fakeStat) Mode() os.FileMode { return os.FileMode(0o000) }
method ModTime (line 143) | func (fs *fakeStat) ModTime() time.Time { return time.Unix(0, 0) }
method IsDir (line 144) | func (fs *fakeStat) IsDir() bool { return false }
method Sys (line 145) | func (fs *fakeStat) Sys() any { return nil }
function readdir (line 147) | func readdir(path string) ([]*file, error) {
type dir (line 166) | type dir struct
method sort (line 205) | func (dir *dir) sort() {
method name (line 344) | func (dir *dir) name() string {
method visualSelections (line 356) | func (dir *dir) visualSelections() []string {
method sel (line 382) | func (dir *dir) sel(name string, height int) {
method boundPos (line 403) | func (dir *dir) boundPos(height int) {
function newDir (line 189) | func newDir(path string) *dir {
type clipboardMode (line 424) | type clipboardMode
constant clipboardCopy (line 427) | clipboardCopy clipboardMode = iota
constant clipboardCut (line 428) | clipboardCut
type clipboard (line 431) | type clipboard struct
type nav (line 436) | type nav struct
method isVisualMode (line 352) | func (nav *nav) isVisualMode() bool {
method getDir (line 486) | func (nav *nav) getDir(path string) *dir {
method checkDir (line 514) | func (nav *nav) checkDir(dir *dir) {
method loadDirs (line 563) | func (nav *nav) loadDirs(wd string) {
method addJumpList (line 610) | func (nav *nav) addJumpList() {
method cdJumpListPrev (line 625) | func (nav *nav) cdJumpListPrev() {
method cdJumpListNext (line 634) | func (nav *nav) cdJumpListNext() {
method renew (line 643) | func (nav *nav) renew() {
method reload (line 660) | func (nav *nav) reload() {
method resize (line 675) | func (nav *nav) resize(ui *ui) {
method position (line 692) | func (nav *nav) position() {
method exportFiles (line 706) | func (nav *nav) exportFiles() {
method preloadLoop (line 736) | func (nav *nav) preloadLoop(ui *ui) {
method previewLoop (line 765) | func (nav *nav) previewLoop(ui *ui) {
method preload (line 826) | func (nav *nav) preload() {
method preview (line 860) | func (nav *nav) preview(path string, win *win, mode string) {
method loadReg (line 944) | func (nav *nav) loadReg(path string, volatile bool) *reg {
method checkReg (line 972) | func (nav *nav) checkReg(reg *reg) {
method sort (line 992) | func (nav *nav) sort() {
method setFilter (line 1008) | func (nav *nav) setFilter(filter []string) error {
method up (line 1033) | func (nav *nav) up(dist int) bool {
method down (line 1055) | func (nav *nav) down(dist int) bool {
method scrollUp (line 1079) | func (nav *nav) scrollUp(dist int) bool {
method scrollDown (line 1094) | func (nav *nav) scrollDown(dist int) bool {
method updir (line 1109) | func (nav *nav) updir() error {
method open (line 1122) | func (nav *nav) open() error {
method top (line 1136) | func (nav *nav) top() bool {
method bottom (line 1147) | func (nav *nav) bottom() bool {
method high (line 1158) | func (nav *nav) high() bool {
method middle (line 1174) | func (nav *nav) middle() bool {
method low (line 1188) | func (nav *nav) low() bool {
method move (line 1212) | func (nav *nav) move(index int) bool {
method toggleSelection (line 1225) | func (nav *nav) toggleSelection(path string) {
method toggle (line 1237) | func (nav *nav) toggle() {
method tagToggleSelection (line 1243) | func (nav *nav) tagToggleSelection(path, tag string) {
method tagToggle (line 1251) | func (nav *nav) tagToggle(tag string) error {
method tag (line 1268) | func (nav *nav) tag(tag string) error {
method invert (line 1285) | func (nav *nav) invert() {
method unselect (line 1291) | func (nav *nav) unselect() {
method save (line 1296) | func (nav *nav) save(mode clipboardMode) error {
method copyAsync (line 1311) | func (nav *nav) copyAsync(app *app, srcs []string, dstDir string) {
method moveAsync (line 1371) | func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
method paste (line 1478) | func (nav *nav) paste(app *app) error {
method del (line 1499) | func (nav *nav) del(app *app) error {
method rename (line 1538) | func (nav *nav) rename() error {
method sync (line 1575) | func (nav *nav) sync() error {
method cd (line 1601) | func (nav *nav) cd(path string) error {
method globSel (line 1611) | func (nav *nav) globSel(pattern string, invert bool) error {
method findSingle (line 1657) | func (nav *nav) findSingle() int {
method findNext (line 1680) | func (nav *nav) findNext() (bool, bool) {
method findPrev (line 1698) | func (nav *nav) findPrev() (bool, bool) {
method searchNext (line 1743) | func (nav *nav) searchNext() (bool, error) {
method searchPrev (line 1765) | func (nav *nav) searchPrev() (bool, error) {
method removeMark (line 1803) | func (nav *nav) removeMark(mark string) error {
method readMarks (line 1811) | func (nav *nav) readMarks() error {
method writeMarks (line 1840) | func (nav *nav) writeMarks() error {
method readTags (line 1869) | func (nav *nav) readTags() error {
method writeTags (line 1903) | func (nav *nav) writeTags() error {
method currDir (line 1930) | func (nav *nav) currDir() *dir {
method currFile (line 1943) | func (nav *nav) currFile() *file {
method currSelections (line 1967) | func (nav *nav) currSelections() []string {
method currFileOrSelections (line 1987) | func (nav *nav) currFileOrSelections() (list []string, err error) {
method calcDirSize (line 1999) | func (nav *nav) calcDirSize() error {
function newNav (line 579) | func newNav(ui *ui) *nav {
function matchPattern (line 811) | func matchPattern(pattern, name, path string) bool {
function findMatch (line 1636) | func findMatch(name, pattern string) bool {
function searchMatch (line 1716) | func searchMatch(name, pattern string, method searchMethod) (matched boo...
function isFiltered (line 1787) | func isFiltered(f os.FileInfo, filter []string) bool {
type indexedSelections (line 1953) | type indexedSelections struct
method Len (line 1958) | func (m indexedSelections) Len() int { return len(m.paths) }
method Swap (line 1960) | func (m indexedSelections) Swap(i, j int) {
method Less (line 1965) | func (m indexedSelections) Less(i, j int) bool { return m.indices[i] <...
FILE: opts.go
type sortMethod (line 10) | type sortMethod
constant naturalSort (line 13) | naturalSort sortMethod = "natural"
constant nameSort (line 14) | nameSort sortMethod = "name"
constant sizeSort (line 15) | sizeSort sortMethod = "size"
constant timeSort (line 16) | timeSort sortMethod = "time"
constant atimeSort (line 17) | atimeSort sortMethod = "atime"
constant btimeSort (line 18) | btimeSort sortMethod = "btime"
constant ctimeSort (line 19) | ctimeSort sortMethod = "ctime"
constant extSort (line 20) | extSort sortMethod = "ext"
constant customSort (line 21) | customSort sortMethod = "custom"
function isValidSortMethod (line 24) | func isValidSortMethod(method sortMethod) bool {
constant invalidSortErrorMessage (line 32) | invalidSortErrorMessage = `sortby: value should either be 'natural', 'na...
type searchMethod (line 34) | type searchMethod
constant textSearch (line 37) | textSearch searchMethod = "text"
constant globSearch (line 38) | globSearch searchMethod = "glob"
constant regexSearch (line 39) | regexSearch searchMethod = "regex"
type cursorStyle (line 42) | type cursorStyle
constant defaultCursor (line 45) | defaultCursor cursorStyle = "default"
constant blockCursor (line 46) | blockCursor cursorStyle = "block"
constant underlineCursor (line 47) | underlineCursor cursorStyle = "underline"
constant barCursor (line 48) | barCursor cursorStyle = "bar"
constant blinkBlockCursor (line 49) | blinkBlockCursor cursorStyle = "blinkblock"
constant blinkUnderlineCursor (line 50) | blinkUnderlineCursor cursorStyle = "blinkunderline"
constant blinkBarCursor (line 51) | blinkBarCursor cursorStyle = "blinkbar"
type borderStyle (line 54) | type borderStyle
method String (line 66) | func (s borderStyle) String() string {
constant borderOutline (line 57) | borderOutline borderStyle = 1 << iota
constant borderSeparators (line 58) | borderSeparators
constant borderRound (line 59) | borderRound
constant borderBox (line 61) | borderBox = borderOutline | borderSeparators
constant borderRoundOutline (line 62) | borderRoundOutline = borderOutline | borderRound
constant borderRoundBox (line 63) | borderRoundBox = borderBox | borderRound
function getDirCounts (line 177) | func getDirCounts(path string) bool {
function getDirFirst (line 184) | func getDirFirst(path string) bool {
function getDirOnly (line 191) | func getDirOnly(path string) bool {
function getHidden (line 198) | func getHidden(path string) bool {
function getInfo (line 205) | func getInfo(path string) []string {
function getReverse (line 212) | func getReverse(path string) bool {
function getSortBy (line 219) | func getSortBy(path string) sortMethod {
function init (line 226) | func init() {
FILE: os.go
function init (line 47) | func init() {
function detachedCommand (line 124) | func detachedCommand(name string, arg ...string) *exec.Cmd {
function shellCommand (line 130) | func shellCommand(s string, args []string) *exec.Cmd {
function shellSetPG (line 142) | func shellSetPG(cmd *exec.Cmd) {
function shellKill (line 146) | func shellKill(cmd *exec.Cmd) error {
function setDefaults (line 158) | func setDefaults() {
function setUserUmask (line 178) | func setUserUmask() {
function isExecutable (line 182) | func isExecutable(f os.FileInfo) bool {
function isHidden (line 186) | func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
function userName (line 196) | func userName(f os.FileInfo) string {
function groupName (line 207) | func groupName(f os.FileInfo) string {
function linkCount (line 218) | func linkCount(f os.FileInfo) string {
function errCrossDevice (line 225) | func errCrossDevice(err error) bool {
function quoteString (line 229) | func quoteString(s string) string {
function shellEscape (line 233) | func shellEscape(s string) string {
function shellUnescape (line 244) | func shellUnescape(s string) string {
FILE: os_windows.go
function init (line 44) | func init() {
function detachedCommand (line 127) | func detachedCommand(name string, arg ...string) *exec.Cmd {
function shellCommand (line 133) | func shellCommand(s string, args []string) *exec.Cmd {
function shellSetPG (line 154) | func shellSetPG(_ *exec.Cmd) {
function shellKill (line 157) | func shellKill(cmd *exec.Cmd) error {
function setDefaults (line 161) | func setDefaults() {
function setUserUmask (line 181) | func setUserUmask() {}
function isExecutable (line 183) | func isExecutable(f os.FileInfo) bool {
function isHidden (line 197) | func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
function userName (line 221) | func userName(_ os.FileInfo) string {
function groupName (line 225) | func groupName(_ os.FileInfo) string {
function linkCount (line 229) | func linkCount(_ os.FileInfo) string {
function errCrossDevice (line 233) | func errCrossDevice(err error) bool {
function quoteString (line 237) | func quoteString(s string) string {
function shellEscape (line 245) | func shellEscape(s string) string {
function shellUnescape (line 254) | func shellUnescape(s string) string {
FILE: parse.go
type expr (line 50) | type expr interface
type setExpr (line 55) | type setExpr struct
method String (line 60) | func (e *setExpr) String() string {
type setLocalExpr (line 67) | type setLocalExpr struct
method String (line 73) | func (e *setLocalExpr) String() string {
type mapExpr (line 80) | type mapExpr struct
method String (line 85) | func (e *mapExpr) String() string {
type nmapExpr (line 92) | type nmapExpr struct
method String (line 97) | func (e *nmapExpr) String() string {
type vmapExpr (line 104) | type vmapExpr struct
method String (line 109) | func (e *vmapExpr) String() string {
type cmapExpr (line 116) | type cmapExpr struct
method String (line 121) | func (e *cmapExpr) String() string {
type cmdExpr (line 128) | type cmdExpr struct
method String (line 133) | func (e *cmdExpr) String() string {
type callExpr (line 140) | type callExpr struct
method String (line 146) | func (e *callExpr) String() string {
type execExpr (line 150) | type execExpr struct
method String (line 155) | func (e *execExpr) String() string {
type listExpr (line 183) | type listExpr struct
method String (line 188) | func (e *listExpr) String() string {
type parser (line 203) | type parser struct
method parseExpr (line 219) | func (p *parser) parseExpr() expr {
method parse (line 411) | func (p *parser) parse() bool {
function newParser (line 209) | func newParser(r io.Reader) *parser {
FILE: ruler.go
type statData (line 16) | type statData struct
type rulerData (line 35) | type rulerData struct
function parseRuler (line 57) | func parseRuler(path string) (*template.Template, error) {
function renderRuler (line 75) | func renderRuler(ruler *template.Template, data rulerData, width int) (s...
FILE: scan.go
type tokenType (line 9) | type tokenType
constant tokenEOF (line 12) | tokenEOF tokenType = iota
constant tokenIdent (line 14) | tokenIdent
constant tokenColon (line 15) | tokenColon
constant tokenPrefix (line 16) | tokenPrefix
constant tokenLBraces (line 17) | tokenLBraces
constant tokenRBraces (line 18) | tokenRBraces
constant tokenCommand (line 19) | tokenCommand
constant tokenSemicolon (line 20) | tokenSemicolon
type scanner (line 24) | type scanner struct
method next (line 62) | func (s *scanner) next() {
method peek (line 74) | func (s *scanner) peek() byte {
method scan (line 102) | func (s *scanner) scan() bool {
function newScanner (line 39) | func newScanner(r io.Reader) *scanner {
function isSpace (line 82) | func isSpace(b byte) bool {
function isDigit (line 90) | func isDigit(b byte) bool {
function isPrefix (line 94) | func isPrefix(b byte) bool {
FILE: server.go
function serve (line 19) | func serve() {
function listen (line 47) | func listen(l net.Listener) {
function echoerr (line 63) | func echoerr(c net.Conn, msg string) {
function echoerrf (line 68) | func echoerrf(c net.Conn, format string, a ...any) {
function handleConn (line 72) | func handleConn(c net.Conn) {
FILE: sixel.go
type sixelScreen (line 14) | type sixelScreen struct
method clearSixel (line 20) | func (sxs *sixelScreen) clearSixel(win *win, screen tcell.Screen, file...
method printSixel (line 26) | func (sxs *sixelScreen) printSixel(win *win, screen tcell.Screen, reg ...
function cellSize (line 93) | func cellSize(screen tcell.Screen) (int, int, error) {
FILE: termseq.go
constant gEscapeCode (line 13) | gEscapeCode byte = '\x1b'
function stripTermSequence (line 23) | func stripTermSequence(s string) string {
function readTermSequence (line 51) | func readTermSequence(s string) string {
function optionToFmtstr (line 90) | func optionToFmtstr(optstr string) string {
function parseEscapeSequence (line 101) | func parseEscapeSequence(s string) tcell.Style {
function applyTermSequence (line 112) | func applyTermSequence(s string, st tcell.Style) tcell.Style {
function applySGR (line 138) | func applySGR(s string, st tcell.Style) tcell.Style {
function applyOSC (line 236) | func applyOSC(body string, st tcell.Style) tcell.Style {
FILE: termseq_test.go
function TestStripTermSequence (line 11) | func TestStripTermSequence(t *testing.T) {
function TestReadTermSequence (line 61) | func TestReadTermSequence(t *testing.T) {
function TestOptionToFmtstr (line 88) | func TestOptionToFmtstr(t *testing.T) {
function TestParseEscapeSequence (line 104) | func TestParseEscapeSequence(t *testing.T) {
function TestApplyTermSequence (line 120) | func TestApplyTermSequence(t *testing.T) {
function TestApplySGR (line 140) | func TestApplySGR(t *testing.T) {
FILE: ui.go
constant previewLoadingDelay (line 24) | previewLoadingDelay = 100 * time.Millisecond
type win (line 26) | type win struct
method renew (line 34) | func (win *win) renew(w, h, x, y int) {
method print (line 66) | func (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s...
method printf (line 103) | func (win *win) printf(screen tcell.Screen, x, y int, st tcell.Style, ...
method printLine (line 107) | func (win *win) printLine(screen tcell.Screen, x, y int, st tcell.Styl...
method printRight (line 111) | func (win *win) printRight(screen tcell.Screen, y int, st tcell.Style,...
method printMsg (line 115) | func (win *win) printMsg(screen tcell.Screen, s string) {
method printReg (line 124) | func (win *win) printReg(screen tcell.Screen, reg *reg, sxs *sixelScre...
method printDir (line 239) | func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirSty...
function newWin (line 30) | func newWin(w, h, x, y int) *win {
function printLength (line 42) | func printLength(s string) int {
function infotimefmt (line 152) | func infotimefmt(t time.Time) string {
function fileInfo (line 159) | func fileInfo(f *file, d *dir, userWidth, groupWidth, customWidth int) (...
type dirContext (line 218) | type dirContext struct
type dirRole (line 225) | type dirRole
constant Active (line 228) | Active dirRole = iota
constant Parent (line 229) | Parent
constant Preview (line 230) | Preview
type dirStyle (line 233) | type dirStyle struct
function getUserWidth (line 449) | func getUserWidth(dir *dir, beg, end int) int {
function getGroupWidth (line 459) | func getGroupWidth(dir *dir, beg, end int) int {
function getCustomWidth (line 469) | func getCustomWidth(dir *dir, beg, end int) int {
function getWins (line 479) | func getWins(screen tcell.Screen) []*win {
type menuSelect (line 499) | type menuSelect struct
type ui (line 504) | type ui struct
method winAt (line 551) | func (ui *ui) winAt(x, y int) (int, *win) {
method renew (line 561) | func (ui *ui) renew() {
method echo (line 570) | func (ui *ui) echo(msg string) {
method echomsg (line 574) | func (ui *ui) echomsg(msg string) {
method echoerr (line 579) | func (ui *ui) echoerr(msg string) {
method echoerrf (line 584) | func (ui *ui) echoerrf(format string, a ...any) {
method loadFile (line 603) | func (ui *ui) loadFile(app *app, volatile bool) {
method drawPromptLine (line 630) | func (ui *ui) drawPromptLine(nav *nav) {
method drawStat (line 702) | func (ui *ui) drawStat(nav *nav) {
method drawRuler (line 752) | func (ui *ui) drawRuler(nav *nav) {
method drawRulerFile (line 854) | func (ui *ui) drawRulerFile(nav *nav) {
method drawPreview (line 994) | func (ui *ui) drawPreview(nav *nav, context *dirContext) {
method drawBox (line 1017) | func (ui *ui) drawBox() {
method drawMenu (line 1070) | func (ui *ui) drawMenu() {
method dirOfWin (line 1102) | func (ui *ui) dirOfWin(nav *nav, wind int) *dir {
method draw (line 1114) | func (ui *ui) draw(nav *nav) {
method readNormalEvent (line 1351) | func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
method readEvent (line 1558) | func (ui *ui) readEvent(ev tcell.Event, nav *nav) expr {
method readEvents (line 1570) | func (ui *ui) readEvents() {
method suspend (line 1576) | func (ui *ui) suspend() error {
method resume (line 1581) | func (ui *ui) resume() error {
method exportSizes (line 1585) | func (ui *ui) exportSizes() {
function newUI (line 530) | func newUI(screen tcell.Screen) *ui {
type reg (line 594) | type reg struct
function formatRulerOpt (line 690) | func formatRulerOpt(name, val string) string {
function findBinds (line 1172) | func findBinds(keys map[string]expr, prefix string) (binds map[string]ex...
function listBinds (line 1186) | func listBinds(binds map[string]map[string]expr) string {
function listMatchingBinds (line 1232) | func listMatchingBinds(binds map[string]expr, prefix string) string {
function listCmds (line 1253) | func listCmds(cmds map[string]expr) string {
function listJumps (line 1273) | func listJumps(jumps []string, ind int) string {
function listHistory (line 1297) | func listHistory(history []string) string {
function listMarks (line 1313) | func listMarks(marks map[string]string) string {
function listFilesInCurrDir (line 1333) | func listFilesInCurrDir(nav *nav) string {
function readCmdEvent (line 1545) | func readCmdEvent(ev tcell.Event) expr {
function anyKey (line 1591) | func anyKey() {
function listMatches (line 1610) | func listMatches(screen tcell.Screen, matches []compMatch, selectedInd i...
FILE: watch.go
type watch (line 12) | type watch struct
method start (line 36) | func (watch *watch) start() {
method stop (line 53) | func (watch *watch) stop() {
method add (line 65) | func (watch *watch) add(path string) {
method loop (line 78) | func (watch *watch) loop() {
method addUpdate (line 131) | func (watch *watch) addUpdate(update watchUpdate) {
method processUpdate (line 143) | func (watch *watch) processUpdate(update watchUpdate) {
method getSameDirs (line 160) | func (watch *watch) getSameDirs(dir string) []string {
function newWatch (line 23) | func newWatch(dirChan chan<- *dir, fileChan chan<- *file, delChan chan<-...
type watchUpdate (line 126) | type watchUpdate struct
Condensed preview — 73 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (802K chars).
[
{
"path": ".github/dependabot.yml",
"chars": 315,
"preview": "version: 2\nupdates:\n - package-ecosystem: github-actions\n directory: /\n schedule:\n interval: daily\n commi"
},
{
"path": ".github/workflows/go.yml",
"chars": 2829,
"preview": "name: Go\n\non:\n push:\n branches: [master]\n pull_request:\n branches: [master]\n\njobs:\n formatting:\n runs-on: ub"
},
{
"path": ".github/workflows/release.yml",
"chars": 2841,
"preview": "name: Release\n\non:\n push:\n tags:\n - \"*\"\n\njobs:\n build:\n runs-on: ubuntu-latest\n strategy:\n matrix:\n"
},
{
"path": ".gitignore",
"chars": 29,
"preview": "lf\nlf.exe\ntags\ndist/\nvendor/\n"
},
{
"path": ".golangci.yaml",
"chars": 611,
"preview": "version: \"2\"\nlinters:\n settings:\n errcheck:\n exclude-functions:\n - (*github.com/fsnotify/fsnotify.Watche"
},
{
"path": "CHANGELOG.md",
"chars": 72301,
"preview": "# Changelog\n\nAll changes observable to end users should be documented in this file.\n\nThe format is based on [Keep a Chan"
},
{
"path": "CONTRIBUTING.md",
"chars": 3640,
"preview": "# Contributing\n\nCode contributions are always welcomed in lf.\n\nIf you are going to introduce a new feature, it is best t"
},
{
"path": "LICENSE",
"chars": 1070,
"preview": "MIT License\n\nCopyright (c) 2016 Gökçehan Kara\n\nPermission is hereby granted, free of charge, to any person obtaining a c"
},
{
"path": "README.md",
"chars": 3094,
"preview": "# LF\n\n[Doc](doc.md)\n| [Wiki](https://github.com/gokcehan/lf/wiki)\n| [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org)"
},
{
"path": "app.go",
"chars": 18357,
"preview": "package main\n\nimport (\n\t\"bufio\"\n\t\"cmp\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"io/fs\"\n\t\"log\"\n\t\"os\"\n\t\"os/exec\"\n\t\"os/signal\"\n\t\"path/filep"
},
{
"path": "client.go",
"chars": 4360,
"preview": "package main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"io\"\n\t\"log\"\n\t\"net\"\n\t\"os\"\n\t\"strings\"\n\t\"sync\"\n\t\"time\"\n\n\t\"github.com/gdamore/tcell/"
},
{
"path": "colors.go",
"chars": 6117,
"preview": "package main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/gdamore/tcell/v3\"\n)\n\ntyp"
},
{
"path": "colors_test.go",
"chars": 1112,
"preview": "package main\n\nimport (\n\t\"testing\"\n\n\t\"github.com/gdamore/tcell/v3\"\n)\n\nfunc TestParseColor(t *testing.T) {\n\ttests := []str"
},
{
"path": "complete.go",
"chars": 10264,
"preview": "package main\n\nimport (\n\t\"log\"\n\t\"maps\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"reflect\"\n\t\"slices\"\n\t\"sort\"\n\t\"strings\"\n)\n\nvar (\n\tgCmdWords"
},
{
"path": "complete_test.go",
"chars": 4405,
"preview": "package main\n\nimport (\n\t\"reflect\"\n\t\"testing\"\n)\n\nfunc TestGetOptWords(t *testing.T) {\n\ttests := []struct {\n\t\topts any\n\t\te"
},
{
"path": "copy.go",
"chars": 4183,
"preview": "package main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"slices\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/djherbis/times\""
},
{
"path": "df_openbsd.go",
"chars": 351,
"preview": "package main\n\nimport (\n\t\"log\"\n\n\t\"golang.org/x/sys/unix\"\n)\n\nfunc diskFree(wd string) string {\n\tvar stat unix.Statfs_t\n\n\ti"
},
{
"path": "df_statfs.go",
"chars": 399,
"preview": "//go:build darwin || dragonfly || freebsd || linux\n\npackage main\n\nimport (\n\t\"log\"\n\n\t\"golang.org/x/sys/unix\"\n)\n\nfunc disk"
},
{
"path": "df_statvfs.go",
"chars": 390,
"preview": "//go:build illumos || netbsd || solaris\n\npackage main\n\nimport (\n\t\"log\"\n\n\t\"golang.org/x/sys/unix\"\n)\n\nfunc diskFree(wd str"
},
{
"path": "df_windows.go",
"chars": 426,
"preview": "package main\n\nimport (\n\t\"log\"\n\n\t\"golang.org/x/sys/windows\"\n)\n\nfunc diskFree(wd string) string {\n\tvar free uint64\n\n\tpathP"
},
{
"path": "diacritics.go",
"chars": 3044,
"preview": "package main\n\nvar normMap = map[rune]rune{\n\t// lowercase (not only) european\n\t'ě': 'e', 'ř': 'r', 'ů': 'u', 'ø': 'o', 'ĉ"
},
{
"path": "diacritics_test.go",
"chars": 3242,
"preview": "package main\n\nimport (\n\t\"testing\"\n)\n\n// typical czech test sentence ;-)\nconst baseTestString = \"Příliš žluťoučký kůň pří"
},
{
"path": "doc.md",
"chars": 88627,
"preview": "# NAME\n\nlf - terminal file manager\n\n# SYNOPSIS\n\n**lf**\n[**-command** *command*]\n[**-config** *path*]\n[**-cpuprofile** *p"
},
{
"path": "doc.txt",
"chars": 88372,
"preview": "NAME\n\nlf - terminal file manager\n\nSYNOPSIS\n\nlf [-command command] [-config path] [-cpuprofile path] [-doc] [-help]\n[-las"
},
{
"path": "etc/colors.example",
"chars": 3396,
"preview": "# vim:ft=dircolors\n# (This is not a dircolors file but it helps to highlight colors and comments)\n\n# default values from"
},
{
"path": "etc/icons.example",
"chars": 7090,
"preview": "# vim:ft=conf\n\n# These examples require Nerd Fonts or a compatible font to be used.\n# See https://www.nerdfonts.com for "
},
{
"path": "etc/icons_colored.example",
"chars": 11381,
"preview": "# vim:ft=conf\n\n# These examples require Nerd Fonts or a compatible font to be used.\n# See https://www.nerdfonts.com for "
},
{
"path": "etc/lf.bash",
"chars": 733,
"preview": "# Autocompletion for bash shell.\n#\n# You may put this file to a directory used by bash-completion:\n#\n# mkdir -p ~/.l"
},
{
"path": "etc/lf.csh",
"chars": 526,
"preview": "# Autocompletion for tcsh shell.\n#\n# You need to either copy the content of this file to your shell rc file\n# (e.g. ~/.t"
},
{
"path": "etc/lf.fish",
"chars": 1336,
"preview": "# Autocompletion for fish shell.\n#\n# You may put this file to a directory in $fish_complete_path variable:\n#\n# mkdir"
},
{
"path": "etc/lf.nu",
"chars": 1570,
"preview": "# Autocompletion for nushell.\n#\n# Documentation: https://www.nushell.sh/book/externs.html\n\n# To enable autocompletion yo"
},
{
"path": "etc/lf.ps1",
"chars": 2596,
"preview": "# Autocompletion for PowerShell.\n#\n# You need to either copy the content of this file to $PROFILE or call this\n# script "
},
{
"path": "etc/lf.vim",
"chars": 805,
"preview": "\" Use lf to select and open file(s) in vim (adapted from ranger).\n\"\n\" You need to either copy the content of this file t"
},
{
"path": "etc/lf.zsh",
"chars": 1209,
"preview": "#compdef lf lfcd\n\n# Autocompletion for zsh shell.\n#\n# You need to rename this file to _lf and add containing folder to $"
},
{
"path": "etc/lfcd.cmd",
"chars": 233,
"preview": "@echo off\nrem Change working dir in cmd.exe to last dir in lf on exit.\nrem\nrem You need to put this file to a folder in "
},
{
"path": "etc/lfcd.csh",
"chars": 514,
"preview": "# Change working dir in tcsh to last dir in lf on exit (adapted from ranger).\n#\n# You need to either copy the content of"
},
{
"path": "etc/lfcd.fish",
"chars": 792,
"preview": "# Change working dir in fish to last dir in lf on exit (adapted from ranger).\n#\n# You may put this file to a directory i"
},
{
"path": "etc/lfcd.nu",
"chars": 673,
"preview": "# Change working dir in shell to last dir in lf on exit (adapted from ranger).\n#\n# You need to add this to your Nushell "
},
{
"path": "etc/lfcd.ps1",
"chars": 559,
"preview": "# Change working dir in PowerShell to last dir in lf on exit.\n#\n# You need to put this file to a folder in $ENV:PATH var"
},
{
"path": "etc/lfcd.sh",
"chars": 561,
"preview": "# Change working dir in shell to last dir in lf on exit (adapted from ranger).\n#\n# You need to either copy the content o"
},
{
"path": "etc/lfrc.cmd.example",
"chars": 1171,
"preview": "# interpreter for shell commands\nset shell cmd\n\n# Shell commands with multiline definitions and/or positional arguments "
},
{
"path": "etc/lfrc.example",
"chars": 3095,
"preview": "# interpreter for shell commands\nset shell sh\n\n# set '-eu' options for shell commands\n# These options are used to have s"
},
{
"path": "etc/lfrc.ps1.example",
"chars": 1210,
"preview": "# interpreter for shell commands\nset shell pwsh\n\n# allow the usage of $args inside shell commands\nset shellflag \"-cwa\"\n\n"
},
{
"path": "etc/ruler.default",
"chars": 857,
"preview": "{{with .Message -}}\n {{. -}}\n{{else with .Stat -}}\n {{.Permissions | printf \"\\033[36m%s\\033[0m\" -}}\n {{with .Li"
},
{
"path": "eval.go",
"chars": 52459,
"preview": "package main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"log\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"slices\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n\t\"un"
},
{
"path": "eval_test.go",
"chars": 17997,
"preview": "package main\n\nimport (\n\t\"fmt\"\n\t\"reflect\"\n\t\"strings\"\n\t\"testing\"\n)\n\nvar gEvalTests = []struct {\n\tinp string\n\ttoks []str"
},
{
"path": "gen/build.sh",
"chars": 594,
"preview": "#!/bin/sh\n# Builds a static stripped binary with version information.\n#\n# This script is used to build a binary for the "
},
{
"path": "gen/deflist.lua",
"chars": 1242,
"preview": "local stringify = pandoc.utils.stringify\nlocal List = pandoc.List\nlocal DefinitionList = pandoc.DefinitionList\n\n-- We us"
},
{
"path": "gen/doc.sh",
"chars": 2485,
"preview": "#!/bin/sh\n# Generates `lf.1` and `doc.txt` from the `doc.md` file.\n#\n# This script is used to generate a man page and a "
},
{
"path": "gen/package.sh",
"chars": 490,
"preview": "#!/bin/sh\n# Compresses a binary into an archived form.\n#\n# This script is used to compress a binary built from `build.sh"
},
{
"path": "go.mod",
"chars": 400,
"preview": "module github.com/gokcehan/lf\n\ngo 1.25.0\n\nrequire (\n\tgithub.com/djherbis/times v1.6.0\n\tgithub.com/fsnotify/fsnotify v1.9"
},
{
"path": "go.sum",
"chars": 4609,
"preview": "github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=\ngithub.com/djherbis/times v1.6.0/go.mod"
},
{
"path": "icons.go",
"chars": 3382,
"preview": "package main\n\nimport (\n\t\"log\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strings\"\n\n\t\"github.com/gdamore/tcell/v3\"\n)\n\ntype iconDef struct {"
},
{
"path": "key.go",
"chars": 5413,
"preview": "package main\n\nimport (\n\t\"fmt\"\n\t\"regexp\"\n\t\"strings\"\n\n\t\"github.com/gdamore/tcell/v3\"\n)\n\nvar gKeyVal = map[tcell.Key]string"
},
{
"path": "key_test.go",
"chars": 1549,
"preview": "package main\n\nimport (\n\t\"testing\"\n\n\t\"github.com/gdamore/tcell/v3\"\n)\n\nvar gKeyTests = []struct {\n\tev *tcell.EventKey\n\ts "
},
{
"path": "lf.1",
"chars": 98485,
"preview": ".\\\" Automatically generated by Pandoc 3.7.0.2\n.\\\"\n.TH \"LF\" \"1\" \"2026\\-03\\-21\" \"r42\" \"DOCUMENTATION\"\n.SH NAME\nlf \\- termi"
},
{
"path": "lf.desktop",
"chars": 202,
"preview": "[Desktop Entry]\nType=Application\nName=lf\nComment=Launches the lf file manager\nIcon=utilities-terminal\nTerminal=true\nExec"
},
{
"path": "main.go",
"chars": 7874,
"preview": "package main\n\nimport (\n\t\"flag\"\n\t\"fmt\"\n\t\"log\"\n\t\"net\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"reflect\"\n\t\"runtime\"\n\t\"runtime/debug\"\n\t\"runt"
},
{
"path": "misc.go",
"chars": 13885,
"preview": "package main\n\nimport (\n\t\"bufio\"\n\t\"bytes\"\n\t\"cmp\"\n\t\"fmt\"\n\t\"io\"\n\t\"io/fs\"\n\t\"math/big\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"regexp\"\n\t\"sli"
},
{
"path": "misc_test.go",
"chars": 17704,
"preview": "package main\n\nimport (\n\t\"math\"\n\t\"os\"\n\t\"reflect\"\n\t\"strings\"\n\t\"testing\"\n\t\"time\"\n)\n\nfunc TestIsRoot(t *testing.T) {\n\tsep :="
},
{
"path": "nav.go",
"chars": 44271,
"preview": "package main\n\nimport (\n\t\"bufio\"\n\t\"bytes\"\n\t\"cmp\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"log\"\n\t\"maps\"\n\t\"os\"\n\t\"os/exec\"\n\t\"path/filepath\"\n"
},
{
"path": "opts.go",
"chars": 13656,
"preview": "package main\n\nimport (\n\t\"fmt\"\n\t\"maps\"\n\t\"time\"\n)\n\n// String values match the sortby string sent by the user at startup\nty"
},
{
"path": "os.go",
"chars": 5817,
"preview": "//go:build !windows\n\npackage main\n\nimport (\n\t\"cmp\"\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"os/exec\"\n\t\"os/user\"\n\t\"path/filepath\"\n\t\"runtime\""
},
{
"path": "os_windows.go",
"chars": 5841,
"preview": "package main\n\nimport (\n\t\"cmp\"\n\t\"fmt\"\n\t\"os\"\n\t\"os/exec\"\n\t\"os/user\"\n\t\"path/filepath\"\n\t\"strings\"\n\t\"syscall\"\n\n\t\"golang.org/x/"
},
{
"path": "parse.go",
"chars": 6492,
"preview": "package main\n\n// Grammar of the language used in the evaluator\n//\n// Expr = SetExpr\n// | SetLocalEx"
},
{
"path": "ruler.go",
"chars": 2452,
"preview": "package main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strings\"\n\t\"text/template\"\n\n\t_ \"embed\"\n)\n\n//go:embed etc/ruler.def"
},
{
"path": "scan.go",
"chars": 5495,
"preview": "package main\n\nimport (\n\t\"io\"\n\t\"log\"\n\t\"strconv\"\n)\n\ntype tokenType byte\n\nconst (\n\ttokenEOF tokenType = iota\n\t// no explici"
},
{
"path": "server.go",
"chars": 4180,
"preview": "package main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"log\"\n\t\"net\"\n\t\"os\"\n\t\"sort\"\n\t\"strconv\"\n)\n\nvar (\n\tgConnList = make(map[int]net.Con"
},
{
"path": "sixel.go",
"chars": 2506,
"preview": "package main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/gdamore/tcell/v3\"\n)\n\ntype sixel"
},
{
"path": "termseq.go",
"chars": 6674,
"preview": "package main\n\nimport (\n\t\"log\"\n\t\"strconv\"\n\t\"strings\"\n\t\"unicode/utf8\"\n\n\t\"github.com/gdamore/tcell/v3\"\n)\n\n// gEscapeCode is"
},
{
"path": "termseq_test.go",
"chars": 8132,
"preview": "package main\n\nimport (\n\t\"reflect\"\n\t\"testing\"\n\n\t\"github.com/gdamore/tcell/v3\"\n\t\"github.com/gdamore/tcell/v3/color\"\n)\n\nfun"
},
{
"path": "ui.go",
"chars": 39812,
"preview": "package main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"reflect\"\n\t\"slices\"\n\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n"
},
{
"path": "watch.go",
"chars": 4114,
"preview": "package main\n\nimport (\n\t\"log\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"time\"\n\n\t\"github.com/fsnotify/fsnotify\"\n)\n\ntype watch struct {\n\twa"
}
]
About this extraction
This page contains the full source code of the gokcehan/lf GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 73 files (721.6 KB), approximately 218.5k tokens, and a symbol index with 489 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.