[
  {
    "path": ".github/dependabot.yml",
    "content": "version: 2\nupdates:\n  - package-ecosystem: github-actions\n    directory: /\n    schedule:\n      interval: daily\n    commit-message:\n      prefix: chore\n      include: scope\n  - package-ecosystem: gomod\n    directory: /\n    schedule:\n      interval: daily\n    commit-message:\n      prefix: chore\n      include: scope\n"
  },
  {
    "path": ".github/workflows/go.yml",
    "content": "name: Go\n\non:\n  push:\n    branches: [master]\n  pull_request:\n    branches: [master]\n\njobs:\n  formatting:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v6\n\n      - name: Setup Go\n        uses: actions/setup-go@v6\n        with:\n          go-version-file: go.mod\n\n      - name: Check formatting\n        run: go fmt && git diff --exit-code\n\n  tests:\n    runs-on: ${{ matrix.os }}\n    strategy:\n      matrix:\n        os: [ubuntu-latest, windows-latest]\n    steps:\n      - uses: actions/checkout@v6\n\n      - name: Setup Go\n        uses: actions/setup-go@v6\n        with:\n          go-version-file: go.mod\n\n      - name: Build\n        run: go build -v ./...\n\n      - name: Test\n        run: go test -v ./...\n\n      - name: golangci-lint\n        uses: golangci/golangci-lint-action@v9\n        with:\n          version: v2.5.0\n\n  build:\n    runs-on: ubuntu-latest\n    strategy:\n      matrix:\n        include:\n          - { os: android, arch: arm64 }\n          - { os: darwin, arch: amd64 }\n          - { os: darwin, arch: arm64 }\n          - { os: dragonfly, arch: amd64 }\n          - { os: freebsd, arch: \"386\" }\n          - { os: freebsd, arch: amd64 }\n          - { os: freebsd, arch: arm }\n          - { os: illumos, arch: amd64 }\n          - { os: linux, arch: \"386\" }\n          - { os: linux, arch: amd64 }\n          - { os: linux, arch: arm }\n          - { os: linux, arch: arm64 }\n          - { os: linux, arch: ppc64 }\n          - { os: linux, arch: ppc64le }\n          - { os: linux, arch: mips }\n          - { os: linux, arch: mipsle }\n          - { os: linux, arch: mips64 }\n          - { os: linux, arch: mips64le }\n          - { os: linux, arch: s390x }\n          - { os: netbsd, arch: \"386\" }\n          - { os: netbsd, arch: amd64 }\n          - { os: netbsd, arch: arm }\n          - { os: openbsd, arch: \"386\" }\n          - { os: openbsd, arch: amd64 }\n          - { os: openbsd, arch: arm }\n          - { os: openbsd, arch: arm64 }\n          - { os: solaris, arch: amd64 }\n          - { os: windows, arch: \"386\" }\n          - { os: windows, arch: amd64 }\n          # Unsupported\n          # - { os: aix, arch: ppc64 }\n          # - { os: android, arch: \"386\" }\n          # - { os: android, arch: amd64 }\n          # - { os: android, arch: arm }\n          # - { os: js, arch: wasm }\n          # - { os: plan9, arch: \"386\" }\n          # - { os: plan9, arch: amd64 }\n          # - { os: plan9, arch: arm }\n    steps:\n      - uses: actions/checkout@v6\n        with:\n          fetch-depth: 0 # https://github.com/actions/checkout/issues/2199\n          fetch-tags: true\n\n      - name: Setup Go\n        uses: actions/setup-go@v6\n        with:\n          go-version-file: go.mod\n\n      - name: Build\n        run: gen/build.sh\n        env:\n          GOOS: ${{ matrix.os }}\n          GOARCH: ${{ matrix.arch }}\n"
  },
  {
    "path": ".github/workflows/release.yml",
    "content": "name: Release\n\non:\n  push:\n    tags:\n      - \"*\"\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    strategy:\n      matrix:\n        include:\n          - { os: android, arch: arm64 }\n          - { os: darwin, arch: amd64 }\n          - { os: darwin, arch: arm64 }\n          - { os: dragonfly, arch: amd64 }\n          - { os: freebsd, arch: \"386\" }\n          - { os: freebsd, arch: amd64 }\n          - { os: freebsd, arch: arm }\n          - { os: illumos, arch: amd64 }\n          - { os: linux, arch: \"386\" }\n          - { os: linux, arch: amd64 }\n          - { os: linux, arch: arm }\n          - { os: linux, arch: arm64 }\n          - { os: linux, arch: ppc64 }\n          - { os: linux, arch: ppc64le }\n          - { os: linux, arch: mips }\n          - { os: linux, arch: mipsle }\n          - { os: linux, arch: mips64 }\n          - { os: linux, arch: mips64le }\n          - { os: linux, arch: s390x }\n          - { os: netbsd, arch: \"386\" }\n          - { os: netbsd, arch: amd64 }\n          - { os: netbsd, arch: arm }\n          - { os: openbsd, arch: \"386\" }\n          - { os: openbsd, arch: amd64 }\n          - { os: openbsd, arch: arm }\n          - { os: openbsd, arch: arm64 }\n          - { os: solaris, arch: amd64 }\n          - { os: windows, arch: \"386\" }\n          - { os: windows, arch: amd64 }\n          # Unsupported\n          # - { os: aix, arch: ppc64 }\n          # - { os: android, arch: \"386\" }\n          # - { os: android, arch: amd64 }\n          # - { os: android, arch: arm }\n          # - { os: js, arch: wasm }\n          # - { os: plan9, arch: \"386\" }\n          # - { os: plan9, arch: amd64 }\n          # - { os: plan9, arch: arm }\n    steps:\n      - uses: actions/checkout@v6\n\n      - name: Setup Go\n        uses: actions/setup-go@v6\n        with:\n          go-version-file: go.mod\n\n      - name: Build\n        run: gen/build.sh\n        env:\n          GOOS: ${{ matrix.os }}\n          GOARCH: ${{ matrix.arch }}\n\n      - name: Package\n        run: gen/package.sh\n        env:\n          GOOS: ${{ matrix.os }}\n          GOARCH: ${{ matrix.arch }}\n\n      - name: Upload artifact\n        uses: actions/upload-artifact@v7\n        with:\n          name: lf-${{ matrix.os }}-${{ matrix.arch }}\n          path: dist/*\n\n  release:\n    runs-on: ubuntu-latest\n    needs: build\n    steps:\n      - name: Download artifacts\n        uses: actions/download-artifact@v8\n        with:\n          path: dist\n          merge-multiple: true\n\n      - name: Release\n        uses: softprops/action-gh-release@v2\n        with:\n          files: dist/*\n\n  winget:\n    runs-on: ubuntu-latest\n    needs: build\n    steps:\n      - uses: vedantmgoyal2009/winget-releaser@v2\n        with:\n          identifier: gokcehan.lf\n          version: ${{ github.ref_name }}\n          installers-regex: '-windows-\\w+\\.zip$'\n          token: ${{ secrets.WINGET_TOKEN }}\n"
  },
  {
    "path": ".gitignore",
    "content": "lf\nlf.exe\ntags\ndist/\nvendor/\n"
  },
  {
    "path": ".golangci.yaml",
    "content": "version: \"2\"\nlinters:\n  settings:\n    errcheck:\n      exclude-functions:\n        - (*github.com/fsnotify/fsnotify.Watcher).Close\n        - (*net.TCPConn).CloseWrite\n        - (*net.UnixConn).CloseWrite\n        - (*os.File).Close\n        - (*os.File).Write\n        - (*text/tabwriter.Writer).Flush\n        - (io.Closer).Close\n        - (io.Writer).Write\n        - (net.Conn).Close\n        - (net.Listener).Close\n        - fmt.Fprintf\n        - fmt.Fprintln\n        - io.WriteString\n        - os.Setenv\n        - syscall.Close\nissues:\n  max-issues-per-linter: 0  # no limit\n  max-same-issues: 0        # no limit\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Changelog\n\nAll changes observable to end users should be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and should contain the following sections for each release:\n\n- `Changed`\n- `Added`\n- `Fixed`\n\n## Unreleased\n\n### Changed\n\n- The key `<backspace2>` has been renamed to `<backspace>` for `map` keybindings (#2286).\n- `.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).\n- `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.\n\n### Added\n\n- Emoji sequences containing Zero Width Joiner characters are now displayed as a single combined glyph (#2286).\n- 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).\n- A new option `numbercursorfmt` is added to further customize the appearance of line numbers (#2395).\n- A new option `terminalcursor` is added to customize the appearance of the terminal cursor (#2441).\n- A new option `borderstyle` is added to control whether `drawbox` draws an outline, separators, or both (#2445).\n- The `loading...` message delay of 100 milliseconds for file previews is now applied to directories as well (#2410).\n- `lf` will now automatically change to the parent directory if the current directory no longer exists and the `watch` option is enabled (#2424).\n\n### Fixed\n\n- Previews are now cleaned when changing to an empty directory (#2369).\n- Previews are now correctly updated on `visual-change` (#2373).\n- The `dircounts` indicator for errors is changed back to `!` instead of `?` (#2372).\n- The `select` command can now select files immediately after creation as part of a script (#2377).\n- The `on-load` hook command now ignores `.git` directories to reduce flicker and repeated `on-load` triggers (#2382).\n- Preview messages like `empty` or `loading...` have their alignment improved (#2400).\n- A bug where the `loading...` message was not displayed for volatile previews after the first time is now fixed (#2410).\n- The `cmd-transpose` command now advances the cursor correctly after swapping characters (#2413).\n- Symbolic links are no longer followed when changing directories (#2423).\n- Using the `select` command with a blank string as the argument now properly raises an error instead of changing to the parent directory (#2429).\n- Executable files on Windows are now correctly recognized for icon and color lookup based on `PATHEXT` (#2448).\n\n## [r41](https://github.com/gokcehan/lf/releases/tag/r41)\n\n### Changed\n\n- The `previewer` script no longer skips non-regular files (#2327).\n- Line numbers now take up less space when both `number` and `relativenumber` are enabled (#2331).\n- Changes have been made to ruler configuration (#2338):\n  - The ruler file is no longer experimental.\n  - The ruler file will be used by default unless `rulerfmt` (now a blank string by default) is specified.\n  - 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.\n\n### Added\n\n- A new server command `list` is added to print the IDs of all currently connected clients (#2314).\n- The `previewer` and `cleaner` scripts now have their `stderr` output logged (#2316).\n- 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).\n- A new option `mergeindicators` is added to reduce the gap before filenames, by merging tag and selection indicators into a single column (#2330).\n\n### Fixed\n\n- A bug where sixel images fail to display when scrolling back and forth is now fixed (#2301).\n- Newline characters are now ignored when drawing the ruler with the `ruler` file configured (#2319).\n- A potential crash when using the `scroll-up`/`scroll-down` commands is now fixed (#2320).\n- Case-insensitive command-line completions no longer cause user input to be displayed in lowercase (#2336).\n- Calculation of window widths for the `ratios` option is now more accurate (#2347).\n\n## [r40](https://github.com/gokcehan/lf/releases/tag/r40)\n\n### Fixed\n\n- Error messages from the server are no longer written to the terminal which causes the UI to break (#2290).\n- A bug where file previews fail to load properly when scrolling quickly is now fixed (#2292).\n\n## [r39](https://github.com/gokcehan/lf/releases/tag/r39)\n\n### Changed\n\n- File extensions are now shown for long filenames even if they are truncated (#2159).\n- 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.\n- 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.\n- The string representation of commands shown when displaying keybindings is simplified (e.g. `cd ~` instead of `cd -- [~]`) (#2165).\n- `yes-no-prompts` now use the same design everywhere (#2212).\n- Logs generated by `-log <path>` now get appended to `<path>` instead of overwriting it (#2215).\n- The `showbinds` menu now hides the redundant `mode` column (#2226) (#2228) and omits already typed keys (#2249).\n- The `setlocal` command no longer requires absolute paths (#2253).\n- The string representation of file permissions now matches the traditional `Unix` format instead of the one used by `Go` (#2270).\n\n### Added\n\n- A new command `cmd-menu-discard` is added to allow exiting the completion menu with completions discarded (#2146).\n- The `lf_mode` environment variable will now be set to `compmenu` if the completion menu is active (#2146).\n- 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.**\n- A new option `preload` is added to enable calling the `previewer` to generate previews in advance (#2206). **This feature is currently experimental.**\n- `OSC 8` escape codes to render clickable hyperlinks are now supported (#2243).\n\n### Fixed\n\n- `shell-pipe` commands no longer wait for output if kept open after the command has finished running (#2155).\n- Natural sorting now compares string lengths when dealing with equivalent numbers (e.g. `0` is ordered before `00`) (#2177).\n- A bug where the copy progress indicator only displayed the first time a file was copied is now fixed (#2181).\n- A bug where the `source` command does not show an error message upon failure is now fixed (#2189).\n- The `addcustominfo` (#2198) and `setlocal` (#2254) (#2259) commands, as well as the `cleaner` and `previewer` options (#2211) now support filename completions.\n- A bug where an empty `custom` info property would still take up space is now fixed (#2208).\n- A bug where setting `drawbox` could lead to scrolling outside the view is now fixed (#2210) (#2218).\n- The preview cache is now not cleared when setting `ratios` to its current value (#2218).\n- Filtering is fixed when using special characters in the search pattern if the `filtermethod` is `text` (#2231).\n- Custom commands that output messages (e.g. `cmd greet echo 'hello world'`) now display properly (#2245).\n- Errors in config files are now displayed properly (#2246).\n\n## [r38](https://github.com/gokcehan/lf/releases/tag/r38)\n\n### Changed\n\n- The deprecated `globfilter` and `globsearch` options are now removed (#2108).\n- Sixel image support is now enabled by default, and the `sixel` option has been removed as it is no longer required (#2109).\n- 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.\n- The experimental `locale` option has been removed in favor of the recommendation to use `addcustominfo`/`set sortby custom` for custom sorting (#2111).\n- The existing `doc` command has been renamed to `help` so that it is more natural for users (#2125).\n- 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/^/  /'`.\n\n### Added\n\n- Sixel image previews can now display multiple images as well as text (#2109).\n- A new option `sizeunits` is added to allow displaying file sizes in either binary or decimal units (#2118).\n- `XDG_CONFIG_HOME` and `XDG_DATA_HOME` are now taken into account when looking up config/data files on Windows (#2119).\n- Three new options `menufmt`, `menuheaderfmt`, and `menuselectfmt` are added to customize the appearance of the menu (#2123).\n\n### Fixed\n\n- Error messages are now cleared after running interactive commands such as `invert`/`unselect`/`tag-toggle` (#2117).\n- The menu is now drawn over sixel images instead of being hidden behind it if they overlap (#2122).\n- A bug which prevents the user from quitting when copying files with a size of 0 has been fixed (#2130).\n- `lf -remote` should no longer busy wait and cause high CPU usage if its output is not being read (#2138).\n- The parameter types for command line options shown by `lf -help` now match the synopsis in the documentation (#2153).\n\n## [r37](https://github.com/gokcehan/lf/releases/tag/r37)\n\n### Changed\n\n- The default paths of files read by `lf` is changed on Windows, to separate configuration files from data files (#2051).\n  - Configuration files (`lfrc`/`colors`/`icons`) are now stored in `%APPDATA%`, which can be overridden by `%LF_CONFIG_HOME%`.\n  - Data files (`files`/`marks`/`tags`/`history`) are now stored in `%LOCALAPPDATA%`, which can be overridden by `%LF_DATA_HOME%`.\n- 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.\n- The existing `globfilter` and `globsearch` options are now deprecated in favor of the new `filtermethod` and `searchmethod` options, which support regex patterns (#2058).\n  - `set globfilter true` should be replaced by `set filtermethod glob`.\n  - `set globsearch true` should be replaced by `set searchmethod glob`.\n- 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.\n\n### Added\n\n- `dircounts` are now respected when sorting by size (#2025).\n- The `info` and `sortby` options now support `btime` (file creation time) (#2042). This depends on support for file creation times from the underlying system.\n- The selection in Visual mode now follows wrapping when `wrapscan`/`wrapscroll` is enabled (#2056).\n- 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.\n- The Command-line mode completion now supports keywords for the `selmode` and `sortby` options (#2061), as well as the `info` and `preserve` options (#2071).\n- Command line options are now exported as environment variables in the form `lf_flag_{flag}` (#2079).\n- Support is added for terminal escape sequences that disable text styles (#2101).\n\n### Fixed\n\n- `dircounts` are now automatically populated after enabling it (#2049).\n- A bug where directories are unsorted after reloading when `dircache` is disabled is now fixed (#2050).\n- Filenames are now escaped when completing shell commands (#2071).\n- A bug where completion menu entries are misaligned when containing fullwidth characters is now fixed (#2071).\n- The `on-load` command now passes all files in the directory as arguments, not just files visible to the user (#2077).\n- Failure to move files across different filesystems is now shown as an error instead of a success in the UI (#2085).\n- Errors are now logged correctly when there are multiple errors during move/copy operations (#2089).\n- 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).\n\n## [r36](https://github.com/gokcehan/lf/releases/tag/r36)\n\n### Changed\n\n- Tagging symbolic links now affects the target instead of the symbolic link itself. This mimics the behavior in `ranger` (#1997).\n- The experimental command `invert-below` has been removed in favor of the newly added support for Visual mode (#2021).\n\n### Added\n\n- A new placeholder `%P` representing the scroll percentage is added to the `rulerfmt` option (#1985).\n- A new `on-load` hook command is added, which is triggered when files in a directory are loaded in `lf` (#2010).\n- 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).\n- Support for `visual-mode` has now been added (#2021) (#2035). This includes the following changes:\n  - A new command `visual` (default `V`) can be used to enter Visual mode.\n  - 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).\n  - 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.\n  - 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.\n  - A new command `visual-unselect` can be used to exit Visual mode, removing the visual selection from the selection list.\n  - 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.\n  - 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.\n  - A new option `visualfmt` is added to customize the appearance of the visual selection.\n  - 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`.\n  - 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`.\n  - The `lf_mode` environment variable will now be set to `visual` while in Visual mode.\n  - The environment variable `$fv` is now exported to shell commands, which lists the files in the visual selection.\n- 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.\n\n### Fixed\n\n- Displaying sixel images now uses the screen locking API in Tcell, which reduces flickering in the UI (#1943).\n- The `cmd-history` command is now ignored outside of Normal or Command-line mode, to prevent accidentally escaping out of other modes (#1971).\n- A potential crash when using the `cmd-delete-word-back` command is fixed (#1976).\n- The `preserve` option now applies to directories in addition to files when copying. This includes preserving `timestamps` (#1979) and `mode` (#1981).\n- The `lfrc.ps1.example` example config file is updated to include PowerShell equivalents for the default commands and keybindings (#1989).\n- Quoting for the `lf` environment variable is fixed for PowerShell users (#1990).\n- `tempmarks` are no longer cleared after the `sync` command is called (#1996).\n- The file stat information is no longer displayed during the execution of a `shell-pipe` command even if the file is updated (#2002).\n- Directories are now reloaded properly if any component in the current path is renamed (#2005).\n- 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).\n- 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).\n\n## [r35](https://github.com/gokcehan/lf/releases/tag/r35)\n\n### Added\n\n- Support is added for displaying underline styles (#1896).\n- Support is added for displaying underline colors (#1933).\n- A new subcommand `files` is added to the `query` server command to list the files in the current directory as displayed in `lf` (#1949).\n- 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.**\n\n### Fixed\n\n- The `trash` command in `lfrc.example` now verifies if the trash directory exists before moving files there (#1918).\n- `lf` should no longer crash if it fails to open the log file (#1937).\n- Arrow keys are now handled properly when waiting for a key press after executing a `shell-wait` (`!`) command (#1956).\n- The `previewer` script is now only invoked for the current directory (instead of all directories), when starting `lf` with `dirpreviews` enabled (#1958).\n\n## [r34](https://github.com/gokcehan/lf/releases/tag/r34)\n\n### Changed\n\n- The `autoquit` option is now enabled by default (#1839).\n\n### Added\n\n- A new option `locale` is added to sort files based on the collation rules of the provided locale (#1818). **This feature is currently experimental.**\n- A new `on-init` hook command is added to allow triggering custom actions when `lf` has finished initializing and connecting to the server (#1838).\n\n### Fixed\n\n- The background color now renders properly when displaying filenames (#1849).\n- A bug where the `on-quit` hook command causes an infinite loop has been fixed (#1856).\n- File sizes now display correctly after being copied when `watch` is enabled (#1881).\n- Files are now automatically unselected when removed by an external process, when `watch` is enabled (#1901).\n\n## [r33](https://github.com/gokcehan/lf/releases/tag/r33)\n\n### Changed\n\n- 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).\n- 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).\n- The `ruler` option (deprecated in favor of `rulerfmt`) is now removed (#1766).\n- Line numbers from the `number` and `relativenumber` options are displayed in the main window only, instead of all windows (#1789).\n\n### Added\n\n- Support for Unix domain sockets (for communicating with the `lf` server) is added for Windows (#1637).\n- Color and icon configurations now support the `target` keyword for symbolic links (#1644).\n- A new option `roundbox` is added to use rounded corners when `drawbox` is enabled (#1653).\n- 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).\n- Icons can now be colored independently of the filename (#1674).\n- The `info` option now supports `perm`, `user` and `group` to display the permissions, user and group respectively for each file (#1799).\n- A new option `showbinds` is added to toggle whether the keybinding hints are shown when a keybinding is partially typed (#1815).\n\n### Fixed\n\n- Sorting by extension is fixed for hidden files (#1670).\n- The `on-quit` hook command is now triggered when the terminal is closed (#1681).\n- Previews no longer flicker when deleting files (#1691).\n- Previews no longer flicker when directories are being reloaded (#1697).\n- `lfcd.nu` now runs properly without raising errors (#1728).\n- Image previews (composed of ASCII art) containing long lines should now display properly (#1737).\n- The performance is improved when copying files (#1749).\n- `lfcd.cmd` now handles directories with special characters (#1772).\n- Icon colors are no longer clipped when displaying in Windows Terminal (#1777).\n- The file stat info is now cleared when changing to an empty directory (#1808).\n- Error messages are cleared when opening files (#1809).\n\n## [r32](https://github.com/gokcehan/lf/releases/tag/r32)\n\n### Changed\n\n- 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).\n- The documentation from `lf -doc` and the `doc` command is now generated from Markdown using `pandoc` (#1474).\n\n### Added\n\n- A new option `hidecursorinactive` is added to hide the cursor when the terminal is not focused (#965).\n- 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).\n- Options `cutfmt`, `copyfmt` and `selectfmt` are added to configure the indicator color for cut/copied/selected files respectively (#1540).\n- `zsh` completion is added for the `lfcd` command (#1564).\n- The file stat information now falls back to displaying user/group ID if looking up the user/group name fails (#1590).\n- A new environment variable `lf_mode` is now exported to indicate which mode `lf` is currently running in (#1594).\n- Default icons are added for Docker Compose files (#1626).\n\n### Fixed\n\n- Default value of `rulerfmt` option is now left-padded with spaces to visually separate it from the file stat information (#1437).\n- Previews should now work for files containing lines with 65536 characters or more (#1447).\n- Sixel previews should now work when using `lfcd` scripts (#1451).\n- Colors and icons should now display properly for character device files (#1469).\n- The selection file is now immediately synced to physical storage after writing to it (#1480).\n- Timestamps are preserved when moving files across devices (#1482).\n- Fix crash for `high` and `low` commands when `scrolloff` is set to a large value (#1504).\n- Documentation is updated with various spelling and grammar fixes (#1518).\n- Files beginning with a dot (e.g. `.gitignore`) are named correctly after `paste` if another file with the same name already exists (#1525).\n- Prevent potential race condition when sorting directory contents (#1526).\n- Signals are now handled properly even after receiving and ignoring `SIGINT` (#1549).\n- The file stat information should now update properly after using the `cd` command to change to a directory for the first time (#1536).\n- Previous error messages should now be cleared after a `mark-save`/`mark-remove` operation (#1544).\n- Fix high CPU usage issue when viewing CryFS filesystems (#1607).\n- Invalid entries in the `marks` and `tags` files now raise an error message instead of crashing (#1614).\n- Startup time is improved on Windows (#1617).\n- Sixel previews are now resized properly when the horizontal size of the preview window changes (#1629).\n- The cut buffer is only cleared if the `paste` operation succeeds (#1652).\n- The extension after `.` is ignored to set the cursor position when renaming a directory (#1664).\n- The option `period` should not cause flickers in sixel previews anymore (#1666).\n\n## [r31](https://github.com/gokcehan/lf/releases/tag/r31)\n\n### Changed\n\n- 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!'`).\n- 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.\n- 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).\n- 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).\n- 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.\n\n### Added\n\n- Modifier keys (i.e. control, shift, alt) with special keys (e.g. arrows, enter) are now supported for most combinations (#1248).\n- A new option `borderfmt` is added to configure colors for pane borders (#1251).\n- 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).\n- Tilde (i.e. `~`) expansion is performed during completion to be able to use expanded tilde paths as command arguments (#1246).\n- A new option `preserve` is added to preserve attributes (i.e. mode and timestamps) while copying (#1026).\n- The file `etc/icons.example` is updated for nerd-fonts v3.0.0 (#1271).\n- 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).\n- A new option `statfmt` is added to configure the status line at the bottom (#1288).\n- A new option `truncatepct` is added to determine the location of truncation from the beginning in terms of percentage (#1029).\n- A new option `dupfilefmt` is added to configure the names of duplicate files while copying (#1315).\n- Shell scripts `etc/lf.nu` and `etc/lfcd.nu` are added to the repository to allow completion and directory change with Nushell (#1341).\n- Sixels are now supported for previewing (#1211). A new option `sixel` is added to enable this behavior.\n- A new configuration keyword `setlocal` is added to configure directory specific options (#1381).\n- 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).\n\n### Fixed\n\n- Cursor positions in the directory should now be preserved after file operations that changes the directory (e.g. create or delete) (#1247).\n- Option `reverse` should now respect to sort stability requirements (#1261).\n- Backspace should not exit `filter` mode anymore (#1269).\n- Truncated double width characters should not cause misalignment for the file information (#1272).\n- Piping shell commands should not refresh the preview anymore (#1281).\n- Cursor position should now update properly after a terminal resize (#1290).\n- Directories should now be reloaded properly after a `delete` operation (#1292).\n- Executable file completion should not add entries to the log file anymore (#1307).\n- Blank input lines are now allowed in piping shell commands (#1308).\n- Shell commands arguments on Windows should now be quoted properly to fix various issues (#1309).\n- Reloading in a symlink directory should not follow the symlink anymore (#1327).\n- Command `load` should not flicker image previews anymore (#1335).\n- Asynchronous shell commands should now trigger `load` automatically when they are finished (#1345).\n- Changing the value of `preview` option should now clear image previews (#1350).\n- Cursor position in the status line at the bottom should now consider double width characters properly (#1348).\n- Filenames should only be quoted for `cmd` on Windows to avoid quoting issues for PowerShell (#1371).\n- Inaccessible files should now be included in the directory list and display their `lstat` errors in the status line at the bottom (#1382).\n- Command line command `cmd-delete-word` should now add the deleted text to the yank buffer (#1409).\n\n## [r30](https://github.com/gokcehan/lf/releases/tag/r30)\n\n### Added\n\n- A new builtin command `jumps` is added to display the jump list (#1233).\n- A new possible field `filter` is added to `ruler` option to display the filter indicator (#1223).\n\n### Fixed\n\n- Broken mappings for `bottom` command due to recent changes are fixed (#1240).\n- Selecting a file does not scroll to bottom anymore (#1222).\n- Broken builds on some platforms due to recent changes are fixed (#1168).\n\n## [r29](https://github.com/gokcehan/lf/releases/tag/r29)\n\n### Changed\n\n- 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\"`.\n- 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.\n- Cursor is now placed at the file extension by default in rename prompts (#1162).\n- The environment variable `VISUAL` is checked before `EDITOR` for the default editor choice (#1197).\n\n### Added\n\n- Mouse wheel events with the Control modifier have been bound to scrolling by default (#1051).\n- Option values for `tagfmt` and `errorfmt` have been simplified to be able to avoid the reset sequence (#1086).\n- Two default command line bindings for `<down>` and `<up>` have been added for `cmd-history-next` and `cmd-history-prev` respectively (#1112).\n- A new command `invert-below` is added to invert all selections below the cursor (#1101). **This feature is currently experimental.**\n- Two new commands `maps` and `cmaps` have been added to display the current list of bindings (#1146) (#1201).\n- A new option `numberfmt` is added to customize line numbers (#1177).\n- A new environment variable `lf_count` is now exported to use the count in shell commands (#1187).\n- A new environment variable `lf` is now exported to be used as the executable path (#1176).\n- An example `mkdir` binding is added to the example configuration (#1188).\n- An example binding to show execution results is added to the example configuration (#1188).\n- Commands `top` and `bottom` now accepts counts to move to a specific line (#1196).\n- A new option `ruler` is added to customize the ruler information with a new addition for free disk space (#1168) (#1205).\n\n### Fixed\n\n- Example `lfcd` files have been made safer to be able to alias the commands as `lf` (#1049).\n- Backspace should not exit from `rename:` mode anymore (#1060).\n- Preview is now refreshed even if the selection does not change (#1074).\n- Stale directory cache entry is now deleted during rename (#1138).\n- File information is now updated properly after reloading (#1149).\n- Window widths are now calculated properly when `drawbox` is enabled (#1150).\n- Line number widths are now calculated properly when there are exactly 10 entries (#1151).\n- Preview is not redrawn in async shell commands (#1164).\n- A small delay is added before showing loading text in preview pane to avoid flickering (#1154).\n- Hard-coded box drawing characters are replaced with Tcell constants to enable the fallback mechanism (#1170).\n- Option `relativenumber` now shows zero in the current line (#1171).\n- Completion is not stuck in an infinite loop anymore when a match is longer than the window width (#1183).\n- Completion now inserts the longest match even if there is no word before the cursor (#1184).\n- Command `doc` should now work even if `lf` is not in the `PATH` variable (#1176).\n- Directory option changes should not crash the program anymore (#1204).\n- Option `selmode` is now validated for the accepted values (#1206).\n\n## [r28](https://github.com/gokcehan/lf/releases/tag/r28)\n\n### Changed\n\n- Extension matching for colors and icons are now case insensitive (#908).\n\n### Added\n\n- Three new commands `high`, `middle`, and `low` are added to move the current selection relative to the screen (#824).\n- Backspace on empty prompt now switches to Normal mode (#836).\n- A new `history` option is now added to be able to disable history (#866).\n- A new special expansion `%S` spacer is added for `promptfmt` to be able to right align parts (#867).\n- A new command-line command `cmd-menu-accept` is now added to accept the currently selected match (#934).\n- Command-line commands should now be shown in completion for `map` and `cmap` (#934).\n- Italic escape codes should now be working in previews (#936).\n- Position and size information are now also passed to the `cleaner` script as arguments (#945).\n- A new option `dirpreviews` is now added to also pass directories to the `previewer` script (#842).\n- A new option `selmode` is now added to be able to limit the selection to the current directory (#849).\n- User defined options with `user_` prefix are now supported (#865).\n- Adding or removing `$`/`%`/`!`/`&` characters in `:` mode should now change the mode accordingly (#960).\n- A new special command `on-select` is now added to be able to run a command after the selection changes (#864).\n- Mouse support is extended to be able to click filenames for selection and opening (#963).\n- Two new environment variables `lf_width` and `lf_height` are now exported for shell commands.\n\n### Fixed\n\n- Option `tagfmt` can now be changed properly.\n- User name, group name, and link count should now be displayed as before where available (#829).\n- Tagging files with colons in their names should now work as expected (#857).\n- Some multibyte characters should now be handled properly for completion (#934).\n- Menu completion for a file in a subdirectory should now be working properly (#934).\n- File completion should now be escaped properly in menu completion (#934).\n- First use of `cmd-menu-complete-back` should now select the last completion as expected (#934).\n- Broken symlinks should now be working properly in completion (#934).\n- Files with stat errors should now be skipped properly in completion (#934).\n- Empty search with `incsearch` option should now be handled properly (#944).\n- History position is now also reset when leaving the command line (#953).\n- Mouse drag events are now ignored properly to avoid command repetition (#962).\n- Environment variables `HOME` and `USER` should now be used as fallback for locations on some systems (#972).\n- File information is now displayed in the status line at first launch when there are no errors in the configuration file (#994).\n\n## [r27](https://github.com/gokcehan/lf/releases/tag/r27)\n\n### Changed\n\n- Creation of log files are now disabled by default. Instead, a new command line option `-log` is provided.\n- `copy` selections are now kept after `paste` (#745). You can use `map p :paste; clear` to get the old behavior.\n- The socket file is now created in `XDG_RUNTIME_DIR` when set, with a fallback to the temporary directory otherwise.\n- 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.\n- The default icons are now replaced with ASCII characters to avoid font issues.\n\n### Added\n\n- 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).\n- A new `tempmarks` option is added to set some marks as temporary (#744).\n- The pattern `*filename` is added for colors and icons.\n- A new `calcdirsize` command is added to calculate directory sizes (#750).\n- Two new options `infotimefmtnew` and `infotimefmtold` are added to configure the time format used in `info` (#751).\n- Two new commands `jump-next` (default `]`) and `jump-prev` (default `[`) are added to navigate the jumplist (#755).\n- 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.\n- For Windows, an example `open` command is now provided in the PowerShell example configuration (#765).\n- 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).\n- A new special command `on-quit` is added to be able to run a command before quitting.\n- Two new commands `tag` and `tag-toggle` (default `t`) are now added to be able to tag files (#791).\n\n### Fixed\n\n- `Chmod` calls in the codebase are now removed to avoid TOC/TOU exploits. Instead, file permissions are now set at file creation.\n- Socket and log files are now created with only user permissions.\n- On Windows, `PWD` variable is now quoted properly.\n- Shell commands `%` and `&` are now run in a separate process group (#753).\n- Navigation initialization is now delayed after the evaluation of configuration files to avoid startup races and redundant loadings (#759).\n- The error message shown when the current working directory does not exist at startup is made more clear.\n- Trailing slashes in `PWD` variable are now handled properly.\n- Files with `stat` errors are now skipped while reading directories.\n\n## [r26](https://github.com/gokcehan/lf/releases/tag/r26)\n\n### Fixed\n\n- On Windows, input handling is properly resumed after shell commands.\n\n## [r25](https://github.com/gokcehan/lf/releases/tag/r25)\n\n### Added\n\n- A new `dironly` option is added to only show directories and hide regular files (#669).\n- A new `dircache` option is added to disable caching of directories (#673).\n- 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).\n- A new special command `pre-cd` is added to run a command before a directory is changed (#685).\n- `cmap` command now accepts all expressions similar to `map` (#686).\n\n### Fixed\n\n- Marking a symlink directory should now save the symlink path instead of the target path (#659).\n- A number of crashes have been fixed when the `hidden` option is changed.\n\n## [r24](https://github.com/gokcehan/lf/releases/tag/r24)\n\n### Fixed\n\n- Data directory is automatically created before the selection file is written.\n- An error is returned for remote commands when the given ID is not connected to the server.\n- Prompts longer than the width should not crash the program anymore.\n\n## [r23](https://github.com/gokcehan/lf/releases/tag/r23)\n\n### Changed\n\n- There has been some changes in the server protocol. Make sure to kill the old server process when you update to avoid errors.\n- 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.\n- 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.\n\n### Added\n\n- 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.\n- 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.\n- Errors for remote commands are now also shown in the output in addition to the server log file.\n- Bright ANSI color escape codes (i.e. 90-97 and 100-107) are now supported.\n\n### Fixed\n\n- Lookahead size for escape codes are increased to recognize longer escape codes used in some image previewers.\n- The file preview cache is invalidated when the terminal height changes to fill the screen properly.\n- The file preview cache is invalidated when the `drawbox` option changes and true image previews should be triggered to be drawn at updated positions.\n- A crash scenario is fixed when `hidden` option is changed.\n- Pane widths should now be calculated properly when big numbers are used in `ratios` (#622).\n- The special bookmark `'` is now preserved properly after `sync` commands (#624).\n- 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.\n- The prompt line should now scroll accordingly when the text is wider than the screen.\n- Text width in the prompt line should now be calculated properly when non-ASCII characters are involved.\n- Erase line escape codes (i.e. `\\033[K`) used in some command outputs should now be ignored properly.\n\n## [r22](https://github.com/gokcehan/lf/releases/tag/r22)\n\n### Added\n\n- A new `-config` command line flag is added to use a custom config file path (#587).\n- The current working directory is now exported as `PWD` environment variable (#591). Subshells in symlink directories should now start in their own paths properly.\n- The initial working directory is now exported as `OLDPWD` environment variable.\n- 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).\n- Using the command `cmd-enter` during `find` and `find-back` now jumps to the first match (#605).\n- A new `waitmsg` option is added to customize the prompt message after `shell-wait` commands (i.e. default `Press any key to continue`) (#604).\n\n### Fixed\n\n- A regression bug is fixed to print a newline in the prompt message properly after `shell-wait` commands.\n- A regression bug is fixed to avoid CPU stuck at 100% when the terminal is closed unexpectedly.\n- A regression bug is fixed to make shell commands use the alternate screen properly and keep the terminal history after quitting.\n- Enter keypad terminfo sequence is now sent on startup so the `delete` key should be recognized properly in `st` terminal.\n\n## [r21](https://github.com/gokcehan/lf/releases/tag/r21)\n\n### Changed\n\n- `cut` and `copy` do not follow symlinks anymore. Broken symlinks can now be selected for the `cut` and `copy` commands (#581).\n\n### Added\n\n- User name, group name, and hard link counts are now shown in the status line at the bottom when available.\n- Number of selected, copied, and cut files are now shown in the ruler at the bottom when they are non-zero.\n- 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.\n\n### Fixed\n\n- A longstanding issue regarding UI suspend/resume for shell commands in macOS is now fixed in Tcell.\n- Renaming a symlink to its target or a symlink to another with the same target should now be handled properly (#581).\n- Autocompletion in a directory containing a broken symlink should now work as intended (#581).\n- Setting `shellopts` to empty in the configuration file should not pass an extra empty argument to shell commands anymore.\n- 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`.\n\n## [r20](https://github.com/gokcehan/lf/releases/tag/r20)\n\n### Added\n\n- 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.\n\n### Fixed\n\n- 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.\n- Redundant preview loadings for the `search` and `find` commands are now avoided (#569).\n- Scanner now only considers ASCII characters for spaces and digits which should avoid unexpected splits in some non-ASCII inputs.\n\n## [r19](https://github.com/gokcehan/lf/releases/tag/r19)\n\n### Changed\n\n- Changes have been made to enable the use of true image previews. See the documentation and the previews wiki page for more information.\n  - 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.\n  - 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.\n  - A new `cleaner` option is added to set the path to a file to be executed when the preview is changed.\n  - Redundant preview loadings for movement commands are now avoided.\n- 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.\n- 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`).\n\n### Added\n\n- Full path, dir name, file name, and base name matching patterns are added to colors and icons. See the updated documentation for more information.\n- PowerShell keybinding example has been added to `etc/lfcd.ps1` (#532).\n- PowerShell autocompletion script has been added as `etc/lf.ps1` (#535).\n- Multiple `-command` flags can now be given (#552).\n- 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.\n- Commands `top` and `bottom` are now allowed in `cmap` mappings in addition to movement commands.\n\n### Fixed\n\n- Extension sorting should now handle extensions with different lengths properly (#539).\n- Heuristic used to show `info` should now take into account the `number` and `icons` options properly.\n- 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).\n- Unicode combining characters in texts should now be displayed properly.\n\n## [r18](https://github.com/gokcehan/lf/releases/tag/r18)\n\n### Changed\n\n- The `ignorecase` and `ignoredia` options should now also apply to sorting in addition to searching.\n- The `ignoredia` option is now enabled by default to be consistent with `ignorecase`.\n- 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.\n- The deprecated option `color256` is now removed.\n\n### Added\n\n- Two new command line commands `cmd-menu-complete` and `cmd-menu-complete-back` are added for completion menu cycling (#482).\n- Simple configuration files for Windows `etc/lfrc.cmd.example` and `etc/lfrc.ps1.example` are now added to the repository.\n- Bash completion script `etc/lf.bash` is now added to the repository.\n- Time formats in `info` option should now show the year instead of `hh:mm` for times older than the current year.\n\n### Fixed\n\n- Signals `SIGHUP`, `SIGQUIT`, and `SIGTERM` should now quit the program properly.\n- Setting `info` to an empty value should not print errors to the log file anymore.\n- Natural sorting is optimized to work faster using less memory.\n- Files and directories that incorrectly show modification times in the future (e.g. Linux builtin exFAT driver) should not cause CPU hogging anymore.\n- The keybinding example in `etc/lfcd.fish` is now updated to avoid hanging in shell commands.\n- Using the `bottom` command immediately after startup should not crash the program anymore.\n- Changing sorting options during sorting operations should not crash the program anymore.\n- Output in `shell-pipe` commands now uses lazy redrawing so that verbose commands should not block the program anymore.\n- The server is now daemonized properly on Unix so that it is not killed anymore when the controlling terminal is killed (#517).\n\n## [r17](https://github.com/gokcehan/lf/releases/tag/r17)\n\n### Changed\n\n- 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.\n  - 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.\n  - 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.\n  - Additional platforms are now supported and the list of pre-built binaries provided are updated accordingly.\n  - Wide characters are now displayed properly in Windows consoles.\n\n### Added\n\n- Descriptions of commands and options are now added to the documentation. Undocumented behaviors should now be considered documentation bugs and they can be reported.\n- 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.\n\n### Fixed\n\n- Corrupted history files should no longer crash the program.\n- The server now only listens connections from `localhost` on Windows so firewall permissions are not required anymore.\n- `push` commands that change the operation mode should now work consistently as expected.\n- Loading directories should now display the previous file list if any, which was a regression due to a bug fix in a previous release.\n- `shell-pipe` commands should now automatically update previews when necessary.\n- Errors from failed shell commands should not be overwritten by file information anymore.\n- 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).\n- Environment variables are now exported automatically for preview scripts without having to call a shell command first (#468).\n- 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).\n- Changing the `hiddenfiles` option should now automatically trigger directory updates when necessary.\n\n## [r16](https://github.com/gokcehan/lf/releases/tag/r16)\n\n### Added\n\n- Option values are now available in shell commands as environment variables with a prefix of `lf_` (e.g. `$lf_hidden`, `$lf_ratios`) (#448).\n\n### Fixed\n\n- Directories containing internal Windows links that show permission denied errors should now display properly.\n\n## [r15](https://github.com/gokcehan/lf/releases/tag/r15)\n\n### Changed\n\n- 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.\n- 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.\n- 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.\n\n### Added\n\n- Symbolic link destinations are now shown in the bottom status line (#374).\n- A new `hiddenfiles` option which takes a list of globs is implemented to customize which files should be `hidden` (#372).\n- Expressions consisting of multiple commands can now use counts (#394).\n- Moving operations now fall back to copy and then delete strategy automatically for cross-device linking.\n- The `hidden` option now works in Windows.\n- The `toggle` command can now take optional arguments to toggle given names instead of the current file (#409).\n- A new option `truncatechar` is implemented to customize the truncate character used in long filenames (#417).\n- Copy and move operations now display a success message when they are finished (#427).\n\n### Fixed\n\n- `SIGHUP` and `SIGTERM` signals are now properly handled. Log files should not remain when terminals are directly closed (#305).\n- The `info` option should now align properly when used with the `number` and `relativenumber` options (#373).\n- Tilde (`~`) is now only expanded at the beginning of the path for the `cd` and `select` commands (#373).\n- The `rename` command should now work properly with names differing only cases on case-insensitive filesystems.\n- Tab characters are now expanded to spaces in Windows.\n- The `incsearch` option now respects the search direction accordingly.\n- The server is now started in the home folder and will not hold mounted filesystems busy.\n- Trailing spaces in configuration files do not confuse the parser anymore.\n- Termbox version is updated to fix a keyboard problem in FreeBSD (#404).\n- Async commands do not leave zombie processes anymore (#407).\n- The `hidden` option now works consistently as expected when set at the initial launch.\n- The `rename` command should now select the new file after the operation.\n- The `rename` command should now handle absolute paths properly.\n- 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.\n- Previous errors in the bottom message line should not persist through the prompt usage anymore.\n- The `push` command should not fail with non-ASCII characters anymore.\n- The `select` command should not fail with broken links anymore.\n- The `load` command should not clear toggled broken links anymore.\n- Copy and move operations do not overwrite broken links anymore.\n\n## [r14](https://github.com/gokcehan/lf/releases/tag/r14)\n\n### Added\n\n- The `delete` command now shows a prompt with the current filename or the number of selected files (#206).\n- Backslash can now be escaped with a backslash even without quotes.\n- A new desktop entry file `lf.desktop` is added (#222).\n- 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.\n- A new shell completion for `zsh` is added to `etc/lf.zsh` (#239).\n- The `delete` command now works asynchronously and shows the progress (#238).\n- Completion and directory change scripts are added for `csh` and `tcsh` as `etc/lf.csh` and `etc/lfcd.csh` respectively (#264).\n- 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).\n\n### Fixed\n\n- Some directories with special permissions that previously show a file icon now shows a directory icon properly.\n- The `etc/lfcd.cmd` script can now also change to a different volume drive (#221).\n- The proper use of `setsid` for opening files is now added to the example configuration and the documentation.\n- The home directory abbreviation `~` is now only applied properly to paths starting with the home directory (#241).\n- The `rename` command now cancels the operation if the old and new paths are the same (#266).\n- Autocompletion and word movements should now work properly with all Unicode characters.\n- The `shell-pipe` command which was broken some time ago should now work as expected.\n- 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).\n\n## [r13](https://github.com/gokcehan/lf/releases/tag/r13)\n\n### Added\n\n- A new `wrapscroll` option is added to wrap top and bottom while scrolling (#166).\n- The `up`, `down` movement commands and their variants, `updir`, and `open` are now allowed in `cmap` mappings.\n- Two new `glob-select` and `glob-unselect` commands are added to use globbing for toggling files (#184).\n- A new `mark-remove` (default `\"`) command is added to allow removing marks (#190).\n- Icon support is added with the `icon` option. See the wiki page for more details.\n- A new builtin `rename` command is added (#197).\n\n### Fixed\n\n- The `cmd-history-next` command now remains in Command-line mode after the last item (#168).\n- The `select` command does not change directories anymore when used on a directory.\n- The working directory is now changed to the first argument when it is a directory.\n- The `ratios` option is now checked before `preview` to avoid crashes (#174).\n- Previous error messages are now cleared after successful commands (#192).\n- Symlink to directories are now colored as symlinks (#195).\n- Permission errors for directories are now displayed properly instead of showing as empty (#203).\n\n## [r12](https://github.com/gokcehan/lf/releases/tag/r12)\n\n### Added\n\n- Go modules replaced `godep` for dependency management. Package maintainers may need to update accordingly.\n- A new `errorfmt` option is added to customize the colors and attributes of error messages.\n\n### Fixed\n\n- Autocompletion for searches now complete filenames instead of commands.\n- 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.\n- On Windows, quotes are added to the exported values `$f`, `$fs`, and `$fx` to handle filenames with spaces properly.\n- On Windows, filenames starting with `.` characters are now shown to avoid crashes when filenames show up as empty.\n\n## [r11](https://github.com/gokcehan/lf/releases/tag/r11)\n\n### Changed\n\n- 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.\n- Preview messages (i.e. `empty`, `binary`, and `loading...`) are now shown with the reverse attribute.\n\n### Added\n\n- Copy and move operations now run asynchronously and the progress is shown in the bottom ruler.\n- 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.\n\n### Fixed\n\n- Terminal initialization errors are now shown in the terminal instead of the log file.\n\n## [r10](https://github.com/gokcehan/lf/releases/tag/r10)\n\n### Changed\n\n- 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.\n\n### Added\n\n- A new command line flag `-command` has been added to execute a command on client initialization (#135).\n- A `select` command is now executed after initialization if the first command line argument is a file.\n- A prompting mechanism has been added to the builtin `delete` command.\n\n### Fixed\n\n- Input and output in `shell-pipe` commands were broken with the `cmap` patch. This should now work as before.\n- 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.\n- `read` and shell commands should now also work when typed manually (e.g. typing `:shell` should switch the prefix to `$`).\n- Configuration files are now read after initialization.\n- Background colors are removed from defaults to avoid confusion with selection highlighting.\n\n## [r9](https://github.com/gokcehan/lf/releases/tag/r9)\n\n### Changed\n\n- 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.\n\n### Added\n\n- A new `incsearch` option is added to enable incremental matching while searching.\n- Two new options `ignoredia` and `smartdia` are added to ignore diacritics in Latin letters for `search` and `find` (#118).\n- 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.\n- 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.\n- A new `fish` completion script is added to the `etc` folder (#131).\n- Two new options `number` and `relativenumber` are added to enable line numbers in directories (#133).\n\n### Fixed\n\n- Autocompletion should now show only a single match for redefined builtin commands.\n\n## [r8](https://github.com/gokcehan/lf/releases/tag/r8)\n\n### Added\n\n- 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.\n- A new `quit` command is added to the server protocol to quit the server.\n- A new `$LF_LEVEL` environment variable is added to show the nesting level.\n\n### Fixed\n\n- The `load` and `reload` commands now work properly when the current directory is deleted. Also `lf` does not start in deleted directories anymore.\n- The server is now started as a detached process in Windows so its lifetime is not tied to the command line window anymore.\n- 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.\n- The old index is now kept when the current selection is deleted.\n- The `shell-pipe` command now triggers `load` instead of `reload`.\n- Error messages are now more informative when `lf` fails to start due to either `$HOME` or `$USER` variables being empty or not set.\n- Searching for the next/previous item is now based on the direction of the initial search.\n\n## [r7](https://github.com/gokcehan/lf/releases/tag/r7)\n\n### Changed\n\n- The system-wide configuration path on Unix is changed from `/etc/lfrc` to `/etc/lf/lfrc`.\n\n### Added\n\n- 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.\n- A new `doc` command (default `<f-1>`) is added to view the documentation in a pager.\n- 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.\n- The history is now saved in a file in the data folder which can be found in the documentation.\n\n## [r6](https://github.com/gokcehan/lf/releases/tag/r6)\n\n### Changed\n\n- 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`.\n- The special command `open-file` to configure file opening is renamed to `open`.\n\n### Added\n\n- 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.\n- The special keys `<home>`, `<end>`, `<pgup>`, and `<pgdn>` are mapped to the `top`, `bottom`, `page-up`, and `page-down` commands respectively by default.\n- A new command `source` is added to read a configuration file.\n- 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.\n- 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.\n- 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.\n\n### Fixed\n\n- Executable completion now works on Windows as well.\n\n## [r5](https://github.com/gokcehan/lf/releases/tag/r5)\n\n### Added\n\n- The server is automatically restarted on startup if it does not work anymore.\n- 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.\n- A new command `load` is added to refresh only modified files and directories which is more efficient than `reload` command.\n\n### Fixed\n\n- `cmd-word-back` does not change the command line anymore.\n- Modified files and directories are automatically detected and refreshed when they are loaded from cache.\n- All clients are now refreshed when the `put` command is used.\n- The correct hidden parent is selected when the `hidden` option is changed.\n- The preview is properly updated when the `hidden` option is changed.\n\n## [r4](https://github.com/gokcehan/lf/releases/tag/r4)\n\n### Changed\n\n- The following commands are renamed for clarity and consistency:\n  - `bot` is renamed to `bottom`\n  - `cmd-delete-word` is renamed to `cmd-delete-unix-word`\n  - `cmd-beg` is renamed to `cmd-home`\n  - `cmd-delete-beg` is renamed to `cmd-delete-home`\n  - `cmd-comp` is renamed to `cmd-complete`\n  - `cmd-hist-next` is renamed to `cmd-history-next`\n  - `cmd-hist-prev` is renamed to `cmd-history-prev`\n  - `cmd-put` is renamed to `cmd-yank`\n\n### Added\n\n- 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.\n- The following command line commands and their default alt keybindings have been added:\n  - `cmd-word` with `<a-f>`\n  - `cmd-word-back` with `<a-b>`\n  - `cmd-capitalize-word` with `<a-c>`\n  - `cmd-delete-word` with `<a-d>`\n  - `cmd-uppercase-word` with `<a-u>`\n  - `cmd-lowercase-word` with `<a-l>`\n  - `cmd-transpose-word` with `<a-t>`\n\n### Fixed\n\n- The default editor, pager, and opener commands should now work in Windows. Opener still only works with paths without spaces though.\n- 8-bit color codes and attributes are not confused anymore.\n- History selection is disabled when a `shell-pipe` command is running.\n- Searches are now excluded from the history.\n\n## [r3](https://github.com/gokcehan/lf/releases/tag/r3)\n\n### Changed\n\n- 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.\n\n### Added\n\n- Pressed keys are now shown in the ruler when they are not matched yet.\n- 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.\n- Support for the `$LS_COLORS` and `$LSCOLORS` environment variables are added for color customization (#96). See the updated documentation for more information.\n- A new option `drawbox` is added to draw a box around panes.\n\n### Fixed\n\n- Resize events that change the height are now handled properly.\n- Changes in sorting methods and options are checked for cached directories and these directories are sorted again if necessary while loading.\n- A `~` character is added as a suffix to file names when they do not fit in the window.\n\n## [r2](https://github.com/gokcehan/lf/releases/tag/r2)\n\n### Changed\n\n- Shell command names are shortened (e.g. `read-shell-wait` is renamed to `shell-wait`).\n\n### Added\n\n- 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.\n- A new command named `cmd-interrupt` (default `<c-c>`) is introduced to interrupt the current `shell-pipe` command.\n- A new command named `select` is introduced that changes the current file selection to its argument.\n\n### Fixed\n\n- 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.\n\n## [r1](https://github.com/gokcehan/lf/releases/tag/r1)\n\n### Added\n\n- Initial release\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# Contributing\n\nCode contributions are always welcomed in lf.\n\nIf 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)**.\n\nFor bug fixes, you can simply send a pull request.\n\n## Code conventions\n\nIn 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:\n\n- Global variables are best avoided except when they are not.\n  Global variable names are prefixed with `g` as in `gFooBar`.\n  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.\n- Type and function names are small case as in `fooBar` since we don't use exporting.\n- 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`.\n- Run `go fmt` to ensure that files are formatted correctly.\n- Consider using [conventional](https://www.conventionalcommits.org/) commit messages.\n\nUse the surrounding code as reference when in doubt as usual.\n\n## Adding a new option\n\nAdding a new option usually requires the following steps:\n\n- Add option name/type to `gOpts` struct in `opts.go`\n- Add default option value to `init` function in `opts.go`\n- Add option evaluation logic to `setExpr.eval` in `eval.go`\n- Implement the option somewhere in the code\n- Add option name and its default value to `Quick Reference` and `Options` sections in `doc.md`\n- Run `gen/doc.sh` to update the documentation (optional as it requires `docker`/`podman`, but appreciated)\n- Commit your changes and send a pull request\n\nOptions should be defined in alphabetical order, but note that boolean options are defined first in `eval.go` as they require special handling.\n\n## Adding a new builtin command\n\nAdding a new command usually requires the following steps:\n\n- Add default key if any to `init` function in `opts.go`\n- Add command evaluation logic to `callExpr.eval` in `eval.go`\n- Implement the command somewhere in the code\n- Add command name to `gCmdWords` in `complete.go` for tab completion\n- Add command name to `Quick Reference` and `Commands` sections in `doc.md`\n- Run `gen/doc.sh` to update the documentation (optional as it requires `docker`/`podman`, but appreciated)\n- Commit your changes and send a pull request\n\nCommands should be defined in alphabetical order, but note that commands are first organized roughly into the following sections in `eval.go` for clarity:\n\n- Navigation\n- Selection\n- File-related operations\n- Shell commands\n- Finding and searching\n- Filtering\n- Marks\n- Tags\n- Echoing\n- Miscellaneous commands\n- Visual mode\n- Command-line mode commands\n- Hook commands\n\n## Platform specific code\n\nThere are two files named `os.go` and `os_windows.go` for Unix and Windows specific code respectively.\nIf you add something to either of these files but not the other, you probably break the build for the other platform.\nIf your addition works the same in both platforms, your addition probably belongs to `main.go` instead.\n\nThere are also different variants of the `df` functionality provided by `df_openbsd.go`, `df_statfs.go`, `df_statvfs.go` and `df_windows.go`.\nWhere applicable, ensure that any changes you make are reflected across all of these files for consistency.\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2016 Gökçehan Kara\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# LF\n\n[Doc](doc.md)\n| [Wiki](https://github.com/gokcehan/lf/wiki)\n| [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org) (with IRC bridge)\n\n[![Go Build](https://github.com/gokcehan/lf/actions/workflows/go.yml/badge.svg)](https://github.com/gokcehan/lf/actions/workflows/go.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/gokcehan/lf)](https://goreportcard.com/report/github.com/gokcehan/lf)\n\n`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.\nSee [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.\n\n![icons-and-border](https://github.com/user-attachments/assets/d5623462-05ab-4921-aeb3-d377d4732f9e)\n![image-preview](https://github.com/user-attachments/assets/9ff42a21-19dd-42fa-8407-5d055aa9d561)\n![new-features](https://github.com/user-attachments/assets/2a9a32aa-a764-438f-a810-e687e979dcee)\n\n## Features\n\n- Cross-platform (Linux, macOS, BSDs, Windows)\n- Single binary without any runtime dependencies\n- Fast startup and low memory footprint due to native code and static binaries\n- Asynchronous IO operations to avoid UI locking\n- Server/client architecture and remote commands to manage multiple instances\n- Extendable and configurable with shell commands\n- Customizable keybindings (vi and readline defaults)\n- A reasonable set of other features (see the [documentation](doc.md))\n\n## Non-Features\n\n- Tabs or windows (better handled by window manager or terminal multiplexer)\n- Builtin pager/editor (better handled by your pager/editor of choice)\n- Builtin commands for file operations (better handled by the underlying shell tools including but not limited to `mkdir`, `touch`, `chmod`, `chown`, `chgrp`, and `ln`)\n\n## Installation\n\nSee [packages](https://github.com/gokcehan/lf/wiki/Packages) for community maintained packages.\n\nSee [releases](https://github.com/gokcehan/lf/releases) for pre-built binaries.\n\nBuilding from the source requires [Go](https://go.dev/).\n\nOn Unix:\n\n```bash\nenv CGO_ENABLED=0 go install -ldflags=\"-s -w\" github.com/gokcehan/lf@latest\n```\n\nOn Windows `cmd`:\n\n```cmd\nset CGO_ENABLED=0\ngo install -ldflags=\"-s -w\" github.com/gokcehan/lf@latest\n```\n\nOn Windows `PowerShell`:\n\n```powershell\n$env:CGO_ENABLED = '0'\ngo install -ldflags=\"-s -w\" github.com/gokcehan/lf@latest\n```\n\n## Usage\n\nAfter the installation `lf` command should start the application in the current directory.\n\nRun `lf -help` to see [command line options](doc.md#options).\n\nRun `lf -doc` to see the [documentation](doc.md).\n\nSee [etc](etc) directory to integrate `lf` to your shell and/or editor.\nExample configuration files along with example colors and icons files can also be found in this directory.\n\nSee [integrations](https://github.com/gokcehan/lf/wiki/Integrations) to integrate `lf` to other tools.\n\nSee [tips](https://github.com/gokcehan/lf/wiki/Tips) for more examples.\n\n## Contributing\n\nSee [contributing](CONTRIBUTING.md) for guidelines.\n"
  },
  {
    "path": "app.go",
    "content": "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/filepath\"\n\t\"slices\"\n\t\"strings\"\n\t\"syscall\"\n\t\"time\"\n)\n\ntype app struct {\n\tui              *ui            // ui state (screen, windows, input)\n\tnav             *nav           // navigation state (dirs, cursor, selections, preview, caches)\n\tticker          *time.Ticker   // refresh ticker if `period` > 0\n\tquitChan        chan struct{}  // signals main loop to exit\n\tcmd             *exec.Cmd      // currently running % (shell-pipe) command\n\tcmdIn           io.WriteCloser // stdin writer for running % command\n\tcmdOutBuf       []byte         // output of running % command\n\tcmdHistory      []string       // command history entries\n\tcmdHistoryBeg   int            // index where commands from this session start in cmdHistory\n\tcmdHistoryInd   int            // history navigation offset from most recent\n\tcmdHistoryInput *string        // initial input used as prefix filter while browsing history\n\tmenuCompActive  bool           // whether completion cycling is active\n\tmenuCompTmp     []string       // token snapshot taken when completion cycling starts, used for `cmd-menu-discard`\n\tmenuComps       []compMatch    // completion candidates for active prompt\n\tmenuCompInd     int            // index of selected completion candidate (-1: none selected)\n\tselectionOut    []string       // paths to output on exit, used for `-print-selection` and `-selection-path`\n\twatch           *watch         // fs watcher if `watch` is enabled\n\tquitting        bool           // guard to prevent re-entering quit logic\n}\n\nfunc newApp(ui *ui, nav *nav) *app {\n\tquitChan := make(chan struct{}, 1)\n\n\tapp := &app{\n\t\tui:       ui,\n\t\tnav:      nav,\n\t\tticker:   new(time.Ticker),\n\t\tquitChan: quitChan,\n\t\twatch:    newWatch(nav.dirChan, nav.fileChan, nav.delChan),\n\t}\n\n\tsigChan := make(chan os.Signal, 1)\n\tsignal.Notify(sigChan, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM)\n\tgo func() {\n\t\tfor {\n\t\t\tswitch <-sigChan {\n\t\t\tcase os.Interrupt:\n\t\t\tcase syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM:\n\t\t\t\tapp.quit()\n\t\t\t\tos.Exit(3)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}()\n\n\treturn app\n}\n\nfunc (app *app) quit() {\n\t// Using synchronous shell commands for `on-quit` can cause this to be\n\t// called again, so a guard variable is introduced here to prevent an\n\t// infinite loop.\n\tif app.quitting {\n\t\treturn\n\t}\n\tapp.quitting = true\n\n\tonQuit(app)\n\n\tif gOpts.history {\n\t\tif err := app.writeHistory(); err != nil {\n\t\t\tlog.Printf(\"writing history file: %s\", err)\n\t\t}\n\t}\n\tif !gSingleMode {\n\t\tif _, err := remote(fmt.Sprintf(\"drop %d\", gClientID)); err != nil {\n\t\t\tlog.Printf(\"dropping connection: %s\", err)\n\t\t}\n\t\tif gOpts.autoquit {\n\t\t\tif _, err := remote(\"quit\"); err != nil {\n\t\t\t\tlog.Printf(\"auto quitting server: %s\", err)\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc (app *app) readFile(path string) {\n\tlog.Printf(\"reading file: %s\", path)\n\n\tf, err := os.Open(path)\n\tif err != nil {\n\t\tapp.ui.echoerrf(\"opening file: %s\", err)\n\t\treturn\n\t}\n\tdefer f.Close()\n\n\tp := newParser(f)\n\n\tfor p.parse() {\n\t\tp.expr.eval(app, nil)\n\t}\n\n\tif p.err != nil {\n\t\tapp.ui.echoerrf(\"%s\", p.err)\n\t}\n}\n\nfunc loadFiles() (clipboard clipboard, err error) {\n\tfiles, err := os.Open(gFilesPath)\n\tif os.IsNotExist(err) {\n\t\terr = nil\n\t\treturn\n\t}\n\tif err != nil {\n\t\terr = fmt.Errorf(\"opening file selections file: %w\", err)\n\t\treturn\n\t}\n\tdefer files.Close()\n\n\ts := bufio.NewScanner(files)\n\n\tif !s.Scan() {\n\t\terr = fmt.Errorf(\"scanning file list: %w\", cmp.Or(s.Err(), io.EOF))\n\t\treturn\n\t}\n\n\tswitch s.Text() {\n\tcase \"copy\":\n\t\tclipboard.mode = clipboardCopy\n\tcase \"move\":\n\t\tclipboard.mode = clipboardCut\n\tdefault:\n\t\terr = fmt.Errorf(\"unexpected option to copy file(s): %s\", s.Text())\n\t\treturn\n\t}\n\n\tfor s.Scan() && s.Text() != \"\" {\n\t\tclipboard.paths = append(clipboard.paths, s.Text())\n\t}\n\n\tif s.Err() != nil {\n\t\terr = fmt.Errorf(\"scanning file list: %w\", s.Err())\n\t\treturn\n\t}\n\n\tlog.Printf(\"loading clipboard: %v\", clipboard.paths)\n\n\treturn\n}\n\nfunc saveFiles(clipboard clipboard) error {\n\tif err := os.MkdirAll(filepath.Dir(gFilesPath), os.ModePerm); err != nil {\n\t\treturn fmt.Errorf(\"creating data directory: %w\", err)\n\t}\n\n\tfiles, err := os.Create(gFilesPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"opening file selections file: %w\", err)\n\t}\n\tdefer files.Close()\n\n\tlog.Printf(\"saving files: %v\", clipboard.paths)\n\n\tvar clipboardModeStr string\n\tif clipboard.mode == clipboardCopy {\n\t\tclipboardModeStr = \"copy\"\n\t} else {\n\t\tclipboardModeStr = \"move\"\n\t}\n\tif _, err := fmt.Fprintln(files, clipboardModeStr); err != nil {\n\t\treturn fmt.Errorf(\"write clipboard mode to file: %w\", err)\n\t}\n\n\tfor _, path := range clipboard.paths {\n\t\tif _, err := fmt.Fprintln(files, path); err != nil {\n\t\t\treturn fmt.Errorf(\"write path to file: %w\", err)\n\t\t}\n\t}\n\n\treturn files.Sync()\n}\n\nfunc (app *app) readHistory() error {\n\tf, err := os.Open(gHistoryPath)\n\tif os.IsNotExist(err) {\n\t\treturn nil\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"opening history file: %w\", err)\n\t}\n\tdefer f.Close()\n\n\tscanner := bufio.NewScanner(f)\n\tfor scanner.Scan() {\n\t\tcmd := scanner.Text()\n\t\tif len(cmd) < 1 || !slices.Contains([]string{\":\", \"$\", \"!\", \"%\", \"&\"}, cmd[:1]) {\n\t\t\tcontinue\n\t\t}\n\t\tapp.cmdHistory = append(app.cmdHistory, cmd)\n\t}\n\n\tapp.cmdHistoryBeg = len(app.cmdHistory)\n\n\tif err := scanner.Err(); err != nil {\n\t\treturn fmt.Errorf(\"reading history file: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (app *app) writeHistory() error {\n\tif len(app.cmdHistory) == 0 {\n\t\treturn nil\n\t}\n\n\tlocal := slices.Clone(app.cmdHistory[app.cmdHistoryBeg:])\n\tapp.cmdHistory = nil\n\n\tif err := app.readHistory(); err != nil {\n\t\treturn fmt.Errorf(\"reading history file: %w\", err)\n\t}\n\n\tapp.cmdHistory = append(app.cmdHistory, local...)\n\tif len(app.cmdHistory) > 1000 {\n\t\tapp.cmdHistory = app.cmdHistory[len(app.cmdHistory)-1000:]\n\t}\n\n\tif err := os.MkdirAll(filepath.Dir(gHistoryPath), os.ModePerm); err != nil {\n\t\treturn fmt.Errorf(\"creating data directory: %w\", err)\n\t}\n\n\tf, err := os.Create(gHistoryPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating history file: %w\", err)\n\t}\n\tdefer f.Close()\n\n\tfor _, cmd := range app.cmdHistory {\n\t\tif _, err = fmt.Fprintln(f, cmd); err != nil {\n\t\t\treturn fmt.Errorf(\"writing history file: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// loop is the main event loop of the application. Expressions are read from\n// the client and the server on separate goroutines and sent here over channels\n// for evaluation. Similarly directories and regular files are also read in\n// separate goroutines and sent here for update.\nfunc (app *app) loop() {\n\tgo app.nav.preloadLoop(app.ui)\n\tgo app.nav.previewLoop(app.ui)\n\n\tvar serverChan <-chan expr\n\tif !gSingleMode {\n\t\tserverChan = readExpr()\n\t}\n\n\tgo app.ui.readEvents()\n\n\tif gConfigPath != \"\" {\n\t\tif _, err := os.Stat(gConfigPath); !os.IsNotExist(err) {\n\t\t\tapp.readFile(gConfigPath)\n\t\t} else {\n\t\t\tlog.Printf(\"config file does not exist: %s\", err)\n\t\t}\n\t} else {\n\t\tfor _, path := range gConfigPaths {\n\t\t\tif _, err := os.Stat(path); !os.IsNotExist(err) {\n\t\t\t\tapp.readFile(path)\n\t\t\t}\n\t\t}\n\t}\n\n\tfor _, cmd := range gCommands {\n\t\tp := newParser(strings.NewReader(cmd))\n\n\t\tfor p.parse() {\n\t\t\tp.expr.eval(app, nil)\n\t\t}\n\n\t\tif p.err != nil {\n\t\t\tapp.ui.echoerrf(\"%s\", p.err)\n\t\t}\n\t}\n\n\tapp.nav.addJumpList()\n\n\tif gSelect != \"\" {\n\t\tgo func() {\n\t\t\tlstat, err := os.Lstat(gSelect)\n\t\t\tif err != nil {\n\t\t\t\tapp.ui.exprChan <- &callExpr{\"echoerr\", []string{err.Error()}, 1}\n\t\t\t} else if lstat.IsDir() {\n\t\t\t\tapp.ui.exprChan <- &callExpr{\"cd\", []string{gSelect}, 1}\n\t\t\t} else {\n\t\t\t\tapp.ui.exprChan <- &callExpr{\"select\", []string{gSelect}, 1}\n\t\t\t}\n\t\t}()\n\t}\n\n\tfor {\n\t\tselect {\n\t\tcase <-app.quitChan:\n\t\t\tif app.nav.copyJobs > 0 {\n\t\t\t\tapp.ui.echoerr(\"quit: copy operation in progress\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif app.nav.moveTotal > 0 {\n\t\t\t\tapp.ui.echoerr(\"quit: move operation in progress\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif app.nav.deleteTotal > 0 {\n\t\t\t\tapp.ui.echoerr(\"quit: delete operation in progress\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tapp.quit()\n\n\t\t\tapp.nav.previewChan <- \"\"\n\n\t\t\tlog.Printf(\"*************** closing client, PID: %d ***************\", gClientID)\n\n\t\t\treturn\n\t\tcase n := <-app.nav.copyJobsChan:\n\t\t\tapp.nav.copyJobs += n\n\t\t\tapp.ui.draw(app.nav)\n\t\tcase n := <-app.nav.copyBytesChan:\n\t\t\tapp.nav.copyBytes += n\n\t\t\t// n is usually 32*1024B (default io.Copy() buffer) so update roughly per 32KB x 128 = 4MB copied\n\t\t\tif app.nav.copyUpdate++; app.nav.copyUpdate >= 128 {\n\t\t\t\tapp.nav.copyUpdate = 0\n\t\t\t\tapp.ui.draw(app.nav)\n\t\t\t}\n\t\tcase n := <-app.nav.copyTotalChan:\n\t\t\tapp.nav.copyTotal += n\n\t\t\tif n < 0 {\n\t\t\t\tapp.nav.copyBytes += n\n\t\t\t}\n\t\t\tif app.nav.copyTotal == 0 {\n\t\t\t\tapp.nav.copyUpdate = 0\n\t\t\t}\n\t\t\tapp.ui.draw(app.nav)\n\t\tcase n := <-app.nav.moveCountChan:\n\t\t\tapp.nav.moveCount += n\n\t\t\tif app.nav.moveUpdate++; app.nav.moveUpdate >= 1000 {\n\t\t\t\tapp.nav.moveUpdate = 0\n\t\t\t\tapp.ui.draw(app.nav)\n\t\t\t}\n\t\tcase n := <-app.nav.moveTotalChan:\n\t\t\tapp.nav.moveTotal += n\n\t\t\tif n < 0 {\n\t\t\t\tapp.nav.moveCount += n\n\t\t\t}\n\t\t\tif app.nav.moveTotal == 0 {\n\t\t\t\tapp.nav.moveUpdate = 0\n\t\t\t}\n\t\t\tapp.ui.draw(app.nav)\n\t\tcase n := <-app.nav.deleteCountChan:\n\t\t\tapp.nav.deleteCount += n\n\t\t\tif app.nav.deleteUpdate++; app.nav.deleteUpdate >= 1000 {\n\t\t\t\tapp.nav.deleteUpdate = 0\n\t\t\t\tapp.ui.draw(app.nav)\n\t\t\t}\n\t\tcase n := <-app.nav.deleteTotalChan:\n\t\t\tapp.nav.deleteTotal += n\n\t\t\tif n < 0 {\n\t\t\t\tapp.nav.deleteCount += n\n\t\t\t}\n\t\t\tif app.nav.deleteTotal == 0 {\n\t\t\t\tapp.nav.deleteUpdate = 0\n\t\t\t}\n\t\t\tapp.ui.draw(app.nav)\n\t\tcase d := <-app.nav.dirChan:\n\t\t\tvar oldCurrPath string\n\t\t\tif curr := app.nav.currFile(); curr != nil {\n\t\t\t\toldCurrPath = curr.path\n\t\t\t}\n\n\t\t\tprev, ok := app.nav.dirCache[d.path]\n\t\t\tif ok {\n\t\t\t\td.ind = prev.ind\n\t\t\t\td.pos = prev.pos\n\t\t\t\td.visualAnchor = min(prev.visualAnchor, len(d.files)-1)\n\t\t\t\td.visualWrap = prev.visualWrap\n\t\t\t\td.filter = prev.filter\n\t\t\t\td.sort()\n\t\t\t\td.sel(prev.name(), app.nav.height)\n\t\t\t}\n\t\t\tapp.nav.dirCache[d.path] = d\n\n\t\t\tapp.nav.position()\n\n\t\t\tif curr := app.nav.currFile(); curr != nil {\n\t\t\t\tif curr.path != oldCurrPath {\n\t\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tapp.watchDir(d)\n\n\t\t\t// Avoid flickering UI and multiple, unnecessary `on-load` calls\n\t\t\t// triggered by Git commands executed inside the users `on-load`\n\t\t\t// command (often used to add git symbols using `addcustominfo`).\n\t\t\t// TODO: Should `watch` also ignore `.git` directories?\n\t\t\tif filepath.Base(d.path) != \".git\" {\n\t\t\t\tpaths := make([]string, len(d.allFiles))\n\t\t\t\tfor i, file := range d.allFiles {\n\t\t\t\t\tpaths[i] = file.path\n\t\t\t\t}\n\t\t\t\tonLoad(app, paths)\n\t\t\t}\n\n\t\t\tif d.path == app.nav.currDir().path {\n\t\t\t\tapp.nav.preload()\n\t\t\t}\n\n\t\t\tapp.ui.draw(app.nav)\n\t\tcase r := <-app.nav.regChan:\n\t\t\tapp.nav.regCache[r.path] = r\n\n\t\t\tif curr := app.nav.currFile(); curr != nil {\n\t\t\t\tif r.path == curr.path {\n\t\t\t\t\tapp.ui.sxScreen.forceClear = true\n\t\t\t\t\tif gOpts.preload && r.volatile {\n\t\t\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tapp.ui.draw(app.nav)\n\t\tcase f := <-app.nav.fileChan:\n\t\t\tfor _, dir := range app.nav.dirCache {\n\t\t\t\tif dir.path != filepath.Dir(f.path) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tfor i := range dir.allFiles {\n\t\t\t\t\tif dir.allFiles[i].path == f.path {\n\t\t\t\t\t\tdir.allFiles[i] = f\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tname := dir.name()\n\t\t\t\tdir.sort()\n\t\t\t\tdir.sel(name, app.nav.height)\n\t\t\t}\n\n\t\t\tdelete(app.nav.regCache, f.path)\n\t\t\tapp.ui.loadFile(app, false)\n\t\t\tonLoad(app, []string{f.path})\n\t\t\tapp.ui.draw(app.nav)\n\t\tcase path := <-app.nav.delChan:\n\t\t\tdeletePathRecursive(app.nav.selections, path)\n\t\t\tif len(app.nav.selections) == 0 {\n\t\t\t\tapp.nav.selectionInd = 0\n\t\t\t}\n\n\t\t\tdeletePathRecursive(app.nav.regCache, path)\n\t\t\tdeletePathRecursive(app.nav.dirCache, path)\n\n\t\t\tfor _, dirPath := range app.nav.dirPaths {\n\t\t\t\tif dirPath == path {\n\t\t\t\t\tif err := app.nav.cd(filepath.Dir(path)); err != nil {\n\t\t\t\t\t\tlog.Print(err)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\tcase ev := <-app.ui.evChan:\n\t\t\te := app.ui.readEvent(ev, app.nav)\n\t\t\tif e == nil {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\te.eval(app, nil)\n\t\tloop:\n\t\t\tfor {\n\t\t\t\tselect {\n\t\t\t\tcase ev := <-app.ui.evChan:\n\t\t\t\t\te = app.ui.readEvent(ev, app.nav)\n\t\t\t\t\tif e == nil {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\te.eval(app, nil)\n\t\t\t\tdefault:\n\t\t\t\t\tbreak loop\n\t\t\t\t}\n\t\t\t}\n\t\t\tapp.ui.draw(app.nav)\n\t\tcase e := <-app.ui.exprChan:\n\t\t\te.eval(app, nil)\n\t\t\tapp.ui.draw(app.nav)\n\t\tcase e := <-serverChan:\n\t\t\te.eval(app, nil)\n\t\t\tapp.ui.draw(app.nav)\n\t\tcase <-app.ticker.C:\n\t\t\tapp.nav.renew()\n\t\t\tapp.ui.loadFile(app, false)\n\t\tcase <-app.nav.previewTimer.C:\n\t\t\tapp.ui.draw(app.nav)\n\t\tcase <-app.nav.preloadTimer.C:\n\t\t\tapp.nav.preload()\n\t\t}\n\t}\n}\n\nfunc (app *app) runCmdSync(cmd *exec.Cmd, pauseAfter bool) {\n\tapp.nav.previewChan <- \"\"\n\n\tif err := app.ui.suspend(); err != nil {\n\t\tlog.Printf(\"suspend: %s\", err)\n\t}\n\tdefer func() {\n\t\tif err := app.ui.resume(); err != nil {\n\t\t\tapp.quit()\n\t\t\tos.Exit(3)\n\t\t}\n\t}()\n\n\tif err := cmd.Run(); err != nil {\n\t\tapp.ui.echoerrf(\"running shell: %s\", err)\n\t}\n\tif pauseAfter {\n\t\tanyKey()\n\t}\n\n\tapp.ui.loadFile(app, true)\n\tapp.nav.renew()\n}\n\n// runShell is used to run a shell command. Modes are as follows:\n//\n//\tPrefix  Wait  Async  Stdin  Stdout  Stderr  UI action\n//\t$       No    No     Yes    Yes     Yes     Pause and then resume\n//\t%       No    No     Yes    Yes     Yes     Statline for input/output\n//\t!       Yes   No     Yes    Yes     Yes     Pause and then resume\n//\t&       No    Yes    No     No      No      Do nothing\nfunc (app *app) runShell(s string, args []string, prefix string) {\n\tapp.nav.exportFiles()\n\tapp.ui.exportSizes()\n\tapp.exportMode()\n\texportLfPath()\n\texportOpts()\n\n\tgState.mutex.Lock()\n\tgState.data[\"maps\"] = listBinds(map[string]map[string]expr{\n\t\t\"n\": gOpts.nkeys,\n\t\t\"v\": gOpts.vkeys,\n\t})\n\tgState.data[\"nmaps\"] = listBinds(map[string]map[string]expr{\n\t\t\"n\": gOpts.nkeys,\n\t})\n\tgState.data[\"vmaps\"] = listBinds(map[string]map[string]expr{\n\t\t\"v\": gOpts.vkeys,\n\t})\n\tgState.data[\"cmaps\"] = listBinds(map[string]map[string]expr{\n\t\t\"c\": gOpts.cmdkeys,\n\t})\n\tgState.data[\"cmds\"] = listCmds(gOpts.cmds)\n\tgState.data[\"jumps\"] = listJumps(app.nav.jumpList, app.nav.jumpListInd)\n\tgState.data[\"history\"] = listHistory(app.cmdHistory)\n\tgState.data[\"files\"] = listFilesInCurrDir(app.nav)\n\tgState.mutex.Unlock()\n\n\tcmd := shellCommand(s, args)\n\n\tswitch prefix {\n\tcase \"$\", \"!\":\n\t\tcmd.Stdin = os.Stdin\n\t\tcmd.Stdout = os.Stderr\n\t\tcmd.Stderr = os.Stderr\n\n\t\tapp.runCmdSync(cmd, prefix == \"!\")\n\t\treturn\n\t}\n\n\t// We are running the command asynchronously\n\tvar inReader, inWriter, outReader, outWriter *os.File\n\tif prefix == \"%\" {\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\n\t\t// [exec.Cmd.StdoutPipe] cannot be used as it requires the output to be fully\n\t\t// read before calling [exec.Cmd.Wait], however in this case Cmd.Wait should\n\t\t// only wait for the command to finish executing regardless of whether the\n\t\t// output has been fully read or not.\n\t\tinReader, inWriter, err := os.Pipe()\n\t\tif err != nil {\n\t\t\tlog.Printf(\"creating input pipe: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tcmd.Stdin = inReader\n\t\tapp.cmdIn = inWriter\n\n\t\toutReader, outWriter, err = os.Pipe()\n\t\tif err != nil {\n\t\t\tlog.Printf(\"creating output pipe: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tcmd.Stdout = outWriter\n\t\tcmd.Stderr = outWriter\n\t}\n\n\tshellSetPG(cmd)\n\tif err := cmd.Start(); err != nil {\n\t\tapp.ui.echoerrf(\"running shell: %s\", err)\n\t}\n\n\tswitch prefix {\n\tcase \"%\":\n\t\tnormal(app)\n\t\tapp.cmd = cmd\n\t\tapp.cmdOutBuf = nil\n\t\tapp.ui.cmdPrefix = \">\"\n\t\tapp.ui.echo(\"\")\n\n\t\tgo func() {\n\t\t\treader := bufio.NewReader(outReader)\n\t\t\tfor {\n\t\t\t\tb, err := reader.ReadByte()\n\t\t\t\tif err != nil {\n\t\t\t\t\tif !errors.Is(err, io.EOF) && !errors.Is(err, fs.ErrClosed) {\n\t\t\t\t\t\tlog.Printf(\"reading command output: %s\", err)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tapp.cmdOutBuf = append(app.cmdOutBuf, b)\n\t\t\t\tif reader.Buffered() == 0 {\n\t\t\t\t\tapp.ui.exprChan <- &callExpr{\"echo\", []string{string(app.cmdOutBuf)}, 1}\n\t\t\t\t}\n\n\t\t\t\tif b == '\\n' || b == '\\r' {\n\t\t\t\t\tapp.cmdOutBuf = nil\n\t\t\t\t}\n\t\t\t}\n\t\t}()\n\n\t\tgo func() {\n\t\t\tif err := cmd.Wait(); err != nil {\n\t\t\t\tlog.Printf(\"running shell: %s\", err)\n\t\t\t}\n\t\t\tinReader.Close()\n\t\t\tinWriter.Close()\n\t\t\toutReader.Close()\n\t\t\toutWriter.Close()\n\n\t\t\tapp.cmd = nil\n\t\t\tapp.ui.cmdPrefix = \"\"\n\t\t\tapp.ui.exprChan <- &callExpr{\"load\", nil, 1}\n\t\t}()\n\tcase \"&\":\n\t\tgo func() {\n\t\t\tif err := cmd.Wait(); err != nil {\n\t\t\t\tlog.Printf(\"running shell: %s\", err)\n\t\t\t}\n\t\t\tapp.ui.exprChan <- &callExpr{\"load\", nil, 1}\n\t\t}()\n\t}\n}\n\nfunc (app *app) doComplete() (matches []compMatch) {\n\tvar longest string\n\n\tswitch app.ui.cmdPrefix {\n\tcase \":\":\n\t\tmatches, longest = completeCmd(app.ui.cmdAccLeft)\n\tcase \"$\", \"%\", \"!\", \"&\":\n\t\tmatches, longest = completeShell(app.ui.cmdAccLeft)\n\tcase \"/\", \"?\":\n\t\tmatches, longest = completeSearch(app.ui.cmdAccLeft)\n\t}\n\n\tapp.ui.cmdAccLeft = longest\n\tapp.ui.menu, app.ui.menuSelect = listMatches(app.ui.screen, matches, -1)\n\treturn\n}\n\nfunc (app *app) menuComplete(direction int) {\n\tif !app.menuCompActive {\n\t\tapp.menuCompTmp = tokenize(app.ui.cmdAccLeft)\n\t\tapp.menuComps = app.doComplete()\n\t\tif len(app.menuComps) > 1 {\n\t\t\tapp.menuCompInd = -1\n\t\t\tapp.menuCompActive = true\n\t\t}\n\t} else {\n\t\tapp.menuCompInd += direction\n\t\tif app.menuCompInd == len(app.menuComps) {\n\t\t\tapp.menuCompInd = 0\n\t\t} else if app.menuCompInd < 0 {\n\t\t\tapp.menuCompInd = len(app.menuComps) - 1\n\t\t}\n\n\t\ttoks := slices.Clone(app.menuCompTmp)\n\t\ttoks[len(toks)-1] = app.menuComps[app.menuCompInd].result\n\t\tapp.ui.cmdAccLeft = strings.Join(toks, \" \")\n\t}\n\tapp.ui.menu, app.ui.menuSelect = listMatches(app.ui.screen, app.menuComps, app.menuCompInd)\n}\n\nfunc (app *app) watchDir(dir *dir) {\n\tif !gOpts.watch {\n\t\treturn\n\t}\n\n\tapp.watch.add(dir.path)\n\n\t// ensure dircounts are updated for child directories\n\tfor _, file := range dir.allFiles {\n\t\tif file.IsDir() {\n\t\t\tapp.watch.add(file.path)\n\t\t}\n\t}\n}\n\nfunc (app *app) exportMode() {\n\tgetMode := func() string {\n\t\tif app.menuCompActive {\n\t\t\treturn \"compmenu\"\n\t\t}\n\n\t\tif strings.HasPrefix(app.ui.cmdPrefix, \"delete\") {\n\t\t\treturn \"delete\"\n\t\t}\n\n\t\tif strings.HasPrefix(app.ui.cmdPrefix, \"replace\") || strings.HasPrefix(app.ui.cmdPrefix, \"create\") {\n\t\t\treturn \"rename\"\n\t\t}\n\n\t\tswitch app.ui.cmdPrefix {\n\t\tcase \"filter: \":\n\t\t\treturn \"filter\"\n\t\tcase \"find: \", \"find-back: \":\n\t\t\treturn \"find\"\n\t\tcase \"mark-save: \", \"mark-load: \", \"mark-remove: \":\n\t\t\treturn \"mark\"\n\t\tcase \"rename: \":\n\t\t\treturn \"rename\"\n\t\tcase \"/\", \"?\":\n\t\t\treturn \"search\"\n\t\tcase \":\":\n\t\t\treturn \"command\"\n\t\tcase \"$\", \"%\", \"!\", \"&\":\n\t\t\treturn \"shell\"\n\t\tcase \">\":\n\t\t\treturn \"pipe\"\n\t\tcase \"\":\n\t\t\tif app.nav.isVisualMode() {\n\t\t\t\treturn \"visual\"\n\t\t\t}\n\t\t\treturn \"normal\"\n\t\tdefault:\n\t\t\treturn \"unknown\"\n\t\t}\n\t}\n\n\tos.Setenv(\"lf_mode\", getMode())\n}\n"
  },
  {
    "path": "client.go",
    "content": "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/v3\"\n)\n\ntype State struct {\n\tmutex sync.Mutex\n\tdata  map[string]string\n}\n\nvar gState State\n\nfunc init() {\n\tgState.data = make(map[string]string)\n}\n\nfunc run() {\n\tif gLogPath != \"\" {\n\t\tf, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600)\n\t\tif err != nil {\n\t\t\tlog.Fatalf(\"failed to open log file: %s\", err)\n\t\t}\n\t\tdefer f.Close()\n\t\tlog.SetOutput(f)\n\t} else {\n\t\tlog.SetOutput(io.Discard)\n\t}\n\n\tlog.Printf(\"*************** starting client, PID: %d ***************\", gClientID)\n\n\tvar screen tcell.Screen\n\tvar err error\n\tif screen, err = tcell.NewScreen(); err != nil {\n\t\tlog.Fatalf(\"creating screen: %s\", err)\n\t} else if err = screen.Init(); err != nil {\n\t\tlog.Fatalf(\"initializing screen: %s\", err)\n\t}\n\tif gOpts.mouse {\n\t\tscreen.EnableMouse()\n\t}\n\tscreen.EnablePaste()\n\n\tui := newUI(screen)\n\tnav := newNav(ui)\n\tapp := newApp(ui, nav)\n\n\tif err := nav.sync(); err != nil {\n\t\tapp.ui.echoerrf(\"sync: %s\", err)\n\t}\n\n\tif err := app.readHistory(); err != nil {\n\t\tapp.ui.echoerrf(\"reading history file: %s\", err)\n\t}\n\n\tapp.loop()\n\n\tapp.ui.screen.Fini()\n\n\tif gLastDirPath != \"\" {\n\t\twriteLastDir(gLastDirPath, app.nav.currDir().path)\n\t}\n\n\tif gSelectionPath != \"\" && len(app.selectionOut) > 0 {\n\t\twriteSelection(gSelectionPath, app.selectionOut)\n\t}\n\n\tif gPrintLastDir {\n\t\tfmt.Println(app.nav.currDir().path)\n\t}\n\n\tif gPrintSelection && len(app.selectionOut) > 0 {\n\t\tfor _, file := range app.selectionOut {\n\t\t\tfmt.Println(file)\n\t\t}\n\t}\n}\n\nfunc writeLastDir(filename, lastDir string) {\n\tf, err := os.Create(filename)\n\tif err != nil {\n\t\tlog.Printf(\"opening last dir file: %s\", err)\n\t\treturn\n\t}\n\tdefer f.Close()\n\n\t_, err = f.WriteString(lastDir)\n\tif err != nil {\n\t\tlog.Printf(\"writing last dir file: %s\", err)\n\t}\n}\n\nfunc writeSelection(filename string, selection []string) {\n\tf, err := os.Create(filename)\n\tif err != nil {\n\t\tlog.Printf(\"opening selection file: %s\", err)\n\t\treturn\n\t}\n\tdefer f.Close()\n\n\t_, err = f.WriteString(strings.Join(selection, \"\\n\"))\n\tif err != nil {\n\t\tlog.Printf(\"writing selection file: %s\", err)\n\t}\n}\n\nfunc readExpr() <-chan expr {\n\tch := make(chan expr)\n\n\tgo func() {\n\t\tduration := 100 * time.Millisecond\n\n\t\tc, err := net.Dial(gSocketProt, gSocketPath)\n\t\tfor err != nil {\n\t\t\tlog.Printf(\"connecting server: %s\", err)\n\t\t\ttime.Sleep(duration)\n\t\t\tduration *= 2\n\t\t\tc, err = net.Dial(gSocketProt, gSocketPath)\n\t\t}\n\n\t\tif _, err := fmt.Fprintf(c, \"conn %d\\n\", gClientID); err != nil {\n\t\t\tlog.Fatalf(\"registering with server: %s\", err)\n\t\t}\n\n\t\tch <- &callExpr{\"sync\", nil, 1}\n\t\tch <- &callExpr{\"on-init\", nil, 1}\n\n\t\ts := bufio.NewScanner(c)\n\t\tfor s.Scan() {\n\t\t\tlog.Printf(\"recv: %s\", s.Text())\n\n\t\t\t// `query` has to be handled outside of the main thread, which is\n\t\t\t// blocked when running a synchronous shell command (\"$\" or \"!\").\n\t\t\t// This is important since `query` is often the result of the user\n\t\t\t// running `$lf -remote \"query $id <something>\"`.\n\t\t\tif word, rest := splitWord(s.Text()); word == \"query\" {\n\t\t\t\tgState.mutex.Lock()\n\t\t\t\tstate := gState.data[rest]\n\t\t\t\tgState.mutex.Unlock()\n\t\t\t\tif _, err := fmt.Fprintln(c, state); err != nil {\n\t\t\t\t\tlog.Fatalf(\"sending response to server: %s\", err)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tp := newParser(strings.NewReader(s.Text()))\n\t\t\t\tif p.parse() {\n\t\t\t\t\tch <- p.expr\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif err := s.Err(); err != nil {\n\t\t\tlog.Printf(\"reading from server: %s\", err)\n\t\t}\n\n\t\tc.Close()\n\t}()\n\n\treturn ch\n}\n\nfunc remote(req string) (string, error) {\n\tc, err := net.Dial(gSocketProt, gSocketPath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"connecting to server: %w\", err)\n\t}\n\tdefer c.Close()\n\n\tif _, err := fmt.Fprintln(c, req); err != nil {\n\t\treturn \"\", fmt.Errorf(\"sending command to server: %w\", err)\n\t}\n\n\t// XXX: Standard net.Conn interface does not include a CloseWrite method\n\t// but net.UnixConn and net.TCPConn implement it so the following should be\n\t// safe as long as we do not use other types of connections. We need\n\t// CloseWrite to notify the server that this is not a persistent connection\n\t// and it should be closed after the response.\n\tswitch c := c.(type) {\n\tcase *net.TCPConn:\n\t\tc.CloseWrite()\n\tcase *net.UnixConn:\n\t\tc.CloseWrite()\n\t}\n\n\tresp, err := io.ReadAll(c)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"reading response from server: %w\", err)\n\t}\n\n\treturn string(resp), nil\n}\n"
  },
  {
    "path": "colors.go",
    "content": "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\ntype styleMap struct {\n\tstyles        map[string]tcell.Style\n\tuseLinkTarget bool\n}\n\nfunc parseStyles() styleMap {\n\tsm := styleMap{\n\t\tstyles:        make(map[string]tcell.Style),\n\t\tuseLinkTarget: false,\n\t}\n\n\t// Default values from dircolors\n\t//\n\t// no*  NORMAL                 00\n\t// fi   FILE                   00\n\t// rs*  RESET                  0\n\t// di   DIR                    01;34\n\t// ln   LINK                   01;36\n\t// mh*  MULTIHARDLINK          00\n\t// pi   FIFO                   40;33\n\t// so   SOCK                   01;35\n\t// do*  DOOR                   01;35\n\t// bd   BLK                    40;33;01\n\t// cd   CHR                    40;33;01\n\t// or   ORPHAN                 40;31;01\n\t// mi*  MISSING                00\n\t// su   SETUID                 37;41\n\t// sg   SETGID                 30;43\n\t// ca*  CAPABILITY             30;41\n\t// tw   STICKY_OTHER_WRITABLE  30;42\n\t// ow   OTHER_WRITABLE         34;42\n\t// st   STICKY                 37;44\n\t// ex   EXEC                   01;32\n\t//\n\t// (Entries marked with * are not implemented in lf)\n\n\t// default values from dircolors with background colors removed\n\tdefaultColors := []string{\n\t\t\"fi=00\",\n\t\t\"di=01;34\",\n\t\t\"ln=01;36\",\n\t\t\"pi=33\",\n\t\t\"so=01;35\",\n\t\t\"bd=33;01\",\n\t\t\"cd=33;01\",\n\t\t\"or=31;01\",\n\t\t\"su=01;32\",\n\t\t\"sg=01;32\",\n\t\t\"tw=01;34\",\n\t\t\"ow=01;34\",\n\t\t\"st=01;34\",\n\t\t\"ex=01;32\",\n\t}\n\n\tsm.parseGNU(strings.Join(defaultColors, \":\"))\n\n\tif env := os.Getenv(\"LSCOLORS\"); env != \"\" {\n\t\tsm.parseBSD(env)\n\t}\n\n\tif env := os.Getenv(\"LS_COLORS\"); env != \"\" {\n\t\tsm.parseGNU(env)\n\t}\n\n\tif env := os.Getenv(\"LF_COLORS\"); env != \"\" {\n\t\tsm.parseGNU(env)\n\t}\n\n\tfor _, path := range gColorsPaths {\n\t\tif _, err := os.Stat(path); !os.IsNotExist(err) {\n\t\t\tsm.parseFile(path)\n\t\t}\n\t}\n\n\treturn sm\n}\n\nfunc parseColor(toks []string) (tcell.Color, int, error) {\n\tif len(toks) == 0 {\n\t\treturn tcell.ColorDefault, 0, fmt.Errorf(\"invalid args: %v\", toks)\n\t}\n\n\tif toks[0] == \"5\" && len(toks) >= 2 {\n\t\tn, err := strconv.Atoi(toks[1])\n\t\tif err != nil {\n\t\t\treturn tcell.ColorDefault, 0, fmt.Errorf(\"invalid args: %v\", toks)\n\t\t}\n\n\t\treturn tcell.PaletteColor(n), 2, nil\n\t}\n\n\tif toks[0] == \"2\" && len(toks) >= 4 {\n\t\tr, err := strconv.Atoi(toks[1])\n\t\tif err != nil {\n\t\t\treturn tcell.ColorDefault, 0, fmt.Errorf(\"invalid args: %v\", toks)\n\t\t}\n\n\t\tg, err := strconv.Atoi(toks[2])\n\t\tif err != nil {\n\t\t\treturn tcell.ColorDefault, 0, fmt.Errorf(\"invalid args: %v\", toks)\n\t\t}\n\n\t\tb, err := strconv.Atoi(toks[3])\n\t\tif err != nil {\n\t\t\treturn tcell.ColorDefault, 0, fmt.Errorf(\"invalid args: %v\", toks)\n\t\t}\n\n\t\treturn tcell.NewRGBColor(int32(r), int32(g), int32(b)), 4, nil\n\t}\n\n\treturn tcell.ColorDefault, 0, fmt.Errorf(\"invalid args: %v\", toks)\n}\n\nfunc (sm styleMap) parseFile(path string) {\n\tlog.Printf(\"reading file: %s\", path)\n\n\tf, err := os.Open(path)\n\tif err != nil {\n\t\tlog.Printf(\"opening colors file: %s\", err)\n\t\treturn\n\t}\n\tdefer f.Close()\n\n\tpairs, err := readPairs(f)\n\tif err != nil {\n\t\tlog.Printf(\"reading colors file: %s\", err)\n\t\treturn\n\t}\n\n\tfor _, pair := range pairs {\n\t\tsm.parsePair(pair)\n\t}\n}\n\n// parseGNU parses the $LS_COLORS environment variable.\nfunc (sm *styleMap) parseGNU(env string) {\n\tfor entry := range strings.SplitSeq(env, \":\") {\n\t\tif entry == \"\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tpair := strings.Split(entry, \"=\")\n\n\t\tif len(pair) != 2 {\n\t\t\tlog.Printf(\"invalid $LS_COLORS entry: %s\", entry)\n\t\t\treturn\n\t\t}\n\n\t\tsm.parsePair(pair)\n\t}\n}\n\nfunc (sm *styleMap) parsePair(pair []string) {\n\tkey, val := pair[0], pair[1]\n\n\tkey = replaceTilde(key)\n\n\tif filepath.IsAbs(key) {\n\t\tkey = filepath.Clean(key)\n\t}\n\n\tif key == \"ln\" && val == \"target\" {\n\t\tsm.useLinkTarget = true\n\t}\n\n\tsm.styles[key] = applySGR(val, tcell.StyleDefault)\n}\n\n// parseBSD parses the $LSCOLORS environment variable.\nfunc (sm styleMap) parseBSD(env string) {\n\tif len(env) != 22 {\n\t\tlog.Printf(\"invalid $LSCOLORS variable: %s\", env)\n\t\treturn\n\t}\n\n\tcolorNames := []string{\"di\", \"ln\", \"so\", \"pi\", \"ex\", \"bd\", \"cd\", \"su\", \"sg\", \"tw\", \"ow\"}\n\n\tgetStyle := func(r1, r2 byte) tcell.Style {\n\t\tst := tcell.StyleDefault\n\n\t\tswitch {\n\t\tcase r1 == 'x':\n\t\t\tst = st.Foreground(tcell.ColorDefault)\n\t\tcase 'A' <= r1 && r1 <= 'H':\n\t\t\tst = st.Foreground(tcell.PaletteColor(int(r1 - 'A'))).Bold(true)\n\t\tcase 'a' <= r1 && r1 <= 'h':\n\t\t\tst = st.Foreground(tcell.PaletteColor(int(r1 - 'a')))\n\t\tdefault:\n\t\t\tlog.Printf(\"invalid $LSCOLORS entry: %c\", r1)\n\t\t\treturn tcell.StyleDefault\n\t\t}\n\n\t\tswitch {\n\t\tcase r2 == 'x':\n\t\t\tst = st.Background(tcell.ColorDefault)\n\t\tcase 'a' <= r2 && r2 <= 'h':\n\t\t\tst = st.Background(tcell.PaletteColor(int(r2 - 'a')))\n\t\tdefault:\n\t\t\tlog.Printf(\"invalid $LSCOLORS entry: %c\", r2)\n\t\t\treturn tcell.StyleDefault\n\t\t}\n\n\t\treturn st\n\t}\n\n\tfor i, key := range colorNames {\n\t\tsm.styles[key] = getStyle(env[i*2], env[i*2+1])\n\t}\n}\n\nfunc (sm styleMap) get(f *file) tcell.Style {\n\tif val, ok := sm.styles[f.path]; ok {\n\t\treturn val\n\t}\n\n\tif f.IsDir() {\n\t\tif val, ok := sm.styles[f.Name()+\"/\"]; ok {\n\t\t\treturn val\n\t\t}\n\t}\n\n\tvar key string\n\n\tswitch {\n\tcase f.linkState == working && !sm.useLinkTarget:\n\t\tkey = \"ln\"\n\tcase f.linkState == broken:\n\t\tkey = \"or\"\n\tcase f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0o002 != 0:\n\t\tkey = \"tw\"\n\tcase f.IsDir() && f.Mode()&0o002 != 0:\n\t\tkey = \"ow\"\n\tcase f.IsDir() && f.Mode()&os.ModeSticky != 0:\n\t\tkey = \"st\"\n\tcase f.IsDir():\n\t\tkey = \"di\"\n\tcase f.Mode()&os.ModeNamedPipe != 0:\n\t\tkey = \"pi\"\n\tcase f.Mode()&os.ModeSocket != 0:\n\t\tkey = \"so\"\n\tcase f.Mode()&os.ModeCharDevice != 0:\n\t\tkey = \"cd\"\n\tcase f.Mode()&os.ModeDevice != 0:\n\t\tkey = \"bd\"\n\tcase f.Mode()&os.ModeSetuid != 0:\n\t\tkey = \"su\"\n\tcase f.Mode()&os.ModeSetgid != 0:\n\t\tkey = \"sg\"\n\tcase isExecutable(f.FileInfo):\n\t\tkey = \"ex\"\n\t}\n\n\tif val, ok := sm.styles[key]; ok {\n\t\treturn val\n\t}\n\n\tif val, ok := sm.styles[f.Name()+\"*\"]; ok {\n\t\treturn val\n\t}\n\n\tif val, ok := sm.styles[\"*\"+f.Name()]; ok {\n\t\treturn val\n\t}\n\n\tif val, ok := sm.styles[filepath.Base(f.Name())+\".*\"]; ok {\n\t\treturn val\n\t}\n\n\tif val, ok := sm.styles[\"*\"+strings.ToLower(f.ext)]; ok {\n\t\treturn val\n\t}\n\n\tif val, ok := sm.styles[\"fi\"]; ok {\n\t\treturn val\n\t}\n\n\treturn tcell.StyleDefault\n}\n"
  },
  {
    "path": "colors_test.go",
    "content": "package main\n\nimport (\n\t\"testing\"\n\n\t\"github.com/gdamore/tcell/v3\"\n)\n\nfunc TestParseColor(t *testing.T) {\n\ttests := []struct {\n\t\ttoks    []string\n\t\tcolor   tcell.Color\n\t\toffset  int\n\t\tsuccess bool\n\t}{\n\t\t{[]string{}, tcell.ColorDefault, 0, false},\n\t\t{[]string{\"foo\"}, tcell.ColorDefault, 0, false},\n\t\t{[]string{\"5\"}, tcell.ColorDefault, 0, false},\n\t\t{[]string{\"5\", \"foo\"}, tcell.ColorDefault, 0, false},\n\t\t{[]string{\"5\", \"42\"}, tcell.PaletteColor(42), 2, true},\n\t\t{[]string{\"2\"}, tcell.ColorDefault, 0, false},\n\t\t{[]string{\"2\", \"foo\"}, tcell.ColorDefault, 0, false},\n\t\t{[]string{\"2\", \"42\", \"foo\"}, tcell.ColorDefault, 0, false},\n\t\t{[]string{\"2\", \"42\", \"43\", \"foo\"}, tcell.ColorDefault, 0, false},\n\t\t{[]string{\"2\", \"42\", \"43\", \"44\"}, tcell.NewRGBColor(42, 43, 44), 4, true},\n\t}\n\n\tfor _, test := range tests {\n\t\tcolor, offset, err := parseColor(test.toks)\n\t\tsuccess := err == nil\n\t\tif color != test.color || offset != test.offset || success != test.success {\n\t\t\tt.Errorf(\"at input %v expected (%v, %v, %v) but got (%v, %v, %v)\",\n\t\t\t\ttest.toks, test.color, test.offset, test.success, color, offset, success)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "complete.go",
    "content": "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 = []string{\n\t\t\"set\",\n\t\t\"setlocal\",\n\t\t\"map\",\n\t\t\"nmap\",\n\t\t\"vmap\",\n\t\t\"cmap\",\n\t\t\"cmd\",\n\t\t\"addcustominfo\",\n\t\t\"bottom\",\n\t\t\"calcdirsize\",\n\t\t\"cd\",\n\t\t\"clear\",\n\t\t\"clearmaps\",\n\t\t\"copy\",\n\t\t\"cut\",\n\t\t\"down\",\n\t\t\"delete\",\n\t\t\"draw\",\n\t\t\"echo\",\n\t\t\"echoerr\",\n\t\t\"echomsg\",\n\t\t\"filter\",\n\t\t\"find\",\n\t\t\"find-back\",\n\t\t\"find-next\",\n\t\t\"find-prev\",\n\t\t\"glob-select\",\n\t\t\"glob-unselect\",\n\t\t\"half-down\",\n\t\t\"half-up\",\n\t\t\"high\",\n\t\t\"invert\",\n\t\t\"jump-next\",\n\t\t\"jump-prev\",\n\t\t\"load\",\n\t\t\"low\",\n\t\t\"mark-load\",\n\t\t\"mark-remove\",\n\t\t\"mark-save\",\n\t\t\"middle\",\n\t\t\"open\",\n\t\t\"page-down\",\n\t\t\"page-up\",\n\t\t\"paste\",\n\t\t\"push\",\n\t\t\"quit\",\n\t\t\"read\",\n\t\t\"redraw\",\n\t\t\"reload\",\n\t\t\"rename\",\n\t\t\"scroll-down\",\n\t\t\"scroll-up\",\n\t\t\"search\",\n\t\t\"search-back\",\n\t\t\"search-next\",\n\t\t\"search-prev\",\n\t\t\"select\",\n\t\t\"setfilter\",\n\t\t\"shell\",\n\t\t\"shell-async\",\n\t\t\"shell-pipe\",\n\t\t\"shell-wait\",\n\t\t\"source\",\n\t\t\"sync\",\n\t\t\"tag\",\n\t\t\"tag-toggle\",\n\t\t\"toggle\",\n\t\t\"top\",\n\t\t\"tty-write\",\n\t\t\"unselect\",\n\t\t\"up\",\n\t\t\"updir\",\n\t\t\"visual\",\n\t\t\"visual-accept\",\n\t\t\"visual-change\",\n\t\t\"visual-discard\",\n\t\t\"visual-unselect\",\n\t\t\"cmd-capitalize-word\",\n\t\t\"cmd-complete\",\n\t\t\"cmd-delete\",\n\t\t\"cmd-delete-back\",\n\t\t\"cmd-delete-end\",\n\t\t\"cmd-delete-home\",\n\t\t\"cmd-delete-unix-word\",\n\t\t\"cmd-delete-word\",\n\t\t\"cmd-delete-word-back\",\n\t\t\"cmd-end\",\n\t\t\"cmd-enter\",\n\t\t\"cmd-escape\",\n\t\t\"cmd-history-next\",\n\t\t\"cmd-history-prev\",\n\t\t\"cmd-home\",\n\t\t\"cmd-interrupt\",\n\t\t\"cmd-left\",\n\t\t\"cmd-lowercase-word\",\n\t\t\"cmd-menu-accept\",\n\t\t\"cmd-menu-complete\",\n\t\t\"cmd-menu-complete-back\",\n\t\t\"cmd-menu-discard\",\n\t\t\"cmd-right\",\n\t\t\"cmd-transpose\",\n\t\t\"cmd-transpose-word\",\n\t\t\"cmd-uppercase-word\",\n\t\t\"cmd-word\",\n\t\t\"cmd-word-back\",\n\t\t\"cmd-yank\",\n\t}\n\n\tgOptWords      = getOptWords(gOpts)\n\tgLocalOptWords = getLocalOptWords(gLocalOpts)\n)\n\nfunc getOptWords(opts any) (optWords []string) {\n\tt := reflect.TypeOf(opts)\n\tfor i := range t.NumField() {\n\t\tfield := t.Field(i)\n\t\tswitch field.Type.Kind() {\n\t\tcase reflect.Map:\n\t\t\tcontinue\n\t\tcase reflect.Bool:\n\t\t\tname := field.Name\n\t\t\toptWords = append(optWords, name, \"no\"+name, name+\"!\")\n\t\tdefault:\n\t\t\toptWords = append(optWords, field.Name)\n\t\t}\n\t}\n\tsort.Strings(optWords)\n\treturn\n}\n\nfunc getLocalOptWords(localOpts any) (localOptWords []string) {\n\tt := reflect.TypeOf(localOpts)\n\tfor i := range t.NumField() {\n\t\tfield := t.Field(i)\n\t\tname := field.Name\n\t\tif field.Type.Kind() != reflect.Map {\n\t\t\tcontinue\n\t\t}\n\t\tif field.Type.Elem().Kind() == reflect.Bool {\n\t\t\tlocalOptWords = append(localOptWords, name, \"no\"+name, name+\"!\")\n\t\t} else {\n\t\t\tlocalOptWords = append(localOptWords, name)\n\t\t}\n\t}\n\tsort.Strings(localOptWords)\n\treturn\n}\n\nfunc getLongest(s1, s2 string) string {\n\tr1 := []rune(s1)\n\tr2 := []rune(s2)\n\n\ti := 0\n\tfor ; i < len(r1) && i < len(r2); i++ {\n\t\tif r1[i] != r2[i] {\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn string(r1[:i])\n}\n\ntype compMatch struct {\n\tname   string // display name in completion menu\n\tresult string // result when cycling through completion menu\n}\n\nfunc matchWord(s string, words []string) (matches []compMatch, longest string) {\n\tfor _, w := range words {\n\t\tif !strings.HasPrefix(w, s) {\n\t\t\tcontinue\n\t\t}\n\n\t\tmatches = append(matches, compMatch{w, w})\n\t\tif len(matches) == 1 {\n\t\t\tlongest = w\n\t\t} else {\n\t\t\tlongest = getLongest(longest, w)\n\t\t}\n\t}\n\n\tswitch len(matches) {\n\tcase 0:\n\t\tlongest = s\n\tcase 1:\n\t\tlongest += \" \"\n\t}\n\treturn\n}\n\nfunc matchList(s string, words []string) (matches []compMatch, longest string) {\n\ttoks := strings.Split(s, \":\")\n\n\tfor _, w := range words {\n\t\tif slices.Contains(toks[:len(toks)-1], w) || !strings.HasPrefix(w, toks[len(toks)-1]) {\n\t\t\tcontinue\n\t\t}\n\n\t\tmatchResult := strings.Join(append(slices.Clone(toks[:len(toks)-1]), w), \":\")\n\t\tmatches = append(matches, compMatch{w, matchResult})\n\n\t\tif len(matches) == 1 {\n\t\t\tlongest = matchResult\n\t\t} else {\n\t\t\tlongest = getLongest(longest, matchResult)\n\t\t}\n\t}\n\n\tswitch len(matches) {\n\tcase 0:\n\t\tlongest = s\n\tcase 1:\n\t\tif longest == s {\n\t\t\tlongest += \" \"\n\t\t}\n\t}\n\treturn\n}\n\nfunc matchCmd(s string) (matches []compMatch, longest string) {\n\twords := slices.Concat(gCmdWords, slices.Collect(maps.Keys(gOpts.cmds)))\n\tslices.Sort(words)\n\tmatches, longest = matchWord(s, slices.Compact(words))\n\treturn\n}\n\nfunc matchFile(s string, dirOnly bool, escape, unescape func(string) string) (matches []compMatch, longest string) {\n\tdir, file := filepath.Split(unescape(replaceTilde(s)))\n\n\td := dir\n\tif dir == \"\" {\n\t\td = \".\"\n\t}\n\tfiles, err := os.ReadDir(d)\n\tif err != nil {\n\t\tlog.Printf(\"reading directory: %s\", err)\n\t\tlongest = s\n\t\treturn\n\t}\n\n\tvar longestName string\n\n\tfor _, f := range files {\n\t\tisDir := false\n\t\tif f.IsDir() {\n\t\t\tisDir = true\n\t\t} else if f.Type()&os.ModeSymlink != 0 {\n\t\t\tif stat, err := os.Stat(filepath.Join(d, f.Name())); err == nil && stat.IsDir() {\n\t\t\t\tisDir = true\n\t\t\t}\n\t\t}\n\n\t\tif !isDir && dirOnly {\n\t\t\tcontinue\n\t\t}\n\n\t\tif !strings.HasPrefix(strings.ToLower(f.Name()), strings.ToLower(file)) {\n\t\t\tcontinue\n\t\t}\n\n\t\tname := f.Name()\n\t\tif isDir {\n\t\t\tname += string(filepath.Separator)\n\t\t}\n\t\tmatches = append(matches, compMatch{name, escape(dir + name)})\n\n\t\tif len(matches) == 1 {\n\t\t\tlongestName = name\n\t\t} else {\n\t\t\t// Match case-insensitively without changing the prefix's case.\n\t\t\tp := getLongest(strings.ToLower(longestName), strings.ToLower(name))\n\t\t\tlongestName = string([]rune(longestName)[:len([]rune(p))])\n\t\t}\n\t}\n\n\tswitch len(matches) {\n\tcase 0:\n\t\tlongest = s\n\tcase 1:\n\t\tlongest = escape(dir + longestName)\n\t\tif !strings.HasSuffix(longestName, string(filepath.Separator)) {\n\t\t\tlongest += \" \"\n\t\t}\n\tdefault:\n\t\tlongest = escape(dir + longestName)\n\t}\n\treturn\n}\n\nfunc matchCmdFile(s string, dirOnly bool) (matches []compMatch, longest string) {\n\tmatches, longest = matchFile(s, dirOnly, cmdEscape, cmdUnescape)\n\treturn\n}\n\nfunc matchShellFile(s string) (matches []compMatch, longest string) {\n\tmatches, longest = matchFile(s, false, shellEscape, shellUnescape)\n\treturn\n}\n\nfunc matchExec(s string) (matches []compMatch, longest string) {\n\tvar words []string\n\tfor p := range strings.SplitSeq(envPath, string(filepath.ListSeparator)) {\n\t\tfiles, err := os.ReadDir(p)\n\t\tif err != nil {\n\t\t\tif !os.IsNotExist(err) {\n\t\t\t\tlog.Printf(\"reading path: %s\", err)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tfor _, f := range files {\n\t\t\tif !strings.HasPrefix(f.Name(), s) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfinfo, err := f.Info()\n\t\t\tif err != nil {\n\t\t\t\tlog.Printf(\"getting file information: %s\", err)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif finfo.Mode().IsRegular() && isExecutable(finfo) {\n\t\t\t\twords = append(words, f.Name())\n\t\t\t}\n\t\t}\n\t}\n\n\tslices.Sort(words)\n\tmatches, longest = matchWord(s, slices.Compact(words))\n\treturn\n}\n\nfunc matchSearch(s string) (matches []compMatch, longest string) {\n\tfiles, err := os.ReadDir(\".\")\n\tif err != nil {\n\t\tlog.Printf(\"reading directory: %s\", err)\n\t\tlongest = s\n\t\treturn\n\t}\n\n\tfor _, f := range files {\n\t\tif !strings.HasPrefix(strings.ToLower(f.Name()), strings.ToLower(s)) {\n\t\t\tcontinue\n\t\t}\n\n\t\tmatches = append(matches, compMatch{f.Name(), f.Name()})\n\t\tif len(matches) == 1 {\n\t\t\tlongest = f.Name()\n\t\t} else {\n\t\t\tp := getLongest(strings.ToLower(longest), strings.ToLower(f.Name()))\n\t\t\tlongest = string([]rune(longest)[:len([]rune(p))])\n\t\t}\n\t}\n\n\tif len(matches) == 0 {\n\t\tlongest = s\n\t}\n\treturn\n}\n\nfunc completeCmd(s string) (matches []compMatch, longest string) {\n\tf := tokenize(s)\n\n\tif len(f) == 1 {\n\t\tmatches, longest = matchCmd(s)\n\t\treturn\n\t}\n\n\tlongest = f[len(f)-1]\n\n\tswitch f[0] {\n\tcase \"set\":\n\t\tif len(f) == 2 {\n\t\t\tmatches, longest = matchWord(f[1], gOptWords)\n\t\t\tbreak\n\t\t}\n\t\tif len(f) != 3 {\n\t\t\tbreak\n\t\t}\n\t\tswitch f[1] {\n\t\tcase \"cleaner\", \"previewer\", \"rulerfile\":\n\t\t\tmatches, longest = matchCmdFile(f[2], false)\n\t\tcase \"borderstyle\":\n\t\t\tmatches, longest = matchWord(f[2], []string{\"box\", \"roundbox\", \"outline\", \"roundoutline\", \"separators\"})\n\t\tcase \"filtermethod\", \"searchmethod\":\n\t\t\tmatches, longest = matchWord(f[2], []string{\"glob\", \"regex\", \"text\"})\n\t\tcase \"info\":\n\t\t\tmatches, longest = matchList(f[2], []string{\"atime\", \"btime\", \"ctime\", \"custom\", \"group\", \"perm\", \"size\", \"time\", \"user\"})\n\t\tcase \"preserve\":\n\t\t\tmatches, longest = matchList(f[2], []string{\"mode\", \"timestamps\"})\n\t\tcase \"selmode\":\n\t\t\tmatches, longest = matchWord(f[2], []string{\"all\", \"dir\"})\n\t\tcase \"sizeunits\":\n\t\t\tmatches, longest = matchWord(f[2], []string{\"binary\", \"decimal\"})\n\t\tcase \"sortby\":\n\t\t\tmatches, longest = matchWord(f[2], []string{\"atime\", \"btime\", \"ctime\", \"custom\", \"ext\", \"name\", \"natural\", \"size\", \"time\"})\n\t\tcase \"terminalcursor\":\n\t\t\tmatches, longest = matchWord(f[2], []string{\"default\", \"block\", \"underline\", \"bar\", \"blinkblock\", \"blinkunderline\", \"blinkbar\"})\n\t\tdefault:\n\t\t\tif slices.Contains(gOptWords, f[1]+\"!\") {\n\t\t\t\tmatches, longest = matchWord(f[2], []string{\"false\", \"true\"})\n\t\t\t}\n\t\t}\n\tcase \"setlocal\":\n\t\tif len(f) == 2 {\n\t\t\tmatches, longest = matchCmdFile(f[1], true)\n\t\t\tbreak\n\t\t}\n\t\tif len(f) == 3 {\n\t\t\tmatches, longest = matchWord(f[2], gLocalOptWords)\n\t\t\tbreak\n\t\t}\n\t\tif len(f) != 4 {\n\t\t\tbreak\n\t\t}\n\t\tswitch f[2] {\n\t\tcase \"info\":\n\t\t\tmatches, longest = matchList(f[3], []string{\"atime\", \"btime\", \"ctime\", \"custom\", \"group\", \"perm\", \"size\", \"time\", \"user\"})\n\t\tcase \"sortby\":\n\t\t\tmatches, longest = matchWord(f[3], []string{\"atime\", \"btime\", \"ctime\", \"custom\", \"ext\", \"name\", \"natural\", \"size\", \"time\"})\n\t\tdefault:\n\t\t\tif slices.Contains(gLocalOptWords, f[2]+\"!\") {\n\t\t\t\tmatches, longest = matchWord(f[3], []string{\"false\", \"true\"})\n\t\t\t}\n\t\t}\n\tcase \"map\", \"nmap\", \"vmap\", \"cmap\":\n\t\tif len(f) == 3 {\n\t\t\tmatches, longest = matchCmd(f[2])\n\t\t}\n\tcase \"cmd\":\n\tcase \"cd\":\n\t\tif len(f) == 2 {\n\t\t\tmatches, longest = matchCmdFile(f[1], true)\n\t\t}\n\tcase \"addcustominfo\", \"select\", \"source\":\n\t\tif len(f) == 2 {\n\t\t\tmatches, longest = matchCmdFile(f[1], false)\n\t\t}\n\tcase \"toggle\":\n\t\tmatches, longest = matchCmdFile(f[len(f)-1], false)\n\tdefault:\n\t\tif !slices.Contains(gCmdWords, f[0]) {\n\t\t\tmatches, longest = matchCmdFile(f[len(f)-1], false)\n\t\t}\n\t}\n\n\tf[len(f)-1] = longest\n\tlongest = strings.Join(f, \" \")\n\treturn\n}\n\nfunc completeShell(s string) (matches []compMatch, longest string) {\n\tf := tokenize(s)\n\n\tswitch len(f) {\n\tcase 1:\n\t\tmatches, longest = matchExec(f[0])\n\tdefault:\n\t\tmatches, longest = matchShellFile(f[len(f)-1])\n\t}\n\n\tf[len(f)-1] = longest\n\tlongest = strings.Join(f, \" \")\n\treturn\n}\n\nfunc completeSearch(s string) (matches []compMatch, longest string) {\n\tmatches, longest = matchSearch(s)\n\treturn\n}\n"
  },
  {
    "path": "complete_test.go",
    "content": "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\texp  []string\n\t}{\n\t\t{struct{ feature bool }{}, []string{\"feature\", \"feature!\", \"nofeature\"}},\n\t\t{struct{ feature int }{}, []string{\"feature\"}},\n\t\t{struct{ feature string }{}, []string{\"feature\"}},\n\t\t{struct{ feature []string }{}, []string{\"feature\"}},\n\t}\n\n\tfor _, test := range tests {\n\t\tresult := getOptWords(test.opts)\n\t\tif !reflect.DeepEqual(result, test.exp) {\n\t\t\tt.Errorf(\"at input '%#v' expected '%s' but got '%s'\", test.opts, test.exp, result)\n\t\t}\n\t}\n}\n\nfunc TestGetLocalOptWords(t *testing.T) {\n\ttests := []struct {\n\t\tlocalOpts any\n\t\texp       []string\n\t}{\n\t\t{struct{ feature map[string]bool }{}, []string{\"feature\", \"feature!\", \"nofeature\"}},\n\t\t{struct{ feature map[string]int }{}, []string{\"feature\"}},\n\t\t{struct{ feature map[string]string }{}, []string{\"feature\"}},\n\t\t{struct{ feature map[string][]string }{}, []string{\"feature\"}},\n\t}\n\n\tfor _, test := range tests {\n\t\tresult := getLocalOptWords(test.localOpts)\n\t\tif !reflect.DeepEqual(result, test.exp) {\n\t\t\tt.Errorf(\"at input '%#v' expected '%s' but got '%s'\", test.localOpts, test.exp, result)\n\t\t}\n\t}\n}\n\nfunc TestGetLongest(t *testing.T) {\n\ttests := []struct {\n\t\ts1  string\n\t\ts2  string\n\t\texp string\n\t}{\n\t\t{\"\", \"\", \"\"},\n\t\t{\"\", \"foo\", \"\"},\n\t\t{\"foo\", \"\", \"\"},\n\t\t{\"foo\", \"bar\", \"\"},\n\t\t{\"foo\", \"foobar\", \"foo\"},\n\t\t{\"foo\", \"barfoo\", \"\"},\n\t\t{\"foobar\", \"foobaz\", \"fooba\"},\n\t\t{\"год\", \"гол\", \"го\"},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := getLongest(test.s1, test.s2); got != test.exp {\n\t\t\tt.Errorf(\"at input '%s' and '%s' expected '%s' but got '%s'\", test.s1, test.s2, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestMatchWord(t *testing.T) {\n\ttests := []struct {\n\t\ts       string\n\t\twords   []string\n\t\tmatches []compMatch\n\t\tlongest string\n\t}{\n\t\t{\"\", nil, nil, \"\"},\n\t\t{\"\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"foo\", \"foo\"}, {\"bar\", \"bar\"}, {\"baz\", \"baz\"}}, \"\"},\n\t\t{\"f\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"foo\", \"foo\"}}, \"foo \"},\n\t\t{\"b\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"bar\", \"bar\"}, {\"baz\", \"baz\"}}, \"ba\"},\n\t\t{\"fo\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"foo\", \"foo\"}}, \"foo \"},\n\t\t{\"ba\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"bar\", \"bar\"}, {\"baz\", \"baz\"}}, \"ba\"},\n\t\t{\"fo\", []string{\"bar\", \"baz\"}, nil, \"fo\"},\n\t}\n\n\tfor _, test := range tests {\n\t\tmatches, longest := matchWord(test.s, test.words)\n\n\t\tif !reflect.DeepEqual(matches, test.matches) {\n\t\t\tt.Errorf(\"at input '%s' with '%s' expected '%v' but got '%v'\", test.s, test.words, test.matches, matches)\n\t\t}\n\n\t\tif longest != test.longest {\n\t\t\tt.Errorf(\"at input '%s' with '%s' expected '%s' but got '%s'\", test.s, test.words, test.longest, longest)\n\t\t}\n\t}\n}\n\nfunc TestMatchList(t *testing.T) {\n\ttests := []struct {\n\t\ts       string\n\t\twords   []string\n\t\tmatches []compMatch\n\t\tlongest string\n\t}{\n\t\t{\"\", nil, nil, \"\"},\n\t\t{\"\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"foo\", \"foo\"}, {\"bar\", \"bar\"}, {\"baz\", \"baz\"}}, \"\"},\n\t\t{\"f\", []string{\"bar\", \"baz\"}, nil, \"f\"},\n\t\t{\"f\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"foo\", \"foo\"}}, \"foo\"},\n\t\t{\"b\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"bar\", \"bar\"}, {\"baz\", \"baz\"}}, \"ba\"},\n\t\t{\"ba\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"bar\", \"bar\"}, {\"baz\", \"baz\"}}, \"ba\"},\n\t\t{\"foo\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"foo\", \"foo\"}}, \"foo \"},\n\t\t{\"foo:\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"bar\", \"foo:bar\"}, {\"baz\", \"foo:baz\"}}, \"foo:ba\"},\n\t\t{\"foo:f\", []string{\"foo\", \"bar\", \"baz\"}, nil, \"foo:f\"},\n\t\t{\"foo:b\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"bar\", \"foo:bar\"}, {\"baz\", \"foo:baz\"}}, \"foo:ba\"},\n\t\t{\"foo:ba\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"bar\", \"foo:bar\"}, {\"baz\", \"foo:baz\"}}, \"foo:ba\"},\n\t\t{\"bar:b\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"baz\", \"bar:baz\"}}, \"bar:baz\"},\n\t\t{\"bar:f\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"foo\", \"bar:foo\"}}, \"bar:foo\"},\n\t\t{\"bar:foo\", []string{\"foo\", \"bar\", \"baz\"}, []compMatch{{\"foo\", \"bar:foo\"}}, \"bar:foo \"},\n\t}\n\n\tfor _, test := range tests {\n\t\tmatches, longest := matchList(test.s, test.words)\n\n\t\tif !reflect.DeepEqual(matches, test.matches) {\n\t\t\tt.Errorf(\"at input '%s' with '%s' expected '%v' but got '%v'\", test.s, test.words, test.matches, matches)\n\t\t}\n\n\t\tif longest != test.longest {\n\t\t\tt.Errorf(\"at input '%s' with '%s' expected '%s' but got '%s'\", test.s, test.words, test.longest, longest)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "copy.go",
    "content": "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\"\n)\n\ntype ProgressWriter struct {\n\twriter io.Writer\n\tnums   chan<- int64\n}\n\nfunc NewProgressWriter(writer io.Writer, nums chan<- int64) *ProgressWriter {\n\treturn &ProgressWriter{\n\t\twriter: writer,\n\t\tnums:   nums,\n\t}\n}\n\nfunc (progressWriter *ProgressWriter) Write(b []byte) (int, error) {\n\tn, err := progressWriter.writer.Write(b)\n\tprogressWriter.nums <- int64(n)\n\treturn n, err\n}\n\nfunc copySize(srcs []string) (int64, error) {\n\tvar total int64\n\n\tfor _, src := range srcs {\n\t\t_, err := os.Lstat(src)\n\t\tif os.IsNotExist(err) {\n\t\t\treturn total, fmt.Errorf(\"src does not exist: %q\", src)\n\t\t}\n\n\t\terr = filepath.Walk(src, func(_ string, info os.FileInfo, err error) error {\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"walk: %w\", err)\n\t\t\t}\n\t\t\ttotal += info.Size()\n\t\t\treturn nil\n\t\t})\n\t\tif err != nil {\n\t\t\treturn total, err\n\t\t}\n\t}\n\n\treturn total, nil\n}\n\nfunc copyFile(src, dst string, preserve []string, info os.FileInfo, nums chan<- int64, errs chan<- error) {\n\tr, err := os.Open(src)\n\tif err != nil {\n\t\terrs <- err\n\t\treturn\n\t}\n\tdefer r.Close()\n\n\tvar dstMode os.FileMode = 0o666\n\tif slices.Contains(preserve, \"mode\") {\n\t\tdstMode = info.Mode()\n\t}\n\tw, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, dstMode)\n\tif err != nil {\n\t\terrs <- err\n\t\treturn\n\t}\n\n\tif _, err := io.Copy(NewProgressWriter(w, nums), r); err != nil {\n\t\terrs <- err\n\t\tw.Close()\n\t\tif err = os.Remove(dst); err != nil {\n\t\t\terrs <- err\n\t\t}\n\t\treturn\n\t}\n\n\tif err := w.Close(); err != nil {\n\t\terrs <- err\n\t\tif err = os.Remove(dst); err != nil {\n\t\t\terrs <- err\n\t\t}\n\t\treturn\n\t}\n\n\tif slices.Contains(preserve, \"timestamps\") {\n\t\tatime := times.Get(info).AccessTime()\n\t\tmtime := info.ModTime()\n\t\tif err := os.Chtimes(dst, atime, mtime); err != nil {\n\t\t\terrs <- err\n\t\t\tif err = os.Remove(dst); err != nil {\n\t\t\t\terrs <- err\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t}\n}\n\nfunc copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64, errs chan error) {\n\tnums = make(chan int64, 1024)\n\terrs = make(chan error, 1024)\n\n\tgo func() {\n\t\tdirInfos := make(map[string]os.FileInfo)\n\n\t\tfor _, src := range srcs {\n\t\t\tfile := filepath.Base(src)\n\t\t\tdst := filepath.Join(dstDir, file)\n\n\t\t\tif lstat, err := os.Lstat(dst); err == nil {\n\t\t\t\text := getFileExtension(lstat)\n\t\t\t\tbasename := file[:len(file)-len(ext)]\n\t\t\t\tvar newPath string\n\t\t\t\tfor i := 1; !os.IsNotExist(err); i++ {\n\t\t\t\t\tfile = strings.ReplaceAll(gOpts.dupfilefmt, \"%f\", basename+ext)\n\t\t\t\t\tfile = strings.ReplaceAll(file, \"%b\", basename)\n\t\t\t\t\tfile = strings.ReplaceAll(file, \"%e\", ext)\n\t\t\t\t\tfile = strings.ReplaceAll(file, \"%n\", strconv.Itoa(i))\n\t\t\t\t\tnewPath = filepath.Join(dstDir, file)\n\t\t\t\t\t_, err = os.Lstat(newPath)\n\t\t\t\t}\n\t\t\t\tdst = newPath\n\t\t\t}\n\n\t\t\terr := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {\n\t\t\t\tif err != nil {\n\t\t\t\t\terrs <- fmt.Errorf(\"walk: %w\", err)\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\trel, err := filepath.Rel(src, path)\n\t\t\t\tif err != nil {\n\t\t\t\t\terrs <- fmt.Errorf(\"relative: %w\", err)\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\tnewPath := filepath.Join(dst, rel)\n\t\t\t\tswitch {\n\t\t\t\tcase info.IsDir():\n\t\t\t\t\tdstMode := os.ModePerm\n\t\t\t\t\tif slices.Contains(preserve, \"mode\") {\n\t\t\t\t\t\tdstMode = info.Mode()\n\t\t\t\t\t}\n\t\t\t\t\tif err := os.MkdirAll(newPath, dstMode); err != nil {\n\t\t\t\t\t\terrs <- fmt.Errorf(\"mkdir: %w\", err)\n\t\t\t\t\t}\n\t\t\t\t\tif slices.Contains(preserve, \"timestamps\") {\n\t\t\t\t\t\tdirInfos[newPath] = info\n\t\t\t\t\t}\n\t\t\t\t\tnums <- info.Size()\n\t\t\t\tcase info.Mode()&os.ModeSymlink != 0:\n\t\t\t\t\tif rlink, err := os.Readlink(path); err != nil {\n\t\t\t\t\t\terrs <- fmt.Errorf(\"symlink: %w\", err)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif err := os.Symlink(rlink, newPath); err != nil {\n\t\t\t\t\t\t\terrs <- fmt.Errorf(\"symlink: %w\", err)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tnums <- info.Size()\n\t\t\t\tdefault:\n\t\t\t\t\tcopyFile(path, newPath, preserve, info, nums, errs)\n\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\terrs <- fmt.Errorf(\"walk: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tfor path, info := range dirInfos {\n\t\t\tatime := times.Get(info).AccessTime()\n\t\t\tmtime := info.ModTime()\n\t\t\tif err := os.Chtimes(path, atime, mtime); err != nil {\n\t\t\t\terrs <- fmt.Errorf(\"chtimes: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tclose(errs)\n\t}()\n\n\treturn nums, errs\n}\n"
  },
  {
    "path": "df_openbsd.go",
    "content": "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\tif err := unix.Statfs(wd, &stat); err != nil {\n\t\tlog.Printf(\"diskfree: %s\", err)\n\t\treturn \"\"\n\t}\n\n\t// Available blocks * size per block = available space in bytes\n\treturn \"df: \" + humanize(int64(stat.F_bavail)*int64(stat.F_bsize))\n}\n"
  },
  {
    "path": "df_statfs.go",
    "content": "//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 diskFree(wd string) string {\n\tvar stat unix.Statfs_t\n\n\tif err := unix.Statfs(wd, &stat); err != nil {\n\t\tlog.Printf(\"diskfree: %s\", err)\n\t\treturn \"\"\n\t}\n\n\t// Available blocks * size per block = available space in bytes\n\treturn \"df: \" + humanize(int64(stat.Bavail)*int64(stat.Bsize))\n}\n"
  },
  {
    "path": "df_statvfs.go",
    "content": "//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 string) string {\n\tvar stat unix.Statvfs_t\n\n\tif err := unix.Statvfs(wd, &stat); err != nil {\n\t\tlog.Printf(\"diskfree: %s\", err)\n\t\treturn \"\"\n\t}\n\n\t// Available blocks * size per block = available space in bytes\n\treturn \"df: \" + humanize(int64(stat.Bavail)*int64(stat.Bsize))\n}\n"
  },
  {
    "path": "df_windows.go",
    "content": "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\tpathPtr, err := windows.UTF16PtrFromString(wd)\n\tif err != nil {\n\t\tlog.Printf(\"diskfree: %s\", err)\n\t\treturn \"\"\n\t}\n\terr = windows.GetDiskFreeSpaceEx(pathPtr, &free, nil, nil) // cwd, free, total, available\n\tif err != nil {\n\t\tlog.Printf(\"diskfree: %s\", err)\n\t\treturn \"\"\n\t}\n\treturn \"df: \" + humanize(int64(free))\n}\n"
  },
  {
    "path": "diacritics.go",
    "content": "package main\n\nvar normMap = map[rune]rune{\n\t// lowercase (not only) european\n\t'ě': 'e', 'ř': 'r', 'ů': 'u', 'ø': 'o', 'ĉ': 'c', 'ĝ': 'g', 'ĥ': 'h', 'ĵ': 'j', 'ŝ': 's',\n\t'ŭ': 'u', 'è': 'e', 'ù': 'u', 'ÿ': 'y', 'ė': 'e', 'į': 'i', 'ų': 'u', 'ā': 'a', 'ē': 'e',\n\t'ī': 'i', 'ū': 'u', 'ļ': 'l', 'ķ': 'k', 'ņ': 'n', 'ģ': 'g', 'ő': 'o', 'ű': 'u', 'ë': 'e',\n\t'ï': 'i', 'ą': 'a', 'ć': 'c', 'ę': 'e', 'ł': 'l', 'ń': 'n', 'ś': 's', 'ź': 'z', 'ż': 'z',\n\t'õ': 'o', 'ș': 's', 'ț': 't', 'č': 'c', 'ď': 'd', 'ĺ': 'l', 'ľ': 'l', 'ň': 'n', 'ŕ': 'r',\n\t'š': 's', 'ť': 't', 'ý': 'y', 'ž': 'z', 'é': 'e', 'í': 'i', 'ñ': 'n', 'ó': 'o', 'ú': 'u',\n\t'ü': 'u', 'å': 'a', 'ä': 'a', 'ö': 'o', 'ç': 'c', 'î': 'i', 'ş': 's', 'û': 'u', 'ğ': 'g',\n\t'ă': 'a', 'â': 'a', 'đ': 'd', 'ê': 'e', 'ô': 'o', 'ơ': 'o', 'ư': 'u', 'á': 'a', 'à': 'a',\n\t'ã': 'a', 'ả': 'a', 'ạ': 'a',\n\t// uppercase (not only) european\n\t'Ě': 'E', 'Ř': 'R', 'Ů': 'U', 'Ø': 'O', 'Ĉ': 'C', 'Ĝ': 'G', 'Ĥ': 'H', 'Ĵ': 'J', 'Ŝ': 'S',\n\t'Ŭ': 'U', 'È': 'E', 'Ù': 'U', 'Ÿ': 'Y', 'Ė': 'E', 'Į': 'I', 'Ų': 'U', 'Ā': 'A', 'Ē': 'E',\n\t'Ī': 'I', 'Ū': 'U', 'Ļ': 'L', 'Ķ': 'K', 'Ņ': 'N', 'Ģ': 'G', 'Ő': 'O', 'Ű': 'U', 'Ë': 'E',\n\t'Ï': 'I', 'Ą': 'A', 'Ć': 'C', 'Ę': 'E', 'Ł': 'L', 'Ń': 'N', 'Ś': 'S', 'Ź': 'Z', 'Ż': 'Z',\n\t'Õ': 'O', 'Ș': 'S', 'Ț': 'T', 'Č': 'C', 'Ď': 'D', 'Ĺ': 'L', 'Ľ': 'L', 'Ň': 'N', 'Ŕ': 'R',\n\t'Š': 'S', 'Ť': 'T', 'Ý': 'Y', 'Ž': 'Z', 'É': 'E', 'Í': 'I', 'Ñ': 'N', 'Ó': 'O', 'Ú': 'U',\n\t'Ü': 'U', 'Å': 'A', 'Ä': 'A', 'Ö': 'O', 'Ç': 'C', 'Î': 'I', 'Ş': 'S', 'Û': 'U', 'Ğ': 'G',\n\t'Ă': 'A', 'Â': 'A', 'Đ': 'D', 'Ê': 'E', 'Ô': 'O', 'Ơ': 'O', 'Ư': 'U', 'Á': 'A', 'À': 'A',\n\t'Ã': 'A', 'Ả': 'A', 'Ạ': 'A',\n\n\t// lowercase Vietnamese\n\t'ắ': 'a', 'ặ': 'a', 'ằ': 'a', 'ẳ': 'a', 'ẵ': 'a', 'ấ': 'a', 'ậ': 'a', 'ầ': 'a', 'ẩ': 'a',\n\t'ẫ': 'a', 'ẹ': 'e', 'ẻ': 'e', 'ẽ': 'e', 'ế': 'e', 'ệ': 'e', 'ề': 'e', 'ể': 'e', 'ễ': 'e',\n\t'i': 'i', 'ị': 'i', 'ì': 'i', 'ỉ': 'i', 'ĩ': 'i', 'o': 'o', 'ọ': 'o', 'ò': 'o', 'ỏ': 'o',\n\t'ố': 'o', 'ộ': 'o', 'ồ': 'o', 'ổ': 'o', 'ỗ': 'o', 'ớ': 'o', 'ợ': 'o', 'ờ': 'o', 'ở': 'o',\n\t'ỡ': 'o', 'ụ': 'u', 'ủ': 'u', 'ũ': 'u', 'ứ': 'u', 'ự': 'u', 'ừ': 'u', 'ử': 'u', 'ữ': 'u',\n\t'y': 'y', 'ỵ': 'y', 'ỳ': 'y', 'ỷ': 'y', 'ỹ': 'y',\n\t// uppercase Vietnamese\n\t'Ắ': 'A', 'Ặ': 'A', 'Ằ': 'A', 'Ẳ': 'A', 'Ẵ': 'A', 'Ấ': 'A', 'Ậ': 'A', 'Ầ': 'A', 'Ẩ': 'A',\n\t'Ẫ': 'A', 'Ẹ': 'E', 'Ẻ': 'E', 'Ẽ': 'E', 'Ế': 'E', 'Ệ': 'E', 'Ề': 'E', 'Ể': 'E', 'Ễ': 'E',\n\t'I': 'I', 'Ị': 'I', 'Ì': 'I', 'Ỉ': 'I', 'Ĩ': 'I', 'O': 'O', 'Ọ': 'O', 'Ò': 'O', 'Ỏ': 'O',\n\t'Ố': 'O', 'Ộ': 'O', 'Ồ': 'O', 'Ổ': 'O', 'Ỗ': 'O', 'Ớ': 'O', 'Ợ': 'O', 'Ờ': 'O', 'Ở': 'O',\n\t'Ỡ': 'O', 'Ụ': 'U', 'Ủ': 'U', 'Ũ': 'U', 'Ứ': 'U', 'Ự': 'U', 'Ừ': 'U', 'Ử': 'U', 'Ữ': 'U',\n\t'Y': 'Y', 'Ỵ': 'Y', 'Ỳ': 'Y', 'Ỷ': 'Y', 'Ỹ': 'Y',\n}\n\nfunc removeDiacritics(baseString string) string {\n\tnormalizedRunes := make([]rune, 0, len(baseString))\n\tfor _, baseRune := range baseString {\n\t\tif normRune, ok := normMap[baseRune]; ok {\n\t\t\tnormalizedRunes = append(normalizedRunes, normRune)\n\t\t} else {\n\t\t\tnormalizedRunes = append(normalizedRunes, baseRune)\n\t\t}\n\t}\n\treturn string(normalizedRunes)\n}\n"
  },
  {
    "path": "diacritics_test.go",
    "content": "package main\n\nimport (\n\t\"testing\"\n)\n\n// typical czech test sentence ;-)\nconst baseTestString = \"Příliš žluťoučký kůň příšerně úpěl ďábelské ódy\"\n\nfunc TestRemoveDiacritics(t *testing.T) {\n\ttestStr := baseTestString\n\texpStr := \"Prilis zlutoucky kun priserne upel dabelske ody\"\n\tcheckRemoveDiacritics(testStr, expStr, t)\n\n\t// other accents (non complete, but all I found)\n\ttestStr = \"áéíóúýčďěňřšťžůåøĉĝĥĵŝŭšžõäöüàâçéèêëîïôùûüÿžščćđáéíóúąęėįųūčšžāēīūčšžļķņģáéíóúöüőűäöüëïąćęłńóśźżáàãâçéêíóõôăâîșțáäčďéíĺľňóôŕšťúýžáéíñóúüåäöâçîşûğăâđêôơưáàãảạ\"\n\texpStr = \"aeiouycdenrstzuaocghjsuszoaouaaceeeeiiouuuyzsccdaeiouaeeiuucszaeiucszlkngaeiouououaoueiacelnoszzaaaaceeioooaaistaacdeillnoorstuyzaeinouuaaoacisugaadeoouaaaaa\"\n\tcheckRemoveDiacritics(testStr, expStr, t)\n\n\ttestStr = \"ÁÉÍÓÚÝČĎĚŇŘŠŤŽŮÅØĈĜĤĴŜŬŠŽÕÄÖÜÀÂÇÉÈÊËÎÏÔÙÛÜŸŽŠČĆĐÁÉÍÓÚĄĘĖĮŲŪČŠŽĀĒĪŪČŠŽĻĶŅĢÁÉÍÓÚÖÜŐŰÄÖÜËÏĄĆĘŁŃÓŚŹŻÁÀÃÂÇÉÊÍÓÕÔĂÂÎȘȚÁÄČĎÉÍĹĽŇÓÔŔŠŤÚÝŽÁÉÍÑÓÚÜÅÄÖÂÇÎŞÛĞĂÂĐÊÔƠƯÁÀÃẢẠ\"\n\texpStr = \"AEIOUYCDENRSTZUAOCGHJSUSZOAOUAACEEEEIIOUUUYZSCCDAEIOUAEEIUUCSZAEIUCSZLKNGAEIOUOUOUAOUEIACELNOSZZAAAACEEIOOOAAISTAACDEILLNOORSTUYZAEINOUUAAOACISUGAADEOOUAAAAA\"\n\tcheckRemoveDiacritics(testStr, expStr, t)\n\n\ttestStr = \"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ\"\n\texpStr = \"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd\"\n\tcheckRemoveDiacritics(testStr, expStr, t)\n\n\ttestStr = \"ÁẠÀẢÃĂẮẶẰẲẴÂẤẬẦẨẪÉẸÈẺẼÊẾỆỀỂỄÍỊÌỈĨÓỌÒỎÕÔỐỘỒỔỖƠỚỢỜỞỠÚỤÙỦŨƯỨỰỪỬỮÝỴỲỶỸĐ\"\n\texpStr = \"AAAAAAAAAAAAAAAAAEEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYYD\"\n\tcheckRemoveDiacritics(testStr, expStr, t)\n}\n\nfunc checkRemoveDiacritics(testStr, expStr string, t *testing.T) {\n\tresultStr := removeDiacritics(testStr)\n\tif resultStr != expStr {\n\t\tt.Errorf(\"at input '%v' expected '%v' but got '%v'\", testStr, expStr, resultStr)\n\t}\n}\n\nfunc TestSearchSettings(t *testing.T) {\n\trunSearch(t, true, false, true, true, \"Veřejný\", \"vere\", true)\n\n\trunSearch(t, true, false, true, false, baseTestString, \"Zlutoucky\", true)\n\trunSearch(t, true, false, true, false, baseTestString, \"zlutoucky\", true)\n\trunSearch(t, true, true, true, false, baseTestString, \"Zlutoucky\", false)\n\trunSearch(t, true, true, true, true, baseTestString, \"zlutoucky\", true)\n\n\trunSearch(t, false, false, true, false, baseTestString, \"žlutoucky\", true)\n\trunSearch(t, false, false, true, false, baseTestString, \"Žlutoucky\", false)\n\n\trunSearch(t, false, false, true, true, baseTestString, \"žluťoučký\", true)\n\trunSearch(t, false, false, true, false, baseTestString, \"žluťoučký\", true)\n\trunSearch(t, false, false, false, false, baseTestString, \"žluťoučký\", true)\n\trunSearch(t, false, false, false, false, baseTestString, \"zlutoucky\", false)\n\trunSearch(t, false, false, true, true, baseTestString, \"zlutoucky\", true)\n}\n\nfunc runSearch(t *testing.T, ignorecase, smartcase, ignorediacritics, smartdiacritics bool, base, pattern string, expected bool) {\n\tgOpts.ignorecase = ignorecase\n\tgOpts.smartcase = smartcase\n\tgOpts.ignoredia = ignorediacritics\n\tgOpts.smartdia = smartdiacritics\n\tmatched, _ := searchMatch(base, pattern, textSearch)\n\tif matched != expected {\n\t\tt.Errorf(\"False search for ignorecase = %t, smartcase = %t, ignoredia = %t, smartdia = %t\",\n\t\t\tgOpts.ignorecase,\n\t\t\tgOpts.smartcase,\n\t\t\tgOpts.ignoredia,\n\t\t\tgOpts.smartdia)\n\t}\n}\n"
  },
  {
    "path": "doc.md",
    "content": "# NAME\n\nlf - terminal file manager\n\n# SYNOPSIS\n\n**lf**\n[**-command** *command*]\n[**-config** *path*]\n[**-cpuprofile** *path*]\n[**-doc**]\n[**-help**]\n[**-last-dir-path** *path*]\n[**-log** *path*]\n[**-memprofile** *path*]\n[**-print-last-dir**]\n[**-print-selection**]\n[**-remote** *command*]\n[**-selection-path** *path*]\n[**-server**]\n[**-single**]\n[**-version**]\n[*cd-or-select-path*]\n\n# DESCRIPTION\n\nlf is a terminal file manager.\n\nThe source code can be found in the repository at https://github.com/gokcehan/lf\n\nThis documentation can either be read from the terminal using `lf -doc` or online at https://github.com/gokcehan/lf/blob/master/doc.md\nYou can also use the `help` command (default `<f-1>`) inside lf to view the documentation in a pager.\nA man page with the same content is also available in the repository at https://github.com/gokcehan/lf/blob/master/lf.1\n\n# OPTIONS\n\n## POSITIONAL ARGUMENTS\n\n**cd-or-select-path**\n\nSet 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.\n\n## META OPTIONS\n\n**-doc**\n\nShow lf's documentation (same content as this file) and exit.\n\n**-help**\n\nShow command-line usage and exit.\n\n**-version**\n\nShow version information and exit.\n\n## STARTUP & CONFIGURATION\n\n**-command** *command*\n\nExecute *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 \";\".\n\n**-config** *path*\n\nUse the config file at *path* instead of the normal search locations. This only affects which `lfrc` is read at startup.\n\n## SHELL INTEGRATION\n\n**-print-last-dir**\n\nPrint 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.\n\n**-last-dir-path** *path*\n\nSame as **-print-last-dir**, but write the directory to *path* instead of stdout.\n\n**-print-selection**\n\nPrint 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.\n\n**-selection-path** *path*\n\nSame as **-print-selection**, but write the newline-separated list to *path* instead of stdout.\n\n## SERVER\n\n**-remote** *command*\n\nSend *command* to the running server (i.e. `send`, `query`, `list`, `quit`, or `quit!`). See `REMOTE COMMANDS` for more details.\n\n**-server**\n\nStart 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.\n\n**-single**\n\nStart a stand-alone client without a server. Disables remote control.\n\n## DIAGNOSTICS\n\n**-log** *path*\n\nAppend runtime log messages to *path*.\n\n**-cpuprofile** *path*\n\nWrite a CPU profile to *path*. The profile can be used by `go tool pprof`.\n\n**-memprofile** *path*\n\nWrite a memory profile to *path*. The profile can be used by `go tool pprof`.\n\n## EXAMPLES\n\nUse `lf` to select files (while hiding certain file types):\n\n\tlf -command 'set nohidden' -command 'set hiddenfiles \"*mp4:*pdf:*txt\"' -print-selection\n\nAnother sophisticated \"open file\" dialog focusing on design:\n\n\tlf -command 'set nopreview; set ratios 1; set drawbox; set promptfmt \"Select files [%w] %S q: cancel, l: confirm\"' -print-selection\n\nOpen Downloads and set `sortby` and `info` to creation date:\n\n\tlf -command 'set sortby btime; set info btime' ~/Downloads\n\nTemporarily prevent `lf` from modifying the command history:\n\n\tlf -command 'set nohistory'\n\nUse default settings and log current session:\n\n\tlf -config /dev/null -log /tmp/lf.log\n\nForce-quit the server:\n\n\tlf -remote 'quit!'\n\nInherit lf's working directory in your shell:\n\n\tcd \"$(lf -print-last-dir)\"\n\n# QUICK REFERENCE\n\nThe following commands are provided by lf:\n\n\tquit                     (default 'q')\n\tup                       (default 'k' and '<up>')\n\thalf-up                  (default '<c-u>')\n\tpage-up                  (default '<c-b>' and '<pgup>')\n\tscroll-up                (default '<c-y>')\n\tdown                     (default 'j' and '<down>')\n\thalf-down                (default '<c-d>')\n\tpage-down                (default '<c-f>' and '<pgdn>')\n\tscroll-down              (default '<c-e>')\n\tupdir                    (default 'h' and '<left>')\n\topen                     (default 'l' and '<right>')\n\tjump-next                (default ']')\n\tjump-prev                (default '[')\n\ttop                      (default 'gg' and '<home>')\n\tbottom                   (default 'G' and '<end>')\n\thigh                     (default 'H')\n\tmiddle                   (default 'M')\n\tlow                      (default 'L')\n\ttoggle\n\tinvert                   (default 'v')\n\tunselect                 (default 'u')\n\tglob-select\n\tglob-unselect\n\tcopy                     (default 'y')\n\tcut                      (default 'd')\n\tpaste                    (default 'p')\n\tclear                    (default 'c')\n\tsync\n\tdraw\n\tredraw                   (default '<c-l>')\n\tload\n\treload                   (default '<c-r>')\n\tdelete         (modal)\n\trename         (modal)   (default 'r')\n\tread           (modal)   (default ':')\n\tshell          (modal)   (default '$')\n\tshell-pipe     (modal)   (default '%')\n\tshell-wait     (modal)   (default '!')\n\tshell-async    (modal)   (default '&')\n\tfind           (modal)   (default 'f')\n\tfind-back      (modal)   (default 'F')\n\tfind-next                (default ';')\n\tfind-prev                (default ',')\n\tsearch         (modal)   (default '/')\n\tsearch-back    (modal)   (default '?')\n\tsearch-next              (default 'n')\n\tsearch-prev              (default 'N')\n\tfilter         (modal)\n\tsetfilter\n\tmark-save      (modal)   (default 'm')\n\tmark-load      (modal)   (default \"'\")\n\tmark-remove    (modal)   (default '\"')\n\ttag\n\ttag-toggle               (default 't')\n\techo\n\techomsg\n\techoerr\n\tcd\n\tselect\n\tsource\n\tpush\n\taddcustominfo\n\tcalcdirsize\n\tclearmaps\n\ttty-write\n\tvisual                   (default 'V')\n\nThe following Visual mode commands are provided by lf:\n\n\tvisual-accept            (default 'V')\n\tvisual-unselect\n\tvisual-discard           (default '<esc>')\n\tvisual-change            (default 'o')\n\nThe following Command-line mode commands are provided by lf:\n\n\tcmd-insert\n\tcmd-escape               (default '<esc>')\n\tcmd-complete             (default '<tab>')\n\tcmd-menu-complete\n\tcmd-menu-complete-back\n\tcmd-menu-accept\n\tcmd-menu-discard\n\tcmd-enter                (default '<c-j>' and '<enter>')\n\tcmd-interrupt            (default '<c-c>')\n\tcmd-history-next         (default '<c-n>' and '<down>')\n\tcmd-history-prev         (default '<c-p>' and '<up>')\n\tcmd-left                 (default '<c-b>' and '<left>')\n\tcmd-right                (default '<c-f>' and '<right>')\n\tcmd-home                 (default '<c-a>' and '<home>')\n\tcmd-end                  (default '<c-e>' and '<end>')\n\tcmd-delete               (default '<c-d>' and '<delete>')\n\tcmd-delete-back          (default '<backspace>')\n\tcmd-delete-home          (default '<c-u>')\n\tcmd-delete-end           (default '<c-k>')\n\tcmd-delete-unix-word     (default '<c-w>')\n\tcmd-yank                 (default '<c-y>')\n\tcmd-transpose            (default '<c-t>')\n\tcmd-transpose-word       (default '<a-t>')\n\tcmd-word                 (default '<a-f>')\n\tcmd-word-back            (default '<a-b>')\n\tcmd-delete-word          (default '<a-d>')\n\tcmd-delete-word-back     (default '<a-backspace>')\n\tcmd-capitalize-word      (default '<a-c>')\n\tcmd-uppercase-word       (default '<a-u>')\n\tcmd-lowercase-word       (default '<a-l>')\n\nThe following options can be used to customize the behavior of lf:\n\n\tanchorfind        bool      (default true)\n\tautoquit          bool      (default true)\n\tborderfmt         string    (default \"\\033[0m\")\n\tborderstyle       string    (default 'box')\n\tcleaner           string    (default '')\n\tcopyfmt           string    (default \"\\033[7;33m\")\n\tcursoractivefmt   string    (default \"\\033[7m\")\n\tcursorparentfmt   string    (default \"\\033[7m\")\n\tcursorpreviewfmt  string    (default \"\\033[4m\")\n\tcutfmt            string    (default \"\\033[7;31m\")\n\tdircounts         bool      (default false)\n\tdirfirst          bool      (default true)\n\tdironly           bool      (default false)\n\tdirpreviews       bool      (default false)\n\tdrawbox           bool      (default false)\n\tdupfilefmt        string    (default '%f.~%n~')\n\terrorfmt          string    (default \"\\033[7;31;47m\")\n\tfilesep           string    (default \"\\n\")\n\tfiltermethod      string    (default 'text')\n\tfindlen           int       (default 1)\n\thidden            bool      (default false)\n\thiddenfiles       []string  (default '.*' for Unix and '' for Windows)\n\thistory           bool      (default true)\n\ticons             bool      (default false)\n\tifs               string    (default '')\n\tignorecase        bool      (default true)\n\tignoredia         bool      (default true)\n\tincfilter         bool      (default false)\n\tincsearch         bool      (default false)\n\tinfo              []string  (default '')\n\tinfotimefmtnew    string    (default 'Jan _2 15:04')\n\tinfotimefmtold    string    (default 'Jan _2  2006')\n\tmenufmt           string    (default \"\\033[0m\")\n\tmenuheaderfmt     string    (default \"\\033[1m\")\n\tmenuselectfmt     string    (default \"\\033[7m\")\n\tmergeindicators   bool      (default false)\n\tmouse             bool      (default false)\n\tnumber            bool      (default false)\n\tnumbercursorfmt   string    (default '')\n\tnumberfmt         string    (default \"\\033[33m\")\n\tperiod            int       (default 0)\n\tpreload           bool      (default false)\n\tpreserve          []string  (default \"mode\")\n\tpreview           bool      (default true)\n\tpreviewer         string    (default '')\n\tpromptfmt         string    (default \"\\033[32;1m%u@%h\\033[0m:\\033[34;1m%d\\033[0m\\033[1m%f\\033[0m\")\n\tratios            []int     (default '1:2:3')\n\trelativenumber    bool      (default false)\n\treverse           bool      (default false)\n\trulerfile         string    (default \"\")\n\trulerfmt          string    (default \"\")\n\tscrolloff         int       (default 0)\n\tsearchmethod      string    (default 'text')\n\tselectfmt         string    (default \"\\033[7;35m\")\n\tselmode           string    (default 'all')\n\tshell             string    (default 'sh' for Unix and 'cmd' for Windows)\n\tshellflag         string    (default '-c' for Unix and '/c' for Windows)\n\tshellopts         []string  (default '')\n\tshowbinds         bool      (default true)\n\tsizeunits         string    (default 'binary')\n\tsmartcase         bool      (default true)\n\tsmartdia          bool      (default false)\n\tsortby            string    (default 'natural')\n\tstatfmt           string    (default \"\\033[36m%p\\033[0m| %c| %u| %g| %S| %t| -> %l\")\n\ttabstop           int       (default 8)\n\ttagfmt            string    (default \"\\033[31m\")\n\ttempmarks         string    (default '')\n\tterminalcursor    string    (default 'default')\n\ttimefmt           string    (default 'Mon Jan _2 15:04:05 2006')\n\ttruncatechar      string    (default '~')\n\ttruncatepct       int       (default 100)\n\tvisualfmt         string    (default \"\\033[7;36m\")\n\twaitmsg           string    (default 'Press any key to continue')\n\twatch             bool      (default false)\n\twrapscan          bool      (default true)\n\twrapscroll        bool      (default false)\n\tuser_{option}     string    (default none)\n\nThe following environment variables are exported for shell commands:\n\n\tf\n\tfs\n\tfv\n\tfx\n\tid\n\tPWD\n\tOLDPWD\n\tLF_LEVEL\n\tOPENER\n\tVISUAL\n\tEDITOR\n\tPAGER\n\tSHELL\n\tlf\n\tlf_{option}\n\tlf_user_{option}\n\tlf_flag_{flag}\n\tlf_width\n\tlf_height\n\tlf_count\n\tlf_mode\n\nThe following special shell commands are used to customize the behavior of lf when defined:\n\n\topen\n\tpaste\n\trename\n\tdelete\n\tpre-cd\n\ton-cd\n\ton-load\n\ton-focus-gained\n\ton-focus-lost\n\ton-init\n\ton-select\n\ton-redraw\n\ton-quit\n\nThe following commands/keybindings are provided by default:\n\n\tUnix\n\tcmd open &$OPENER \"$f\"\n\tmap e $$EDITOR \"$f\"\n\tmap i $$PAGER \"$f\"\n\tmap w $$SHELL\n\tcmd help $$lf -doc | $PAGER\n\tmap <f-1> help\n\tcmd maps $lf -remote \"query $id maps\" | $PAGER\n\tcmd nmaps $lf -remote \"query $id nmaps\" | $PAGER\n\tcmd vmaps $lf -remote \"query $id vmaps\" | $PAGER\n\tcmd cmaps $lf -remote \"query $id cmaps\" | $PAGER\n\tcmd cmds $lf -remote \"query $id cmds\" | $PAGER\n\n\tWindows\n\tcmd open &%OPENER% %f%\n\tmap e $%EDITOR% %f%\n\tmap i !%PAGER% %f%\n\tmap w $%SHELL%\n\tcmd help !%lf% -doc | %PAGER%\n\tmap <f-1> help\n\tcmd maps !%lf% -remote \"query %id% maps\" | %PAGER%\n\tcmd nmaps !%lf% -remote \"query %id% nmaps\" | %PAGER%\n\tcmd vmaps !%lf% -remote \"query %id% vmaps\" | %PAGER%\n\tcmd cmaps !%lf% -remote \"query %id% cmaps\" | %PAGER%\n\tcmd cmds !%lf% -remote \"query %id% cmds\" | %PAGER%\n\nThe defaults for Windows are using `cmd` syntax.\nA `PowerShell` compatible configuration file can be found at\nhttps://github.com/gokcehan/lf/blob/master/etc/lfrc.ps1.example\n\nThe following additional keybindings are provided by default:\n\n\tmap zh set hidden!\n\tmap zr set reverse!\n\tmap zn set info\n\tmap zs set info size\n\tmap zt set info time\n\tmap za set info size:time\n\tmap sn :set sortby natural; set info\n\tmap ss :set sortby size; set info size\n\tmap st :set sortby time; set info time\n\tmap sa :set sortby atime; set info atime\n\tmap sb :set sortby btime; set info btime\n\tmap sc :set sortby ctime; set info ctime\n\tmap se :set sortby ext; set info\n\tmap gh cd ~\n\tnmap <space> :toggle; down\n\nIf the `mouse` option is enabled, mouse buttons have the following default effects:\n\n\tLeft mouse button\n\t    Click on a file or directory to select it.\n\n\tRight mouse button\n\t    Enter a directory or open a file. Also works on the preview pane.\n\n\tScroll wheel\n\t    Move up or down. If Ctrl is pressed, scroll up or down.\n\n# CONFIGURATION\n\nConfiguration files should be located at:\n\n\tOS       system-wide               user-specific\n\tUnix     /etc/lf/lfrc              ~/.config/lf/lfrc\n\tWindows  C:\\ProgramData\\lf\\lfrc    C:\\Users\\<user>\\AppData\\Roaming\\lf\\lfrc\n\nThe colors file should be located at:\n\n\tOS       system-wide               user-specific\n\tUnix     /etc/lf/colors            ~/.config/lf/colors\n\tWindows  C:\\ProgramData\\lf\\colors  C:\\Users\\<user>\\AppData\\Roaming\\lf\\colors\n\nThe icons file should be located at:\n\n\tOS       system-wide               user-specific\n\tUnix     /etc/lf/icons             ~/.config/lf/icons\n\tWindows  C:\\ProgramData\\lf\\icons   C:\\Users\\<user>\\AppData\\Roaming\\lf\\icons\n\nThe selection file should be located at:\n\n\tUnix     ~/.local/share/lf/files\n\tWindows  C:\\Users\\<user>\\AppData\\Local\\lf\\files\n\nThe marks file should be located at:\n\n\tUnix     ~/.local/share/lf/marks\n\tWindows  C:\\Users\\<user>\\AppData\\Local\\lf\\marks\n\nThe tags file should be located at:\n\n\tUnix     ~/.local/share/lf/tags\n\tWindows  C:\\Users\\<user>\\AppData\\Local\\lf\\tags\n\nThe history file should be located at:\n\n\tUnix     ~/.local/share/lf/history\n\tWindows  C:\\Users\\<user>\\AppData\\Local\\lf\\history\n\nYou can configure these locations with the following variables given with their order of precedences and their default values:\n\n\tUnix\n\t    $LF_CONFIG_HOME\n\t    $XDG_CONFIG_HOME\n\t    ~/.config\n\n\t    $LF_DATA_HOME\n\t    $XDG_DATA_HOME\n\t    ~/.local/share\n\n\tWindows\n\t    %LF_CONFIG_HOME%\n\t    %XDG_CONFIG_HOME%\n\t    %APPDATA%\n\n\t    %LF_DATA_HOME%\n\t    %XDG_DATA_HOME%\n\t    %LOCALAPPDATA%\n\nA sample configuration file can be found at\nhttps://github.com/gokcehan/lf/blob/master/etc/lfrc.example\n\n# COMMANDS\n\nThis section shows information about built-in commands.\nModal 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.\n\n## quit (default `q`)\n\nQuit lf and return to the shell.\n\n## 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>`)\n\nMove/scroll the current file selection upwards/downwards by one/half a page/full page.\n\n## updir (default `h` and `<left>`)\n\nChange the current working directory to the parent directory.\n\n## open (default `l` and `<right>`)\n\nIf the current file is a directory, then change the current directory to it, otherwise, execute the `open` command.\nA default `open` command is provided to call the default system opener asynchronously with the current file as the argument.\nA custom `open` command can be defined to override this default.\n\n## jump-next (default `]`), jump-prev (default `[`)\n\nChange the current working directory to the next/previous jumplist item.\n\n## top (default `gg` and `<home>`), bottom (default `G` and `<end>`)\n\nMove the current file selection to the top/bottom of the directory.\nA count can be specified to move to a specific line, for example, use `3G` to move to the third line.\n\n## high (default `H`), middle (default `M`), low (default `L`)\n\nMove the current file selection to the high/middle/low of the screen.\n\n## toggle\n\nToggle the selection of the current file or files given as arguments.\n\n## invert (default `v`)\n\nReverse the selection of all files in the current directory (i.e. `toggle` all files).\nSelections in other directories are not affected by this command.\nYou 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.\n\n## unselect (default `u`)\n\nRemove the selection of all files in all directories.\n\n## glob-select, glob-unselect\n\nSelect/unselect files that match the given glob.\n\n## copy (default `y`)\n\nSave the paths of selected files to the clipboard as files to be copied.\nIf there are no selected files, the path of the current file is used instead.\n\n## cut (default `d`)\n\nSave the paths of selected files to the clipboard as files to be moved.\nIf there are no selected files, the path of the current file is used instead.\n\n## paste (default `p`)\n\nCopy/Move files in the clipboard to the current working directory.\nA custom `paste` command can be defined to override this default.\n\n## clear (default `c`)\n\nClear file paths in the clipboard.\n\n## sync\n\nSynchronize copied/cut files with the server.\nThis command is automatically called when required.\n\n## draw\n\nDraw the screen.\nThis command is automatically called when required.\n\n## redraw (default `<c-l>`)\n\nSynchronize the terminal and redraw the screen.\n\n## load\n\nLoad modified files and directories.\nThis command is automatically called when required.\n\n## reload (default `<c-r>`)\n\nFlush the cache and reload all files and directories.\n\n## delete (modal)\n\nRemove the current file or selected file(s).\nA custom `delete` command can be defined to override this default.\n\n## rename (modal) (default `r`)\n\nRename the current file using the built-in method.\nA custom `rename` command can be defined to override this default.\n\n## read (modal) (default `:`)\n\nRead a command to evaluate.\n\n## shell (modal) (default `$`)\n\nRead a shell command to execute.\n\n## shell-pipe (modal) (default `%`)\n\nRead a shell command to execute piping its standard I/O to the bottom statline.\n\n## shell-wait (modal) (default `!`)\n\nRead a shell command to execute and wait for a key press at the end.\n\n## shell-async (modal) (default `&`)\n\nRead a shell command to execute asynchronously without standard I/O.\n\n## find (modal) (default `f`), find-back (modal) (default `F`), find-next (default `;`), find-prev (default `,`)\n\nRead key(s) to find the appropriate filename match in the forward/backward direction and jump to the next/previous match.\n\n## search (default `/`), search-back (default `?`), search-next (default `n`), search-prev (default `N`)\n\nRead a pattern to search for a filename match in the forward/backward direction and jump to the next/previous match.\n\n## filter (modal), setfilter\n\nCommand `filter` reads a pattern to filter out and only view files matching the pattern.\nCommand `setfilter` does the same but uses an argument to set the filter immediately.\nYou can supply an argument to `filter` to use as the starting prompt.\n\n## mark-save (modal) (default `m`)\n\nSave the current directory as a bookmark assigned to the given key.\n\n## mark-load (modal) (default `'`)\n\nChange the current directory to the bookmark assigned to the given key.\nA special bookmark `'` holds the previous directory after a `mark-load`, `cd`, or `select` command.\n\n## mark-remove (modal) (default `\"`)\n\nRemove a bookmark assigned to the given key.\n\n## tag\n\nTag a file with `*` or a single-width character given in the argument.\nYou can define a new tag-clearing command by combining `tag` with `tag-toggle` (i.e. `cmd tag-clear :tag; tag-toggle`).\n\n## tag-toggle (default `t`)\n\nTag a file with `*` or a single-width character given in the argument if the file is untagged, otherwise remove the tag.\n\n## echo\n\nPrint the given arguments to the message line at the bottom.\n\n## echomsg\n\nPrint the given arguments to the message line at the bottom and also to the log file.\n\n## echoerr\n\nPrint given arguments to the message line at the bottom as `errorfmt` and also to the log file.\n\n## cd\n\nChange the working directory to the given argument.\n\n## select\n\nChange the current file selection to the given argument.\n\n## source\n\nRead the configuration file given in the argument.\n\n## push\n\nSimulate key pushes given in the argument.\n\n## addcustominfo\n\nUpdate the `custom` info and `.Stat.CustomInfo` field of the given file with the given string.\nThe info string may contain ANSI escape codes to further customize its appearance.\nIf no info is provided, clear the file's info instead.\n\n## calcdirsize\n\nCalculate the total size for each of the selected directories.\nOption `info` should include `size` and option `dircounts` should be disabled to show this size.\nIf the total size of a directory is not calculated, it will be shown as `-`.\n\n## clearmaps\n\nRemove all keybindings associated with the `map`, `nmap` and `vmap` command.\nThis command can be used in the config file to remove the default keybindings.\nFor 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`.\n\n## tty-write\n\nWrite the given string to the tty.\nThis is useful for sending escape sequences to the terminal to control its behavior (e.g. OSC 0 to set the window title).\nUsing `tty-write` is preferred over directly writing to `/dev/tty` because the latter is not synchronized and can interfere with drawing the UI.\n\n## visual (default `V`)\n\nSwitch to Visual mode.\nIf already in Visual mode, discard the visual selection and stay in Visual mode.\n\n# VISUAL MODE COMMANDS\n\n## visual-accept (default `V`)\n\nAdd the visual selection to the selection list, quit Visual mode and return to Normal mode.\n\n## visual-unselect\n\nRemove the visual selection from the selection list, quit Visual mode and return to Normal mode.\n\n## visual-discard (default `<esc>`)\n\nDiscard the visual selection, quit Visual mode and return to Normal mode.\n\n## visual-change (default `o`)\n\nGo to the other end of the current Visual mode selection.\n\n# COMMAND-LINE MODE COMMANDS\n\nThe prompt character specifies which of the several Command-line modes you are in.\nFor example, the `read` command takes you to the `:` mode.\n\nWhen the cursor is at the first character in `:` mode, pressing one of the keys `!`, `$`, `%`, or `&` takes you to the corresponding mode.\nYou can go back with `cmd-delete-back` (`<backspace>` by default).\n\nThe command line commands should be mostly compatible with readline keybindings.\nA character refers to a Unicode code point, a word consists of letters and digits, and a Unix word consists of any non-blank characters.\n\n## cmd-insert\n\nInsert the character given in the argument.\nThis command is automatically called when required.\n\n## cmd-escape (default `<esc>`)\n\nQuit Command-line mode and return to Normal mode.\n\n## cmd-complete (default `<tab>`)\n\nAutocomplete the current word.\n\n## cmd-menu-complete, cmd-menu-complete-back\n\nAutocomplete the current word with the menu selection.\nYou need to assign keys to these commands (e.g. `cmap <tab> cmd-menu-complete; cmap <backtab> cmd-menu-complete-back`).\nYou can use the assigned keys to display the menu and then cycle through completion options.\n\n## cmd-menu-accept\n\nAccept the currently selected match in menu completion and close the menu.\n\n## cmd-menu-discard\n\nDiscard the currently selected match in menu completion and close the menu.\n\n## cmd-enter (default `<c-j>` and `<enter>`)\n\nExecute the current line.\n\n## cmd-interrupt (default `<c-c>`)\n\nInterrupt the current shell-pipe command and return to the Normal mode.\n\n## cmd-history-next (default `<c-n>` and `<down>`), cmd-history-prev (default `<c-p>` and `<up>`)\n\nGo to the next/previous entry in the command history.\nIf part of the command is already typed, then only matching entries will be considered, and consecutive duplicate entries are skipped.\n\n## cmd-left (default `<c-b>` and `<left>`), cmd-right (default `<c-f>` and `<right>`)\n\nMove the cursor to the left/right.\n\n## cmd-home (default `<c-a>` and `<home>`), cmd-end (default `<c-e>` and `<end>`)\n\nMove the cursor to the beginning/end of the line.\n\n## cmd-delete (default `<c-d>` and `<delete>`)\n\nDelete the next character.\n\n## cmd-delete-back (default `<backspace>`)\n\nDelete the previous character.\nWhen at the beginning of a prompt, returns either to Normal mode or to `:` mode.\n\n## cmd-delete-home (default `<c-u>`), cmd-delete-end (default `<c-k>`)\n\nDelete everything up to the beginning/end of the line.\n\n## cmd-delete-unix-word (default `<c-w>`)\n\nDelete the previous Unix word.\n\n## cmd-yank (default `<c-y>`)\n\nPaste the buffer content containing the last deleted item.\n\n## cmd-transpose (default `<c-t>`)\n\nSwap the characters before and after the cursor, then move the cursor forward.\nIf there is no character after the cursor, swap the previous two characters instead.\n\n## cmd-transpose-word (default `<a-t>`)\n\nSwap the words before and after the cursor, then move the cursor forward.\nIf there is no word after the cursor, swap the previous two words instead.\n\n## cmd-word (default `<a-f>`), cmd-word-back (default `<a-b>`)\n\nMove the cursor by one word in the forward/backward direction.\n\n## cmd-delete-word (default `<a-d>`)\n\nDelete the next word in the forward direction.\n\n## cmd-delete-word-back (default `<a-backspace>`)\n\nDelete the previous word in the backward direction.\n\n## cmd-capitalize-word (default `<a-c>`), cmd-uppercase-word (default `<a-u>`), cmd-lowercase-word (default `<a-l>`)\n\nCapitalize/uppercase/lowercase the current word and jump to the next word.\n\n# SETTINGS\n\nThis section shows information about options to customize the behavior.\nCharacter `:` is used as the separator for list options `[]int` and `[]string`.\n\n## anchorfind (bool) (default true)\n\nWhen this option is enabled, the find command starts matching patterns from the beginning of filenames, otherwise, it can match at an arbitrary position.\n\n## autoquit (bool) (default true)\n\nAutomatically quit the server when there are no clients left connected.\n\n## borderfmt (string) (default `\\033[0m`)\n\nFormat string of border characters.\n\n## borderstyle (string) (default `box`)\n\nBorder style used by `drawbox`.\n\nThe following styles are supported:\n\n\tbox           outline around all panes and separators between them\n\troundbox      like `box`, but with rounded outer corners\n\toutline       outline around all panes\n\troundoutline  like `outline`, but with rounded outer corners\n\tseparators    separators between panes\n\n## cleaner (string) (default ``) (not called if empty)\n\nSet the path of a cleaner file.\nThe file should be executable.\nThis file is called if previewing is enabled, the previewer is set, and the previously selected file has its preview cache disabled.\nThe 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.\nPreview cleaning is disabled when the value of this option is left empty.\n\n## copyfmt (string) (default `\\033[7;33m`)\n\nFormat string of the indicator for files to be copied.\n\n## cursoractivefmt (string) (default `\\033[7m`), cursorparentfmt (string) (default `\\033[7m`), cursorpreviewfmt (string) (default `\\033[4m`)\n\nFormat strings for highlighting the cursor.\n`cursoractivefmt` applies in the current directory pane,\n`cursorparentfmt` applies in panes that show parents of the current directory,\nand `cursorpreviewfmt` applies in panes that preview directories.\n\nThe default is to make the active cursor and the parent directory cursor inverted. The preview cursor is underlined.\n\nSome 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.\n\nIf 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.\nFor example, `\\033[4m%s\\033[0m` has the same effect as `\\033[4m`.\n\n## cutfmt (string) (default `\\033[7;31m`)\n\nFormat string of the indicator for files to be cut.\n\n## dircounts (bool) (default false)\n\nWhen 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`.\nThis information needs to be calculated by reading the directory and counting the items inside.\nTherefore, this option is disabled by default for performance reasons.\nThis option only has an effect when `info` has a `size` field and the pane is wide enough to show the information.\n999 items are counted per directory at most, and bigger directories are shown as `999+`.\n\n## dirfirst (bool) (default true)\n\nShow directories first above regular files.\nWith `dircounts` enabled, sorting by `size` always separates directories and files, regardless of `dirfirst`.\n\n## dironly (bool) (default false)\n\nShow only directories.\n\n## dirpreviews (bool) (default false)\n\nIf enabled, directories will also be passed to the previewer script. This allows custom previews for directories.\n\n## drawbox (bool) (default false)\n\nDraw borders around panes using box drawing characters.\n\n## dupfilefmt (string) (default `%f.~%n~`)\n\nFormat 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~`.\nSpecial 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.\n\n## errorfmt (string) (default `\\033[7;31;47m`)\n\nFormat string of error messages shown in the bottom message line.\n\nIf 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.\nFor example, `\\033[4m%s\\033[0m` has the same effect as `\\033[4m`.\n\n## filesep (string) (default `\\n`)\n\nFile separator used in environment variables `fs`, `fv` and `fx`.\n\n## filtermethod (string) (default `text`)\n\nHow filter command patterns are treated.\nCurrently supported methods are `text` (i.e. string literals), `glob` (i.e. shell globs) and `regex` (i.e. regular expressions).\nSee `SEARCHING FILES` for more details.\n\n## findlen (int) (default 1)\n\nNumber of characters prompted for the find command.\nWhen this value is set to 0, find command prompts until there is only a single match left.\n\n## hidden (bool) (default false)\n\nShow hidden files.\nOn Unix systems, hidden files are determined by the value of `hiddenfiles`.\nOn Windows, files with hidden attributes are also considered hidden files.\n\n## hiddenfiles ([]string) (default `.*` for Unix and `` for Windows)\n\nList of hidden file glob patterns.\nPatterns can be given as relative or absolute paths.\nGlobbing supports the usual special characters, `*` to match any sequence, `?` to match any character, and `[...]` or `[^...]` to match character sets or ranges.\nIn 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`\n\n## history (bool) (default true)\n\nSave command history.\n\n## icons (bool) (default false)\n\nShow icons before each item in the list.\n\n## ifs (string) (default ``)\n\nSets `IFS` variable in shell commands.\nIt works by adding the assignment to the beginning of the command string as `IFS=...; ...`.\nThe reason is that `IFS` variable is not inherited by the shell for security reasons.\nThis method assumes a POSIX shell syntax so it can fail for non-POSIX shells.\nThis option has no effect when the value is left empty.\nThis option does not have any effect on Windows.\n\n## ignorecase (bool) (default true)\n\nIgnore case in sorting and search patterns.\n\n## ignoredia (bool) (default true)\n\nIgnore diacritics in sorting and search patterns.\n\n## incfilter (bool) (default false)\n\nApply filter pattern after each keystroke during filtering.\n\n## incsearch (bool) (default false)\n\nJump to the first match after each keystroke during searching.\n\n## info ([]string)  (default ``)\n\nA list of information that is shown for directory items at the right side of the pane.\n\nThe following information types are supported:\n\n\tperm      file permission\n\tuser      user name\n\tgroup     group name\n\tsize      file size\n\ttime      time of last data modification\n\tatime     time of last access\n\tbtime     time of file birth\n\tctime     time of last status (inode) change\n\tcustom    property defined via `addcustominfo` (empty by default)\n\nInformation is only shown when the pane width is more than twice the width of information.\n\n## infotimefmtnew (string) (default `Jan _2 15:04`)\n\nFormat string of the file time shown in the info column when it matches this year.\n\n## infotimefmtold (string) (default `Jan _2  2006`)\n\nFormat string of the file time shown in the info column when it doesn't match this year.\n\n## menufmt (string) (default `\\033[0m`)\n\nFormat string of the menu.\n\n## menuheaderfmt (string) (default `\\033[1m`)\n\nFormat string of the header row in the menu.\n\n## menuselectfmt (string) (default `\\033[7m`)\n\nFormat string of the currently selected item in the menu.\n\n## mergeindicators (bool) (default false)\n\nWhen `mergeindicators` is enabled, tag and selection indicators are drawn in a single column to reduce the gap before filenames.\nIf a file is both tagged and selected, the tag uses the selection format (e.g. `copyfmt`) instead of `tagfmt`.\n\n## mouse (bool) (default false)\n\nSend mouse events as input.\n\n## number (bool) (default false)\n\nShow the position number for directory items on the left side of the pane.\nWhen the `relativenumber` option is enabled, only the current line shows the absolute position and relative positions are shown for the rest.\n\n## numberfmt (string) (default `\\033[33m`), numbercursorfmt (string) (default ``)\n\nFormat strings for highlighting line numbers.\n`numberfmt` applies to all lines.\n`numbercursorfmt` applies to the cursor line and falls back to `numberfmt` when left empty.\n\n## period (int) (default 0)\n\nSet the interval in seconds for periodic checks of directory updates.\nThis works by periodically calling the `load` command.\nNote that directories are already updated automatically in many cases.\nThis option can be useful when there is an external process changing the displayed directory and you are not doing anything in lf.\nPeriodic checks are disabled when the value of this option is set to zero.\n\n## preload (bool) (default false)\n\nAllow previews to be generated in advance using the `previewer` script as the user navigates through the filesystem.\n\n## preserve ([]string) (default `mode`)\n\nList of attributes that are preserved when copying files.\nCurrently supported attributes are `mode` (i.e. access mode) and `timestamps` (i.e. modification time and access time).\nNote that preserving other attributes like ownership of change/birth timestamp is desirable, but not portably supported in Go.\n\n## preview (bool) (default true)\n\nShow previews of files and directories at the rightmost pane.\nIf the file has more lines than the preview pane, the rest of the lines are not read.\nFiles containing the null character (U+0000) in the read portion are considered binary files and displayed as `binary`.\n\n## previewer (string) (default ``) (not filtered if empty)\n\nSet the path of a previewer file to filter the content of regular files for previewing.\nThe file should be executable.\nThe 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\").\nSIGPIPE signal is sent when enough lines are read.\nIf the previewer returns a non-zero exit code, then the preview cache for the given file is disabled.\nThis means that if the file is selected in the future, the previewer is called once again.\nPreview filtering is disabled and files are displayed as they are when the value of this option is left empty.\nIf the `preload` option is enabled, then this will be called with `preload` as the mode when preloading file previews.\nRefer 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.\n\n## promptfmt (string) (default `\\033[32;1m%u@%h\\033[0m:\\033[34;1m%d\\033[0m\\033[1m%f\\033[0m`)\n\nFormat string of the prompt shown in the top line.\n\nThe following special expansions are supported:\n\n\t%f        file name\n\t%h        host name\n\t%u        user name\n\t%w        working directory\n\t%d        working directory (with trailing path separator)\n\t%F        current filter\n\t%S        spacer to right-align the following parts (can be used once)\n\nThe home folder is shown as `~` in the working directory expansion.\nDirectory names are automatically shortened to a single character starting from the leftmost parent when the prompt does not fit the screen.\n\n## ratios ([]int) (default `1:2:3`)\n\nList of ratios of pane widths.\nNumber of items in the list determines the number of panes in the UI.\nWhen the `preview` option is enabled, the rightmost number is used for the width of the preview pane.\n\n## relativenumber (bool) (default false)\n\nShow the position number relative to the current line.\nWhen `number` is enabled, the current line shows the absolute position, otherwise nothing is shown.\n\n## reverse (bool) (default false)\n\nReverse the direction of sort.\n\n## rulerfile (string) (default ``)\n\nSet the path of the ruler file.\nIf not set, then a default template will be used for the ruler.\nRefer to the [RULER section](https://github.com/gokcehan/lf/blob/master/doc.md#ruler) for more information about how the ruler file works.\n\n## rulerfmt (string) (default ``)\n\nFormat string of the ruler shown in the bottom right corner.\nWhen set, it will be used along with `statfmt` to draw the ruler, and `rulerfile` will be ignored.\nHowever, using `rulerfile` is preferred and this option is provided for backwards compatibility.\n\nThe following special expansions are supported:\n\n\t%a        pressed keys\n\t%p        progress of file operations\n\t%m        number of files to be cut (moved)\n\t%c        number of files to be copied\n\t%s        number of selected files\n\t%v        number of visually selected files\n\t%t        number of shown files in the current directory\n\t%h        number of hidden files in the current directory\n\t%f        current filter\n\t%i        cursor position\n\t%P        scroll percentage\n\t%d        amount of free disk space\n\nAdditional 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.\nExpansions are also provided for user-defined options, in the form `%{lf_user_<name>}` (e.g. `%{lf_user_foo}`).\nThe `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown.\n\n## scrolloff (int) (default 0)\n\nMinimum number of offset lines shown at all times at the top and bottom of the screen when scrolling.\nThe 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.\nA 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.\n\n## searchmethod (string) (default `text`)\n\nHow search command patterns are treated.\nCurrently supported methods are `text` (i.e. string literals), `glob` (i.e. shell globs) and `regex` (i.e. regular expressions).\nSee `SEARCHING FILES` for more details.\n\n## selectfmt (string) (default `\\033[7;35m`)\n\nFormat string of the indicator for files that are selected.\n\n## selmode (string) (default `all`)\n\nSelection mode for commands.\nWhen set to `all` it will use the selected files from all directories.\nWhen set to `dir` it will only use the selected files in the current directory.\n\n## shell (string) (default `sh` for Unix and `cmd` for Windows)\n\nShell executable to use for shell commands.\nShell commands are executed as `shell shellopts shellflag command -- arguments`.\n\n## shellflag (string) (default `-c` for Unix and `/c` for Windows)\n\nCommand line flag used to pass shell commands.\n\n## shellopts ([]string)  (default ``)\n\nList of shell options to pass to the shell executable.\n\n## showbinds (bool) (default true)\n\nShow bindings associated with pressed keys.\n\n## sizeunits (string) (default `binary`)\n\nDetermines whether file sizes are displayed using binary units (`1K` is 1024 bytes) or decimal units (`1K` is 1000 bytes).\n\n## smartcase (bool) (default true)\n\nOverride `ignorecase` option when the pattern contains an uppercase character.\nThis option has no effect when `ignorecase` is disabled.\n\n## smartdia (bool) (default false)\n\nOverride `ignoredia` option when the pattern contains a character with diacritic.\nThis option has no effect when `ignoredia` is disabled.\n\n## sortby (string) (default `natural`)\n\nSort type for directories.\n\nThe following sort types are supported:\n\n\tnatural   file name (track_2.flac comes before track_10.flac)\n\tname      file name (track_10.flac comes before track_2.flac)\n\text       file extension\n\tsize      file size\n\ttime      time of last data modification\n\tatime     time of last access\n\tbtime     time of file birth\n\tctime     time of last status (inode) change\n\tcustom    property defined via `addcustominfo` (empty by default)\n\n## statfmt (string) (default `\\033[36m%p\\033[0m| %c| %u| %g| %S| %t| -> %l`)\n\nFormat string of the file info shown in the bottom left corner.\nThis option has no effect unless `rulerfmt` is also set.\nUsing `rulerfile` is preferred and this option is provided for backwards compatibility.\n\nThe following special expansions are supported:\n\n\t%p        file permission\n\t%c        link count\n\t%u        user name\n\t%g        group name\n\t%s        file size\n\t%S        file size (left-padded with spaces to a fixed width of 5 characters)\n\t%t        time of last data modification\n\t%l        link target\n\t%m        current mode\n\t%M        current mode (displaying `NORMAL` instead of a blank string in Normal mode)\n\nThe `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown.\n\n## tabstop (int) (default 8)\n\nNumber of space characters to show for horizontal tabulation (U+0009) character.\n\n## tagfmt (string) (default `\\033[31m`)\n\nFormat string of the tags.\n\nIf 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.\nFor example, `\\033[4m%s\\033[0m` has the same effect as `\\033[4m`.\n\n## tempmarks (string) (default ``)\n\nMarks to be considered temporary (e.g. `abc` refers to marks `a`, `b`, and `c`).\nThese marks are not synced to other clients and they are not saved in the bookmarks file.\nNote that the special bookmark `'` is always treated as temporary and it does not need to be specified.\n\n## terminalcursor (string) (default `default`)\n\nSet the appearance of the terminal cursor for prompts shown in the bottom line.\nCurrently supported values are `default`, `block`, `underline`, `bar`, `blinkblock`, `blinkunderline` and `blinkbar`.\n\n## timefmt (string) (default `Mon Jan _2 15:04:05 2006`)\n\nFormat string of the file modification time shown in the bottom line.\n\n## truncatechar (string) (default `~`)\n\nThe truncate character that is shown at the end when the filename does not fit into the pane.\n\n## truncatepct (int) (default 100)\n\nWhen a filename is too long to be shown completely, the available space will be partitioned into two parts.\n`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.\nThe second part uses the rest of the available space, and will be shown at the end of the filename.\nBoth parts are separated by the truncation character (`truncatechar`).\nTruncation is not applied to the file extension.\n\nFor example, with the filename `very_long_filename.txt`:\n\n- `set truncatepct 100` -> `very_long_filena~.txt` (default)\n\n- `set truncatepct 50`  -> `very_lon~filename.txt`\n\n- `set truncatepct 0`   -> `~ry_long_filename.txt`\n\n## visualfmt (string) (default `\\033[7;36m`)\n\nFormat string of the indicator for files that are visually selected.\n\n## waitmsg (string) (default `Press any key to continue`)\n\nString shown after commands of shell-wait type.\n\n## watch (bool) (default false)\n\nWatch the filesystem for changes using `fsnotify` to automatically refresh file information.\nFUSE is currently not supported due to limitations in `fsnotify`.\n\n## wrapscan (bool) (default true)\n\nSearching can wrap around the file list.\n\n## wrapscroll (bool) (default false)\n\nScrolling can wrap around the file list.\n\n## user_{option} (string) (default none)\n\nAny option that is prefixed with `user_` is a user-defined option and can be set to any string.\nInside a user-defined command, the value will be provided in the `lf_user_{option}` environment variable.\nThese options are not used by lf and are not persisted.\n\n# ENVIRONMENT VARIABLES\n\nThe following variables are exported for shell commands:\nThese 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`).\n\n## f\n\nCurrent file selection as a full path.\n\n## fs\n\nSelected file(s) separated with the value of `filesep` option as full path(s).\n\n## fv\n\nVisually selected file(s) separated with the value of `filesep` option as full path(s).\n\n## fx\n\nSelected file(s) (i.e. `fs`, never `fv`) if there are any selected files, otherwise current file selection (i.e. `f`).\n\n## id\n\nId of the running client.\n\n## PWD\n\nPresent working directory.\n\n## OLDPWD\n\nInitial working directory.\n\n## LF_LEVEL\n\nThe value of this variable is set to the current nesting level when you run lf from a shell spawned inside lf.\nYou can add the value of this variable to your shell prompt to make it clear that your shell runs inside lf.\nFor example, with POSIX shells, you can use `[ -n \"$LF_LEVEL\" ] && PS1=\"$PS1\"\"(lf level: $LF_LEVEL) \"` in your shell configuration file (e.g. `~/.bashrc`).\n\n## OPENER\n\nIf 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.\n\n## EDITOR\n\nIf 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.\n\n## PAGER\n\nIf this variable is set in the environment, use the same value. Otherwise, this is set to `less` on Unix, `more` in Windows.\n\n## SHELL\n\nIf this variable is set in the environment, use the same value. Otherwise, this is set to `sh` on Unix, `cmd` in Windows.\n\n## lf\n\nAbsolute path to the currently running lf binary, if it can be found. Otherwise, this is set to the string `lf`.\n\n## lf_{option}\n\nValue of the {option}.\n\n## lf_user_{option}\n\nValue of the user_{option}.\n\n## lf_flag_{flag}\n\nValue of the command line {flag}.\n\n## lf_width, lf_height\n\nWidth/Height of the terminal.\n\n## lf_count\n\nValue of the count associated with the current command.\n\n## lf_mode\n\nCurrent mode that `lf` is operating in.\nThis is useful for customizing keybindings depending on what the current mode is.\nPossible values are `compmenu`, `delete`, `rename`, `filter`, `find`, `mark`, `search`, `command`, `shell`, `pipe` (when running a shell-pipe command), `normal`, `visual` and `unknown`.\n\n# SPECIAL COMMANDS\n\nThis section shows information about special shell commands.\n\n## open\n\nThis shell command can be defined to override the default `open` command when the current file is not a directory.\n\n## paste\n\nThis shell command can be defined to override the default `paste` command.\n\n## rename\n\nThis shell command can be defined to override the default `rename` command.\n\n## delete\n\nThis shell command can be defined to override the default `delete` command.\n\n## pre-cd\n\nThis shell command can be defined to be executed before changing a directory.\n\n## on-cd\n\nThis shell command can be defined to be executed after changing a directory.\n\n## on-load\n\nThis shell command can be defined to be executed after loading a directory.\nIt provides the files inside the directory as arguments.\n\n## on-focus-gained\n\nThis shell command can be defined to be executed when the terminal gains focus.\n\n## on-focus-lost\n\nThis shell command can be defined to be executed when the terminal loses focus.\n\n## on-init\n\nThis shell command can be defined to be executed after initializing and connecting to the server.\n\n## on-select\n\nThis shell command can be defined to be executed after the selection changes.\n\n## on-redraw\n\nThis shell command can be defined to be executed after the screen is redrawn or if the terminal is resized.\n\n## on-quit\n\nThis shell command can be defined to be executed before quitting.\n\n# PREFIXES\n\nThe following command prefixes are used by lf:\n\n\t:  read (default)  built-in/custom command\n\t$  shell           shell command\n\t%  shell-pipe      shell command running with the UI\n\t!  shell-wait      shell command waiting for a key press\n\t&  shell-async     shell command running asynchronously\n\nThe same evaluator is used for the command line and the configuration file for reading shell commands.\nThe difference is that prefixes are not necessary in the command line.\nInstead, different modes are provided to read corresponding commands.\nThese modes are mapped to the prefix keys above by default.\nVisual mode mappings are defined the same way Normal mode mappings are defined.\n\n# SYNTAX\n\nCharacters from `#` to newline are comments and ignored:\n\n\t# comments start with `#`\n\nThe following commands (`set`, `setlocal`, `map`, `nmap`, `vmap`, `cmap`, and `cmd`) are used for configuration.\n\nCommand `set` is used to set an option which can be a boolean, integer, or string:\n\n\tset hidden         # boolean enable\n\tset hidden true    # boolean enable\n\tset nohidden       # boolean disable\n\tset hidden false   # boolean disable\n\tset hidden!        # boolean toggle\n\tset scrolloff 10   # integer value\n\tset sortby time    # string value without quotes\n\tset sortby 'time'  # string value with single quotes (whitespace)\n\tset sortby \"time\"  # string value with double quotes (backslash escapes)\n\nCommand `setlocal` is used to set a local option for a directory which can be a boolean or string.\nCurrently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `reverse` and `sortby`.\n\n\tsetlocal /foo/bar hidden         # boolean enable\n\tsetlocal /foo/bar hidden true    # boolean enable\n\tsetlocal /foo/bar nohidden       # boolean disable\n\tsetlocal /foo/bar hidden false   # boolean disable\n\tsetlocal /foo/bar hidden!        # boolean toggle\n\tsetlocal /foo/bar sortby time    # string value without quotes\n\tsetlocal /foo/bar sortby 'time'  # string value with single quotes (whitespace)\n\tsetlocal /foo/bar sortby \"time\"  # string value with double quotes (backslash escapes)\n\nCommand `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:\n\n\tmap gh cd ~        # built-in command\n\tmap D trash        # custom command\n\tmap i $less $f     # shell command\n\tmap U !du -csh *   # waiting shell command\n\nCommand `nmap` does the same but for Normal mode only.\n\nCommand `vmap` does the same but for Visual mode only.\n\nOverview of which map command works in which mode:\n\n\tmap                Normal, Visual\n\tnmap               Normal\n\tvmap               Visual\n\tcmap               Command-line\n\nCommand `cmap` is used to bind a key on the command line to a command line command or any other command:\n\n\tcmap <c-g> cmd-escape\n\tcmap <a-i> set incsearch!\n\nYou can delete an existing binding by leaving the expression empty:\n\n\tmap gh             # deletes 'gh' mapping in Normal and Visual mode\n\tnmap v             # deletes 'v' mapping in Normal mode\n\tvmap o             # deletes 'o' mapping in Visual mode\n\tcmap <c-g>         # deletes '<c-g>' mapping\n\nCommand `cmd` is used to define a custom command:\n\n\tcmd usage $du -h -d1 | less\n\nYou can delete an existing command by leaving the expression empty:\n\n\tcmd trash          # deletes 'trash' command\n\nIf there is no prefix then `:` is assumed:\n\n\tmap zt set info time\n\nAn explicit `:` can be provided to group statements until a newline which is especially useful for `map` and `cmd` commands:\n\n\tmap st :set sortby time; set info time\n\nIf you need multiline you can wrap statements in `{{` and `}}` after the proper prefix.\n\n\tmap st :{{\n\t    set sortby time\n\t    set info time\n\t}}\n\n# KEY MAPPINGS\n\nRegular keys are assigned to a command with the usual syntax:\n\n\tmap a down\n\nKeys combined with the Shift key simply use the uppercase letter:\n\n\tmap A down\n\nSpecial keys are written in between `<` and `>` characters and always use lowercase letters:\n\n\tmap <enter> down\n\nAngle brackets can be assigned with their special names:\n\n\tmap <lt> down\n\tmap <gt> down\n\nFunction keys are prefixed with an `f` character:\n\n\tmap <f-1> down\n\nKeys combined with the Ctrl key are prefixed with a `c` character:\n\n\tmap <c-a> down\n\nKeys combined with the Alt key are assigned in two different ways depending on the behavior of your terminal.\nOlder terminals (e.g. xterm) may set the 8th bit of a character when the Alt key is pressed.\nOn these terminals, you can use the corresponding byte for the mapping:\n\n\tmap á down\n\nNewer terminals (e.g. gnome-terminal) may prefix the key with an escape character when the Alt key is pressed.\nlf uses the escape delaying mechanism to recognize Alt keys in these terminals (delay is 100ms).\nOn these terminals, keys combined with the Alt key are prefixed with an `a` character:\n\n\tmap <a-a> down\n\nIt is possible to combine special keys with modifiers:\n\n\tmap <a-enter> down\n\nCombining multiple modifiers (e.g. `Ctrl+Shift+Space`) is not supported.\n\nNote that lf's key mapping syntax is similar to Vim's, but not identical.\nSome special keys and modifiers use different names and separators, and key names are matched literally (i.e. no case-folding, no aliases), so some familiar forms will not work:\n\n\tmap <enter> down  # not <Enter>, <Return> or <CR>\n\tmap <f-1> down    # not <F1>\n\tmap <a-j> down    # not <A-j> or <M-j> (Meta)\n\tmap <m-2> down    # not <RightMouse>\n\tmap <m-up> down   # not <ScrollWheelUp>\n\nWARNING: Some key combinations will likely be intercepted by your OS, window manager, or terminal.\nOther key combinations cannot be recognized by lf due to the way terminals work (e.g. `Ctrl+h` combination sends a backspace key instead).\nThe easiest way to find out the name of a key combination and whether it will work on your system is to press the key while lf is running and read the name from the `unknown mapping` error.\n\nMouse buttons are prefixed with an `m` character:\n\n\tmap <m-1> down  # primary\n\tmap <m-2> down  # secondary\n\tmap <m-3> down  # middle\n\tmap <m-4> down  # thumb next\n\tmap <m-5> down  # thumb prev\n\tmap <m-6> down\n\tmap <m-7> down\n\tmap <m-8> down\n\nMouse wheel events are also prefixed with an `m` character:\n\n\tmap <m-up>    down\n\tmap <m-down>  down\n\tmap <m-left>  down\n\tmap <m-right> down\n\n# PUSH MAPPINGS\n\nThe usual way to map a key sequence is to assign it to a named or unnamed command.\nWhile this provides a clean way to remap built-in keys as well as other commands, it can be limiting at times.\nFor this reason, the `push` command is provided by lf.\nThis command is used to simulate key pushes given as its arguments.\nYou can `map` a key to a `push` command with an argument to create various keybindings.\n\nThis is mainly useful for two purposes.\nFirst, it can be used to map a command with a command count:\n\n\tmap <c-j> push 10j\n\nSecond, it can be used to avoid typing the name when a command takes arguments:\n\n\tmap r push :rename<space>\n\nOne thing to be careful of is that since the `push` command works with keys instead of commands it is possible to accidentally create recursive bindings:\n\n\tmap j push 2j\n\nThese types of bindings create a deadlock when executed.\n\n# SHELL COMMANDS\n\nRegular shell commands are the most basic command type that is useful for many purposes.\nFor example, we can write a shell command to move the selected file(s) to trash.\nA first attempt to write such a command may look like this:\n\n\tcmd trash ${{\n\t    mkdir -p ~/.trash\n\t    if [ -z \"$fs\" ]; then\n\t        mv \"$f\" ~/.trash\n\t    else\n\t        IFS=\"$(printf '\\n\\t')\"; mv $fs ~/.trash\n\t    fi\n\t}}\n\nWe check `$fs` to see if there are any selected files.\nOtherwise, we just delete the current file.\nSince this is such a common pattern, a separate `$fx` variable is provided.\nWe can use this variable to get rid of the conditional:\n\n\tcmd trash ${{\n\t    mkdir -p ~/.trash\n\t    IFS=\"$(printf '\\n\\t')\"; mv $fx ~/.trash\n\t}}\n\nThe trash directory is checked each time the command is executed.\nWe can move it outside of the command so it would only run once at startup:\n\n\t${{ mkdir -p ~/.trash }}\n\n\tcmd trash ${{ IFS=\"$(printf '\\n\\t')\"; mv $fx ~/.trash }}\n\nSince these are one-liners, we can drop `{{` and `}}`:\n\n\t$mkdir -p ~/.trash\n\n\tcmd trash $IFS=\"$(printf '\\n\\t')\"; mv $fx ~/.trash\n\nFinally, note that we set the `IFS` variable manually in these commands.\nInstead, we could use the `ifs` option to set it for all shell commands (i.e. `set ifs \"\\n\"`).\nThis can be especially useful for interactive use (e.g. `$rm $f` or `$rm $fs` would simply work).\nThis option is not set by default as it can behave unexpectedly for new users.\nHowever, use of this option is highly recommended and it is assumed in the rest of the documentation.\n\n# PIPING SHELL COMMANDS\n\nRegular shell commands have some limitations in some cases.\nWhen an output or error message is given and the command exits afterwards, the UI is immediately resumed and there is no way to see the message without dropping to shell again.\nAlso, even when there is no output or error, the UI still needs to be paused while the command is running.\nThis can cause flickering on the screen for short commands and similar distractions for longer commands.\n\nInstead of pausing the UI, piping shell commands connect stdin, stdout, and stderr of the command to the statline at the bottom of the UI.\nThis can be useful for programs following the Unix philosophy to give no output in the success case, and brief error messages or prompts in other cases.\n\nFor example, the following rename command prompts for overwrite in the statline if there is an existing file with the given name:\n\n\tcmd rename %mv -i $f $1\n\nYou can also output error messages in the command and they will show up in the statline.\nFor example, an alternative rename command may look like this:\n\n\tcmd rename %[ -e $1 ] && printf \"file exists\" || mv $f $1\n\nNote that input is line buffered and output and error are byte buffered.\n\n# WAITING SHELL COMMANDS\n\nWaiting shell commands are similar to regular shell commands except that they wait for a key press when the command is finished.\nThese can be useful to see the output of a program before the UI is resumed.\nWaiting shell commands are more appropriate than piping shell commands when the command is verbose and the output is best displayed as multiline.\n\n# ASYNCHRONOUS SHELL COMMANDS\n\nAsynchronous shell commands are used to start a command in the background and then resume operation without waiting for the command to finish.\nStdin, stdout, and stderr of the command are neither connected to the terminal nor the UI.\n\n# REMOTE COMMANDS\n\nOne of the more advanced features in lf is remote commands.\nAll clients connect to a server on startup.\nIt is possible to send commands to all or any of the connected clients over the common server.\nThis is used internally to notify file selection changes to other clients.\n\nTo use this feature, you need to use a client which supports communicating with a Unix domain socket.\nOpenBSD implementation of netcat (nc) is one such example.\nYou can use it to send a command to the socket file:\n\n\techo 'send echo hello world' | nc -U ${XDG_RUNTIME_DIR:-/tmp}/lf.${USER}.sock\n\nSince such a client may not be available everywhere, lf comes bundled with a command line flag to be used as such.\nWhen using lf, you do not need to specify the address of the socket file.\nThis is the recommended way of using remote commands since it is shorter and immune to socket file address changes:\n\n\tlf -remote 'send echo hello world'\n\nIn this command `send` is used to send the rest of the string as a command to all connected clients.\nYou can optionally give it an ID number to send a command to a single client:\n\n\tlf -remote 'send 1234 echo hello world'\n\nAll clients have a unique ID number but you may not be aware of the ID number when you are writing a command.\nFor this purpose, an `$id` variable is exported to the environment for shell commands.\nThe value of this variable is set to the process ID of the client.\nYou can use it to send a remote command from a client to the server which in return sends a command back to itself.\nSo now you can display a message in the current client by calling the following in a shell command:\n\n\tlf -remote \"send $id echo hello world\"\n\nSince lf does not have control flow syntax, remote commands are used for such needs.\nFor example, you can configure the number of columns in the UI with respect to the terminal width as follows:\n\n\tcmd recol %{{\n\t    if [ $lf_width -le 80 ]; then\n\t        lf -remote \"send $id set ratios 1:2\"\n\t    elif [ $lf_width -le 160 ]; then\n\t        lf -remote \"send $id set ratios 1:2:3\"\n\t    else\n\t        lf -remote \"send $id set ratios 1:2:3:5\"\n\t    fi\n\t}}\n\nIn addition, the `query` command can be used to obtain information about a specific lf instance by providing its ID:\n\n\tlf -remote \"query $id maps\"\n\nThe following types of information are supported:\n\n\tmaps     list of mappings created by the 'map', 'nmap' and 'vmap' command\n\tnmaps    list of mappings created by the 'nmap' and 'map' command\n\tvmaps    list of mappings created by the 'vmap' and 'map' command\n\tcmaps    list of mappings created by the 'cmap' command\n\tcmds     list of commands created by the 'cmd' command\n\tjumps    contents of the jump list, showing previously visited locations\n\thistory  list of previously executed commands on the command line\n\tfiles    list of files in the currently open directory as displayed by lf, empty if dir is still loading\n\nWhen listing mappings the characters in the first column are:\n\n\tn  Normal\n\tv  Visual\n\tc  Command-line\n\nThis is useful for scripting actions based on the internal state of lf.\nFor example, to select a previous command using fzf and execute it:\n\n\tmap <a-h> ${{\n\t    clear\n\t    cmd=$(\n\t        lf -remote \"query $id history\" |\n\t        awk -F'\\t' 'NR > 1 { print $NF}' |\n\t        sort -u |\n\t        fzf --reverse --prompt='Execute command: '\n\t    )\n\t    lf -remote \"send $id $cmd\"\n\t}}\n\nThe `list` command prints the IDs of all currently connected clients:\n\n\tlf -remote 'list'\n\nThere is also a `quit` command to quit the server when there are no connected clients left, and a `quit!` command to force quit the server by closing client connections first:\n\n\tlf -remote 'quit'\n\tlf -remote 'quit!'\n\nLastly, the commands `conn` and `drop` connect or disconnect ID to/from the server:\n\n\tlf -remote 'conn $id'\n\tlf -remote 'drop $id'\n\nThese are internal and generally not needed by users.\n\n# FILE OPERATIONS\n\nlf uses its own built-in copy and move operations by default.\nThese are implemented as asynchronous operations and progress is shown in the bottom ruler.\nThese commands do not overwrite existing files or directories with the same name.\nInstead, a suffix that is compatible with the `--backup=numbered` option in GNU cp is added to the new files or directories.\nOnly file modes and (some) timestamps can be preserved (see `preserve` option), all other attributes are ignored including ownership, context, and xattr.\nSpecial files such as character and block devices, named pipes, and sockets are skipped and links are not followed.\nMoving is performed using the rename operation of the underlying OS.\nFor cross-device moving, lf falls back to copying and then deletes the original files if there are no errors.\nOperation errors are shown in the message line as well as the log file and they do not prematurely terminate the corresponding file operation.\n\nFile operations can be performed on the currently selected file or on multiple files by selecting them first.\nWhen you `copy` a file, lf doesn't actually copy the file on the disk, but only records its name to a file.\nThe actual file copying takes place when you `paste`.\nSimilarly `paste` after a `cut` operation moves the file.\n\nYou can customize copy and move operations by defining a `paste` command.\nThis is a special command that is called when it is defined instead of the built-in implementation.\nYou can use the following example as a starting point:\n\n\tcmd paste %{{\n\t    load=$(cat ~/.local/share/lf/files)\n\t    mode=$(echo \"$load\" | sed -n '1p')\n\t    list=$(echo \"$load\" | sed '1d')\n\t    if [ $mode = 'copy' ]; then\n\t        cp -R $list .\n\t    elif [ $mode = 'move' ]; then\n\t        mv $list .\n\t        rm ~/.local/share/lf/files\n\t        lf -remote 'send clear'\n\t    fi\n\t}}\n\nSome useful things to be considered are to use the backup (`--backup`) and/or preserve attributes (`-a`) options with `cp` and `mv` commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use `rsync` command with progress bar option for copying and feed the progress to the client periodically with remote `echo` calls.\n\nBy default, lf does not assign `delete` command to a key to protect new users.\nYou can customize file deletion by defining a `delete` command.\nYou can also assign a key to this command if you like.\nAn example command to move selected files to a trash folder and remove files completely after a prompt is provided in the example configuration file.\n\n# SEARCHING FILES\n\nThere are two mechanisms implemented in lf to search a file in the current directory.\nSearching is the traditional method to move the selection to a file matching a given pattern.\nFinding is an alternative way to search for a pattern possibly using fewer keystrokes.\n\nThe searching mechanism is implemented with commands `search` (default `/`), `search-back` (default `?`), `search-next` (default `n`), and `search-prev` (default `N`).\nYou can set `searchmethod` to `glob` to match using a glob pattern.\nGlobbing supports `*` to match any sequence, `?` to match any character, and `[...]` or `[^...]` to match character sets or ranges.\nYou can set `searchmethod` to `regex` to match using a regex pattern.\nFor a full overview of Go's RE2 syntax, see https://pkg.go.dev/regexp/syntax.\nYou can enable `incsearch` option to jump to the current match at each keystroke while typing.\nIn this mode, you can either use `cmd-enter` to accept the search or use `cmd-escape` to cancel the search.\nYou can also map some other commands with `cmap` to accept the search and execute the command immediately afterwards.\nFor example, you can use the right arrow key to finish the search and open the selected file with the following mapping:\n\n\tcmap <right> :cmd-enter; open\n\nThe finding mechanism is implemented with commands `find` (default `f`), `find-back` (default `F`), `find-next` (default `;`), `find-prev` (default `,`).\nYou can disable `anchorfind` option to match a pattern at an arbitrary position in the filename instead of the beginning.\nYou can set the number of keys to match using `findlen` option.\nIf you set this value to zero, then the keys are read until there is only a single match.\nThe default values of these two options are set to jump to the first file with the given initial.\n\nSome options affect both searching and finding.\nYou can disable `wrapscan` option to prevent searches from being wrapped around at the end of the file list.\nYou can disable `ignorecase` option to match cases in the pattern and the filename.\nThis option is already automatically overridden if the pattern contains uppercase characters.\nYou can disable `smartcase` option to disable this behavior.\nTwo similar options `ignoredia` and `smartdia` are provided to control matching diacritics in Latin letters.\n\n# OPENING FILES\n\nYou can define an `open` command (default `l` and `<right>`) to configure file opening.\nThis command is only called when the current file is not a directory, otherwise, the directory is entered instead.\nYou can define it just as you would define any other command:\n\n\tcmd open $vi $fx\n\nIt is possible to use different command types:\n\n\tcmd open &xdg-open $f\n\nYou may want to use either file extensions or MIME types from `file` command:\n\n\tcmd open ${{\n\t    case $(file --mime-type -Lb $f) in\n\t        text/*) vi $fx;;\n\t        *) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;\n\t    esac\n\t}}\n\nYou may want to use `setsid` before your opener command to have persistent processes that continue to run after lf quits.\n\nRegular shell commands (i.e. `$`) drop to the terminal which results in a flicker for commands that finish immediately (e.g. `xdg-open` in the above example).\nIf you want to use asynchronous shell commands (i.e. `&`) but also want to use the terminal when necessary (e.g. `vi` in the above example), you can use a remote command:\n\n\tcmd open &{{\n\t    case $(file --mime-type -Lb $f) in\n\t        text/*) lf -remote \"send $id \\$vi \\$fx\";;\n\t        *) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;\n\t    esac\n\t}}\n\nNote that asynchronous shell commands run in their own process group by default so they do not require the manual use of `setsid`.\n\nThe following command is provided by default:\n\n\tcmd open &$OPENER $f\n\nYou may also use any other existing file openers as you like.\nPossible options are `libfile-mimeinfo-perl` (executable name is `mimeopen`), `rifle` (ranger's default file opener), or `mimeo` to name a few.\n\n# PREVIEWING FILES\n\nlf previews files on the preview pane by printing the file until the end or until the preview pane is filled.\nThis output can be enhanced by providing a custom preview script for filtering.\nThis can be used to highlight source code, list contents of archive files or view PDF or image files to name a few.\nFor coloring lf recognizes ANSI escape codes.\n\nTo use this feature, you need to set the value of `previewer` option to the path of an executable file.\nThe 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\").\nThe output of the execution is printed in the preview pane.\n\nDifferent types of files can be handled by matching by extension (or MIME type from the `file` command):\n\n\t#!/bin/sh\n\n\tcase \"$1\" in\n\t    *.tar*) tar tf \"$1\";;\n\t    *.zip) unzip -l \"$1\";;\n\t    *.rar) unrar l \"$1\";;\n\t    *.7z) 7z l \"$1\";;\n\t    *.pdf) pdftotext \"$1\" -;;\n\t    *) highlight -O ansi \"$1\";;\n\tesac\n\nBecause files can be large, lf automatically closes the previewer script output pipe with a SIGPIPE when enough lines are read.\nNote that some programs may not respond well to SIGPIPE and will exit with a non-zero return code, which avoids caching.\nYou may add a trailing `|| true` command to avoid such errors:\n\n\thighlight -O ansi \"$1\" || true\n\nYou may also want to use the same script in your pager mapping as well:\n\n\tset previewer ~/.config/lf/pv.sh\n\tmap i $~/.config/lf/pv.sh $f | less -R\n\nFor `less` pager, you may instead utilize `LESSOPEN` mechanism so that useful information about the file such as the full path of the file can still be displayed in the statusline below:\n\n\tset previewer ~/.config/lf/pv.sh\n\tmap i $LESSOPEN='| ~/.config/lf/pv.sh %s' less -R $f\n\nSince the preview script is called for each file selection change, it may not generate previews fast enough if the user scrolls through files quickly.\nTo deal with this, the `preload` option can be set to enable file previews to be preloaded in advance.\nIf enabled, the preview script will be run on files in advance as the user navigates through them.\nIn this case, if the exit code of the preview script is zero, then the output will be cached in memory and displayed by lf (useful for text or sixel previews).\nOtherwise, it will fallback to calling the preview script again when the file is actually selected (useful for previews managed by an external program).\n\n# CHANGING DIRECTORY\n\nlf changes the working directory of the process to the current directory so that shell commands always work in the displayed directory.\nAfter quitting, it returns to the original directory where it is first launched like all shell programs.\nIf you want to stay in the current directory after quitting, you can use one of the example lfcd wrapper shell scripts provided in the repository at\nhttps://github.com/gokcehan/lf/tree/master/etc\n\nThere is a special command `on-cd` that runs a shell command when it is defined and the directory is changed.\nYou can define it just as you would define any other command:\n\n\tcmd on-cd &{{\n\t    bash -c '\n\t    # display git repository status in your prompt\n\t    source /usr/share/git/completion/git-prompt.sh\n\t    GIT_PS1_SHOWDIRTYSTATE=auto\n\t    GIT_PS1_SHOWSTASHSTATE=auto\n\t    GIT_PS1_SHOWUNTRACKEDFILES=auto\n\t    GIT_PS1_SHOWUPSTREAM=auto\n\t    git=$(__git_ps1 \" (%s)\")\n\t    fmt=\"\\033[32;1m%u@%h\\033[0m:\\033[34;1m%d\\033[0m\\033[1m%f$git\\033[0m\"\n\t    lf -remote \"send $id set promptfmt \\\"$fmt\\\"\"\n\t    '\n\t}}\n\nIf you want to send escape sequences to the terminal, you can use the `tty-write` command to do so.\nThe following xterm-specific escape sequence sets the terminal title to the working directory:\n\n\tcmd on-cd &{{\n\t    lf -remote \"send $id tty-write \\\"\\033]0;$PWD\\007\\\"\"\n\t}}\n\nThis command runs whenever you change the directory but not on startup.\nYou can add an extra call to make it run on startup as well:\n\n\tcmd on-cd &{{ ... }}\n\ton-cd\n\nNote that all shell commands are possible but `%` and `&` are usually more appropriate as `$` and `!` causes flickers and pauses respectively.\n\nThere is also a `pre-cd` command, that works like `on-cd`, but is run before the directory is actually changed.\nAnother related command is `on-load` which gets executed when loading a directory.\n\n# LOADING DIRECTORY\n\nSimilar to `on-cd` there also is `on-load` that when defined runs a shell command after loading a directory.\nIt works well when combined with `addcustominfo`.\n\nThe following example can be used to display git indicators in the info column:\n\n\tcmd on-load &{{\n\t    cd \"$(dirname \"$1\")\" || exit 1\n\t    [ \"$(git rev-parse --is-inside-git-dir 2>/dev/null)\" = false ] || exit 0\n\n\t    cmds=\"\"\n\n\t    for file in \"$@\"; do\n\t        case \"$file\" in\n\t            */.git|*/.git/*) continue;;\n\t        esac\n\n\t        status=$(git status --porcelain --ignored -- \"$file\" | cut -c1-2 | head -n1)\n\n\t        if [ -n \"$status\" ]; then\n\t            cmds=\"${cmds}addcustominfo \\\"${file}\\\" \\\"$status\\\"; \"\n\t        else\n\t            cmds=\"${cmds}addcustominfo \\\"${file}\\\" ''; \"\n\t        fi\n\t    done\n\n\t    if [ -n \"$cmds\" ]; then\n\t        lf -remote \"send $id :$cmds\"\n\t    fi\n\t}}\n\nAnother use case could be showing the dimensions of images and videos:\n\n\tcmd on-load &{{\n\t    cmds=\"\"\n\n\t    for file in \"$@\"; do\n\t        mime=$(file --mime-type -Lb -- \"$file\")\n\t        case \"$mime\" in\n\t            # vector images cause problems\n\t            image/svg+xml)\n\t                ;;\n\t            image/*|video/*)\n\t                dimensions=$(exiftool -s3 -imagesize -- \"$file\")\n\t                cmds=\"${cmds}addcustominfo \\\"${file}\\\" \\\"$dimensions\\\"; \"\n\t                ;;\n\t        esac\n\t    done\n\n\t    if [ -n \"$cmds\" ]; then\n\t        lf -remote \"send $id :$cmds\"\n\t    fi\n\t}}\n\n# COLORS\n\nlf tries to automatically adapt its colors to the environment.\nIt starts with a default color scheme and updates colors using values of existing environment variables possibly by overwriting its previous values.\nColors are set in the following order:\n\n 1. default\n 2. LSCOLORS (macOS/BSD ls)\n 3. LS_COLORS (GNU ls)\n 4. LF_COLORS (lf specific)\n 5. colors file (lf specific)\n\nPlease refer to the corresponding man pages for more information about `LSCOLORS` and `LS_COLORS`.\n`LF_COLORS` is provided with the same syntax as `LS_COLORS` in case you want to configure colors only for lf but not ls.\nThis can be useful since there are some differences between ls and lf, though one should expect the same behavior for common cases.\nThe colors file (refer to the [CONFIGURATION section](https://github.com/gokcehan/lf/blob/master/doc.md#configuration)) is provided for easier configuration without environment variables.\nThis file should consist of whitespace-separated pairs with a `#` character to start comments until the end of the line.\n\nYou can configure lf colors in two different ways.\nFirst, you can only configure 8 basic colors used by your terminal and lf should pick up those colors automatically.\nDepending on your terminal, you should be able to select your colors from a 24-bit palette.\nThis is the recommended approach as colors used by other programs will also match each other.\n\nSecond, you can set the values of environment variables or colors file mentioned above for fine-grained customization.\nNote that `LS_COLORS/LF_COLORS` are more powerful than `LSCOLORS` and they can be used even when GNU programs are not installed on the system.\nYou can combine this second method with the first method for the best results.\n\nLastly, you may also want to configure the colors of the prompt line to match the rest of the colors.\nColors of the prompt line can be configured using the `promptfmt` option which can include hardcoded colors as ANSI escapes.\nSee the default value of this option to have an idea about how to color this line.\n\nIt is worth noting that lf uses as many colors advertised by your terminal's entry in terminfo or infocmp databases on your system.\nIf an entry is not present, it falls back to an internal database.\nIf your terminal supports 24-bit colors but either does not have a database entry or does not advertise all capabilities, you can enable support by setting the `$COLORTERM` variable to `truecolor` or ensuring `$TERM` is set to a value that ends with `-truecolor`.\n\nDefault lf colors are mostly taken from GNU dircolors defaults.\nThese defaults use 8 basic colors and bold attribute.\nDefault dircolors entries with background colors are simplified to avoid confusion with current file selection in lf.\nSimilarly, there are only file type matchings and extension matchings are left out for simplicity.\nDefault values are as follows given with their matching order in lf:\n\n\tln  01;36\n\tor  31;01\n\ttw  01;34\n\tow  01;34\n\tst  01;34\n\tdi  01;34\n\tpi  33\n\tso  01;35\n\tbd  33;01\n\tcd  33;01\n\tsu  01;32\n\tsg  01;32\n\tex  01;32\n\tfi  00\n\nNote that lf first tries matching file names and then falls back to file types.\nThe full order of matchings from most specific to least are as follows:\n\n 1. Full Path (e.g. `~/.config/lf/lfrc`)\n 2. Dir Name  (e.g. `.git/`) (only matches dirs with a trailing slash at the end)\n 3. File Type (e.g. `ln`) (except `fi`)\n 4. File Name (e.g. `README*`)\n 5. File Name (e.g. `*README`)\n 6. Base Name (e.g. `README.*`)\n 7. Extension (e.g. `*.txt`)\n 8. Default   (i.e. `fi`)\n\nFor example, given a regular text file `/path/to/README.txt`, the following entries are checked in the configuration and the first one to match is used:\n\n 1. `/path/to/README.txt`\n 2. (skipped since the file is not a directory)\n 3. (skipped since the file is of type `fi`)\n 4. `README.txt*`\n 5. `*README.txt`\n 6. `README.*`\n 7. `*.txt`\n 8. `fi`\n\nGiven a regular directory `/path/to/example.d`, the following entries are checked in the configuration and the first one to match is used:\n\n 1. `/path/to/example.d`\n 2. `example.d/`\n 3. `di`\n 4. `example.d*`\n 5. `*example.d`\n 6. `example.*`\n 7. `*.d`\n 8. `fi`\n\nNote that glob-like patterns do not perform glob matching for performance reasons.\n\nFor example, you can set a variable as follows:\n\n\texport LF_COLORS=\"~/Documents=01;31:~/Downloads=01;31:~/.local/share=01;31:~/.config/lf/lfrc=31:.git/=01;32:.git*=32:*.gitignore=32:*Makefile=32:README.*=33:*.txt=34:*.md=34:ln=01;36:di=01;34:ex=01;32:\"\n\nHaving all entries on a single line can make it hard to read.\nYou may instead divide it into multiple lines in between double quotes by escaping newlines with backslashes as follows:\n\n\texport LF_COLORS=\"\\\n\t~/Documents=01;31:\\\n\t~/Downloads=01;31:\\\n\t~/.local/share=01;31:\\\n\t~/.config/lf/lfrc=31:\\\n\t.git/=01;32:\\\n\t.git*=32:\\\n\t*.gitignore=32:\\\n\t*Makefile=32:\\\n\tREADME.*=33:\\\n\t*.txt=34:\\\n\t*.md=34:\\\n\tln=01;36:\\\n\tdi=01;34:\\\n\tex=01;32:\\\n\t\"\n\nThe `ln` entry supports the special value `target`, which will use the link target to select a style. Filename rules will still apply based on the link's name -- this mirrors GNU's `ls` and `dircolors` behavior.\nHaving such a long variable definition in a shell configuration file might be undesirable.\nYou may instead use the colors file (refer to the [CONFIGURATION section](https://github.com/gokcehan/lf/blob/master/doc.md#configuration)) for configuration.\nA sample colors file can be found at\nhttps://github.com/gokcehan/lf/blob/master/etc/colors.example\nYou may also see the wiki page for ANSI escape codes\nhttps://en.wikipedia.org/wiki/ANSI_escape_code\n\n# ICONS\n\nIcons are configured using `LF_ICONS` environment variable or an icons file (refer to the [CONFIGURATION section](https://github.com/gokcehan/lf/blob/master/doc.md#configuration)).\nThe variable uses the same syntax as `LS_COLORS/LF_COLORS`.\nInstead of colors, you should use single characters or symbols as values.\nThe `ln` entry supports the special value `target`, which will use the link target to select a icon. Filename rules will still apply based on the link's name -- this mirrors GNU's `ls` and `dircolors` behavior.\nThe icons file (refer to the [CONFIGURATION section](https://github.com/gokcehan/lf/blob/master/doc.md#configuration)) should consist of whitespace-separated arrays with a `#` character to start comments until the end of the line.\nEach line should contain 1-3 columns: a file type or file name pattern, the icon, and an optional icon color. Using only one column disables all rules for that type or name.\nDo not forget to add `set icons true` to your `lfrc` to see the icons.\nDefault values are listed below in the order lf matches them:\n\n\tln  l\n\tor  l\n\ttw  t\n\tow  d\n\tst  t\n\tdi  d\n\tpi  p\n\tso  s\n\tbd  b\n\tcd  c\n\tsu  u\n\tsg  g\n\tex  x\n\tfi  -\n\nA sample icons file can be found at\nhttps://github.com/gokcehan/lf/blob/master/etc/icons.example\n\nA sample colored icons file can be found at\nhttps://github.com/gokcehan/lf/blob/master/etc/icons_colored.example\n\n# RULER\n\nThe ruler can be configured using the `rulerfile` option (refer to the [CONFIGURATION section](https://github.com/gokcehan/lf/blob/master/doc.md#configuration)).\nThe contents of the ruler file should be a Go template which is then rendered to create the actual output (refer to https://pkg.go.dev/text/template for more details on the syntax).\n\nThe following data fields are exported:\n\n\t.Message          string              Includes internal messages, errors, and messages generated by the `echo`/`echomsg`/`echoerr` commands\n\t.Keys             string              Keys pressed by the user\n\t.Progress         []string            Progress indicators for copied, moved and deleted files\n\t.Copy             []string            List of files in the clipboard to be copied\n\t.Cut              []string            List of files in the clipboard to be moved\n\t.Select           []string            Selection list\n\t.Visual           []string            Visual selection\n\t.Index            int                 Index of the cursor\n\t.Total            int                 Number of visible files in the current working directory\n\t.Hidden           int                 Number of hidden files in the current working directory\n\t.All              int                 Number of all files in the current working directory\n\t.LinePercentage   string              Line percentage (analogous to `%p` for the `statusline` option in Vim)\n\t.ScrollPercentage string              Scroll percentage (analogous to `%P` for the `statusline` option in Vim)\n\t.Filter           []string            Filter currently being applied\n\t.Mode             string              Current mode (\"NORMAL\" for Normal mode, and \"VISUAL\" for Visual mode)\n\t.Options          map[string]string   The value of options (e.g. `{{.Options.hidden}}`)\n\t.UserOptions      map[string]string   The value of user-defined options (e.g. `{{.UserOptions.foo}}`)\n\t.Stat.Path        string              Path of the current file\n\t.Stat.Name        string              Name of the current file\n\t.Stat.Extension   string              Extension of the current file\n\t.Stat.Size        int64               Size of the current file\n\t.Stat.DirSize     int64               Total size of the current directory if calculated via `calcdirsize` (`-1` if not calculated)\n\t.Stat.DirCount    int                 Number of items in the current directory if the `dircounts` option is enabled (`-1` if the directory cannot be read)\n\t.Stat.Permissions string              Permissions of the current file\n\t.Stat.ModTime     string              Last modified time of the current file (formatted based on the `timefmt` option)\n\t.Stat.AccessTime  string              Last access time of the current file (formatted based on the `timefmt` option)\n\t.Stat.BirthTime   string              Birth time of the current file (formatted based on the `timefmt` option)\n\t.Stat.ChangeTime  string              Last status (inode) change time of the current file (formatted based on the `timefmt` option)\n\t.Stat.LinkCount   string              Number of hard links for the current file\n\t.Stat.User        string              User of the current file\n\t.Stat.Group       string              Group of the current file\n\t.Stat.Target      string              Target if the current file is a symbolic link, otherwise a blank string\n\t.Stat.CustomInfo  string              Custom property if defined via `addcustominfo`, otherwise a blank string\n\nThe following functions are exported:\n\n\tdf       func() string                   Get an indicator representing the amount of free disk space available\n\tenv      func(string) string             Get the value of an environment variable\n\thumanize func(int64) string              Express a file size in a human-readable format\n\tjoin     func([]string, string) string   Join a string array by a separator\n\tlower    func(string) string             Convert a string to lowercase\n\tsubstr   func(string, int, int) string   Get a substring based on starting index and length\n\tupper    func(string) string             Convert a string to uppercase\n\nThe special identifier `{{.SPACER}}` can be used to divide the ruler into sections that are spaced evenly from each other.\n\nThe default ruler file can be found at\nhttps://github.com/gokcehan/lf/blob/master/etc/ruler.default\n"
  },
  {
    "path": "doc.txt",
    "content": "NAME\n\nlf - terminal file manager\n\nSYNOPSIS\n\nlf [-command command] [-config path] [-cpuprofile path] [-doc] [-help]\n[-last-dir-path path] [-log path] [-memprofile path] [-print-last-dir]\n[-print-selection] [-remote command] [-selection-path path] [-server]\n[-single] [-version] [cd-or-select-path]\n\nDESCRIPTION\n\nlf is a terminal file manager.\n\nThe source code can be found in the repository at\nhttps://github.com/gokcehan/lf\n\nThis documentation can either be read from the terminal using lf -doc or\nonline at https://github.com/gokcehan/lf/blob/master/doc.md You can also\nuse the help command (default <f-1>) inside lf to view the documentation\nin a pager. A man page with the same content is also available in the\nrepository at https://github.com/gokcehan/lf/blob/master/lf.1\n\nOPTIONS\n\nPOSITIONAL ARGUMENTS\n\ncd-or-select-path\n\n    Set the starting location. If path is a directory, start in there.\n    If it's a file, start in the file's parent directory and select the\n    file. When no path is supplied, lf uses the current directory. Only\n    accepts one argument.\n\nMETA OPTIONS\n\n-doc\n\n    Show lf's documentation (same content as this file) and exit.\n\n-help\n\n    Show command-line usage and exit.\n\n-version\n\n    Show version information and exit.\n\nSTARTUP & CONFIGURATION\n\n-command command\n\n    Execute command during client initialization (i.e. after reading\n    configuration, before on-init). To execute more than one command,\n    you can either use the -command flag multiple times or pass multiple\n    commands at once by chaining them with \";\".\n\n-config path\n\n    Use the config file at path instead of the normal search locations.\n    This only affects which lfrc is read at startup.\n\nSHELL INTEGRATION\n\n-print-last-dir\n\n    Print the last directory to stdout when lf exits. This can be used\n    to let lf change your shells working directory. See\n    CHANGING DIRECTORY for more details.\n\n-last-dir-path path\n\n    Same as -print-last-dir, but write the directory to path instead of\n    stdout.\n\n-print-selection\n\n    Print selected files to stdout when opening a file in lf. This can\n    be used to use lf as an \"open file\" dialog. First, select the files\n    you want to pass to another program. Then, confirm the selection by\n    opening a file. This causes lf to quit and print out the selection.\n    Quitting lf prematurely discards the selection.\n\n-selection-path path\n\n    Same as -print-selection, but write the newline-separated list to\n    path instead of stdout.\n\nSERVER\n\n-remote command\n\n    Send command to the running server (i.e. send, query, list, quit, or\n    quit!). See REMOTE COMMANDS for more details.\n\n-server\n\n    Start the (headless) server process explicitly. Runs in the\n    foreground and writes server logs to stderr (or the file set with\n    -log). Clients auto-start a server if none is running unless -single\n    is used.\n\n-single\n\n    Start a stand-alone client without a server. Disables remote\n    control.\n\nDIAGNOSTICS\n\n-log path\n\n    Append runtime log messages to path.\n\n-cpuprofile path\n\n    Write a CPU profile to path. The profile can be used by\n    go tool pprof.\n\n-memprofile path\n\n    Write a memory profile to path. The profile can be used by\n    go tool pprof.\n\nEXAMPLES\n\nUse lf to select files (while hiding certain file types):\n\n    lf -command 'set nohidden' -command 'set hiddenfiles \"*mp4:*pdf:*txt\"' -print-selection\n\nAnother sophisticated \"open file\" dialog focusing on design:\n\n    lf -command 'set nopreview; set ratios 1; set drawbox; set promptfmt \"Select files [%w] %S q: cancel, l: confirm\"' -print-selection\n\nOpen Downloads and set sortby and info to creation date:\n\n    lf -command 'set sortby btime; set info btime' ~/Downloads\n\nTemporarily prevent lf from modifying the command history:\n\n    lf -command 'set nohistory'\n\nUse default settings and log current session:\n\n    lf -config /dev/null -log /tmp/lf.log\n\nForce-quit the server:\n\n    lf -remote 'quit!'\n\nInherit lf's working directory in your shell:\n\n    cd \"$(lf -print-last-dir)\"\n\nQUICK REFERENCE\n\nThe following commands are provided by lf:\n\n    quit                     (default 'q')\n    up                       (default 'k' and '<up>')\n    half-up                  (default '<c-u>')\n    page-up                  (default '<c-b>' and '<pgup>')\n    scroll-up                (default '<c-y>')\n    down                     (default 'j' and '<down>')\n    half-down                (default '<c-d>')\n    page-down                (default '<c-f>' and '<pgdn>')\n    scroll-down              (default '<c-e>')\n    updir                    (default 'h' and '<left>')\n    open                     (default 'l' and '<right>')\n    jump-next                (default ']')\n    jump-prev                (default '[')\n    top                      (default 'gg' and '<home>')\n    bottom                   (default 'G' and '<end>')\n    high                     (default 'H')\n    middle                   (default 'M')\n    low                      (default 'L')\n    toggle\n    invert                   (default 'v')\n    unselect                 (default 'u')\n    glob-select\n    glob-unselect\n    copy                     (default 'y')\n    cut                      (default 'd')\n    paste                    (default 'p')\n    clear                    (default 'c')\n    sync\n    draw\n    redraw                   (default '<c-l>')\n    load\n    reload                   (default '<c-r>')\n    delete         (modal)\n    rename         (modal)   (default 'r')\n    read           (modal)   (default ':')\n    shell          (modal)   (default '$')\n    shell-pipe     (modal)   (default '%')\n    shell-wait     (modal)   (default '!')\n    shell-async    (modal)   (default '&')\n    find           (modal)   (default 'f')\n    find-back      (modal)   (default 'F')\n    find-next                (default ';')\n    find-prev                (default ',')\n    search         (modal)   (default '/')\n    search-back    (modal)   (default '?')\n    search-next              (default 'n')\n    search-prev              (default 'N')\n    filter         (modal)\n    setfilter\n    mark-save      (modal)   (default 'm')\n    mark-load      (modal)   (default \"'\")\n    mark-remove    (modal)   (default '\"')\n    tag\n    tag-toggle               (default 't')\n    echo\n    echomsg\n    echoerr\n    cd\n    select\n    source\n    push\n    addcustominfo\n    calcdirsize\n    clearmaps\n    tty-write\n    visual                   (default 'V')\n\nThe following Visual mode commands are provided by lf:\n\n    visual-accept            (default 'V')\n    visual-unselect\n    visual-discard           (default '<esc>')\n    visual-change            (default 'o')\n\nThe following Command-line mode commands are provided by lf:\n\n    cmd-insert\n    cmd-escape               (default '<esc>')\n    cmd-complete             (default '<tab>')\n    cmd-menu-complete\n    cmd-menu-complete-back\n    cmd-menu-accept\n    cmd-menu-discard\n    cmd-enter                (default '<c-j>' and '<enter>')\n    cmd-interrupt            (default '<c-c>')\n    cmd-history-next         (default '<c-n>' and '<down>')\n    cmd-history-prev         (default '<c-p>' and '<up>')\n    cmd-left                 (default '<c-b>' and '<left>')\n    cmd-right                (default '<c-f>' and '<right>')\n    cmd-home                 (default '<c-a>' and '<home>')\n    cmd-end                  (default '<c-e>' and '<end>')\n    cmd-delete               (default '<c-d>' and '<delete>')\n    cmd-delete-back          (default '<backspace>')\n    cmd-delete-home          (default '<c-u>')\n    cmd-delete-end           (default '<c-k>')\n    cmd-delete-unix-word     (default '<c-w>')\n    cmd-yank                 (default '<c-y>')\n    cmd-transpose            (default '<c-t>')\n    cmd-transpose-word       (default '<a-t>')\n    cmd-word                 (default '<a-f>')\n    cmd-word-back            (default '<a-b>')\n    cmd-delete-word          (default '<a-d>')\n    cmd-delete-word-back     (default '<a-backspace>')\n    cmd-capitalize-word      (default '<a-c>')\n    cmd-uppercase-word       (default '<a-u>')\n    cmd-lowercase-word       (default '<a-l>')\n\nThe following options can be used to customize the behavior of lf:\n\n    anchorfind        bool      (default true)\n    autoquit          bool      (default true)\n    borderfmt         string    (default \"\\033[0m\")\n    borderstyle       string    (default 'box')\n    cleaner           string    (default '')\n    copyfmt           string    (default \"\\033[7;33m\")\n    cursoractivefmt   string    (default \"\\033[7m\")\n    cursorparentfmt   string    (default \"\\033[7m\")\n    cursorpreviewfmt  string    (default \"\\033[4m\")\n    cutfmt            string    (default \"\\033[7;31m\")\n    dircounts         bool      (default false)\n    dirfirst          bool      (default true)\n    dironly           bool      (default false)\n    dirpreviews       bool      (default false)\n    drawbox           bool      (default false)\n    dupfilefmt        string    (default '%f.~%n~')\n    errorfmt          string    (default \"\\033[7;31;47m\")\n    filesep           string    (default \"\\n\")\n    filtermethod      string    (default 'text')\n    findlen           int       (default 1)\n    hidden            bool      (default false)\n    hiddenfiles       []string  (default '.*' for Unix and '' for Windows)\n    history           bool      (default true)\n    icons             bool      (default false)\n    ifs               string    (default '')\n    ignorecase        bool      (default true)\n    ignoredia         bool      (default true)\n    incfilter         bool      (default false)\n    incsearch         bool      (default false)\n    info              []string  (default '')\n    infotimefmtnew    string    (default 'Jan _2 15:04')\n    infotimefmtold    string    (default 'Jan _2  2006')\n    menufmt           string    (default \"\\033[0m\")\n    menuheaderfmt     string    (default \"\\033[1m\")\n    menuselectfmt     string    (default \"\\033[7m\")\n    mergeindicators   bool      (default false)\n    mouse             bool      (default false)\n    number            bool      (default false)\n    numbercursorfmt   string    (default '')\n    numberfmt         string    (default \"\\033[33m\")\n    period            int       (default 0)\n    preload           bool      (default false)\n    preserve          []string  (default \"mode\")\n    preview           bool      (default true)\n    previewer         string    (default '')\n    promptfmt         string    (default \"\\033[32;1m%u@%h\\033[0m:\\033[34;1m%d\\033[0m\\033[1m%f\\033[0m\")\n    ratios            []int     (default '1:2:3')\n    relativenumber    bool      (default false)\n    reverse           bool      (default false)\n    rulerfile         string    (default \"\")\n    rulerfmt          string    (default \"\")\n    scrolloff         int       (default 0)\n    searchmethod      string    (default 'text')\n    selectfmt         string    (default \"\\033[7;35m\")\n    selmode           string    (default 'all')\n    shell             string    (default 'sh' for Unix and 'cmd' for Windows)\n    shellflag         string    (default '-c' for Unix and '/c' for Windows)\n    shellopts         []string  (default '')\n    showbinds         bool      (default true)\n    sizeunits         string    (default 'binary')\n    smartcase         bool      (default true)\n    smartdia          bool      (default false)\n    sortby            string    (default 'natural')\n    statfmt           string    (default \"\\033[36m%p\\033[0m| %c| %u| %g| %S| %t| -> %l\")\n    tabstop           int       (default 8)\n    tagfmt            string    (default \"\\033[31m\")\n    tempmarks         string    (default '')\n    terminalcursor    string    (default 'default')\n    timefmt           string    (default 'Mon Jan _2 15:04:05 2006')\n    truncatechar      string    (default '~')\n    truncatepct       int       (default 100)\n    visualfmt         string    (default \"\\033[7;36m\")\n    waitmsg           string    (default 'Press any key to continue')\n    watch             bool      (default false)\n    wrapscan          bool      (default true)\n    wrapscroll        bool      (default false)\n    user_{option}     string    (default none)\n\nThe following environment variables are exported for shell commands:\n\n    f\n    fs\n    fv\n    fx\n    id\n    PWD\n    OLDPWD\n    LF_LEVEL\n    OPENER\n    VISUAL\n    EDITOR\n    PAGER\n    SHELL\n    lf\n    lf_{option}\n    lf_user_{option}\n    lf_flag_{flag}\n    lf_width\n    lf_height\n    lf_count\n    lf_mode\n\nThe following special shell commands are used to customize the behavior\nof lf when defined:\n\n    open\n    paste\n    rename\n    delete\n    pre-cd\n    on-cd\n    on-load\n    on-focus-gained\n    on-focus-lost\n    on-init\n    on-select\n    on-redraw\n    on-quit\n\nThe following commands/keybindings are provided by default:\n\n    Unix\n    cmd open &$OPENER \"$f\"\n    map e $$EDITOR \"$f\"\n    map i $$PAGER \"$f\"\n    map w $$SHELL\n    cmd help $$lf -doc | $PAGER\n    map <f-1> help\n    cmd maps $lf -remote \"query $id maps\" | $PAGER\n    cmd nmaps $lf -remote \"query $id nmaps\" | $PAGER\n    cmd vmaps $lf -remote \"query $id vmaps\" | $PAGER\n    cmd cmaps $lf -remote \"query $id cmaps\" | $PAGER\n    cmd cmds $lf -remote \"query $id cmds\" | $PAGER\n\n    Windows\n    cmd open &%OPENER% %f%\n    map e $%EDITOR% %f%\n    map i !%PAGER% %f%\n    map w $%SHELL%\n    cmd help !%lf% -doc | %PAGER%\n    map <f-1> help\n    cmd maps !%lf% -remote \"query %id% maps\" | %PAGER%\n    cmd nmaps !%lf% -remote \"query %id% nmaps\" | %PAGER%\n    cmd vmaps !%lf% -remote \"query %id% vmaps\" | %PAGER%\n    cmd cmaps !%lf% -remote \"query %id% cmaps\" | %PAGER%\n    cmd cmds !%lf% -remote \"query %id% cmds\" | %PAGER%\n\nThe defaults for Windows are using cmd syntax. A PowerShell compatible\nconfiguration file can be found at\nhttps://github.com/gokcehan/lf/blob/master/etc/lfrc.ps1.example\n\nThe following additional keybindings are provided by default:\n\n    map zh set hidden!\n    map zr set reverse!\n    map zn set info\n    map zs set info size\n    map zt set info time\n    map za set info size:time\n    map sn :set sortby natural; set info\n    map ss :set sortby size; set info size\n    map st :set sortby time; set info time\n    map sa :set sortby atime; set info atime\n    map sb :set sortby btime; set info btime\n    map sc :set sortby ctime; set info ctime\n    map se :set sortby ext; set info\n    map gh cd ~\n    nmap <space> :toggle; down\n\nIf the mouse option is enabled, mouse buttons have the following default\neffects:\n\n    Left mouse button\n        Click on a file or directory to select it.\n\n    Right mouse button\n        Enter a directory or open a file. Also works on the preview pane.\n\n    Scroll wheel\n        Move up or down. If Ctrl is pressed, scroll up or down.\n\nCONFIGURATION\n\nConfiguration files should be located at:\n\n    OS       system-wide               user-specific\n    Unix     /etc/lf/lfrc              ~/.config/lf/lfrc\n    Windows  C:\\ProgramData\\lf\\lfrc    C:\\Users\\<user>\\AppData\\Roaming\\lf\\lfrc\n\nThe colors file should be located at:\n\n    OS       system-wide               user-specific\n    Unix     /etc/lf/colors            ~/.config/lf/colors\n    Windows  C:\\ProgramData\\lf\\colors  C:\\Users\\<user>\\AppData\\Roaming\\lf\\colors\n\nThe icons file should be located at:\n\n    OS       system-wide               user-specific\n    Unix     /etc/lf/icons             ~/.config/lf/icons\n    Windows  C:\\ProgramData\\lf\\icons   C:\\Users\\<user>\\AppData\\Roaming\\lf\\icons\n\nThe selection file should be located at:\n\n    Unix     ~/.local/share/lf/files\n    Windows  C:\\Users\\<user>\\AppData\\Local\\lf\\files\n\nThe marks file should be located at:\n\n    Unix     ~/.local/share/lf/marks\n    Windows  C:\\Users\\<user>\\AppData\\Local\\lf\\marks\n\nThe tags file should be located at:\n\n    Unix     ~/.local/share/lf/tags\n    Windows  C:\\Users\\<user>\\AppData\\Local\\lf\\tags\n\nThe history file should be located at:\n\n    Unix     ~/.local/share/lf/history\n    Windows  C:\\Users\\<user>\\AppData\\Local\\lf\\history\n\nYou can configure these locations with the following variables given\nwith their order of precedences and their default values:\n\n    Unix\n        $LF_CONFIG_HOME\n        $XDG_CONFIG_HOME\n        ~/.config\n\n        $LF_DATA_HOME\n        $XDG_DATA_HOME\n        ~/.local/share\n\n    Windows\n        %LF_CONFIG_HOME%\n        %XDG_CONFIG_HOME%\n        %APPDATA%\n\n        %LF_DATA_HOME%\n        %XDG_DATA_HOME%\n        %LOCALAPPDATA%\n\nA sample configuration file can be found at\nhttps://github.com/gokcehan/lf/blob/master/etc/lfrc.example\n\nCOMMANDS\n\nThis section shows information about built-in commands. Modal commands\ndo not take any arguments, but instead change the operation mode to read\ntheir input conveniently, and so they are meant to be assigned to\nkeybindings.\n\nquit (default q)\n\nQuit lf and return to the shell.\n\nup (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>)\n\nMove/scroll the current file selection upwards/downwards by one/half a\npage/full page.\n\nupdir (default h and <left>)\n\nChange the current working directory to the parent directory.\n\nopen (default l and <right>)\n\nIf the current file is a directory, then change the current directory to\nit, otherwise, execute the open command. A default open command is\nprovided to call the default system opener asynchronously with the\ncurrent file as the argument. A custom open command can be defined to\noverride this default.\n\njump-next (default ]), jump-prev (default [)\n\nChange the current working directory to the next/previous jumplist item.\n\ntop (default gg and <home>), bottom (default G and <end>)\n\nMove the current file selection to the top/bottom of the directory. A\ncount can be specified to move to a specific line, for example, use 3G\nto move to the third line.\n\nhigh (default H), middle (default M), low (default L)\n\nMove the current file selection to the high/middle/low of the screen.\n\ntoggle\n\nToggle the selection of the current file or files given as arguments.\n\ninvert (default v)\n\nReverse the selection of all files in the current directory (i.e. toggle\nall files). Selections in other directories are not affected by this\ncommand. You can define a new command to select all files in the\ndirectory by combining invert with unselect (i.e.\ncmd select-all :unselect; invert), though this will also remove\nselections in other directories.\n\nunselect (default u)\n\nRemove the selection of all files in all directories.\n\nglob-select, glob-unselect\n\nSelect/unselect files that match the given glob.\n\ncopy (default y)\n\nSave the paths of selected files to the clipboard as files to be copied.\nIf there are no selected files, the path of the current file is used\ninstead.\n\ncut (default d)\n\nSave the paths of selected files to the clipboard as files to be moved.\nIf there are no selected files, the path of the current file is used\ninstead.\n\npaste (default p)\n\nCopy/Move files in the clipboard to the current working directory. A\ncustom paste command can be defined to override this default.\n\nclear (default c)\n\nClear file paths in the clipboard.\n\nsync\n\nSynchronize copied/cut files with the server. This command is\nautomatically called when required.\n\ndraw\n\nDraw the screen. This command is automatically called when required.\n\nredraw (default <c-l>)\n\nSynchronize the terminal and redraw the screen.\n\nload\n\nLoad modified files and directories. This command is automatically\ncalled when required.\n\nreload (default <c-r>)\n\nFlush the cache and reload all files and directories.\n\ndelete (modal)\n\nRemove the current file or selected file(s). A custom delete command can\nbe defined to override this default.\n\nrename (modal) (default r)\n\nRename the current file using the built-in method. A custom rename\ncommand can be defined to override this default.\n\nread (modal) (default :)\n\nRead a command to evaluate.\n\nshell (modal) (default $)\n\nRead a shell command to execute.\n\nshell-pipe (modal) (default %)\n\nRead a shell command to execute piping its standard I/O to the bottom\nstatline.\n\nshell-wait (modal) (default !)\n\nRead a shell command to execute and wait for a key press at the end.\n\nshell-async (modal) (default &)\n\nRead a shell command to execute asynchronously without standard I/O.\n\nfind (modal) (default f), find-back (modal) (default F), find-next (default ;), find-prev (default ,)\n\nRead key(s) to find the appropriate filename match in the\nforward/backward direction and jump to the next/previous match.\n\nsearch (default /), search-back (default ?), search-next (default n), search-prev (default N)\n\nRead a pattern to search for a filename match in the forward/backward\ndirection and jump to the next/previous match.\n\nfilter (modal), setfilter\n\nCommand filter reads a pattern to filter out and only view files\nmatching the pattern. Command setfilter does the same but uses an\nargument to set the filter immediately. You can supply an argument to\nfilter to use as the starting prompt.\n\nmark-save (modal) (default m)\n\nSave the current directory as a bookmark assigned to the given key.\n\nmark-load (modal) (default ')\n\nChange the current directory to the bookmark assigned to the given key.\nA special bookmark ' holds the previous directory after a mark-load, cd,\nor select command.\n\nmark-remove (modal) (default \")\n\nRemove a bookmark assigned to the given key.\n\ntag\n\nTag a file with * or a single-width character given in the argument. You\ncan define a new tag-clearing command by combining tag with tag-toggle\n(i.e. cmd tag-clear :tag; tag-toggle).\n\ntag-toggle (default t)\n\nTag a file with * or a single-width character given in the argument if\nthe file is untagged, otherwise remove the tag.\n\necho\n\nPrint the given arguments to the message line at the bottom.\n\nechomsg\n\nPrint the given arguments to the message line at the bottom and also to\nthe log file.\n\nechoerr\n\nPrint given arguments to the message line at the bottom as errorfmt and\nalso to the log file.\n\ncd\n\nChange the working directory to the given argument.\n\nselect\n\nChange the current file selection to the given argument.\n\nsource\n\nRead the configuration file given in the argument.\n\npush\n\nSimulate key pushes given in the argument.\n\naddcustominfo\n\nUpdate the custom info and .Stat.CustomInfo field of the given file with\nthe given string. The info string may contain ANSI escape codes to\nfurther customize its appearance. If no info is provided, clear the\nfile's info instead.\n\ncalcdirsize\n\nCalculate the total size for each of the selected directories. Option\ninfo should include size and option dircounts should be disabled to show\nthis size. If the total size of a directory is not calculated, it will\nbe shown as -.\n\nclearmaps\n\nRemove all keybindings associated with the map, nmap and vmap command.\nThis command can be used in the config file to remove the default\nkeybindings. For safety purposes, : is left mapped to the read command,\nand cmap keybindings are retained so that it is still possible to exit\nlf using :quit.\n\ntty-write\n\nWrite the given string to the tty. This is useful for sending escape\nsequences to the terminal to control its behavior (e.g. OSC 0 to set the\nwindow title). Using tty-write is preferred over directly writing to\n/dev/tty because the latter is not synchronized and can interfere with\ndrawing the UI.\n\nvisual (default V)\n\nSwitch to Visual mode. If already in Visual mode, discard the visual\nselection and stay in Visual mode.\n\nVISUAL MODE COMMANDS\n\nvisual-accept (default V)\n\nAdd the visual selection to the selection list, quit Visual mode and\nreturn to Normal mode.\n\nvisual-unselect\n\nRemove the visual selection from the selection list, quit Visual mode\nand return to Normal mode.\n\nvisual-discard (default <esc>)\n\nDiscard the visual selection, quit Visual mode and return to Normal\nmode.\n\nvisual-change (default o)\n\nGo to the other end of the current Visual mode selection.\n\nCOMMAND-LINE MODE COMMANDS\n\nThe prompt character specifies which of the several Command-line modes\nyou are in. For example, the read command takes you to the : mode.\n\nWhen the cursor is at the first character in : mode, pressing one of the\nkeys !, $, %, or & takes you to the corresponding mode. You can go back\nwith cmd-delete-back (<backspace> by default).\n\nThe command line commands should be mostly compatible with readline\nkeybindings. A character refers to a Unicode code point, a word consists\nof letters and digits, and a Unix word consists of any non-blank\ncharacters.\n\ncmd-insert\n\nInsert the character given in the argument. This command is\nautomatically called when required.\n\ncmd-escape (default <esc>)\n\nQuit Command-line mode and return to Normal mode.\n\ncmd-complete (default <tab>)\n\nAutocomplete the current word.\n\ncmd-menu-complete, cmd-menu-complete-back\n\nAutocomplete the current word with the menu selection. You need to\nassign keys to these commands (e.g.\ncmap <tab> cmd-menu-complete; cmap <backtab> cmd-menu-complete-back).\nYou can use the assigned keys to display the menu and then cycle through\ncompletion options.\n\ncmd-menu-accept\n\nAccept the currently selected match in menu completion and close the\nmenu.\n\ncmd-menu-discard\n\nDiscard the currently selected match in menu completion and close the\nmenu.\n\ncmd-enter (default <c-j> and <enter>)\n\nExecute the current line.\n\ncmd-interrupt (default <c-c>)\n\nInterrupt the current shell-pipe command and return to the Normal mode.\n\ncmd-history-next (default <c-n> and <down>), cmd-history-prev (default <c-p> and <up>)\n\nGo to the next/previous entry in the command history. If part of the\ncommand is already typed, then only matching entries will be considered,\nand consecutive duplicate entries are skipped.\n\ncmd-left (default <c-b> and <left>), cmd-right (default <c-f> and <right>)\n\nMove the cursor to the left/right.\n\ncmd-home (default <c-a> and <home>), cmd-end (default <c-e> and <end>)\n\nMove the cursor to the beginning/end of the line.\n\ncmd-delete (default <c-d> and <delete>)\n\nDelete the next character.\n\ncmd-delete-back (default <backspace>)\n\nDelete the previous character. When at the beginning of a prompt,\nreturns either to Normal mode or to : mode.\n\ncmd-delete-home (default <c-u>), cmd-delete-end (default <c-k>)\n\nDelete everything up to the beginning/end of the line.\n\ncmd-delete-unix-word (default <c-w>)\n\nDelete the previous Unix word.\n\ncmd-yank (default <c-y>)\n\nPaste the buffer content containing the last deleted item.\n\ncmd-transpose (default <c-t>)\n\nSwap the characters before and after the cursor, then move the cursor\nforward. If there is no character after the cursor, swap the previous\ntwo characters instead.\n\ncmd-transpose-word (default <a-t>)\n\nSwap the words before and after the cursor, then move the cursor\nforward. If there is no word after the cursor, swap the previous two\nwords instead.\n\ncmd-word (default <a-f>), cmd-word-back (default <a-b>)\n\nMove the cursor by one word in the forward/backward direction.\n\ncmd-delete-word (default <a-d>)\n\nDelete the next word in the forward direction.\n\ncmd-delete-word-back (default <a-backspace>)\n\nDelete the previous word in the backward direction.\n\ncmd-capitalize-word (default <a-c>), cmd-uppercase-word (default <a-u>), cmd-lowercase-word (default <a-l>)\n\nCapitalize/uppercase/lowercase the current word and jump to the next\nword.\n\nSETTINGS\n\nThis section shows information about options to customize the behavior.\nCharacter : is used as the separator for list options []int and\n[]string.\n\nanchorfind (bool) (default true)\n\nWhen this option is enabled, the find command starts matching patterns\nfrom the beginning of filenames, otherwise, it can match at an arbitrary\nposition.\n\nautoquit (bool) (default true)\n\nAutomatically quit the server when there are no clients left connected.\n\nborderfmt (string) (default \\033[0m)\n\nFormat string of border characters.\n\nborderstyle (string) (default box)\n\nBorder style used by drawbox.\n\nThe following styles are supported:\n\n    box           outline around all panes and separators between them\n    roundbox      like `box`, but with rounded outer corners\n    outline       outline around all panes\n    roundoutline  like `outline`, but with rounded outer corners\n    separators    separators between panes\n\ncleaner (string) (default ``) (not called if empty)\n\nSet the path of a cleaner file. The file should be executable. This file\nis called if previewing is enabled, the previewer is set, and the\npreviously selected file has its preview cache disabled. The following\narguments are passed to the file, (1) current filename, (2) width, (3)\nheight, (4) horizontal position, (5) vertical position of preview pane\nand (6) next filename to be previewed respectively. Preview cleaning is\ndisabled when the value of this option is left empty.\n\ncopyfmt (string) (default \\033[7;33m)\n\nFormat string of the indicator for files to be copied.\n\ncursoractivefmt (string) (default \\033[7m), cursorparentfmt (string) (default \\033[7m), cursorpreviewfmt (string) (default \\033[4m)\n\nFormat strings for highlighting the cursor. cursoractivefmt applies in\nthe current directory pane, cursorparentfmt applies in panes that show\nparents of the current directory, and cursorpreviewfmt applies in panes\nthat preview directories.\n\nThe default is to make the active cursor and the parent directory cursor\ninverted. The preview cursor is underlined.\n\nSome other possibilities to consider for the preview or parent cursors:\nan empty string for no cursor, \\033[7;2m for dimmed inverted text\n(visibility varies by terminal), \\033[7;90m for inverted text with grey\n(aka \"brightblack\") background.\n\nIf the format string contains the characters %s, it is interpreted as a\nformat string for fmt.Sprintf. Such a string should end with the\nterminal reset sequence. For example, \\033[4m%s\\033[0m has the same\neffect as \\033[4m.\n\ncutfmt (string) (default \\033[7;31m)\n\nFormat string of the indicator for files to be cut.\n\ndircounts (bool) (default false)\n\nWhen this option is enabled, directory sizes show the number of items\ninside instead of the total size of the directory, which needs to be\ncalculated for each directory using calcdirsize. This information needs\nto be calculated by reading the directory and counting the items inside.\nTherefore, this option is disabled by default for performance reasons.\nThis option only has an effect when info has a size field and the pane\nis wide enough to show the information. 999 items are counted per\ndirectory at most, and bigger directories are shown as 999+.\n\ndirfirst (bool) (default true)\n\nShow directories first above regular files. With dircounts enabled,\nsorting by size always separates directories and files, regardless of\ndirfirst.\n\ndironly (bool) (default false)\n\nShow only directories.\n\ndirpreviews (bool) (default false)\n\nIf enabled, directories will also be passed to the previewer script.\nThis allows custom previews for directories.\n\ndrawbox (bool) (default false)\n\nDraw borders around panes using box drawing characters.\n\ndupfilefmt (string) (default %f.~%n~)\n\nFormat string of filename when creating duplicate files. With the\ndefault format, copying a file abc.txt to the same directory will result\nin a duplicate file called abc.txt.~1~. Special expansions are provided,\n%f as the file name, %b for the base name (file name without extension),\n%e as the extension (including the dot) and %n as the number of\nduplicates.\n\nerrorfmt (string) (default \\033[7;31;47m)\n\nFormat string of error messages shown in the bottom message line.\n\nIf the format string contains the characters %s, it is interpreted as a\nformat string for fmt.Sprintf. Such a string should end with the\nterminal reset sequence. For example, \\033[4m%s\\033[0m has the same\neffect as \\033[4m.\n\nfilesep (string) (default \\n)\n\nFile separator used in environment variables fs, fv and fx.\n\nfiltermethod (string) (default text)\n\nHow filter command patterns are treated. Currently supported methods are\ntext (i.e. string literals), glob (i.e. shell globs) and regex (i.e.\nregular expressions). See SEARCHING FILES for more details.\n\nfindlen (int) (default 1)\n\nNumber of characters prompted for the find command. When this value is\nset to 0, find command prompts until there is only a single match left.\n\nhidden (bool) (default false)\n\nShow hidden files. On Unix systems, hidden files are determined by the\nvalue of hiddenfiles. On Windows, files with hidden attributes are also\nconsidered hidden files.\n\nhiddenfiles ([]string) (default .* for Unix and `` for Windows)\n\nList of hidden file glob patterns. Patterns can be given as relative or\nabsolute paths. Globbing supports the usual special characters, * to\nmatch any sequence, ? to match any character, and [...] or [^...] to\nmatch character sets or ranges. In addition, if a pattern starts with !,\nthen its matches are excluded from hidden files. To add multiple\npatterns, use : as a separator. Example: .*:lost+found:*.bak\n\nhistory (bool) (default true)\n\nSave command history.\n\nicons (bool) (default false)\n\nShow icons before each item in the list.\n\nifs (string) (default ``)\n\nSets IFS variable in shell commands. It works by adding the assignment\nto the beginning of the command string as IFS=...; .... The reason is\nthat IFS variable is not inherited by the shell for security reasons.\nThis method assumes a POSIX shell syntax so it can fail for non-POSIX\nshells. This option has no effect when the value is left empty. This\noption does not have any effect on Windows.\n\nignorecase (bool) (default true)\n\nIgnore case in sorting and search patterns.\n\nignoredia (bool) (default true)\n\nIgnore diacritics in sorting and search patterns.\n\nincfilter (bool) (default false)\n\nApply filter pattern after each keystroke during filtering.\n\nincsearch (bool) (default false)\n\nJump to the first match after each keystroke during searching.\n\ninfo ([]string) (default ``)\n\nA list of information that is shown for directory items at the right\nside of the pane.\n\nThe following information types are supported:\n\n    perm      file permission\n    user      user name\n    group     group name\n    size      file size\n    time      time of last data modification\n    atime     time of last access\n    btime     time of file birth\n    ctime     time of last status (inode) change\n    custom    property defined via `addcustominfo` (empty by default)\n\nInformation is only shown when the pane width is more than twice the\nwidth of information.\n\ninfotimefmtnew (string) (default Jan _2 15:04)\n\nFormat string of the file time shown in the info column when it matches\nthis year.\n\ninfotimefmtold (string) (default Jan _2  2006)\n\nFormat string of the file time shown in the info column when it doesn't\nmatch this year.\n\nmenufmt (string) (default \\033[0m)\n\nFormat string of the menu.\n\nmenuheaderfmt (string) (default \\033[1m)\n\nFormat string of the header row in the menu.\n\nmenuselectfmt (string) (default \\033[7m)\n\nFormat string of the currently selected item in the menu.\n\nmergeindicators (bool) (default false)\n\nWhen mergeindicators is enabled, tag and selection indicators are drawn\nin a single column to reduce the gap before filenames. If a file is both\ntagged and selected, the tag uses the selection format (e.g. copyfmt)\ninstead of tagfmt.\n\nmouse (bool) (default false)\n\nSend mouse events as input.\n\nnumber (bool) (default false)\n\nShow the position number for directory items on the left side of the\npane. When the relativenumber option is enabled, only the current line\nshows the absolute position and relative positions are shown for the\nrest.\n\nnumberfmt (string) (default \\033[33m), numbercursorfmt (string) (default ``)\n\nFormat strings for highlighting line numbers. numberfmt applies to all\nlines. numbercursorfmt applies to the cursor line and falls back to\nnumberfmt when left empty.\n\nperiod (int) (default 0)\n\nSet the interval in seconds for periodic checks of directory updates.\nThis works by periodically calling the load command. Note that\ndirectories are already updated automatically in many cases. This option\ncan be useful when there is an external process changing the displayed\ndirectory and you are not doing anything in lf. Periodic checks are\ndisabled when the value of this option is set to zero.\n\npreload (bool) (default false)\n\nAllow previews to be generated in advance using the previewer script as\nthe user navigates through the filesystem.\n\npreserve ([]string) (default mode)\n\nList of attributes that are preserved when copying files. Currently\nsupported attributes are mode (i.e. access mode) and timestamps (i.e.\nmodification time and access time). Note that preserving other\nattributes like ownership of change/birth timestamp is desirable, but\nnot portably supported in Go.\n\npreview (bool) (default true)\n\nShow previews of files and directories at the rightmost pane. If the\nfile has more lines than the preview pane, the rest of the lines are not\nread. Files containing the null character (U+0000) in the read portion\nare considered binary files and displayed as binary.\n\npreviewer (string) (default ``) (not filtered if empty)\n\nSet the path of a previewer file to filter the content of regular files\nfor previewing. The file should be executable. The following arguments\nare passed to the file, (1) current filename, (2) width, (3) height, (4)\nhorizontal position, (5) vertical position, and (6) mode (\"preview\" or\n\"preload\"). SIGPIPE signal is sent when enough lines are read. If the\npreviewer returns a non-zero exit code, then the preview cache for the\ngiven file is disabled. This means that if the file is selected in the\nfuture, the previewer is called once again. Preview filtering is\ndisabled and files are displayed as they are when the value of this\noption is left empty. If the preload option is enabled, then this will\nbe called with preload as the mode when preloading file previews. Refer\nto the PREVIEWING FILES section for more information about how to\nconfigure custom previews.\n\npromptfmt (string) (default \\033[32;1m%u@%h\\033[0m:\\033[34;1m%d\\033[0m\\033[1m%f\\033[0m)\n\nFormat string of the prompt shown in the top line.\n\nThe following special expansions are supported:\n\n    %f        file name\n    %h        host name\n    %u        user name\n    %w        working directory\n    %d        working directory (with trailing path separator)\n    %F        current filter\n    %S        spacer to right-align the following parts (can be used once)\n\nThe home folder is shown as ~ in the working directory expansion.\nDirectory names are automatically shortened to a single character\nstarting from the leftmost parent when the prompt does not fit the\nscreen.\n\nratios ([]int) (default 1:2:3)\n\nList of ratios of pane widths. Number of items in the list determines\nthe number of panes in the UI. When the preview option is enabled, the\nrightmost number is used for the width of the preview pane.\n\nrelativenumber (bool) (default false)\n\nShow the position number relative to the current line. When number is\nenabled, the current line shows the absolute position, otherwise nothing\nis shown.\n\nreverse (bool) (default false)\n\nReverse the direction of sort.\n\nrulerfile (string) (default ``)\n\nSet the path of the ruler file. If not set, then a default template will\nbe used for the ruler. Refer to the RULER section for more information\nabout how the ruler file works.\n\nrulerfmt (string) (default ``)\n\nFormat string of the ruler shown in the bottom right corner. When set,\nit will be used along with statfmt to draw the ruler, and rulerfile will\nbe ignored. However, using rulerfile is preferred and this option is\nprovided for backwards compatibility.\n\nThe following special expansions are supported:\n\n    %a        pressed keys\n    %p        progress of file operations\n    %m        number of files to be cut (moved)\n    %c        number of files to be copied\n    %s        number of selected files\n    %v        number of visually selected files\n    %t        number of shown files in the current directory\n    %h        number of hidden files in the current directory\n    %f        current filter\n    %i        cursor position\n    %P        scroll percentage\n    %d        amount of free disk space\n\nAdditional expansions are provided for environment variables exported by\nlf, in the form %{lf_<name>} (e.g. %{lf_selmode}). This is useful for\ndisplaying the current settings. Expansions are also provided for\nuser-defined options, in the form %{lf_user_<name>} (e.g.\n%{lf_user_foo}). The | character splits the format string into sections.\nAny section containing a failed expansion (result is a blank string) is\ndiscarded and not shown.\n\nscrolloff (int) (default 0)\n\nMinimum number of offset lines shown at all times at the top and bottom\nof the screen when scrolling. The current line is kept in the middle\nwhen this option is set to a large value that is bigger than half the\nnumber of lines. A smaller offset can be used when the current file is\nclose to the beginning or end of the list to show the maximum number of\nitems.\n\nsearchmethod (string) (default text)\n\nHow search command patterns are treated. Currently supported methods are\ntext (i.e. string literals), glob (i.e. shell globs) and regex (i.e.\nregular expressions). See SEARCHING FILES for more details.\n\nselectfmt (string) (default \\033[7;35m)\n\nFormat string of the indicator for files that are selected.\n\nselmode (string) (default all)\n\nSelection mode for commands. When set to all it will use the selected\nfiles from all directories. When set to dir it will only use the\nselected files in the current directory.\n\nshell (string) (default sh for Unix and cmd for Windows)\n\nShell executable to use for shell commands. Shell commands are executed\nas shell shellopts shellflag command -- arguments.\n\nshellflag (string) (default -c for Unix and /c for Windows)\n\nCommand line flag used to pass shell commands.\n\nshellopts ([]string) (default ``)\n\nList of shell options to pass to the shell executable.\n\nshowbinds (bool) (default true)\n\nShow bindings associated with pressed keys.\n\nsizeunits (string) (default binary)\n\nDetermines whether file sizes are displayed using binary units (1K is\n1024 bytes) or decimal units (1K is 1000 bytes).\n\nsmartcase (bool) (default true)\n\nOverride ignorecase option when the pattern contains an uppercase\ncharacter. This option has no effect when ignorecase is disabled.\n\nsmartdia (bool) (default false)\n\nOverride ignoredia option when the pattern contains a character with\ndiacritic. This option has no effect when ignoredia is disabled.\n\nsortby (string) (default natural)\n\nSort type for directories.\n\nThe following sort types are supported:\n\n    natural   file name (track_2.flac comes before track_10.flac)\n    name      file name (track_10.flac comes before track_2.flac)\n    ext       file extension\n    size      file size\n    time      time of last data modification\n    atime     time of last access\n    btime     time of file birth\n    ctime     time of last status (inode) change\n    custom    property defined via `addcustominfo` (empty by default)\n\nstatfmt (string) (default \\033[36m%p\\033[0m| %c| %u| %g| %S| %t| -> %l)\n\nFormat string of the file info shown in the bottom left corner. This\noption has no effect unless rulerfmt is also set. Using rulerfile is\npreferred and this option is provided for backwards compatibility.\n\nThe following special expansions are supported:\n\n    %p        file permission\n    %c        link count\n    %u        user name\n    %g        group name\n    %s        file size\n    %S        file size (left-padded with spaces to a fixed width of 5 characters)\n    %t        time of last data modification\n    %l        link target\n    %m        current mode\n    %M        current mode (displaying `NORMAL` instead of a blank string in Normal mode)\n\nThe | character splits the format string into sections. Any section\ncontaining a failed expansion (result is a blank string) is discarded\nand not shown.\n\ntabstop (int) (default 8)\n\nNumber of space characters to show for horizontal tabulation (U+0009)\ncharacter.\n\ntagfmt (string) (default \\033[31m)\n\nFormat string of the tags.\n\nIf the format string contains the characters %s, it is interpreted as a\nformat string for fmt.Sprintf. Such a string should end with the\nterminal reset sequence. For example, \\033[4m%s\\033[0m has the same\neffect as \\033[4m.\n\ntempmarks (string) (default ``)\n\nMarks to be considered temporary (e.g. abc refers to marks a, b, and c).\nThese marks are not synced to other clients and they are not saved in\nthe bookmarks file. Note that the special bookmark ' is always treated\nas temporary and it does not need to be specified.\n\nterminalcursor (string) (default default)\n\nSet the appearance of the terminal cursor for prompts shown in the\nbottom line. Currently supported values are default, block, underline,\nbar, blinkblock, blinkunderline and blinkbar.\n\ntimefmt (string) (default Mon Jan _2 15:04:05 2006)\n\nFormat string of the file modification time shown in the bottom line.\n\ntruncatechar (string) (default ~)\n\nThe truncate character that is shown at the end when the filename does\nnot fit into the pane.\n\ntruncatepct (int) (default 100)\n\nWhen a filename is too long to be shown completely, the available space\nwill be partitioned into two parts. truncatepct is a percentage value\nbetween 0 and 100 that determines the size of the first part, which will\nbe shown at the beginning of the filename. The second part uses the rest\nof the available space, and will be shown at the end of the filename.\nBoth parts are separated by the truncation character (truncatechar).\nTruncation is not applied to the file extension.\n\nFor example, with the filename very_long_filename.txt:\n\n- set truncatepct 100 -> very_long_filena~.txt (default)\n\n- set truncatepct 50 -> very_lon~filename.txt\n\n- set truncatepct 0 -> ~ry_long_filename.txt\n\nvisualfmt (string) (default \\033[7;36m)\n\nFormat string of the indicator for files that are visually selected.\n\nwaitmsg (string) (default Press any key to continue)\n\nString shown after commands of shell-wait type.\n\nwatch (bool) (default false)\n\nWatch the filesystem for changes using fsnotify to automatically refresh\nfile information. FUSE is currently not supported due to limitations in\nfsnotify.\n\nwrapscan (bool) (default true)\n\nSearching can wrap around the file list.\n\nwrapscroll (bool) (default false)\n\nScrolling can wrap around the file list.\n\nuser_{option} (string) (default none)\n\nAny option that is prefixed with user_ is a user-defined option and can\nbe set to any string. Inside a user-defined command, the value will be\nprovided in the lf_user_{option} environment variable. These options are\nnot used by lf and are not persisted.\n\nENVIRONMENT VARIABLES\n\nThe following variables are exported for shell commands: These are\nreferred to with a $ prefix on POSIX shells (e.g. $f), between %\ncharacters on Windows cmd (e.g. %f%), and with a $env: prefix on Windows\nPowerShell (e.g. $env:f).\n\nf\n\nCurrent file selection as a full path.\n\nfs\n\nSelected file(s) separated with the value of filesep option as full\npath(s).\n\nfv\n\nVisually selected file(s) separated with the value of filesep option as\nfull path(s).\n\nfx\n\nSelected file(s) (i.e. fs, never fv) if there are any selected files,\notherwise current file selection (i.e. f).\n\nid\n\nId of the running client.\n\nPWD\n\nPresent working directory.\n\nOLDPWD\n\nInitial working directory.\n\nLF_LEVEL\n\nThe value of this variable is set to the current nesting level when you\nrun lf from a shell spawned inside lf. You can add the value of this\nvariable to your shell prompt to make it clear that your shell runs\ninside lf. For example, with POSIX shells, you can use\n[ -n \"$LF_LEVEL\" ] && PS1=\"$PS1\"\"(lf level: $LF_LEVEL) \" in your shell\nconfiguration file (e.g. ~/.bashrc).\n\nOPENER\n\nIf this variable is set in the environment, use the same value.\nOtherwise, this is set to start in Windows, open in macOS, xdg-open in\nothers.\n\nEDITOR\n\nIf VISUAL is set in the environment, use its value. Otherwise, use the\nvalue of the environment variable EDITOR. If neither variable is set,\nthis is set to vi on Unix, notepad in Windows.\n\nPAGER\n\nIf this variable is set in the environment, use the same value.\nOtherwise, this is set to less on Unix, more in Windows.\n\nSHELL\n\nIf this variable is set in the environment, use the same value.\nOtherwise, this is set to sh on Unix, cmd in Windows.\n\nlf\n\nAbsolute path to the currently running lf binary, if it can be found.\nOtherwise, this is set to the string lf.\n\nlf_{option}\n\nValue of the {option}.\n\nlf_user_{option}\n\nValue of the user_{option}.\n\nlf_flag_{flag}\n\nValue of the command line {flag}.\n\nlf_width, lf_height\n\nWidth/Height of the terminal.\n\nlf_count\n\nValue of the count associated with the current command.\n\nlf_mode\n\nCurrent mode that lf is operating in. This is useful for customizing\nkeybindings depending on what the current mode is. Possible values are\ncompmenu, delete, rename, filter, find, mark, search, command, shell,\npipe (when running a shell-pipe command), normal, visual and unknown.\n\nSPECIAL COMMANDS\n\nThis section shows information about special shell commands.\n\nopen\n\nThis shell command can be defined to override the default open command\nwhen the current file is not a directory.\n\npaste\n\nThis shell command can be defined to override the default paste command.\n\nrename\n\nThis shell command can be defined to override the default rename\ncommand.\n\ndelete\n\nThis shell command can be defined to override the default delete\ncommand.\n\npre-cd\n\nThis shell command can be defined to be executed before changing a\ndirectory.\n\non-cd\n\nThis shell command can be defined to be executed after changing a\ndirectory.\n\non-load\n\nThis shell command can be defined to be executed after loading a\ndirectory. It provides the files inside the directory as arguments.\n\non-focus-gained\n\nThis shell command can be defined to be executed when the terminal gains\nfocus.\n\non-focus-lost\n\nThis shell command can be defined to be executed when the terminal loses\nfocus.\n\non-init\n\nThis shell command can be defined to be executed after initializing and\nconnecting to the server.\n\non-select\n\nThis shell command can be defined to be executed after the selection\nchanges.\n\non-redraw\n\nThis shell command can be defined to be executed after the screen is\nredrawn or if the terminal is resized.\n\non-quit\n\nThis shell command can be defined to be executed before quitting.\n\nPREFIXES\n\nThe following command prefixes are used by lf:\n\n    :  read (default)  built-in/custom command\n    $  shell           shell command\n    %  shell-pipe      shell command running with the UI\n    !  shell-wait      shell command waiting for a key press\n    &  shell-async     shell command running asynchronously\n\nThe same evaluator is used for the command line and the configuration\nfile for reading shell commands. The difference is that prefixes are not\nnecessary in the command line. Instead, different modes are provided to\nread corresponding commands. These modes are mapped to the prefix keys\nabove by default. Visual mode mappings are defined the same way Normal\nmode mappings are defined.\n\nSYNTAX\n\nCharacters from # to newline are comments and ignored:\n\n    # comments start with `#`\n\nThe following commands (set, setlocal, map, nmap, vmap, cmap, and cmd)\nare used for configuration.\n\nCommand set is used to set an option which can be a boolean, integer, or\nstring:\n\n    set hidden         # boolean enable\n    set hidden true    # boolean enable\n    set nohidden       # boolean disable\n    set hidden false   # boolean disable\n    set hidden!        # boolean toggle\n    set scrolloff 10   # integer value\n    set sortby time    # string value without quotes\n    set sortby 'time'  # string value with single quotes (whitespace)\n    set sortby \"time\"  # string value with double quotes (backslash escapes)\n\nCommand setlocal is used to set a local option for a directory which can\nbe a boolean or string. Currently supported local options are dircounts,\ndirfirst, dironly, hidden, info, reverse and sortby.\n\n    setlocal /foo/bar hidden         # boolean enable\n    setlocal /foo/bar hidden true    # boolean enable\n    setlocal /foo/bar nohidden       # boolean disable\n    setlocal /foo/bar hidden false   # boolean disable\n    setlocal /foo/bar hidden!        # boolean toggle\n    setlocal /foo/bar sortby time    # string value without quotes\n    setlocal /foo/bar sortby 'time'  # string value with single quotes (whitespace)\n    setlocal /foo/bar sortby \"time\"  # string value with double quotes (backslash escapes)\n\nCommand map is used to bind a key in Normal and Visual mode to a command\nwhich can be a built-in command, custom command, or shell command:\n\n    map gh cd ~        # built-in command\n    map D trash        # custom command\n    map i $less $f     # shell command\n    map U !du -csh *   # waiting shell command\n\nCommand nmap does the same but for Normal mode only.\n\nCommand vmap does the same but for Visual mode only.\n\nOverview of which map command works in which mode:\n\n    map                Normal, Visual\n    nmap               Normal\n    vmap               Visual\n    cmap               Command-line\n\nCommand cmap is used to bind a key on the command line to a command line\ncommand or any other command:\n\n    cmap <c-g> cmd-escape\n    cmap <a-i> set incsearch!\n\nYou can delete an existing binding by leaving the expression empty:\n\n    map gh             # deletes 'gh' mapping in Normal and Visual mode\n    nmap v             # deletes 'v' mapping in Normal mode\n    vmap o             # deletes 'o' mapping in Visual mode\n    cmap <c-g>         # deletes '<c-g>' mapping\n\nCommand cmd is used to define a custom command:\n\n    cmd usage $du -h -d1 | less\n\nYou can delete an existing command by leaving the expression empty:\n\n    cmd trash          # deletes 'trash' command\n\nIf there is no prefix then : is assumed:\n\n    map zt set info time\n\nAn explicit : can be provided to group statements until a newline which\nis especially useful for map and cmd commands:\n\n    map st :set sortby time; set info time\n\nIf you need multiline you can wrap statements in {{ and }} after the\nproper prefix.\n\n    map st :{{\n        set sortby time\n        set info time\n    }}\n\nKEY MAPPINGS\n\nRegular keys are assigned to a command with the usual syntax:\n\n    map a down\n\nKeys combined with the Shift key simply use the uppercase letter:\n\n    map A down\n\nSpecial keys are written in between < and > characters and always use\nlowercase letters:\n\n    map <enter> down\n\nAngle brackets can be assigned with their special names:\n\n    map <lt> down\n    map <gt> down\n\nFunction keys are prefixed with an f character:\n\n    map <f-1> down\n\nKeys combined with the Ctrl key are prefixed with a c character:\n\n    map <c-a> down\n\nKeys combined with the Alt key are assigned in two different ways\ndepending on the behavior of your terminal. Older terminals (e.g. xterm)\nmay set the 8th bit of a character when the Alt key is pressed. On these\nterminals, you can use the corresponding byte for the mapping:\n\n    map á down\n\nNewer terminals (e.g. gnome-terminal) may prefix the key with an escape\ncharacter when the Alt key is pressed. lf uses the escape delaying\nmechanism to recognize Alt keys in these terminals (delay is 100ms). On\nthese terminals, keys combined with the Alt key are prefixed with an a\ncharacter:\n\n    map <a-a> down\n\nIt is possible to combine special keys with modifiers:\n\n    map <a-enter> down\n\nCombining multiple modifiers (e.g. Ctrl+Shift+Space) is not supported.\n\nNote that lf's key mapping syntax is similar to Vim's, but not\nidentical. Some special keys and modifiers use different names and\nseparators, and key names are matched literally (i.e. no case-folding,\nno aliases), so some familiar forms will not work:\n\n    map <enter> down  # not <Enter>, <Return> or <CR>\n    map <f-1> down    # not <F1>\n    map <a-j> down    # not <A-j> or <M-j> (Meta)\n    map <m-2> down    # not <RightMouse>\n    map <m-up> down   # not <ScrollWheelUp>\n\nWARNING: Some key combinations will likely be intercepted by your OS,\nwindow manager, or terminal. Other key combinations cannot be recognized\nby lf due to the way terminals work (e.g. Ctrl+h combination sends a\nbackspace key instead). The easiest way to find out the name of a key\ncombination and whether it will work on your system is to press the key\nwhile lf is running and read the name from the unknown mapping error.\n\nMouse buttons are prefixed with an m character:\n\n    map <m-1> down  # primary\n    map <m-2> down  # secondary\n    map <m-3> down  # middle\n    map <m-4> down  # thumb next\n    map <m-5> down  # thumb prev\n    map <m-6> down\n    map <m-7> down\n    map <m-8> down\n\nMouse wheel events are also prefixed with an m character:\n\n    map <m-up>    down\n    map <m-down>  down\n    map <m-left>  down\n    map <m-right> down\n\nPUSH MAPPINGS\n\nThe usual way to map a key sequence is to assign it to a named or\nunnamed command. While this provides a clean way to remap built-in keys\nas well as other commands, it can be limiting at times. For this reason,\nthe push command is provided by lf. This command is used to simulate key\npushes given as its arguments. You can map a key to a push command with\nan argument to create various keybindings.\n\nThis is mainly useful for two purposes. First, it can be used to map a\ncommand with a command count:\n\n    map <c-j> push 10j\n\nSecond, it can be used to avoid typing the name when a command takes\narguments:\n\n    map r push :rename<space>\n\nOne thing to be careful of is that since the push command works with\nkeys instead of commands it is possible to accidentally create recursive\nbindings:\n\n    map j push 2j\n\nThese types of bindings create a deadlock when executed.\n\nSHELL COMMANDS\n\nRegular shell commands are the most basic command type that is useful\nfor many purposes. For example, we can write a shell command to move the\nselected file(s) to trash. A first attempt to write such a command may\nlook like this:\n\n    cmd trash ${{\n        mkdir -p ~/.trash\n        if [ -z \"$fs\" ]; then\n            mv \"$f\" ~/.trash\n        else\n            IFS=\"$(printf '\\n\\t')\"; mv $fs ~/.trash\n        fi\n    }}\n\nWe check $fs to see if there are any selected files. Otherwise, we just\ndelete the current file. Since this is such a common pattern, a separate\n$fx variable is provided. We can use this variable to get rid of the\nconditional:\n\n    cmd trash ${{\n        mkdir -p ~/.trash\n        IFS=\"$(printf '\\n\\t')\"; mv $fx ~/.trash\n    }}\n\nThe trash directory is checked each time the command is executed. We can\nmove it outside of the command so it would only run once at startup:\n\n    ${{ mkdir -p ~/.trash }}\n\n    cmd trash ${{ IFS=\"$(printf '\\n\\t')\"; mv $fx ~/.trash }}\n\nSince these are one-liners, we can drop {{ and }}:\n\n    $mkdir -p ~/.trash\n\n    cmd trash $IFS=\"$(printf '\\n\\t')\"; mv $fx ~/.trash\n\nFinally, note that we set the IFS variable manually in these commands.\nInstead, we could use the ifs option to set it for all shell commands\n(i.e. set ifs \"\\n\"). This can be especially useful for interactive use\n(e.g. $rm $f or $rm $fs would simply work). This option is not set by\ndefault as it can behave unexpectedly for new users. However, use of\nthis option is highly recommended and it is assumed in the rest of the\ndocumentation.\n\nPIPING SHELL COMMANDS\n\nRegular shell commands have some limitations in some cases. When an\noutput or error message is given and the command exits afterwards, the\nUI is immediately resumed and there is no way to see the message without\ndropping to shell again. Also, even when there is no output or error,\nthe UI still needs to be paused while the command is running. This can\ncause flickering on the screen for short commands and similar\ndistractions for longer commands.\n\nInstead of pausing the UI, piping shell commands connect stdin, stdout,\nand stderr of the command to the statline at the bottom of the UI. This\ncan be useful for programs following the Unix philosophy to give no\noutput in the success case, and brief error messages or prompts in other\ncases.\n\nFor example, the following rename command prompts for overwrite in the\nstatline if there is an existing file with the given name:\n\n    cmd rename %mv -i $f $1\n\nYou can also output error messages in the command and they will show up\nin the statline. For example, an alternative rename command may look\nlike this:\n\n    cmd rename %[ -e $1 ] && printf \"file exists\" || mv $f $1\n\nNote that input is line buffered and output and error are byte buffered.\n\nWAITING SHELL COMMANDS\n\nWaiting shell commands are similar to regular shell commands except that\nthey wait for a key press when the command is finished. These can be\nuseful to see the output of a program before the UI is resumed. Waiting\nshell commands are more appropriate than piping shell commands when the\ncommand is verbose and the output is best displayed as multiline.\n\nASYNCHRONOUS SHELL COMMANDS\n\nAsynchronous shell commands are used to start a command in the\nbackground and then resume operation without waiting for the command to\nfinish. Stdin, stdout, and stderr of the command are neither connected\nto the terminal nor the UI.\n\nREMOTE COMMANDS\n\nOne of the more advanced features in lf is remote commands. All clients\nconnect to a server on startup. It is possible to send commands to all\nor any of the connected clients over the common server. This is used\ninternally to notify file selection changes to other clients.\n\nTo use this feature, you need to use a client which supports\ncommunicating with a Unix domain socket. OpenBSD implementation of\nnetcat (nc) is one such example. You can use it to send a command to the\nsocket file:\n\n    echo 'send echo hello world' | nc -U ${XDG_RUNTIME_DIR:-/tmp}/lf.${USER}.sock\n\nSince such a client may not be available everywhere, lf comes bundled\nwith a command line flag to be used as such. When using lf, you do not\nneed to specify the address of the socket file. This is the recommended\nway of using remote commands since it is shorter and immune to socket\nfile address changes:\n\n    lf -remote 'send echo hello world'\n\nIn this command send is used to send the rest of the string as a command\nto all connected clients. You can optionally give it an ID number to\nsend a command to a single client:\n\n    lf -remote 'send 1234 echo hello world'\n\nAll clients have a unique ID number but you may not be aware of the ID\nnumber when you are writing a command. For this purpose, an $id variable\nis exported to the environment for shell commands. The value of this\nvariable is set to the process ID of the client. You can use it to send\na remote command from a client to the server which in return sends a\ncommand back to itself. So now you can display a message in the current\nclient by calling the following in a shell command:\n\n    lf -remote \"send $id echo hello world\"\n\nSince lf does not have control flow syntax, remote commands are used for\nsuch needs. For example, you can configure the number of columns in the\nUI with respect to the terminal width as follows:\n\n    cmd recol %{{\n        if [ $lf_width -le 80 ]; then\n            lf -remote \"send $id set ratios 1:2\"\n        elif [ $lf_width -le 160 ]; then\n            lf -remote \"send $id set ratios 1:2:3\"\n        else\n            lf -remote \"send $id set ratios 1:2:3:5\"\n        fi\n    }}\n\nIn addition, the query command can be used to obtain information about a\nspecific lf instance by providing its ID:\n\n    lf -remote \"query $id maps\"\n\nThe following types of information are supported:\n\n    maps     list of mappings created by the 'map', 'nmap' and 'vmap' command\n    nmaps    list of mappings created by the 'nmap' and 'map' command\n    vmaps    list of mappings created by the 'vmap' and 'map' command\n    cmaps    list of mappings created by the 'cmap' command\n    cmds     list of commands created by the 'cmd' command\n    jumps    contents of the jump list, showing previously visited locations\n    history  list of previously executed commands on the command line\n    files    list of files in the currently open directory as displayed by lf, empty if dir is still loading\n\nWhen listing mappings the characters in the first column are:\n\n    n  Normal\n    v  Visual\n    c  Command-line\n\nThis is useful for scripting actions based on the internal state of lf.\nFor example, to select a previous command using fzf and execute it:\n\n    map <a-h> ${{\n        clear\n        cmd=$(\n            lf -remote \"query $id history\" |\n            awk -F'\\t' 'NR > 1 { print $NF}' |\n            sort -u |\n            fzf --reverse --prompt='Execute command: '\n        )\n        lf -remote \"send $id $cmd\"\n    }}\n\nThe list command prints the IDs of all currently connected clients:\n\n    lf -remote 'list'\n\nThere is also a quit command to quit the server when there are no\nconnected clients left, and a quit! command to force quit the server by\nclosing client connections first:\n\n    lf -remote 'quit'\n    lf -remote 'quit!'\n\nLastly, the commands conn and drop connect or disconnect ID to/from the\nserver:\n\n    lf -remote 'conn $id'\n    lf -remote 'drop $id'\n\nThese are internal and generally not needed by users.\n\nFILE OPERATIONS\n\nlf uses its own built-in copy and move operations by default. These are\nimplemented as asynchronous operations and progress is shown in the\nbottom ruler. These commands do not overwrite existing files or\ndirectories with the same name. Instead, a suffix that is compatible\nwith the --backup=numbered option in GNU cp is added to the new files or\ndirectories. Only file modes and (some) timestamps can be preserved (see\npreserve option), all other attributes are ignored including ownership,\ncontext, and xattr. Special files such as character and block devices,\nnamed pipes, and sockets are skipped and links are not followed. Moving\nis performed using the rename operation of the underlying OS. For\ncross-device moving, lf falls back to copying and then deletes the\noriginal files if there are no errors. Operation errors are shown in the\nmessage line as well as the log file and they do not prematurely\nterminate the corresponding file operation.\n\nFile operations can be performed on the currently selected file or on\nmultiple files by selecting them first. When you copy a file, lf doesn't\nactually copy the file on the disk, but only records its name to a file.\nThe actual file copying takes place when you paste. Similarly paste\nafter a cut operation moves the file.\n\nYou can customize copy and move operations by defining a paste command.\nThis is a special command that is called when it is defined instead of\nthe built-in implementation. You can use the following example as a\nstarting point:\n\n    cmd paste %{{\n        load=$(cat ~/.local/share/lf/files)\n        mode=$(echo \"$load\" | sed -n '1p')\n        list=$(echo \"$load\" | sed '1d')\n        if [ $mode = 'copy' ]; then\n            cp -R $list .\n        elif [ $mode = 'move' ]; then\n            mv $list .\n            rm ~/.local/share/lf/files\n            lf -remote 'send clear'\n        fi\n    }}\n\nSome useful things to be considered are to use the backup (--backup)\nand/or preserve attributes (-a) options with cp and mv commands if they\nsupport it (i.e. GNU implementation), change the command type to\nasynchronous, or use rsync command with progress bar option for copying\nand feed the progress to the client periodically with remote echo calls.\n\nBy default, lf does not assign delete command to a key to protect new\nusers. You can customize file deletion by defining a delete command. You\ncan also assign a key to this command if you like. An example command to\nmove selected files to a trash folder and remove files completely after\na prompt is provided in the example configuration file.\n\nSEARCHING FILES\n\nThere are two mechanisms implemented in lf to search a file in the\ncurrent directory. Searching is the traditional method to move the\nselection to a file matching a given pattern. Finding is an alternative\nway to search for a pattern possibly using fewer keystrokes.\n\nThe searching mechanism is implemented with commands search (default /),\nsearch-back (default ?), search-next (default n), and search-prev\n(default N). You can set searchmethod to glob to match using a glob\npattern. Globbing supports * to match any sequence, ? to match any\ncharacter, and [...] or [^...] to match character sets or ranges. You\ncan set searchmethod to regex to match using a regex pattern. For a full\noverview of Go's RE2 syntax, see https://pkg.go.dev/regexp/syntax. You\ncan enable incsearch option to jump to the current match at each\nkeystroke while typing. In this mode, you can either use cmd-enter to\naccept the search or use cmd-escape to cancel the search. You can also\nmap some other commands with cmap to accept the search and execute the\ncommand immediately afterwards. For example, you can use the right arrow\nkey to finish the search and open the selected file with the following\nmapping:\n\n    cmap <right> :cmd-enter; open\n\nThe finding mechanism is implemented with commands find (default f),\nfind-back (default F), find-next (default ;), find-prev (default ,). You\ncan disable anchorfind option to match a pattern at an arbitrary\nposition in the filename instead of the beginning. You can set the\nnumber of keys to match using findlen option. If you set this value to\nzero, then the keys are read until there is only a single match. The\ndefault values of these two options are set to jump to the first file\nwith the given initial.\n\nSome options affect both searching and finding. You can disable wrapscan\noption to prevent searches from being wrapped around at the end of the\nfile list. You can disable ignorecase option to match cases in the\npattern and the filename. This option is already automatically\noverridden if the pattern contains uppercase characters. You can disable\nsmartcase option to disable this behavior. Two similar options ignoredia\nand smartdia are provided to control matching diacritics in Latin\nletters.\n\nOPENING FILES\n\nYou can define an open command (default l and <right>) to configure file\nopening. This command is only called when the current file is not a\ndirectory, otherwise, the directory is entered instead. You can define\nit just as you would define any other command:\n\n    cmd open $vi $fx\n\nIt is possible to use different command types:\n\n    cmd open &xdg-open $f\n\nYou may want to use either file extensions or MIME types from file\ncommand:\n\n    cmd open ${{\n        case $(file --mime-type -Lb $f) in\n            text/*) vi $fx;;\n            *) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;\n        esac\n    }}\n\nYou may want to use setsid before your opener command to have persistent\nprocesses that continue to run after lf quits.\n\nRegular shell commands (i.e. $) drop to the terminal which results in a\nflicker for commands that finish immediately (e.g. xdg-open in the above\nexample). If you want to use asynchronous shell commands (i.e. &) but\nalso want to use the terminal when necessary (e.g. vi in the above\nexample), you can use a remote command:\n\n    cmd open &{{\n        case $(file --mime-type -Lb $f) in\n            text/*) lf -remote \"send $id \\$vi \\$fx\";;\n            *) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;\n        esac\n    }}\n\nNote that asynchronous shell commands run in their own process group by\ndefault so they do not require the manual use of setsid.\n\nThe following command is provided by default:\n\n    cmd open &$OPENER $f\n\nYou may also use any other existing file openers as you like. Possible\noptions are libfile-mimeinfo-perl (executable name is mimeopen), rifle\n(ranger's default file opener), or mimeo to name a few.\n\nPREVIEWING FILES\n\nlf previews files on the preview pane by printing the file until the end\nor until the preview pane is filled. This output can be enhanced by\nproviding a custom preview script for filtering. This can be used to\nhighlight source code, list contents of archive files or view PDF or\nimage files to name a few. For coloring lf recognizes ANSI escape codes.\n\nTo use this feature, you need to set the value of previewer option to\nthe path of an executable file. The following arguments are passed to\nthe file, (1) current filename, (2) width, (3) height, (4) horizontal\nposition, (5) vertical position, and (6) mode (\"preview\" or \"preload\").\nThe output of the execution is printed in the preview pane.\n\nDifferent types of files can be handled by matching by extension (or\nMIME type from the file command):\n\n    #!/bin/sh\n\n    case \"$1\" in\n        *.tar*) tar tf \"$1\";;\n        *.zip) unzip -l \"$1\";;\n        *.rar) unrar l \"$1\";;\n        *.7z) 7z l \"$1\";;\n        *.pdf) pdftotext \"$1\" -;;\n        *) highlight -O ansi \"$1\";;\n    esac\n\nBecause files can be large, lf automatically closes the previewer script\noutput pipe with a SIGPIPE when enough lines are read. Note that some\nprograms may not respond well to SIGPIPE and will exit with a non-zero\nreturn code, which avoids caching. You may add a trailing || true\ncommand to avoid such errors:\n\n    highlight -O ansi \"$1\" || true\n\nYou may also want to use the same script in your pager mapping as well:\n\n    set previewer ~/.config/lf/pv.sh\n    map i $~/.config/lf/pv.sh $f | less -R\n\nFor less pager, you may instead utilize LESSOPEN mechanism so that\nuseful information about the file such as the full path of the file can\nstill be displayed in the statusline below:\n\n    set previewer ~/.config/lf/pv.sh\n    map i $LESSOPEN='| ~/.config/lf/pv.sh %s' less -R $f\n\nSince the preview script is called for each file selection change, it\nmay not generate previews fast enough if the user scrolls through files\nquickly. To deal with this, the preload option can be set to enable file\npreviews to be preloaded in advance. If enabled, the preview script will\nbe run on files in advance as the user navigates through them. In this\ncase, if the exit code of the preview script is zero, then the output\nwill be cached in memory and displayed by lf (useful for text or sixel\npreviews). Otherwise, it will fallback to calling the preview script\nagain when the file is actually selected (useful for previews managed by\nan external program).\n\nCHANGING DIRECTORY\n\nlf changes the working directory of the process to the current directory\nso that shell commands always work in the displayed directory. After\nquitting, it returns to the original directory where it is first\nlaunched like all shell programs. If you want to stay in the current\ndirectory after quitting, you can use one of the example lfcd wrapper\nshell scripts provided in the repository at\nhttps://github.com/gokcehan/lf/tree/master/etc\n\nThere is a special command on-cd that runs a shell command when it is\ndefined and the directory is changed. You can define it just as you\nwould define any other command:\n\n    cmd on-cd &{{\n        bash -c '\n        # display git repository status in your prompt\n        source /usr/share/git/completion/git-prompt.sh\n        GIT_PS1_SHOWDIRTYSTATE=auto\n        GIT_PS1_SHOWSTASHSTATE=auto\n        GIT_PS1_SHOWUNTRACKEDFILES=auto\n        GIT_PS1_SHOWUPSTREAM=auto\n        git=$(__git_ps1 \" (%s)\")\n        fmt=\"\\033[32;1m%u@%h\\033[0m:\\033[34;1m%d\\033[0m\\033[1m%f$git\\033[0m\"\n        lf -remote \"send $id set promptfmt \\\"$fmt\\\"\"\n        '\n    }}\n\nIf you want to send escape sequences to the terminal, you can use the\ntty-write command to do so. The following xterm-specific escape sequence\nsets the terminal title to the working directory:\n\n    cmd on-cd &{{\n        lf -remote \"send $id tty-write \\\"\\033]0;$PWD\\007\\\"\"\n    }}\n\nThis command runs whenever you change the directory but not on startup.\nYou can add an extra call to make it run on startup as well:\n\n    cmd on-cd &{{ ... }}\n    on-cd\n\nNote that all shell commands are possible but % and & are usually more\nappropriate as $ and ! causes flickers and pauses respectively.\n\nThere is also a pre-cd command, that works like on-cd, but is run before\nthe directory is actually changed. Another related command is on-load\nwhich gets executed when loading a directory.\n\nLOADING DIRECTORY\n\nSimilar to on-cd there also is on-load that when defined runs a shell\ncommand after loading a directory. It works well when combined with\naddcustominfo.\n\nThe following example can be used to display git indicators in the info\ncolumn:\n\n    cmd on-load &{{\n        cd \"$(dirname \"$1\")\" || exit 1\n        [ \"$(git rev-parse --is-inside-git-dir 2>/dev/null)\" = false ] || exit 0\n\n        cmds=\"\"\n\n        for file in \"$@\"; do\n            case \"$file\" in\n                */.git|*/.git/*) continue;;\n            esac\n\n            status=$(git status --porcelain --ignored -- \"$file\" | cut -c1-2 | head -n1)\n\n            if [ -n \"$status\" ]; then\n                cmds=\"${cmds}addcustominfo \\\"${file}\\\" \\\"$status\\\"; \"\n            else\n                cmds=\"${cmds}addcustominfo \\\"${file}\\\" ''; \"\n            fi\n        done\n\n        if [ -n \"$cmds\" ]; then\n            lf -remote \"send $id :$cmds\"\n        fi\n    }}\n\nAnother use case could be showing the dimensions of images and videos:\n\n    cmd on-load &{{\n        cmds=\"\"\n\n        for file in \"$@\"; do\n            mime=$(file --mime-type -Lb -- \"$file\")\n            case \"$mime\" in\n                # vector images cause problems\n                image/svg+xml)\n                    ;;\n                image/*|video/*)\n                    dimensions=$(exiftool -s3 -imagesize -- \"$file\")\n                    cmds=\"${cmds}addcustominfo \\\"${file}\\\" \\\"$dimensions\\\"; \"\n                    ;;\n            esac\n        done\n\n        if [ -n \"$cmds\" ]; then\n            lf -remote \"send $id :$cmds\"\n        fi\n    }}\n\nCOLORS\n\nlf tries to automatically adapt its colors to the environment. It starts\nwith a default color scheme and updates colors using values of existing\nenvironment variables possibly by overwriting its previous values.\nColors are set in the following order:\n\n1.  default\n2.  LSCOLORS (macOS/BSD ls)\n3.  LS_COLORS (GNU ls)\n4.  LF_COLORS (lf specific)\n5.  colors file (lf specific)\n\nPlease refer to the corresponding man pages for more information about\nLSCOLORS and LS_COLORS. LF_COLORS is provided with the same syntax as\nLS_COLORS in case you want to configure colors only for lf but not ls.\nThis can be useful since there are some differences between ls and lf,\nthough one should expect the same behavior for common cases. The colors\nfile (refer to the CONFIGURATION section) is provided for easier\nconfiguration without environment variables. This file should consist of\nwhitespace-separated pairs with a # character to start comments until\nthe end of the line.\n\nYou can configure lf colors in two different ways. First, you can only\nconfigure 8 basic colors used by your terminal and lf should pick up\nthose colors automatically. Depending on your terminal, you should be\nable to select your colors from a 24-bit palette. This is the\nrecommended approach as colors used by other programs will also match\neach other.\n\nSecond, you can set the values of environment variables or colors file\nmentioned above for fine-grained customization. Note that\nLS_COLORS/LF_COLORS are more powerful than LSCOLORS and they can be used\neven when GNU programs are not installed on the system. You can combine\nthis second method with the first method for the best results.\n\nLastly, you may also want to configure the colors of the prompt line to\nmatch the rest of the colors. Colors of the prompt line can be\nconfigured using the promptfmt option which can include hardcoded colors\nas ANSI escapes. See the default value of this option to have an idea\nabout how to color this line.\n\nIt is worth noting that lf uses as many colors advertised by your\nterminal's entry in terminfo or infocmp databases on your system. If an\nentry is not present, it falls back to an internal database. If your\nterminal supports 24-bit colors but either does not have a database\nentry or does not advertise all capabilities, you can enable support by\nsetting the $COLORTERM variable to truecolor or ensuring $TERM is set to\na value that ends with -truecolor.\n\nDefault lf colors are mostly taken from GNU dircolors defaults. These\ndefaults use 8 basic colors and bold attribute. Default dircolors\nentries with background colors are simplified to avoid confusion with\ncurrent file selection in lf. Similarly, there are only file type\nmatchings and extension matchings are left out for simplicity. Default\nvalues are as follows given with their matching order in lf:\n\n    ln  01;36\n    or  31;01\n    tw  01;34\n    ow  01;34\n    st  01;34\n    di  01;34\n    pi  33\n    so  01;35\n    bd  33;01\n    cd  33;01\n    su  01;32\n    sg  01;32\n    ex  01;32\n    fi  00\n\nNote that lf first tries matching file names and then falls back to file\ntypes. The full order of matchings from most specific to least are as\nfollows:\n\n1.  Full Path (e.g. ~/.config/lf/lfrc)\n2.  Dir Name (e.g. .git/) (only matches dirs with a trailing slash at\n    the end)\n3.  File Type (e.g. ln) (except fi)\n4.  File Name (e.g. README*)\n5.  File Name (e.g. *README)\n6.  Base Name (e.g. README.*)\n7.  Extension (e.g. *.txt)\n8.  Default (i.e. fi)\n\nFor example, given a regular text file /path/to/README.txt, the\nfollowing entries are checked in the configuration and the first one to\nmatch is used:\n\n1.  /path/to/README.txt\n2.  (skipped since the file is not a directory)\n3.  (skipped since the file is of type fi)\n4.  README.txt*\n5.  *README.txt\n6.  README.*\n7.  *.txt\n8.  fi\n\nGiven a regular directory /path/to/example.d, the following entries are\nchecked in the configuration and the first one to match is used:\n\n1.  /path/to/example.d\n2.  example.d/\n3.  di\n4.  example.d*\n5.  *example.d\n6.  example.*\n7.  *.d\n8.  fi\n\nNote that glob-like patterns do not perform glob matching for\nperformance reasons.\n\nFor example, you can set a variable as follows:\n\n    export LF_COLORS=\"~/Documents=01;31:~/Downloads=01;31:~/.local/share=01;31:~/.config/lf/lfrc=31:.git/=01;32:.git*=32:*.gitignore=32:*Makefile=32:README.*=33:*.txt=34:*.md=34:ln=01;36:di=01;34:ex=01;32:\"\n\nHaving all entries on a single line can make it hard to read. You may\ninstead divide it into multiple lines in between double quotes by\nescaping newlines with backslashes as follows:\n\n    export LF_COLORS=\"\\\n    ~/Documents=01;31:\\\n    ~/Downloads=01;31:\\\n    ~/.local/share=01;31:\\\n    ~/.config/lf/lfrc=31:\\\n    .git/=01;32:\\\n    .git*=32:\\\n    *.gitignore=32:\\\n    *Makefile=32:\\\n    README.*=33:\\\n    *.txt=34:\\\n    *.md=34:\\\n    ln=01;36:\\\n    di=01;34:\\\n    ex=01;32:\\\n    \"\n\nThe ln entry supports the special value target, which will use the link\ntarget to select a style. Filename rules will still apply based on the\nlink's name -- this mirrors GNU's ls and dircolors behavior. Having such\na long variable definition in a shell configuration file might be\nundesirable. You may instead use the colors file (refer to the\nCONFIGURATION section) for configuration. A sample colors file can be\nfound at https://github.com/gokcehan/lf/blob/master/etc/colors.example\nYou may also see the wiki page for ANSI escape codes\nhttps://en.wikipedia.org/wiki/ANSI_escape_code\n\nICONS\n\nIcons are configured using LF_ICONS environment variable or an icons\nfile (refer to the CONFIGURATION section). The variable uses the same\nsyntax as LS_COLORS/LF_COLORS. Instead of colors, you should use single\ncharacters or symbols as values. The ln entry supports the special value\ntarget, which will use the link target to select a icon. Filename rules\nwill still apply based on the link's name -- this mirrors GNU's ls and\ndircolors behavior. The icons file (refer to the CONFIGURATION section)\nshould consist of whitespace-separated arrays with a # character to\nstart comments until the end of the line. Each line should contain 1-3\ncolumns: a file type or file name pattern, the icon, and an optional\nicon color. Using only one column disables all rules for that type or\nname. Do not forget to add set icons true to your lfrc to see the icons.\nDefault values are listed below in the order lf matches them:\n\n    ln  l\n    or  l\n    tw  t\n    ow  d\n    st  t\n    di  d\n    pi  p\n    so  s\n    bd  b\n    cd  c\n    su  u\n    sg  g\n    ex  x\n    fi  -\n\nA sample icons file can be found at\nhttps://github.com/gokcehan/lf/blob/master/etc/icons.example\n\nA sample colored icons file can be found at\nhttps://github.com/gokcehan/lf/blob/master/etc/icons_colored.example\n\nRULER\n\nThe ruler can be configured using the rulerfile option (refer to the\nCONFIGURATION section). The contents of the ruler file should be a Go\ntemplate which is then rendered to create the actual output (refer to\nhttps://pkg.go.dev/text/template for more details on the syntax).\n\nThe following data fields are exported:\n\n    .Message          string              Includes internal messages, errors, and messages generated by the `echo`/`echomsg`/`echoerr` commands\n    .Keys             string              Keys pressed by the user\n    .Progress         []string            Progress indicators for copied, moved and deleted files\n    .Copy             []string            List of files in the clipboard to be copied\n    .Cut              []string            List of files in the clipboard to be moved\n    .Select           []string            Selection list\n    .Visual           []string            Visual selection\n    .Index            int                 Index of the cursor\n    .Total            int                 Number of visible files in the current working directory\n    .Hidden           int                 Number of hidden files in the current working directory\n    .All              int                 Number of all files in the current working directory\n    .LinePercentage   string              Line percentage (analogous to `%p` for the `statusline` option in Vim)\n    .ScrollPercentage string              Scroll percentage (analogous to `%P` for the `statusline` option in Vim)\n    .Filter           []string            Filter currently being applied\n    .Mode             string              Current mode (\"NORMAL\" for Normal mode, and \"VISUAL\" for Visual mode)\n    .Options          map[string]string   The value of options (e.g. `{{.Options.hidden}}`)\n    .UserOptions      map[string]string   The value of user-defined options (e.g. `{{.UserOptions.foo}}`)\n    .Stat.Path        string              Path of the current file\n    .Stat.Name        string              Name of the current file\n    .Stat.Extension   string              Extension of the current file\n    .Stat.Size        int64               Size of the current file\n    .Stat.DirSize     int64               Total size of the current directory if calculated via `calcdirsize` (`-1` if not calculated)\n    .Stat.DirCount    int                 Number of items in the current directory if the `dircounts` option is enabled (`-1` if the directory cannot be read)\n    .Stat.Permissions string              Permissions of the current file\n    .Stat.ModTime     string              Last modified time of the current file (formatted based on the `timefmt` option)\n    .Stat.AccessTime  string              Last access time of the current file (formatted based on the `timefmt` option)\n    .Stat.BirthTime   string              Birth time of the current file (formatted based on the `timefmt` option)\n    .Stat.ChangeTime  string              Last status (inode) change time of the current file (formatted based on the `timefmt` option)\n    .Stat.LinkCount   string              Number of hard links for the current file\n    .Stat.User        string              User of the current file\n    .Stat.Group       string              Group of the current file\n    .Stat.Target      string              Target if the current file is a symbolic link, otherwise a blank string\n    .Stat.CustomInfo  string              Custom property if defined via `addcustominfo`, otherwise a blank string\n\nThe following functions are exported:\n\n    df       func() string                   Get an indicator representing the amount of free disk space available\n    env      func(string) string             Get the value of an environment variable\n    humanize func(int64) string              Express a file size in a human-readable format\n    join     func([]string, string) string   Join a string array by a separator\n    lower    func(string) string             Convert a string to lowercase\n    substr   func(string, int, int) string   Get a substring based on starting index and length\n    upper    func(string) string             Convert a string to uppercase\n\nThe special identifier {{.SPACER}} can be used to divide the ruler into\nsections that are spaced evenly from each other.\n\nThe default ruler file can be found at\nhttps://github.com/gokcehan/lf/blob/master/etc/ruler.default\n"
  },
  {
    "path": "etc/colors.example",
    "content": "# vim:ft=dircolors\n# (This is not a dircolors file but it helps to highlight colors and comments)\n\n# default values from dircolors\n# (entries with a leading # are not implemented in lf)\n# #no     00              # NORMAL\n# fi      00              # FILE\n# #rs     0               # RESET\n# di      01;34           # DIR\n# ln      01;36           # LINK\n# #mh     00              # MULTIHARDLINK\n# pi      40;33           # FIFO\n# so      01;35           # SOCK\n# #do     01;35           # DOOR\n# bd      40;33;01        # BLK\n# cd      40;33;01        # CHR\n# or      40;31;01        # ORPHAN\n# #mi     00              # MISSING\n# su      37;41           # SETUID\n# sg      30;43           # SETGID\n# #ca     30;41           # CAPABILITY\n# tw      30;42           # STICKY_OTHER_WRITABLE\n# ow      34;42           # OTHER_WRITABLE\n# st      37;44           # STICKY\n# ex      01;32           # EXEC\n\n# default values from lf (with matching order)\n# ln      01;36   # LINK\n# or      31;01   # ORPHAN\n# tw      01;34   # STICKY_OTHER_WRITABLE\n# ow      01;34   # OTHER_WRITABLE\n# st      01;34   # STICKY\n# di      01;34   # DIR\n# pi      33      # FIFO\n# so      01;35   # SOCK\n# bd      33;01   # BLK\n# cd      33;01   # CHR\n# su      01;32   # SETUID\n# sg      01;32   # SETGID\n# ex      01;32   # EXEC\n# fi      00      # FILE\n\n# file types (with matching order)\nln      01;36   # LINK\nor      31;01   # ORPHAN\ntw      34      # STICKY_OTHER_WRITABLE\now      34      # OTHER_WRITABLE\nst      01;34   # STICKY\ndi      01;34   # DIR\npi      33      # FIFO\nso      01;35   # SOCK\nbd      33;01   # BLK\ncd      33;01   # CHR\nsu      01;32   # SETUID\nsg      01;32   # SETGID\nex      01;32   # EXEC\nfi      00      # FILE\n\n# archives or compressed (dircolors defaults)\n*.tar   01;31\n*.tgz   01;31\n*.arc   01;31\n*.arj   01;31\n*.taz   01;31\n*.lha   01;31\n*.lz4   01;31\n*.lzh   01;31\n*.lzma  01;31\n*.tlz   01;31\n*.txz   01;31\n*.tzo   01;31\n*.t7z   01;31\n*.zip   01;31\n*.z     01;31\n*.dz    01;31\n*.gz    01;31\n*.lrz   01;31\n*.lz    01;31\n*.lzo   01;31\n*.xz    01;31\n*.zst   01;31\n*.tzst  01;31\n*.bz2   01;31\n*.bz    01;31\n*.tbz   01;31\n*.tbz2  01;31\n*.tz    01;31\n*.deb   01;31\n*.rpm   01;31\n*.jar   01;31\n*.war   01;31\n*.ear   01;31\n*.sar   01;31\n*.rar   01;31\n*.alz   01;31\n*.ace   01;31\n*.zoo   01;31\n*.cpio  01;31\n*.7z    01;31\n*.rz    01;31\n*.cab   01;31\n*.wim   01;31\n*.swm   01;31\n*.dwm   01;31\n*.esd   01;31\n\n# image formats (dircolors defaults)\n*.jpg   01;35\n*.jpeg  01;35\n*.mjpg  01;35\n*.mjpeg 01;35\n*.gif   01;35\n*.bmp   01;35\n*.pbm   01;35\n*.pgm   01;35\n*.ppm   01;35\n*.tga   01;35\n*.xbm   01;35\n*.xpm   01;35\n*.tif   01;35\n*.tiff  01;35\n*.png   01;35\n*.svg   01;35\n*.svgz  01;35\n*.mng   01;35\n*.pcx   01;35\n*.mov   01;35\n*.mpg   01;35\n*.mpeg  01;35\n*.m2v   01;35\n*.mkv   01;35\n*.webm  01;35\n*.ogm   01;35\n*.mp4   01;35\n*.m4v   01;35\n*.mp4v  01;35\n*.vob   01;35\n*.qt    01;35\n*.nuv   01;35\n*.wmv   01;35\n*.asf   01;35\n*.rm    01;35\n*.rmvb  01;35\n*.flc   01;35\n*.avi   01;35\n*.fli   01;35\n*.flv   01;35\n*.gl    01;35\n*.dl    01;35\n*.xcf   01;35\n*.xwd   01;35\n*.yuv   01;35\n*.cgm   01;35\n*.emf   01;35\n*.ogv   01;35\n*.ogx   01;35\n\n# audio formats (dircolors defaults)\n*.aac   00;36\n*.au    00;36\n*.flac  00;36\n*.m4a   00;36\n*.mid   00;36\n*.midi  00;36\n*.mka   00;36\n*.mp3   00;36\n*.mpc   00;36\n*.ogg   00;36\n*.ra    00;36\n*.wav   00;36\n*.oga   00;36\n*.opus  00;36\n*.spx   00;36\n*.xspf  00;36\n"
  },
  {
    "path": "etc/icons.example",
    "content": "# vim:ft=conf\n\n# These examples require Nerd Fonts or a compatible font to be used.\n# See https://www.nerdfonts.com for more information.\n\n# default values from lf (with matching order)\n# ln      l       # LINK\n# or      l       # ORPHAN\n# tw      t       # STICKY_OTHER_WRITABLE\n# ow      d       # OTHER_WRITABLE\n# st      t       # STICKY\n# di      d       # DIR\n# pi      p       # FIFO\n# so      s       # SOCK\n# bd      b       # BLK\n# cd      c       # CHR\n# su      u       # SETUID\n# sg      g       # SETGID\n# ex      x       # EXEC\n# fi      -       # FILE\n\n# file types (with matching order)\nln             # LINK\nor             # ORPHAN\ntw      t       # STICKY_OTHER_WRITABLE\now             # OTHER_WRITABLE\nst      t       # STICKY\ndi             # DIR\npi      p       # FIFO\nso      s       # SOCK\nbd      b       # BLK\ncd      c       # CHR\nsu      u       # SETUID\nsg      g       # SETGID\nex             # EXEC\nfi             # FILE\n\n# disable some default filetype icons, let them choose icon by filename\n# ln             # LINK\n# or             # ORPHAN\n# tw              # STICKY_OTHER_WRITABLE\n# ow              # OTHER_WRITABLE\n# st              # STICKY\n# di             # DIR\n# pi              # FIFO\n# so              # SOCK\n# bd              # BLK\n# cd              # CHR\n# su              # SETUID\n# sg              # SETGID\n# ex              # EXEC\n# fi             # FILE\n\n# file extensions (vim-devicons)\n*.styl          \n*.sass          \n*.scss          \n*.htm           \n*.html          \n*.slim          \n*.haml          \n*.ejs           \n*.css           \n*.less          \n*.md            \n*.mdx           \n*.markdown      \n*.rmd           \n*.json          \n*.webmanifest   \n*.js            \n*.mjs           \n*.jsx           \n*.rb            \n*.gemspec       \n*.rake          \n*.php           \n*.py            \n*.pyc           \n*.pyo           \n*.pyd           \n*.coffee        \n*.mustache      \n*.hbs           \n*.conf          \n*.ini           \n*.yml           \n*.yaml          \n*.toml          \n*.bat           \n*.mk            \n*.jpg           \n*.jpeg          \n*.bmp           \n*.png           \n*.webp          \n*.gif           \n*.ico           \n*.twig          \n*.cpp           \n*.c++           \n*.cxx           \n*.cc            \n*.cp            \n*.c             \n*.cs            󰌛\n*.h             \n*.hh            \n*.hpp           \n*.hxx           \n*.hs            \n*.lhs           \n*.nix           \n*.lua           \n*.java          \n*.sh            \n*.fish          \n*.bash          \n*.zsh           \n*.ksh           \n*.csh           \n*.awk           \n*.ps1           \n*.ml            λ\n*.mli           λ\n*.diff          \n*.db            \n*.sql           \n*.dump          \n*.clj           \n*.cljc          \n*.cljs          \n*.edn           \n*.scala         \n*.go            \n*.dart          \n*.xul           \n*.sln           \n*.suo           \n*.pl            \n*.pm            \n*.t             \n*.rss           \n'*.f#'          \n*.fsscript      \n*.fsx           \n*.fs            \n*.fsi           \n*.rs            \n*.rlib          \n*.d             \n*.erl           \n*.hrl           \n*.ex            \n*.exs           \n*.eex           \n*.leex          \n*.heex          \n*.vim           \n*.ai            \n*.psd           \n*.psb           \n*.ts            \n*.tsx           \n*.jl            \n*.pp            \n*.vue           \n*.elm           \n*.swift         \n*.xcplayground  \n*.tex           󰙩\n*.r             󰟔\n*.rproj         󰗆\n*.sol           󰡪\n*.pem           \n\n# file names (vim-devicons) (case-insensitive not supported in lf)\n*gruntfile.coffee       \n*gruntfile.js           \n*gruntfile.ls           \n*gulpfile.coffee        \n*gulpfile.js            \n*gulpfile.ls            \n*mix.lock               \n*dropbox                \n*.ds_store              \n*.gitconfig             \n*.gitignore             \n*.gitattributes         \n*.gitlab-ci.yml         \n*.bashrc                \n*.zshrc                 \n*.zshenv                \n*.zprofile              \n*.vimrc                 \n*.gvimrc                \n*_vimrc                 \n*_gvimrc                \n*.bashprofile           \n*favicon.ico            \n*license                \n*node_modules           \n*react.jsx              \n*procfile               \n*dockerfile             \n*docker-compose.yml     \n*docker-compose.yaml    \n*compose.yml            \n*compose.yaml           \n*rakefile               \n*config.ru              \n*gemfile                \n*makefile               \n*cmakelists.txt         \n*robots.txt             󰚩\n\n# file names (case-sensitive adaptations)\n*Gruntfile.coffee       \n*Gruntfile.js           \n*Gruntfile.ls           \n*Gulpfile.coffee        \n*Gulpfile.js            \n*Gulpfile.ls            \n*Dropbox                \n*.DS_Store              \n*LICENSE                \n*React.jsx              \n*Procfile               \n*Dockerfile             \n*Docker-compose.yml     \n*Docker-compose.yaml    \n*Rakefile               \n*Gemfile                \n*Makefile               \n*CMakeLists.txt         \n\n# file patterns (vim-devicons) (patterns not supported in lf)\n# .*jquery.*\\.js$         \n# .*angular.*\\.js$        \n# .*backbone.*\\.js$       \n# .*require.*\\.js$        \n# .*materialize.*\\.js$    \n# .*materialize.*\\.css$   \n# .*mootools.*\\.js$       \n# .*vimrc.*               \n# Vagrantfile$            \n\n# file patterns (file name adaptations)\n*jquery.min.js          \n*angular.min.js         \n*backbone.min.js        \n*require.min.js         \n*materialize.min.js     \n*materialize.min.css    \n*mootools.min.js        \n*vimrc                  \nVagrantfile             \n\n# archives or compressed (extensions from dircolors defaults)\n*.tar   \n*.tgz   \n*.arc   \n*.arj   \n*.taz   \n*.lha   \n*.lz4   \n*.lzh   \n*.lzma  \n*.tlz   \n*.txz   \n*.tzo   \n*.t7z   \n*.zip   \n*.z     \n*.dz    \n*.gz    \n*.lrz   \n*.lz    \n*.lzo   \n*.xz    \n*.zst   \n*.tzst  \n*.bz2   \n*.bz    \n*.tbz   \n*.tbz2  \n*.tz    \n*.deb   \n*.rpm   \n*.jar   \n*.war   \n*.ear   \n*.sar   \n*.rar   \n*.alz   \n*.ace   \n*.zoo   \n*.cpio  \n*.7z    \n*.rz    \n*.cab   \n*.wim   \n*.swm   \n*.dwm   \n*.esd   \n\n# image formats (extensions from dircolors defaults)\n*.jpg   \n*.jpeg  \n*.mjpg  \n*.mjpeg \n*.gif   \n*.bmp   \n*.pbm   \n*.pgm   \n*.ppm   \n*.tga   \n*.xbm   \n*.xpm   \n*.tif   \n*.tiff  \n*.png   \n*.svg   \n*.svgz  \n*.mng   \n*.pcx   \n*.mov   \n*.mpg   \n*.mpeg  \n*.m2v   \n*.mkv   \n*.webm  \n*.ogm   \n*.mp4   \n*.m4v   \n*.mp4v  \n*.vob   \n*.qt    \n*.nuv   \n*.wmv   \n*.asf   \n*.rm    \n*.rmvb  \n*.flc   \n*.avi   \n*.fli   \n*.flv   \n*.gl    \n*.dl    \n*.xcf   \n*.xwd   \n*.yuv   \n*.cgm   \n*.emf   \n*.ogv   \n*.ogx   \n\n# audio formats (extensions from dircolors defaults)\n*.aac   \n*.au    \n*.flac  \n*.m4a   \n*.mid   \n*.midi  \n*.mka   \n*.mp3   \n*.mpc   \n*.ogg   \n*.ra    \n*.wav   \n*.oga   \n*.opus  \n*.spx   \n*.xspf  \n\n# other formats\n*.pdf   \n"
  },
  {
    "path": "etc/icons_colored.example",
    "content": "# vim:ft=conf\n\n# These examples require Nerd Fonts or a compatible font to be used.\n# See https://www.nerdfonts.com for more information.\n\n# default values from lf (with matching order)\n# ln      l       # LINK\n# or      l       # ORPHAN\n# tw      t       # STICKY_OTHER_WRITABLE\n# ow      d       # OTHER_WRITABLE\n# st      t       # STICKY\n# di      d       # DIR\n# pi      p       # FIFO\n# so      s       # SOCK\n# bd      b       # BLK\n# cd      c       # CHR\n# su      u       # SETUID\n# sg      g       # SETGID\n# ex      x       # EXEC\n# fi      -       # FILE\n\n# file types (with matching order)\nln             # LINK\nor             # ORPHAN\ntw      t       # STICKY_OTHER_WRITABLE\now             # OTHER_WRITABLE\nst      t       # STICKY\ndi             # DIR\npi      p       # FIFO\nso      s       # SOCK\nbd      b       # BLK\ncd      c       # CHR\nsu      u       # SETUID\nsg      g       # SETGID\nex             # EXEC\nfi             # FILE\n\n# disable some default filetype icons, let them choose icon by filename\n# ln             # LINK\n# or             # ORPHAN\n# tw              # STICKY_OTHER_WRITABLE\n# ow              # OTHER_WRITABLE\n# st              # STICKY\n# di             # DIR\n# pi              # FIFO\n# so              # SOCK\n# bd              # BLK\n# cd              # CHR\n# su              # SETUID\n# sg              # SETGID\n# ex              # EXEC\n# fi             # FILE\n\n# file extensions (vim-devicons)\n*.styl              00;38;2;141;193;73\n*.sass              00;38;2;245;83;133\n*.scss              00;38;2;245;83;133\n*.htm               00;38;2;227;76;38\n*.html              00;38;2;227;76;38\n*.slim              00;38;2;227;76;38\n*.haml              00;38;2;234;234;225\n*.ejs               00;38;2;203;203;65\n*.css               00;38;2;86;61;124\n*.less              00;38;2;86;61;124\n*.md                00;38;2;81;154;186\n*.mdx               00;38;2;81;154;186\n*.markdown          00;38;2;81;154;186\n*.rmd               00;38;2;81;154;186\n*.json              00;38;2;149;157;165\n*.webmanifest       00;38;2;241;224;90\n*.js                00;38;2;203;203;65\n*.mjs               00;38;2;241;224;90\n*.jsx               00;38;2;81;154;186\n*.rb                00;38;2;112;21;22\n*.gemspec           00;38;2;112;21;22\n*.rake              00;38;2;112;21;22\n*.php               00;38;2;160;116;196\n*.py                00;38;2;81;154;186\n*.pyc               00;38;2;81;154;186\n*.pyo               00;38;2;81;154;186\n*.pyd               00;38;2;81;154;186\n*.coffee            00;38;2;203;203;65\n*.mustache          00;38;2;227;121;51\n*.hbs               00;38;2;240;119;43\n*.conf              00;38;2;109;128;134\n*.ini               00;38;2;109;128;134\n*.yml               00;38;2;149;157;165\n*.yaml              00;38;2;149;157;165\n*.toml              00;38;2;109;128;134\n*.bat               00;38;2;193;241;46\n*.mk                00;38;2;109;128;134\n*.jpg               00;38;2;160;116;196\n*.jpeg              00;38;2;160;116;196\n*.bmp               00;38;2;160;116;196\n*.png               00;38;2;160;116;196\n*.webp              00;38;2;160;116;196\n*.gif               00;38;2;160;116;196\n*.ico               00;38;2;203;203;65\n*.twig              00;38;2;141;193;73\n*.cpp               00;38;2;81;154;186\n*.c++               00;38;2;89;158;255\n*.cxx               00;38;2;81;154;186\n*.cc                00;38;2;81;154;186\n*.cp                00;38;2;81;154;186\n*.c                 00;38;2;89;158;255\n*.cs            󰌛    00;38;2;89;103;6\n*.h                 00;38;2;160;116;196\n*.hh                00;38;2;160;116;196\n*.hpp               00;38;2;160;116;196\n*.hxx               00;38;2;160;116;196\n*.hs                00;38;2;160;116;196\n*.lhs               00;38;2;160;116;196\n*.nix               00;38;2;126;186;228\n*.lua               00;38;2;81;160;207\n*.java              00;38;2;204;62;68\n*.sh                00;38;2;137;224;81\n*.fish              00;38;2;137;224;81\n*.bash              00;38;2;137;224;81\n*.zsh               00;38;2;137;224;81\n*.ksh               00;38;2;137;224;81\n*.csh               00;38;2;137;224;81\n*.awk               00;38;2;137;224;81\n*.ps1               00;38;2;137;224;81\n*.ml            λ    00;38;2;227;121;51\n*.mli           λ    00;38;2;227;121;51\n*.diff              00;38;2;65;83;91\n*.db                00;38;2;218;216;216\n*.sql               00;38;2;218;216;216\n*.dump              00;38;2;218;216;216\n*.clj               00;38;2;141;193;73\n*.cljc              00;38;2;141;193;73\n*.cljs              00;38;2;81;154;186\n*.edn               00;38;2;81;154;186\n*.scala             00;38;2;204;62;68\n*.go                00;38;2;81;154;186\n*.dart              00;38;2;3;88;156\n*.xul               00;38;2;227;121;51\n*.sln               00;38;2;133;76;199\n*.suo               00;38;2;133;76;199\n*.pl                00;38;2;81;154;186\n*.pm                00;38;2;81;154;186\n*.t                 00;38;2;81;154;186\n*.rss               00;38;2;251;157;59\n'*.f#'              00;38;2;81;154;186\n*.fsscript          00;38;2;81;154;186\n*.fsx               00;38;2;81;154;186\n*.fs                00;38;2;81;154;186\n*.fsi               00;38;2;81;154;186\n*.rs                00;38;2;222;165;132\n*.rlib              00;38;2;222;165;132\n*.d                 00;38;2;66;120;25\n*.erl               00;38;2;184;57;152\n*.hrl               00;38;2;184;57;152\n*.ex                00;38;2;160;116;196\n*.exs               00;38;2;160;116;196\n*.eex               00;38;2;160;116;196\n*.leex              00;38;2;160;116;196\n*.heex              00;38;2;160;116;196\n*.vim               00;38;2;1;152;51\n*.ai                00;38;2;203;203;65\n*.psd               00;38;2;81;154;186\n*.psb               00;38;2;81;154;186\n*.ts                00;38;2;81;154;186\n*.tsx               00;38;2;81;154;186\n*.jl                00;38;2;162;112;186\n*.pp                00;38;2;255;166;26\n*.vue               00;38;2;141;193;73\n*.elm               00;38;2;81;154;186\n*.swift             00;38;2;227;121;51\n*.xcplayground      00;38;2;227;121;51\n*.tex           󰙩    00;38;2;61;97;23\n*.r             󰟔    00;38;2;53;138;91\n*.rproj         󰗆   00;38;2;53;138;91\n*.sol           󰡪    00;38;2;81;154;186\n*.pem               00;38;2;205;155;62\n\n# file names (vim-devicons) (case-insensitive not supported in lf)\n*gruntfile.coffee           00;38;2;227;121;51\n*gruntfile.js               00;38;2;227;121;51\n*gruntfile.ls               00;38;2;227;121;51\n*gulpfile.coffee            00;38;2;204;62;68\n*gulpfile.js                00;38;2;204;62;68\n*gulpfile.ls                00;38;2;204;62;68\n*mix.lock                   00;38;2;160;116;196\n*dropbox                    00;38;2;0;97;254\n*.ds_store                  00;38;2;77;90;94\n*.gitconfig                 00;38;2;65;83;91\n*.gitignore                 00;38;2;65;83;91\n*.gitattributes             00;38;2;65;83;91\n*.gitlab-ci.yml             00;38;2;226;67;41\n*.bashrc                    00;38;2;137;224;81\n*.zshrc                     00;38;2;137;224;81\n*.zshenv                    00;38;2;137;224;81\n*.zprofile                  00;38;2;137;224;81\n*.vimrc                     00;38;2;1;152;51\n*.gvimrc                    00;38;2;1;152;51\n*_vimrc                     00;38;2;1;152;51\n*_gvimrc                    00;38;2;1;152;51\n*.bashprofile               00;38;2;137;224;81\n*favicon.ico                00;38;2;203;203;65\n*license                    00;38;2;203;203;65\n*node_modules               00;38;2;232;39;75\n*react.jsx                  00;38;2;81;154;186\n*procfile                   00;38;2;160;116;196\n*dockerfile                 00;38;2;81;154;186\n*docker-compose.yml         00;38;2;81;154;186\n*docker-compose.yaml        00;38;2;81;154;186\n*compose.yml                00;38;2;81;154;186\n*compose.yaml               00;38;2;81;154;186\n*rakefile                   00;38;2;112;21;22\n*config.ru                  00;38;2;112;21;22\n*gemfile                    00;38;2;112;21;22\n*makefile                   00;38;2;109;128;134\n*cmakelists.txt             00;38;2;109;128;134\n*robots.txt             󰚩    00;38;2;109;128;134\n\n# file names (case-sensitive adaptations)\n*Gruntfile.coffee           00;38;2;227;121;51\n*Gruntfile.js               00;38;2;227;121;51\n*Gruntfile.ls               00;38;2;227;121;51\n*Gulpfile.coffee            00;38;2;204;62;68\n*Gulpfile.js                00;38;2;204;62;68\n*Gulpfile.ls                00;38;2;204;62;68\n*Dropbox                    00;38;2;0;97;254\n*.DS_Store                  00;38;2;193;241;46\n*LICENSE                    00;38;2;203;203;65\n*React.jsx                  00;38;2;81;154;186\n*Procfile                   00;38;2;160;116;196\n*Dockerfile                 00;38;2;81;154;186\n*Docker-compose.yml         00;38;2;81;154;186\n*Docker-compose.yaml        00;38;2;81;154;186\n*Rakefile                   00;38;2;112;21;22\n*Gemfile                    00;38;2;112;21;22\n*Makefile                   00;38;2;109;128;134\n*CMakeLists.txt             00;38;2;109;128;134\n\n# file patterns (vim-devicons) (patterns not supported in lf)\n# .*jquery.*\\.js$             00;38;2;227;117;187\n# .*angular.*\\.js$            00;38;2;226;50;55\n# .*backbone.*\\.js$           00;38;2;0;113;181\n# .*require.*\\.js$            00;38;2;244;74;65\n# .*materialize.*\\.js$        00;38;2;238;110;115\n# .*materialize.*\\.css$       00;38;2;238;110;115\n# .*mootools.*\\.js$           00;38;2;236;236;236\n# .*vimrc.*                   00;38;2;1;152;51\n# Vagrantfile$                00;38;2;21;99;255\n\n# file patterns (file name adaptations)\n*jquery.min.js              00;38;2;227;117;187\n*angular.min.js             00;38;2;226;50;55\n*backbone.min.js            00;38;2;0;113;181\n*require.min.js             00;38;2;244;74;65\n*materialize.min.js         00;38;2;238;110;115\n*materialize.min.css        00;38;2;238;110;115\n*mootools.min.js            00;38;2;236;236;236\n*vimrc                      00;38;2;1;152;51\nVagrantfile                 00;38;2;21;99;255\n\n# archives or compressed (extensions from dircolors defaults)\n*.tar   \n*.tgz   \n*.arc   \n*.arj   \n*.taz   \n*.lha   \n*.lz4   \n*.lzh   \n*.lzma  \n*.tlz   \n*.txz   \n*.tzo   \n*.t7z   \n*.zip   \n*.z     \n*.dz    \n*.gz    \n*.lrz   \n*.lz    \n*.lzo   \n*.xz    \n*.zst   \n*.tzst  \n*.bz2   \n*.bz    \n*.tbz   \n*.tbz2  \n*.tz    \n*.deb   \n*.rpm   \n*.jar   \n*.war   \n*.ear   \n*.sar   \n*.rar   \n*.alz   \n*.ace   \n*.zoo   \n*.cpio  \n*.7z    \n*.rz    \n*.cab   \n*.wim   \n*.swm   \n*.dwm   \n*.esd   \n\n# image formats (extensions from dircolors defaults)\n*.jpg   \n*.jpeg  \n*.mjpg  \n*.mjpeg \n*.gif   \n*.bmp   \n*.pbm   \n*.pgm   \n*.ppm   \n*.tga   \n*.xbm   \n*.xpm   \n*.tif   \n*.tiff  \n*.png   \n*.svg   \n*.svgz  \n*.mng   \n*.pcx   \n*.mov   \n*.mpg   \n*.mpeg  \n*.m2v   \n*.mkv   \n*.webm  \n*.ogm   \n*.mp4   \n*.m4v   \n*.mp4v  \n*.vob   \n*.qt    \n*.nuv   \n*.wmv   \n*.asf   \n*.rm    \n*.rmvb  \n*.flc   \n*.avi   \n*.fli   \n*.flv   \n*.gl    \n*.dl    \n*.xcf   \n*.xwd   \n*.yuv   \n*.cgm   \n*.emf   \n*.ogv   \n*.ogx   \n\n# audio formats (extensions from dircolors defaults)\n*.aac   \n*.au    \n*.flac  \n*.m4a   \n*.mid   \n*.midi  \n*.mka   \n*.mp3   \n*.mpc   \n*.ogg   \n*.ra    \n*.wav   \n*.oga   \n*.opus  \n*.spx   \n*.xspf  \n\n# other formats\n*.pdf        00;38;2;179;11;0\n"
  },
  {
    "path": "etc/lf.bash",
    "content": "# Autocompletion for bash shell.\n#\n# You may put this file to a directory used by bash-completion:\n#\n#     mkdir -p ~/.local/share/bash-completion/completions\n#     ln -s \"/path/to/lf.bash\" ~/.local/share/bash-completion/completions\n#\n\n_lf () {\n    local -a opts=(\n        -command\n        -config\n        -cpuprofile\n        -doc\n        -last-dir-path\n        -log\n        -memprofile\n        -print-last-dir\n        -print-selection\n        -remote\n        -selection-path\n        -server\n        -single\n        -version\n        -help\n    )\n    if [[ $2 == -* ]]; then\n        COMPREPLY=( $(compgen -W \"${opts[*]}\" -- \"$2\") )\n    else\n        COMPREPLY=( $(compgen -f -d -- \"$2\") )\n    fi\n}\n\ncomplete -o filenames -F _lf lf lfcd\n"
  },
  {
    "path": "etc/lf.csh",
    "content": "# Autocompletion for tcsh shell.\n#\n# You need to either copy the content of this file to your shell rc file\n# (e.g. ~/.tcshrc) or source this file directly:\n#\n#     set LF_COMPLETE = \"/path/to/lf.csh\"\n#     if ( -f \"$LF_COMPLETE\" ) then\n#         source \"$LF_COMPLETE\"\n#     endif\n#\n\nset LF_ARGS = \"-command -config -cpuprofile -doc -last-dir-path -log -memprofile -print-last-dir -print-selection -remote -selection-path -server -single -version -help \"\n\ncomplete lf   \"C/-*/(${LF_ARGS})/\"\ncomplete lfcd \"C/-*/(${LF_ARGS})/\"\n"
  },
  {
    "path": "etc/lf.fish",
    "content": "# Autocompletion for fish shell.\n#\n# You may put this file to a directory in $fish_complete_path variable:\n#\n#     mkdir -p ~/.config/fish/completions\n#     ln -s \"/path/to/lf.fish\" ~/.config/fish/completions\n#\n\ncomplete -c lf -o command -r -d 'command to execute on client initialization'\ncomplete -c lf -o config -r -d 'path to the config file (instead of the usual paths)'\ncomplete -c lf -o cpuprofile -r -d 'path to the file to write the CPU profile'\ncomplete -c lf -o doc -d 'show documentation'\ncomplete -c lf -o last-dir-path -r -d 'path to the file to write the last dir on exit (to use for cd)'\ncomplete -c lf -o log -r -d 'path to the log file to write messages'\ncomplete -c lf -o memprofile -r -d 'path to the file to write the memory profile'\ncomplete -c lf -o print-last-dir -d 'print the last dir to stdout on exit (to use for cd)'\ncomplete -c lf -o print-selection -d 'print the selected files to stdout on open (to use as open file dialog)'\ncomplete -c lf -o remote -x -d 'send remote command to server'\ncomplete -c lf -o selection-path -r -d 'path to the file to write selected files on open (to use as open file dialog)'\ncomplete -c lf -o server -d 'start server (automatic)'\ncomplete -c lf -o single -d 'start a client without server'\ncomplete -c lf -o version -d 'show version'\ncomplete -c lf -o help -d 'show help'\n"
  },
  {
    "path": "etc/lf.nu",
    "content": "# Autocompletion for nushell.\n#\n# Documentation: https://www.nushell.sh/book/externs.html\n\n# To enable autocompletion you may put this file into a directory:\n#\n#     mkdir -p ~/.config/nushell/completions\n#     ln -s \"/path/to/lf.nu\" ~/.config/nushell/completions\n#\n# Then you need to source this file in your nu config (Open the config with the\n# command 'config nu' inside the nushell) by adding:\n#\n#     source ~/.config/nushell/completions/lf.nu\n\nexport extern \"lf\" [\n  --command                   # command to execute on client initialization\n  --config: string            # path to the config file (instead of the usual paths)\n  --cpuprofile: string        # path to the file to write the CPU profile\n  --doc                       # show documentation\n  --last-dir-path: string     # path to the file to write the last dir on exit (to use for cd)\n  --log: string               # path to the log file to write messages\n  --memprofile: string        # path to the file to write the memory profile\n  --print-last-dir            # print the last dir to stdout on exit (to use for cd)\n  --print-selection           # print the selected files to stdout on open (to use as open file dialog)\n  --remote: string            # send remote command to server\n  --selection-path: string    # path to the file to write selected files on open (to use as open file dialog)\n  --server                    # start server (automatic)\n  --single                    # start a client without server\n  --version                   # show version\n  --help                      # show help\n]\n"
  },
  {
    "path": "etc/lf.ps1",
    "content": "# Autocompletion for PowerShell.\n#\n# You need to either copy the content of this file to $PROFILE or call this\n# script directly.\n#\n\nusing namespace System.Management.Automation\n\nRegister-ArgumentCompleter -Native -CommandName 'lf' -ScriptBlock {\n    param($wordToComplete)\n    $completions = @(\n        [CompletionResult]::new('-command ', '-command', [CompletionResultType]::ParameterName, 'command to execute on client initialization')\n        [CompletionResult]::new('-config ', '-config', [CompletionResultType]::ParameterName, 'path to the config file (instead of the usual paths)')\n        [CompletionResult]::new('-cpuprofile ', '-cpuprofile', [CompletionResultType]::ParameterName, 'path to the file to write the CPU profile')\n        [CompletionResult]::new('-doc', '-doc', [CompletionResultType]::ParameterName, 'show documentation')\n        [CompletionResult]::new('-last-dir-path ', '-last-dir-path', [CompletionResultType]::ParameterName, 'path to the file to write the last dir on exit (to use for cd)')\n        [CompletionResult]::new('-log ', '-log', [CompletionResultType]::ParameterName, 'path to the log file to write messages')\n        [CompletionResult]::new('-memprofile ', '-memprofile', [CompletionResultType]::ParameterName, 'path to the file to write the memory profile')\n        [CompletionResult]::new('-print-last-dir', '-print-last-dir', [CompletionResultType]::ParameterName, 'print the last dir to stdout on exit (to use for cd)')\n        [CompletionResult]::new('-print-selection', '-print-selection', [CompletionResultType]::ParameterName, 'print the selected files to stdout on open (to use as open file dialog)')\n        [CompletionResult]::new('-remote ', '-remote', [CompletionResultType]::ParameterName, 'send remote command to server')\n        [CompletionResult]::new('-selection-path ', '-selection-path', [CompletionResultType]::ParameterName, 'path to the file to write selected files on open (to use as open file dialog)')\n        [CompletionResult]::new('-server', '-server', [CompletionResultType]::ParameterName, 'start server (automatic)')\n        [CompletionResult]::new('-single', '-single', [CompletionResultType]::ParameterName, 'start a client without server')\n        [CompletionResult]::new('-version', '-version', [CompletionResultType]::ParameterName, 'show version')\n        [CompletionResult]::new('-help', '-help', [CompletionResultType]::ParameterName, 'show help')\n    )\n\n    if ($wordToComplete.StartsWith('-')) {\n        $completions.Where{ $_.CompletionText -like \"$wordToComplete*\" } | Sort-Object -Property ListItemText\n    }\n}\n"
  },
  {
    "path": "etc/lf.vim",
    "content": "\" 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 to your ~/.vimrc or source\n\" this file directly:\n\"\n\"     let lfvim = \"/path/to/lf.vim\"\n\"     if filereadable(lfvim)\n\"         exec \"source \" . lfvim\n\"     endif\n\"\n\" You may also like to assign a key to this command:\n\"\n\"     nnoremap <leader>l :LF<cr>\n\"\n\nfunction! LF()\n    let temp = tempname()\n    exec 'silent !lf -selection-path=' . shellescape(temp)\n    if !filereadable(temp)\n        redraw!\n        return\n    endif\n    let names = readfile(temp)\n    if empty(names)\n        redraw!\n        return\n    endif\n    exec 'edit ' . fnameescape(names[0])\n    for name in names[1:]\n        exec 'argadd ' . fnameescape(name)\n    endfor\n    redraw!\nendfunction\ncommand! -bar LF call LF()\n"
  },
  {
    "path": "etc/lf.zsh",
    "content": "#compdef lf lfcd\n\n# Autocompletion for zsh shell.\n#\n# You need to rename this file to _lf and add containing folder to $fpath in\n# ~/.zshrc file:\n#\n#     fpath=(/path/to/directory/containing/the/file $fpath)\n#     autoload -U compinit\n#     compinit\n#\n\nlocal arguments\n\narguments=(\n    '-command[command to execute on client initialization]'\n    '-config[path to the config file (instead of the usual paths)]'\n    '-cpuprofile[path to the file to write the CPU profile]'\n    '-doc[show documentation]'\n    '-last-dir-path[path to the file to write the last dir on exit (to use for cd)]'\n    '-log[path to the log file to write messages]'\n    '-memprofile[path to the file to write the memory profile]'\n    '-print-last-dir[print the last dir to stdout on exit (to use for cd)]'\n    '-print-selection[print the selected files to stdout on open (to use as open file dialog)]'\n    '-remote[send remote command to server]'\n    '-selection-path[path to the file to write selected files on open (to use as open file dialog)]'\n    '-server[start server (automatic)]'\n    '-single[start a client without server]'\n    '-version[show version]'\n    '-help[show help]'\n    '*:filename:_files'\n)\n\n_arguments -s $arguments\n"
  },
  {
    "path": "etc/lfcd.cmd",
    "content": "@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% variable.\n\nchcp 65001 > nul 2>&1\nfor /f \"usebackq tokens=*\" %%d in (`lf -print-last-dir %*`) do cd /d %%d\n"
  },
  {
    "path": "etc/lfcd.csh",
    "content": "# 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 this file to your shell rc file (e.g.\n# ~/.tcshrc) or source this file directly:\n#\n#     setenv LF_HOME \"${HOME}/.config/lf\"\n#     [ -e \"${LF_HOME}/lfcd.csh\" ] && source \"${LF_HOME}/lfcd.csh\"\n#\n# You may also like to assign a key to this command:\n#\n#     bindkey -c \"^O\" lfcd\n#\n\nalias lfcd 'set _=`mktemp` && lf -last-dir-path=$_ \"\\!*\" && set _=`cat $_ && rm -f $_` && [ -d \"$_\" ] && cd \"$_\"'\n"
  },
  {
    "path": "etc/lfcd.fish",
    "content": "# 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 in $fish_function_path variable:\n#\n#     mkdir -p ~/.config/fish/functions\n#     ln -s \"/path/to/lfcd.fish\" ~/.config/fish/functions\n#\n# You may also like to assign a key (Ctrl-O) to this command:\n#\n#     bind \\co 'set old_tty (stty -g); stty sane; lfcd; stty $old_tty; commandline -f repaint'\n#\n# You may put this in a function called fish_user_key_bindings.\n\nfunction lfcd --wraps=\"lf\" --description=\"lf - Terminal file manager (changing directory on exit)\"\n    # `command` is needed in case `lfcd` is aliased to `lf`.\n    # Quotes will cause `cd` to not change directory if `lf` prints nothing to stdout due to an error.\n    cd \"$(command lf -print-last-dir $argv)\"\nend\n"
  },
  {
    "path": "etc/lfcd.nu",
    "content": "# 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 Environment Config File\n# (Execute 'config env' in the nushell to open it).\n\n# You may also like to assign a key (Ctrl-O) to this command:\n# See the documentation: https://www.nushell.sh/book/line_editor.html#keybindings\n#\n# keybindings: [\n#   {\n#     name: lfcd\n#     modifier: control\n#     keycode: char_o\n#     mode: [emacs, vi_normal, vi_insert]\n#     event: {\n#       send: executehostcommand\n#       cmd: \"lfcd\"\n#     }\n#   }\n# ]\n\n# For nushell version >= 0.87.0\ndef --env --wrapped lfcd [...args: string] { \n  cd (lf -print-last-dir ...$args)\n}\n"
  },
  {
    "path": "etc/lfcd.ps1",
    "content": "# 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 variable.\n#\n# You may also like to assign a key to this command:\n#\n#     Set-PSReadLineKeyHandler -Chord Ctrl+o -ScriptBlock {\n#         [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()\n#         [Microsoft.PowerShell.PSConsoleReadLine]::Insert('lfcd.ps1')\n#         [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()\n#     }\n#\n# You may put this in one of the profiles found in $PROFILE.\n#\n\nlf -print-last-dir $args | Set-Location\n"
  },
  {
    "path": "etc/lfcd.sh",
    "content": "# Change working dir in shell to last dir in lf on exit (adapted from ranger).\n#\n# You need to either copy the content of this file to your shell rc file\n# (e.g. ~/.bashrc) or source this file directly:\n#\n#     LFCD=\"/path/to/lfcd.sh\"\n#     if [ -f \"$LFCD\" ]; then\n#         source \"$LFCD\"\n#     fi\n#\n# You may also like to assign a key (Ctrl-O) to this command:\n#\n#     bind '\"\\C-o\":\"lfcd\\C-m\"'  # bash\n#     bindkey -s '^o' 'lfcd\\n'  # zsh\n#\n\nlfcd () {\n    # `command` is needed in case `lfcd` is aliased to `lf`\n    cd \"$(command lf -print-last-dir \"$@\")\"\n}\n"
  },
  {
    "path": "etc/lfrc.cmd.example",
    "content": "# interpreter for shell commands\nset shell cmd\n\n# Shell commands with multiline definitions and/or positional arguments and/or\n# quotes do not work in Windows. For anything but the simplest shell commands,\n# it is recommended to create separate script files and simply call them here\n# in commands or mappings.\n\n# change the editor used in default editor keybinding\n# There is no builtin terminal editor installed in Windows. The default editor\n# mapping uses 'notepad' which launches in a separate GUI window. You may\n# instead install a terminal editor of your choice and replace the default\n# editor keybinding accordingly.\nmap e $vim %f%\n\n# change the pager used in default pager keybinding\n# The standard pager used in Windows is 'more' which is not a very capable\n# pager. You may instead install a pager of your choice and replace the default\n# pager keybinding accordingly.\nmap i $less %f%\n\n# change the shell used in default shell keybinding\nmap w $powershell\n\n# change 'help' command to use a different pager\ncmd help $lf -doc | less\n\n# leave some space at the top and the bottom of the screen\nset scrolloff 10\n\n# use enter for shell commands\nmap <enter> shell\n"
  },
  {
    "path": "etc/lfrc.example",
    "content": "# interpreter for shell commands\nset shell sh\n\n# set '-eu' options for shell commands\n# These options are used to have safer shell commands. Option '-e' is used to\n# exit on error and option '-u' is used to give error for unset variables.\n# Option '-f' disables pathname expansion which can be useful when $f, $fs, and\n# $fx variables contain names with '*' or '?' characters. However, this option\n# is used selectively within individual commands as it can be limiting at\n# times.\nset shellopts '-eu'\n\n# set internal field separator (IFS) to \"\\n\" for shell commands\n# This is useful to automatically split file names in $fs and $fx properly\n# since default file separator used in these variables (i.e. 'filesep' option)\n# is newline. You need to consider the values of these options and create your\n# commands accordingly.\nset ifs \"\\n\"\n\n# leave some space at the top and the bottom of the screen\nset scrolloff 10\n\n# Use the `dim` attribute instead of underline for the cursor in the preview pane\nset cursorpreviewfmt \"\\033[7;2m\"\n\n# use enter for shell commands\nmap <enter> shell\n\n# show the result of execution of previous commands\nmap ` !true\n\n# execute current file (must be executable)\nmap x $$f\nmap X !$f\n\n# dedicated keys for file opener actions\nmap o &mimeopen $f\nmap O $mimeopen --ask $f\n\n# define a custom 'open' command\n# This command is called when current file is not a directory. You may want to\n# use either file extensions and/or mime types here. Below uses an editor for\n# text files and a file opener for the rest.\ncmd open &{{\n    case $(file --mime-type -Lb $f) in\n        text/*) lf -remote \"send $id \\$$EDITOR \\$fx\";;\n        *) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;;\n    esac\n}}\n\n# mkdir command. See wiki if you want it to select created dir\nmap a :push %mkdir<space>\n\n# define a custom 'rename' command without prompt for overwrite\n# cmd rename %[ -e $1 ] && printf \"file exists\" || mv $f $1\n# map r push :rename<space>\n\n# make sure trash folder exists\n# %mkdir -p ~/.trash\n\n# move current file or selected files to trash folder\n# (also see 'man mv' for backup/overwrite options)\ncmd trash %set -f; mv -t ~/.trash $fx\n\n# define a custom 'delete' command\n# cmd delete ${{\n#     set -f\n#     printf \"$fx\\n\"\n#     printf \"delete? [y/N] \"\n#     read ans\n#     [ \"$ans\" = \"y\" ] && rm -rf $fx\n# }}\n\n# use '<delete>' key for either 'trash' or 'delete' command\n# map <delete> trash\n# map <delete> delete\n\n# extract the current file with the right command\n# (xkcd link: https://xkcd.com/1168/)\ncmd extract ${{\n    set -f\n    case $f in\n        *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;\n        *.tar.gz|*.tgz) tar xzvf $f;;\n        *.tar.xz|*.txz) tar xJvf $f;;\n        *.zip) unzip $f;;\n        *.rar) unrar x $f;;\n        *.7z) 7z x $f;;\n    esac\n}}\n\n# compress current file or selected files with tar and gunzip\ncmd tar ${{\n    set -f\n    mkdir $1\n    cp -r $fx $1\n    tar czf $1.tar.gz $1\n    rm -rf $1\n}}\n\n# compress current file or selected files with zip\ncmd zip ${{\n    set -f\n    mkdir $1\n    cp -r $fx $1\n    zip -r $1.zip $1\n    rm -rf $1\n}}\n"
  },
  {
    "path": "etc/lfrc.ps1.example",
    "content": "# interpreter for shell commands\nset shell pwsh\n\n# allow the usage of $args inside shell commands\nset shellflag \"-cwa\"\n\n# speed up Powershell by skipping the profile\nset shellopts \"-nop\"\n\n# Shell commands with multiline definitions and/or positional arguments and/or\n# quotes only partly work in Windows. For anything but the simplest shell commands,\n# it is recommended to create separate script files and simply call them here\n# in commands or mappings.\n#\n# Also, the default commands and keybindings are defined using cmd syntax (i.e. '%EDITOR%')\n# which does not work with Powershell. Therefore, you need to override these\n# with explicit choices accordingly.\n\n# change the default commands and keybindings to work in Powershell\ncmd open &&$Env:OPENER.Trim('\"', ' ') \"$Env:f\"\nmap e $&$Env:EDITOR \"$Env:f\"\nmap i !&$Env:PAGER \"$Env:f\"\nmap w $&$Env:SHELL\ncmd help !&$Env:lf -doc | &$Env:PAGER\ncmd maps !&$Env:lf -remote \"query $Env:id maps\" | &$Env:PAGER\ncmd nmaps !&$Env:lf -remote \"query $Env:id nmaps\" | &$Env:PAGER\ncmd vmaps !&$Env:lf -remote \"query $Env:id vmaps\" | &$Env:PAGER\ncmd cmaps !&$Env:lf -remote \"query $Env:id cmaps\" | &$Env:PAGER\ncmd cmds !&$Env:lf -remote \"query $Env:id cmds\" | &$Env:PAGER\n"
  },
  {
    "path": "etc/ruler.default",
    "content": "{{with .Message -}}\n    {{. -}}\n{{else with .Stat -}}\n    {{.Permissions | printf \"\\033[36m%s\\033[0m\" -}}\n    {{with .LinkCount}} {{.}}{{end -}}\n    {{with .User}} {{.}}{{end -}}\n    {{with .Group}} {{.}}{{end -}}\n    {{.Size | humanize | printf \" %5s\" -}}\n    {{.ModTime | printf \" %s\" -}}\n    {{with .Target}} -> {{.}}{{end -}}\n{{end -}}\n{{.SPACER -}}\n{{with .Keys}}  {{.}}{{end -}}\n{{with .Progress}}  {{join . \" \"}}{{end -}}\n{{with .Copy}}  {{len . | printf \"%s %d \\033[0m\" $.Options.copyfmt}}{{end -}}\n{{with .Cut}}  {{len . | printf \"%s %d \\033[0m\" $.Options.cutfmt}}{{end -}}\n{{with .Select}}  {{len . | printf \"%s %d \\033[0m\" $.Options.selectfmt}}{{end -}}\n{{with .Visual}}  {{len . | printf \"%s %d \\033[0m\" $.Options.visualfmt}}{{end -}}\n{{with .Filter}}  {{join . \" \" | printf \"\\033[7;34m %s \\033[0m\"}}{{end -}}\n{{printf \"  %d/%d\" .Index .Total}}\n"
  },
  {
    "path": "eval.go",
    "content": "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\"unicode\"\n\t\"unicode/utf8\"\n\n\t\"github.com/gdamore/tcell/v3\"\n\t\"github.com/rivo/uniseg\"\n)\n\nfunc applyBoolOpt(opt *bool, e *setExpr) error {\n\tswitch {\n\tcase strings.HasPrefix(e.opt, \"no\"):\n\t\tif e.val != \"\" {\n\t\t\treturn fmt.Errorf(\"%s: unexpected value: %s\", e.opt, e.val)\n\t\t}\n\t\t*opt = false\n\tcase strings.HasSuffix(e.opt, \"!\"):\n\t\tif e.val != \"\" {\n\t\t\treturn fmt.Errorf(\"%s: unexpected value: %s\", e.opt, e.val)\n\t\t}\n\t\t*opt = !*opt\n\tdefault:\n\t\tswitch e.val {\n\t\tcase \"\", \"true\":\n\t\t\t*opt = true\n\t\tcase \"false\":\n\t\t\t*opt = false\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"%s: value should be empty, 'true', or 'false'\", e.opt)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc applyLocalBoolOpt(localOpt map[string]bool, globalOpt bool, e *setLocalExpr) error {\n\topt, ok := localOpt[e.path]\n\tif !ok {\n\t\topt = globalOpt\n\t}\n\n\tif err := applyBoolOpt(&opt, &setExpr{e.opt, e.val}); err != nil {\n\t\treturn err\n\t}\n\n\tlocalOpt[e.path] = opt\n\treturn nil\n}\n\nfunc (e *setExpr) eval(app *app, _ []string) {\n\tvar err error\n\tswitch e.opt {\n\tcase \"anchorfind\", \"noanchorfind\", \"anchorfind!\":\n\t\terr = applyBoolOpt(&gOpts.anchorfind, e)\n\tcase \"autoquit\", \"noautoquit\", \"autoquit!\":\n\t\terr = applyBoolOpt(&gOpts.autoquit, e)\n\tcase \"dircounts\", \"nodircounts\", \"dircounts!\":\n\t\terr = applyBoolOpt(&gOpts.dircounts, e)\n\t\tif err == nil {\n\t\t\tapp.nav.renew()\n\t\t\tapp.ui.loadFile(app, false)\n\t\t}\n\tcase \"dirfirst\", \"nodirfirst\", \"dirfirst!\":\n\t\terr = applyBoolOpt(&gOpts.dirfirst, e)\n\t\tif err == nil {\n\t\t\tapp.nav.sort()\n\t\t}\n\tcase \"dironly\", \"nodironly\", \"dironly!\":\n\t\terr = applyBoolOpt(&gOpts.dironly, e)\n\t\tif err == nil {\n\t\t\tapp.nav.sort()\n\t\t\tapp.nav.position()\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"dirpreviews\", \"nodirpreviews\", \"dirpreviews!\":\n\t\terr = applyBoolOpt(&gOpts.dirpreviews, e)\n\tcase \"drawbox\", \"nodrawbox\", \"drawbox!\":\n\t\terr = applyBoolOpt(&gOpts.drawbox, e)\n\t\tif err == nil {\n\t\t\tapp.ui.renew()\n\t\t\tapp.nav.resize(app.ui)\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"hidden\", \"nohidden\", \"hidden!\":\n\t\terr = applyBoolOpt(&gOpts.hidden, e)\n\t\tif err == nil {\n\t\t\tapp.nav.sort()\n\t\t\tapp.nav.position()\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"history\", \"nohistory\", \"history!\":\n\t\terr = applyBoolOpt(&gOpts.history, e)\n\tcase \"icons\", \"noicons\", \"icons!\":\n\t\terr = applyBoolOpt(&gOpts.icons, e)\n\tcase \"ignorecase\", \"noignorecase\", \"ignorecase!\":\n\t\terr = applyBoolOpt(&gOpts.ignorecase, e)\n\t\tif err == nil {\n\t\t\tapp.nav.sort()\n\t\t\tapp.nav.position()\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"ignoredia\", \"noignoredia\", \"ignoredia!\":\n\t\terr = applyBoolOpt(&gOpts.ignoredia, e)\n\t\tif err == nil {\n\t\t\tapp.nav.sort()\n\t\t\tapp.nav.position()\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"incfilter\", \"noincfilter\", \"incfilter!\":\n\t\terr = applyBoolOpt(&gOpts.incfilter, e)\n\tcase \"incsearch\", \"noincsearch\", \"incsearch!\":\n\t\terr = applyBoolOpt(&gOpts.incsearch, e)\n\tcase \"mergeindicators\", \"nomergeindicators\", \"mergeindicators!\":\n\t\terr = applyBoolOpt(&gOpts.mergeindicators, e)\n\tcase \"mouse\", \"nomouse\", \"mouse!\":\n\t\terr = applyBoolOpt(&gOpts.mouse, e)\n\t\tif err == nil {\n\t\t\tif gOpts.mouse {\n\t\t\t\tapp.ui.screen.EnableMouse(tcell.MouseButtonEvents)\n\t\t\t} else {\n\t\t\t\tapp.ui.screen.DisableMouse()\n\t\t\t}\n\t\t}\n\tcase \"number\", \"nonumber\", \"number!\":\n\t\terr = applyBoolOpt(&gOpts.number, e)\n\tcase \"preload\", \"nopreload\", \"preload!\":\n\t\terr = applyBoolOpt(&gOpts.preload, e)\n\tcase \"preview\", \"nopreview\", \"preview!\":\n\t\tpreview := gOpts.preview\n\t\terr = applyBoolOpt(&preview, e)\n\t\tif preview && len(gOpts.ratios) < 2 {\n\t\t\terr = errors.New(\"preview: 'ratios' should consist of at least two numbers before enabling 'preview'\")\n\t\t}\n\t\tif err == nil {\n\t\t\tgOpts.preview = preview\n\t\t\tapp.ui.sxScreen.forceClear = true\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"relativenumber\", \"norelativenumber\", \"relativenumber!\":\n\t\terr = applyBoolOpt(&gOpts.relativenumber, e)\n\tcase \"reverse\", \"noreverse\", \"reverse!\":\n\t\terr = applyBoolOpt(&gOpts.reverse, e)\n\t\tif err == nil {\n\t\t\tapp.nav.sort()\n\t\t}\n\t// DEPRECATED: remove after r42 is released\n\tcase \"roundbox\", \"noroundbox\", \"roundbox!\":\n\t\tapp.ui.echoerr(\"option 'roundbox' is deprecated, use 'borderstyle' instead\")\n\tcase \"showbinds\", \"noshowbinds\", \"showbinds!\":\n\t\terr = applyBoolOpt(&gOpts.showbinds, e)\n\tcase \"smartcase\", \"nosmartcase\", \"smartcase!\":\n\t\terr = applyBoolOpt(&gOpts.smartcase, e)\n\t\tif err == nil {\n\t\t\tapp.nav.sort()\n\t\t\tapp.nav.position()\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"smartdia\", \"nosmartdia\", \"smartdia!\":\n\t\terr = applyBoolOpt(&gOpts.smartdia, e)\n\t\tif err == nil {\n\t\t\tapp.nav.sort()\n\t\t\tapp.nav.position()\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"watch\", \"nowatch\", \"watch!\":\n\t\terr = applyBoolOpt(&gOpts.watch, e)\n\t\tif err == nil {\n\t\t\tif gOpts.watch {\n\t\t\t\tapp.watch.start()\n\t\t\t\tfor _, dir := range app.nav.dirCache {\n\t\t\t\t\tapp.watchDir(dir)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tapp.watch.stop()\n\t\t\t}\n\t\t}\n\tcase \"wrapscan\", \"nowrapscan\", \"wrapscan!\":\n\t\terr = applyBoolOpt(&gOpts.wrapscan, e)\n\tcase \"wrapscroll\", \"nowrapscroll\", \"wrapscroll!\":\n\t\terr = applyBoolOpt(&gOpts.wrapscroll, e)\n\tcase \"borderfmt\":\n\t\tgOpts.borderfmt = e.val\n\tcase \"cleaner\":\n\t\tgOpts.cleaner = replaceTilde(e.val)\n\tcase \"copyfmt\":\n\t\tgOpts.copyfmt = e.val\n\tcase \"cursoractivefmt\":\n\t\tgOpts.cursoractivefmt = e.val\n\tcase \"cursorparentfmt\":\n\t\tgOpts.cursorparentfmt = e.val\n\tcase \"cursorpreviewfmt\":\n\t\tgOpts.cursorpreviewfmt = e.val\n\tcase \"cutfmt\":\n\t\tgOpts.cutfmt = e.val\n\tcase \"borderstyle\":\n\t\tswitch e.val {\n\t\tcase \"box\":\n\t\t\tgOpts.borderstyle = borderBox\n\t\tcase \"roundbox\":\n\t\t\tgOpts.borderstyle = borderRoundBox\n\t\tcase \"outline\":\n\t\t\tgOpts.borderstyle = borderOutline\n\t\tcase \"roundoutline\":\n\t\t\tgOpts.borderstyle = borderRoundOutline\n\t\tcase \"separators\":\n\t\t\tgOpts.borderstyle = borderSeparators\n\t\tdefault:\n\t\t\tapp.ui.echoerr(\"borderstyle: value should either be 'box', 'roundbox', 'outline', 'roundoutline' or 'separators'\")\n\t\t\treturn\n\t\t}\n\t\tapp.ui.renew()\n\t\tapp.nav.resize(app.ui)\n\t\tapp.ui.loadFile(app, true)\n\tcase \"dupfilefmt\":\n\t\tgOpts.dupfilefmt = e.val\n\tcase \"errorfmt\":\n\t\tgOpts.errorfmt = e.val\n\tcase \"filesep\":\n\t\tgOpts.filesep = e.val\n\tcase \"filtermethod\":\n\t\tswitch e.val {\n\t\tcase \"text\", \"glob\", \"regex\":\n\t\t\tgOpts.filtermethod = searchMethod(e.val)\n\t\tdefault:\n\t\t\tapp.ui.echoerr(\"filtermethod: value should either be 'text', 'glob' or 'regex\")\n\t\t\treturn\n\t\t}\n\t\tapp.nav.sort()\n\t\tapp.nav.position()\n\t\tapp.ui.loadFile(app, true)\n\tcase \"findlen\":\n\t\tn, err := strconv.Atoi(e.val)\n\t\tif err != nil {\n\t\t\tapp.ui.echoerrf(\"findlen: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tif n < 0 {\n\t\t\tapp.ui.echoerr(\"findlen: value should be a non-negative number\")\n\t\t\treturn\n\t\t}\n\t\tgOpts.findlen = n\n\tcase \"hiddenfiles\":\n\t\ttoks := strings.Split(e.val, \":\")\n\t\tfor _, s := range toks {\n\t\t\tif s == \"\" {\n\t\t\t\tapp.ui.echoerr(\"hiddenfiles: glob should be non-empty\")\n\t\t\t\treturn\n\t\t\t}\n\t\t\t_, err := filepath.Match(s, \"a\")\n\t\t\tif err != nil {\n\t\t\t\tapp.ui.echoerrf(\"hiddenfiles: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t\tgOpts.hiddenfiles = toks\n\t\tapp.nav.sort()\n\t\tapp.nav.position()\n\t\tapp.ui.loadFile(app, true)\n\tcase \"ifs\":\n\t\tgOpts.ifs = e.val\n\tcase \"info\":\n\t\tif e.val == \"\" {\n\t\t\tgOpts.info = nil\n\t\t\treturn\n\t\t}\n\t\ttoks := strings.Split(e.val, \":\")\n\t\tfor _, s := range toks {\n\t\t\tswitch s {\n\t\t\tcase \"size\", \"time\", \"atime\", \"btime\", \"ctime\", \"perm\", \"user\", \"group\", \"custom\":\n\t\t\tdefault:\n\t\t\t\tapp.ui.echoerr(\"info: should consist of 'size', 'time', 'atime', 'btime', 'ctime', 'perm', 'user', 'group' or 'custom' separated with colon\")\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t\tgOpts.info = toks\n\tcase \"infotimefmtnew\":\n\t\tgOpts.infotimefmtnew = e.val\n\tcase \"infotimefmtold\":\n\t\tgOpts.infotimefmtold = e.val\n\tcase \"menufmt\":\n\t\tgOpts.menufmt = e.val\n\tcase \"menuheaderfmt\":\n\t\tgOpts.menuheaderfmt = e.val\n\tcase \"menuselectfmt\":\n\t\tgOpts.menuselectfmt = e.val\n\tcase \"numbercursorfmt\":\n\t\tgOpts.numbercursorfmt = e.val\n\tcase \"numberfmt\":\n\t\tgOpts.numberfmt = e.val\n\tcase \"period\":\n\t\tn, err := strconv.Atoi(e.val)\n\t\tif err != nil {\n\t\t\tapp.ui.echoerrf(\"period: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tif n < 0 {\n\t\t\tapp.ui.echoerr(\"period: value should be a non-negative number\")\n\t\t\treturn\n\t\t}\n\t\tgOpts.period = n\n\t\tif n == 0 {\n\t\t\tapp.ticker.Stop()\n\t\t} else {\n\t\t\tapp.ticker.Stop()\n\t\t\tapp.ticker = time.NewTicker(time.Duration(gOpts.period) * time.Second)\n\t\t}\n\tcase \"preserve\":\n\t\tif e.val == \"\" {\n\t\t\tgOpts.preserve = nil\n\t\t\treturn\n\t\t}\n\t\ttoks := strings.Split(e.val, \":\")\n\t\tfor _, s := range toks {\n\t\t\tswitch s {\n\t\t\tcase \"mode\", \"timestamps\":\n\t\t\tdefault:\n\t\t\t\tapp.ui.echoerr(\"preserve: should consist of 'mode' or 'timestamps' separated with colon\")\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t\tgOpts.preserve = toks\n\tcase \"previewer\":\n\t\tgOpts.previewer = replaceTilde(e.val)\n\tcase \"promptfmt\":\n\t\tgOpts.promptfmt = e.val\n\tcase \"ratios\":\n\t\ttoks := strings.Split(e.val, \":\")\n\t\trats := make([]int, 0, len(toks))\n\t\tfor _, s := range toks {\n\t\t\tn, err := strconv.Atoi(s)\n\t\t\tif err != nil {\n\t\t\t\tapp.ui.echoerrf(\"ratios: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif n <= 0 {\n\t\t\t\tapp.ui.echoerr(\"ratios: value should be a positive number\")\n\t\t\t\treturn\n\t\t\t}\n\t\t\trats = append(rats, n)\n\t\t}\n\t\tif gOpts.preview && len(rats) < 2 {\n\t\t\tapp.ui.echoerr(\"ratios: should consist of at least two numbers when 'preview' is enabled\")\n\t\t\treturn\n\t\t}\n\t\tgOpts.ratios = rats\n\t\tapp.ui.wins = getWins(app.ui.screen)\n\t\tapp.nav.resize(app.ui)\n\t\tapp.ui.loadFile(app, true)\n\tcase \"rulerfile\", \"norulerfile\", \"rulerfile!\":\n\t\tgOpts.rulerfile = replaceTilde(e.val)\n\t\tapp.ui.ruler, app.ui.rulerErr = parseRuler(gOpts.rulerfile)\n\tcase \"rulerfmt\":\n\t\tgOpts.rulerfmt = e.val\n\tcase \"scrolloff\":\n\t\tn, err := strconv.Atoi(e.val)\n\t\tif err != nil {\n\t\t\tapp.ui.echoerrf(\"scrolloff: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tif n < 0 {\n\t\t\tapp.ui.echoerr(\"scrolloff: value should be a non-negative number\")\n\t\t\treturn\n\t\t}\n\t\tgOpts.scrolloff = n\n\tcase \"searchmethod\":\n\t\tswitch e.val {\n\t\tcase \"text\", \"glob\", \"regex\":\n\t\t\tgOpts.searchmethod = searchMethod(e.val)\n\t\tdefault:\n\t\t\tapp.ui.echoerr(\"searchmethod: value should either be 'text', 'glob' or 'regex'\")\n\t\t\treturn\n\t\t}\n\tcase \"selectfmt\":\n\t\tgOpts.selectfmt = e.val\n\tcase \"selmode\":\n\t\tswitch e.val {\n\t\tcase \"all\", \"dir\":\n\t\t\tgOpts.selmode = e.val\n\t\tdefault:\n\t\t\tapp.ui.echoerr(\"selmode: value should either be 'all' or 'dir'\")\n\t\t\treturn\n\t\t}\n\tcase \"shell\":\n\t\tgOpts.shell = e.val\n\tcase \"shellflag\":\n\t\tgOpts.shellflag = e.val\n\tcase \"shellopts\":\n\t\tif e.val == \"\" {\n\t\t\tgOpts.shellopts = nil\n\t\t\treturn\n\t\t}\n\t\tgOpts.shellopts = strings.Split(e.val, \":\")\n\tcase \"sizeunits\":\n\t\tswitch e.val {\n\t\tcase \"binary\", \"decimal\":\n\t\t\tgOpts.sizeunits = e.val\n\t\tdefault:\n\t\t\tapp.ui.echoerr(\"sizeunits: value should either be 'binary' or 'decimal'\")\n\t\t\treturn\n\t\t}\n\tcase \"sortby\":\n\t\tmethod := sortMethod(e.val)\n\t\tif !isValidSortMethod(method) {\n\t\t\tapp.ui.echoerr(invalidSortErrorMessage)\n\t\t\treturn\n\t\t}\n\t\tgOpts.sortby = method\n\t\tapp.nav.sort()\n\tcase \"statfmt\":\n\t\tgOpts.statfmt = e.val\n\tcase \"tabstop\":\n\t\tn, err := strconv.Atoi(e.val)\n\t\tif err != nil {\n\t\t\tapp.ui.echoerrf(\"tabstop: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tif n <= 0 {\n\t\t\tapp.ui.echoerr(\"tabstop: value should be a positive number\")\n\t\t\treturn\n\t\t}\n\t\tgOpts.tabstop = n\n\tcase \"tagfmt\":\n\t\tgOpts.tagfmt = e.val\n\tcase \"tempmarks\":\n\t\tgOpts.tempmarks = \"'\" + e.val\n\tcase \"terminalcursor\":\n\t\tstyle := cursorStyle(e.val)\n\t\tswitch style {\n\t\tcase defaultCursor:\n\t\t\tapp.ui.screen.SetCursorStyle(tcell.CursorStyleDefault)\n\t\tcase blockCursor:\n\t\t\tapp.ui.screen.SetCursorStyle(tcell.CursorStyleSteadyBlock)\n\t\tcase underlineCursor:\n\t\t\tapp.ui.screen.SetCursorStyle(tcell.CursorStyleSteadyUnderline)\n\t\tcase barCursor:\n\t\t\tapp.ui.screen.SetCursorStyle(tcell.CursorStyleSteadyBar)\n\t\tcase blinkBlockCursor:\n\t\t\tapp.ui.screen.SetCursorStyle(tcell.CursorStyleBlinkingBlock)\n\t\tcase blinkUnderlineCursor:\n\t\t\tapp.ui.screen.SetCursorStyle(tcell.CursorStyleBlinkingUnderline)\n\t\tcase blinkBarCursor:\n\t\t\tapp.ui.screen.SetCursorStyle(tcell.CursorStyleBlinkingBar)\n\t\tdefault:\n\t\t\tapp.ui.echoerr(\"terminalcursor: value should either be 'default', 'block', 'underline', 'bar', 'blinkblock', 'blinkunderline' or 'blinkbar'\")\n\t\t\treturn\n\t\t}\n\t\tgOpts.terminalcursor = style\n\tcase \"timefmt\":\n\t\tgOpts.timefmt = e.val\n\tcase \"truncatechar\":\n\t\tif uniseg.StringWidth(e.val) != 1 {\n\t\t\tapp.ui.echoerr(\"truncatechar: value should be a single character\")\n\t\t\treturn\n\t\t}\n\t\tgOpts.truncatechar = e.val\n\tcase \"truncatepct\":\n\t\tn, err := strconv.Atoi(e.val)\n\t\tif err != nil {\n\t\t\tapp.ui.echoerrf(\"truncatepct: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tif n < 0 || n > 100 {\n\t\t\tapp.ui.echoerrf(\"truncatepct: must be between 0 and 100 (both inclusive), got %d\", n)\n\t\t\treturn\n\t\t}\n\t\tgOpts.truncatepct = n\n\tcase \"visualfmt\":\n\t\tgOpts.visualfmt = e.val\n\tcase \"waitmsg\":\n\t\tgOpts.waitmsg = e.val\n\tdefault:\n\t\t// any key with the prefix user_ is accepted as a user defined option\n\t\tif strings.HasPrefix(e.opt, \"user_\") {\n\t\t\tgOpts.user[e.opt[5:]] = e.val\n\t\t\t// Export user defined options immediately, so that the current values\n\t\t\t// are available for some external previewer, which is started in a\n\t\t\t// different thread and thus cannot export (as `setenv` is not thread-safe).\n\t\t\tos.Setenv(\"lf_\"+e.opt, e.val)\n\t\t} else {\n\t\t\terr = fmt.Errorf(\"unknown option: %s\", e.opt)\n\t\t}\n\t}\n\n\tif err != nil {\n\t\tapp.ui.echoerr(err.Error())\n\t}\n}\n\nfunc (e *setLocalExpr) eval(app *app, _ []string) {\n\tvar err error\n\te.path, err = filepath.Abs(replaceTilde(e.path))\n\tif err != nil {\n\t\tapp.ui.echoerrf(\"setlocal: %s\", err)\n\t\treturn\n\t}\n\n\tswitch e.opt {\n\tcase \"dircounts\", \"nodircounts\", \"dircounts!\":\n\t\terr = applyLocalBoolOpt(gLocalOpts.dircounts, gOpts.dircounts, e)\n\tcase \"dirfirst\", \"nodirfirst\", \"dirfirst!\":\n\t\terr = applyLocalBoolOpt(gLocalOpts.dirfirst, gOpts.dirfirst, e)\n\t\tif err == nil {\n\t\t\tapp.nav.sort()\n\t\t}\n\tcase \"dironly\", \"nodironly\", \"dironly!\":\n\t\terr = applyLocalBoolOpt(gLocalOpts.dironly, gOpts.dironly, e)\n\t\tif err == nil {\n\t\t\tapp.nav.sort()\n\t\t\tapp.nav.position()\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"hidden\", \"nohidden\", \"hidden!\":\n\t\terr = applyLocalBoolOpt(gLocalOpts.hidden, gOpts.hidden, e)\n\t\tif err == nil {\n\t\t\tapp.nav.sort()\n\t\t\tapp.nav.position()\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"reverse\", \"noreverse\", \"reverse!\":\n\t\terr = applyLocalBoolOpt(gLocalOpts.reverse, gOpts.reverse, e)\n\t\tif err == nil {\n\t\t\tapp.nav.sort()\n\t\t}\n\tcase \"info\":\n\t\tif e.val == \"\" {\n\t\t\tgLocalOpts.info[e.path] = nil\n\t\t\treturn\n\t\t}\n\t\ttoks := strings.Split(e.val, \":\")\n\t\tfor _, s := range toks {\n\t\t\tswitch s {\n\t\t\tcase \"size\", \"time\", \"atime\", \"btime\", \"ctime\", \"perm\", \"user\", \"group\", \"custom\":\n\t\t\tdefault:\n\t\t\t\tapp.ui.echoerr(\"info: should consist of 'size', 'time', 'atime', 'btime', 'ctime', 'perm', 'user', 'group' or 'custom' separated with colon\")\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t\tgLocalOpts.info[e.path] = toks\n\tcase \"sortby\":\n\t\tmethod := sortMethod(e.val)\n\t\tif !isValidSortMethod(method) {\n\t\t\tapp.ui.echoerr(invalidSortErrorMessage)\n\t\t\treturn\n\t\t}\n\t\tgLocalOpts.sortby[e.path] = method\n\t\tapp.nav.sort()\n\tdefault:\n\t\terr = fmt.Errorf(\"unknown option: %s\", e.opt)\n\t}\n\n\tif err != nil {\n\t\tapp.ui.echoerr(err.Error())\n\t}\n}\n\nfunc (e *mapExpr) eval(app *app, _ []string) {\n\tif e.expr == nil {\n\t\tdelete(gOpts.nkeys, e.keys)\n\t\tdelete(gOpts.vkeys, e.keys)\n\t} else {\n\t\tgOpts.nkeys[e.keys] = e.expr\n\t\tgOpts.vkeys[e.keys] = e.expr\n\t}\n}\n\nfunc (e *nmapExpr) eval(app *app, _ []string) {\n\tif e.expr == nil {\n\t\tdelete(gOpts.nkeys, e.keys)\n\t} else {\n\t\tgOpts.nkeys[e.keys] = e.expr\n\t}\n}\n\nfunc (e *vmapExpr) eval(app *app, _ []string) {\n\tif e.expr == nil {\n\t\tdelete(gOpts.vkeys, e.keys)\n\t} else {\n\t\tgOpts.vkeys[e.keys] = e.expr\n\t}\n}\n\nfunc (e *cmapExpr) eval(app *app, _ []string) {\n\tif e.expr == nil {\n\t\tdelete(gOpts.cmdkeys, e.key)\n\t} else {\n\t\tgOpts.cmdkeys[e.key] = e.expr\n\t}\n}\n\nfunc (e *cmdExpr) eval(app *app, _ []string) {\n\tif e.expr == nil {\n\t\tdelete(gOpts.cmds, e.name)\n\t} else {\n\t\tgOpts.cmds[e.name] = e.expr\n\t}\n\n\t// only enable focus reporting if required by the user\n\tif e.name == \"on-focus-gained\" || e.name == \"on-focus-lost\" {\n\t\t_, onFocusGainedExists := gOpts.cmds[\"on-focus-gained\"]\n\t\t_, onFocusLostExists := gOpts.cmds[\"on-focus-lost\"]\n\t\tif onFocusGainedExists || onFocusLostExists {\n\t\t\tapp.ui.screen.EnableFocus()\n\t\t} else {\n\t\t\tapp.ui.screen.DisableFocus()\n\t\t}\n\t}\n}\n\nfunc preChdir(app *app) {\n\tif cmd, ok := gOpts.cmds[\"pre-cd\"]; ok {\n\t\tcmd.eval(app, nil)\n\t}\n}\n\nfunc onChdir(app *app) {\n\tapp.nav.addJumpList()\n\tif cmd, ok := gOpts.cmds[\"on-cd\"]; ok {\n\t\tcmd.eval(app, nil)\n\t}\n}\n\nfunc onLoad(app *app, files []string) {\n\tif cmd, ok := gOpts.cmds[\"on-load\"]; ok {\n\t\tcmd.eval(app, files)\n\t}\n}\n\nfunc onFocusGained(app *app) {\n\tif cmd, ok := gOpts.cmds[\"on-focus-gained\"]; ok {\n\t\tcmd.eval(app, nil)\n\t}\n}\n\nfunc onFocusLost(app *app) {\n\tif cmd, ok := gOpts.cmds[\"on-focus-lost\"]; ok {\n\t\tcmd.eval(app, nil)\n\t}\n}\n\nfunc onInit(app *app) {\n\tif cmd, ok := gOpts.cmds[\"on-init\"]; ok {\n\t\tcmd.eval(app, nil)\n\t}\n}\n\nfunc onRedraw(app *app) {\n\tif cmd, ok := gOpts.cmds[\"on-redraw\"]; ok {\n\t\tcmd.eval(app, nil)\n\t}\n}\n\nfunc onSelect(app *app) {\n\tapp.nav.preload()\n\tif cmd, ok := gOpts.cmds[\"on-select\"]; ok {\n\t\tcmd.eval(app, nil)\n\t}\n}\n\nfunc onQuit(app *app) {\n\tif cmd, ok := gOpts.cmds[\"on-quit\"]; ok {\n\t\tcmd.eval(app, nil)\n\t}\n}\n\nfunc splitKeys(s string) (keys []string) {\n\tfor i := 0; i < len(s); {\n\t\tr, w := utf8.DecodeRuneInString(s[i:])\n\t\tif r != '<' {\n\t\t\tkeys = append(keys, s[i:i+w])\n\t\t\ti += w\n\t\t} else {\n\t\t\tj := i + w\n\t\t\tfor r != '>' && j < len(s) {\n\t\t\t\tr, w = utf8.DecodeRuneInString(s[j:])\n\t\t\t\tj += w\n\t\t\t}\n\t\t\tkeys = append(keys, s[i:j])\n\t\t\ti = j\n\t\t}\n\t}\n\treturn\n}\n\nfunc update(app *app) {\n\texitCompMenu(app)\n\tapp.cmdHistoryInput = nil\n\n\tswitch {\n\tcase gOpts.incsearch && app.ui.cmdPrefix == \"/\":\n\t\tapp.nav.search = app.ui.cmdAccLeft + app.ui.cmdAccRight\n\t\tif app.nav.search == \"\" {\n\t\t\treturn\n\t\t}\n\n\t\tdir := app.nav.currDir()\n\t\told := dir.ind\n\t\tdir.ind = app.nav.searchInd\n\t\tdir.pos = app.nav.searchPos\n\n\t\tif _, err := app.nav.searchNext(); err != nil {\n\t\t\tapp.ui.echoerrf(\"search: %s: %s\", err, app.nav.search)\n\t\t} else if old != dir.ind {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase gOpts.incsearch && app.ui.cmdPrefix == \"?\":\n\t\tapp.nav.search = app.ui.cmdAccLeft + app.ui.cmdAccRight\n\t\tif app.nav.search == \"\" {\n\t\t\treturn\n\t\t}\n\n\t\tdir := app.nav.currDir()\n\t\told := dir.ind\n\t\tdir.ind = app.nav.searchInd\n\t\tdir.pos = app.nav.searchPos\n\n\t\tif _, err := app.nav.searchPrev(); err != nil {\n\t\t\tapp.ui.echoerrf(\"search: %s: %s\", err, app.nav.search)\n\t\t} else if old != dir.ind {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase gOpts.incfilter && app.ui.cmdPrefix == \"filter: \":\n\t\tfilter := app.ui.cmdAccLeft + app.ui.cmdAccRight\n\t\tdir := app.nav.currDir()\n\t\told := dir.ind\n\n\t\tif err := app.nav.setFilter(strings.Split(filter, \" \")); err != nil {\n\t\t\tapp.ui.echoerrf(\"filter: %s\", err)\n\t\t} else if old != dir.ind {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\t}\n}\n\nfunc restartIncCmd(app *app) {\n\tif gOpts.incsearch && (app.ui.cmdPrefix == \"/\" || app.ui.cmdPrefix == \"?\") {\n\t\tdir := app.nav.currDir()\n\t\tapp.nav.searchInd = dir.ind\n\t\tapp.nav.searchPos = dir.pos\n\t\tupdate(app)\n\t} else if gOpts.incfilter && app.ui.cmdPrefix == \"filter: \" {\n\t\tdir := app.nav.currDir()\n\t\tapp.nav.prevFilter = dir.filter\n\t\tupdate(app)\n\t}\n}\n\nfunc resetIncCmd(app *app) {\n\tif gOpts.incsearch && (app.ui.cmdPrefix == \"/\" || app.ui.cmdPrefix == \"?\") {\n\t\tdir := app.nav.currDir()\n\t\tdir.pos = app.nav.searchPos\n\t\tif dir.ind != app.nav.searchInd {\n\t\t\tdir.ind = app.nav.searchInd\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\t} else if gOpts.incfilter && app.ui.cmdPrefix == \"filter: \" {\n\t\tdir := app.nav.currDir()\n\t\told := dir.ind\n\t\tif err := app.nav.setFilter(app.nav.prevFilter); err != nil {\n\t\t\tlog.Printf(\"reset filter: %s\", err)\n\t\t} else if old != dir.ind {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\t}\n}\n\nfunc normal(app *app) {\n\tresetIncCmd(app)\n\texitCompMenu(app)\n\n\tapp.cmdHistoryInd = 0\n\tapp.cmdHistoryInput = nil\n\n\tapp.ui.cmdAccLeft = \"\"\n\tapp.ui.cmdAccRight = \"\"\n\tapp.ui.cmdPrefix = \"\"\n}\n\nfunc insert(app *app, arg string) {\n\tswitch {\n\tcase gOpts.incsearch && (app.ui.cmdPrefix == \"/\" || app.ui.cmdPrefix == \"?\"):\n\t\tapp.ui.cmdAccLeft += arg\n\t\tupdate(app)\n\tcase gOpts.incfilter && app.ui.cmdPrefix == \"filter: \":\n\t\tapp.ui.cmdAccLeft += arg\n\t\tupdate(app)\n\tcase app.ui.cmdPrefix == \"find: \":\n\t\tapp.nav.find = app.ui.cmdAccLeft + arg + app.ui.cmdAccRight\n\n\t\tif gOpts.findlen == 0 {\n\t\t\tswitch app.nav.findSingle() {\n\t\t\tcase 0:\n\t\t\t\tapp.ui.echoerrf(\"find: pattern not found: %s\", app.nav.find)\n\t\t\tcase 1:\n\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\tdefault:\n\t\t\t\tapp.ui.cmdAccLeft += arg\n\t\t\t\treturn\n\t\t\t}\n\t\t} else {\n\t\t\tif len(app.nav.find) < gOpts.findlen {\n\t\t\t\tapp.ui.cmdAccLeft += arg\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif moved, found := app.nav.findNext(); !found {\n\t\t\t\tapp.ui.echoerrf(\"find: pattern not found: %s\", app.nav.find)\n\t\t\t} else if moved {\n\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t}\n\t\t}\n\n\t\tnormal(app)\n\tcase app.ui.cmdPrefix == \"find-back: \":\n\t\tapp.nav.find = app.ui.cmdAccLeft + arg + app.ui.cmdAccRight\n\n\t\tif gOpts.findlen == 0 {\n\t\t\tswitch app.nav.findSingle() {\n\t\t\tcase 0:\n\t\t\t\tapp.ui.echoerrf(\"find-back: pattern not found: %s\", app.nav.find)\n\t\t\tcase 1:\n\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\tdefault:\n\t\t\t\tapp.ui.cmdAccLeft += arg\n\t\t\t\treturn\n\t\t\t}\n\t\t} else {\n\t\t\tif len(app.nav.find) < gOpts.findlen {\n\t\t\t\tapp.ui.cmdAccLeft += arg\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif moved, found := app.nav.findPrev(); !found {\n\t\t\t\tapp.ui.echoerrf(\"find-back: pattern not found: %s\", app.nav.find)\n\t\t\t} else if moved {\n\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t}\n\t\t}\n\n\t\tnormal(app)\n\tcase strings.HasPrefix(app.ui.cmdPrefix, \"delete\"):\n\t\tnormal(app)\n\n\t\tif arg == \"y\" {\n\t\t\tif err := app.nav.del(app); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"delete: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tapp.nav.unselect()\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase strings.HasPrefix(app.ui.cmdPrefix, \"replace\"):\n\t\tnormal(app)\n\n\t\tif arg == \"y\" {\n\t\t\tif err := app.nav.rename(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"rename: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif gSingleMode {\n\t\t\t\tapp.nav.renew()\n\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t} else {\n\t\t\t\tif _, err := remote(\"send load\"); err != nil {\n\t\t\t\t\tapp.ui.echoerrf(\"rename: %s\", err)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase strings.HasPrefix(app.ui.cmdPrefix, \"create\"):\n\t\tnormal(app)\n\n\t\tif arg == \"y\" {\n\t\t\tif err := os.MkdirAll(filepath.Dir(app.nav.renameNewPath), os.ModePerm); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"rename: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif err := app.nav.rename(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"rename: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif gSingleMode {\n\t\t\t\tapp.nav.renew()\n\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t} else {\n\t\t\t\tif _, err := remote(\"send load\"); err != nil {\n\t\t\t\t\tapp.ui.echoerrf(\"rename: %s\", err)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase app.ui.cmdPrefix == \"mark-save: \":\n\t\tnormal(app)\n\n\t\tapp.nav.marks[arg] = app.nav.currDir().path\n\t\tif err := app.nav.writeMarks(); err != nil {\n\t\t\tapp.ui.echoerrf(\"mark-save: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tif gSingleMode {\n\t\t\tif err := app.nav.sync(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"mark-save: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t} else {\n\t\t\tif _, err := remote(\"send sync\"); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"mark-save: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\tcase app.ui.cmdPrefix == \"mark-load: \":\n\t\tnormal(app)\n\n\t\tpath, ok := app.nav.marks[arg]\n\t\tif !ok {\n\t\t\tapp.ui.echoerr(\"mark-load: no such mark\")\n\t\t\treturn\n\t\t}\n\n\t\tif err := cd(app, path); err != nil {\n\t\t\tapp.ui.echoerrf(\"mark-load: %s\", err)\n\t\t}\n\tcase app.ui.cmdPrefix == \"mark-remove: \":\n\t\tnormal(app)\n\t\tif err := app.nav.removeMark(arg); err != nil {\n\t\t\tapp.ui.echoerrf(\"mark-remove: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tif err := app.nav.writeMarks(); err != nil {\n\t\t\tapp.ui.echoerrf(\"mark-remove: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tif gSingleMode {\n\t\t\tif err := app.nav.sync(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"mark-remove: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t} else {\n\t\t\tif _, err := remote(\"send sync\"); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"mark-remove: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\tcase app.ui.cmdPrefix == \":\" && app.ui.cmdAccLeft == \"\":\n\t\tswitch arg {\n\t\tcase \"!\", \"$\", \"%\", \"&\":\n\t\t\tapp.ui.cmdPrefix = arg\n\t\t\tapp.cmdHistoryInd = 0\n\t\t\tapp.cmdHistoryInput = nil\n\t\t\treturn\n\t\t}\n\t\tfallthrough\n\tdefault:\n\t\texitCompMenu(app)\n\t\tapp.cmdHistoryInput = nil\n\t\tapp.ui.cmdAccLeft += arg\n\t}\n}\n\nfunc cd(app *app, path string) error {\n\twd := app.nav.currDir().path\n\n\tpath, err := filepath.Abs(replaceTilde(path))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting absolute path: %w\", err)\n\t}\n\n\tif path == wd {\n\t\treturn nil\n\t}\n\n\tresetIncCmd(app)\n\tpreChdir(app)\n\n\tif err := app.nav.cd(path); err != nil {\n\t\treturn fmt.Errorf(\"changing directory: %w\", err)\n\t}\n\n\tapp.ui.loadFile(app, true)\n\n\tapp.nav.marks[\"'\"] = wd\n\trestartIncCmd(app)\n\tonChdir(app)\n\n\treturn nil\n}\n\nfunc exitCompMenu(app *app) {\n\tapp.ui.menu = \"\"\n\tapp.ui.menuSelect = nil\n\tapp.menuCompActive = false\n}\n\nfunc (e *callExpr) eval(app *app, _ []string) {\n\tos.Setenv(\"lf_count\", strconv.Itoa(e.count))\n\n\t// commands that shouldn't clear the message line\n\tsilentCmds := []string{\n\t\t\"addcustominfo\",\n\t\t\"clearmaps\",\n\t\t\"draw\",\n\t\t\"load\",\n\t\t\"push\",\n\t\t\"redraw\",\n\t\t\"source\",\n\t\t\"sync\",\n\t\t\"tty-write\",\n\t\t\"on-focus-gained\",\n\t\t\"on-focus-lost\",\n\t\t\"on-init\",\n\t}\n\tif !slices.Contains(silentCmds, e.name) && app.ui.cmdPrefix != \">\" {\n\t\tapp.ui.echo(\"\")\n\t}\n\n\tswitch e.name {\n\tcase \"quit\":\n\t\tapp.quitChan <- struct{}{}\n\tcase \"up\":\n\t\tif app.nav.up(e.count) {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"half-up\":\n\t\tif app.nav.up(e.count * app.nav.height / 2) {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"page-up\":\n\t\tif app.nav.up(e.count * app.nav.height) {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"scroll-up\":\n\t\tif app.nav.scrollUp(e.count) {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"down\":\n\t\tif app.nav.down(e.count) {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"half-down\":\n\t\tif app.nav.down(e.count * app.nav.height / 2) {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"page-down\":\n\t\tif app.nav.down(e.count * app.nav.height) {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"scroll-down\":\n\t\tif app.nav.scrollDown(e.count) {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"updir\":\n\t\tresetIncCmd(app)\n\t\tpreChdir(app)\n\t\tfor range e.count {\n\t\t\tif err := app.nav.updir(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"%s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t\tapp.ui.loadFile(app, true)\n\t\trestartIncCmd(app)\n\t\tonChdir(app)\n\tcase \"open\":\n\t\tcurr := app.nav.currFile()\n\t\tif curr == nil {\n\t\t\treturn\n\t\t}\n\n\t\tif curr.IsDir() {\n\t\t\tresetIncCmd(app)\n\t\t\tpreChdir(app)\n\t\t\terr := app.nav.open()\n\t\t\tif err != nil {\n\t\t\t\tapp.ui.echoerrf(\"opening directory: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tapp.ui.loadFile(app, true)\n\t\t\trestartIncCmd(app)\n\t\t\tonChdir(app)\n\t\t} else {\n\t\t\tif gSelectionPath != \"\" || gPrintSelection {\n\t\t\t\tapp.selectionOut, _ = app.nav.currFileOrSelections()\n\t\t\t\tapp.quitChan <- struct{}{}\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif cmd, ok := gOpts.cmds[\"open\"]; ok {\n\t\t\t\tcmd.eval(app, e.args)\n\t\t\t}\n\t\t}\n\tcase \"jump-next\":\n\t\tresetIncCmd(app)\n\t\tpreChdir(app)\n\t\tfor range e.count {\n\t\t\tapp.nav.cdJumpListNext()\n\t\t}\n\t\tapp.ui.loadFile(app, true)\n\t\trestartIncCmd(app)\n\t\tonChdir(app)\n\tcase \"jump-prev\":\n\t\tresetIncCmd(app)\n\t\tpreChdir(app)\n\t\tfor range e.count {\n\t\t\tapp.nav.cdJumpListPrev()\n\t\t}\n\t\tapp.ui.loadFile(app, true)\n\t\trestartIncCmd(app)\n\t\tonChdir(app)\n\tcase \"top\":\n\t\tvar moved bool\n\t\tif e.count == 1 {\n\t\t\tmoved = app.nav.top()\n\t\t} else {\n\t\t\tmoved = app.nav.move(e.count - 1)\n\t\t}\n\t\tif moved {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"bottom\":\n\t\tvar moved bool\n\t\tif e.count == 1 {\n\t\t\t// Different from Vim, which would treat a count of 1 as meaning to\n\t\t\t// move to the first line (i.e. the top)\n\t\t\tmoved = app.nav.bottom()\n\t\t} else {\n\t\t\tmoved = app.nav.move(e.count - 1)\n\t\t}\n\t\tif moved {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"high\":\n\t\tif app.nav.high() {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"middle\":\n\t\tif app.nav.middle() {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"low\":\n\t\tif app.nav.low() {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"toggle\":\n\t\tif len(e.args) == 0 {\n\t\t\tapp.nav.toggle()\n\t\t} else {\n\t\t\tfor _, path := range e.args {\n\t\t\t\tpath, err := filepath.Abs(replaceTilde(path))\n\t\t\t\tif err != nil {\n\t\t\t\t\tapp.ui.echoerrf(\"toggle: %s\", err)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tif _, err := os.Lstat(path); os.IsNotExist(err) {\n\t\t\t\t\tapp.ui.echoerrf(\"toggle: %s\", err)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tapp.nav.toggleSelection(path)\n\t\t\t}\n\t\t}\n\tcase \"invert\":\n\t\tapp.nav.invert()\n\tcase \"unselect\":\n\t\tapp.nav.unselect()\n\tcase \"glob-select\":\n\t\tif len(e.args) != 1 {\n\t\t\tapp.ui.echoerr(\"glob-select: requires a pattern to match\")\n\t\t\treturn\n\t\t}\n\t\tif err := app.nav.globSel(e.args[0], false); err != nil {\n\t\t\tapp.ui.echoerrf(\"%s\", err)\n\t\t\treturn\n\t\t}\n\tcase \"glob-unselect\":\n\t\tif len(e.args) != 1 {\n\t\t\tapp.ui.echoerr(\"glob-unselect: requires a pattern to match\")\n\t\t\treturn\n\t\t}\n\t\tif err := app.nav.globSel(e.args[0], true); err != nil {\n\t\t\tapp.ui.echoerrf(\"%s\", err)\n\t\t\treturn\n\t\t}\n\tcase \"copy\":\n\t\tif err := app.nav.save(clipboardCopy); err != nil {\n\t\t\tapp.ui.echoerrf(\"copy: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tapp.nav.unselect()\n\t\tif gSingleMode {\n\t\t\tif err := app.nav.sync(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"copy: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t} else {\n\t\t\tif _, err := remote(\"send sync\"); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"copy: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\tcase \"cut\":\n\t\tif err := app.nav.save(clipboardCut); err != nil {\n\t\t\tapp.ui.echoerrf(\"cut: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tapp.nav.unselect()\n\t\tif gSingleMode {\n\t\t\tif err := app.nav.sync(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"cut: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t} else {\n\t\t\tif _, err := remote(\"send sync\"); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"cut: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\tcase \"paste\":\n\t\tif cmd, ok := gOpts.cmds[\"paste\"]; ok {\n\t\t\tcmd.eval(app, e.args)\n\t\t} else if err := app.nav.paste(app); err != nil {\n\t\t\tapp.ui.echoerrf(\"paste: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tapp.ui.loadFile(app, true)\n\tcase \"clear\":\n\t\tif err := saveFiles(clipboard{nil, clipboardCut}); err != nil {\n\t\t\tapp.ui.echoerrf(\"clear: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tif gSingleMode {\n\t\t\tif err := app.nav.sync(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"clear: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t} else {\n\t\t\tif _, err := remote(\"send sync\"); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"clear: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\tcase \"sync\":\n\t\tif err := app.nav.sync(); err != nil {\n\t\t\tapp.ui.echoerrf(\"sync: %s\", err)\n\t\t}\n\tcase \"draw\":\n\tcase \"redraw\":\n\t\tapp.ui.screen.Sync()\n\t\tapp.ui.renew()\n\t\tapp.nav.resize(app.ui)\n\t\tapp.ui.sxScreen.forceClear = true\n\t\tapp.ui.loadFile(app, true)\n\t\tonRedraw(app)\n\tcase \"load\":\n\t\tif gOpts.watch {\n\t\t\treturn\n\t\t}\n\t\tapp.nav.renew()\n\t\tapp.ui.loadFile(app, false)\n\tcase \"reload\":\n\t\tapp.nav.reload()\n\t\tapp.ui.loadFile(app, true)\n\tcase \"delete\":\n\t\tif cmd, ok := gOpts.cmds[\"delete\"]; ok {\n\t\t\tcmd.eval(app, e.args)\n\t\t\tapp.nav.unselect()\n\t\t\tif gSingleMode {\n\t\t\t\tapp.nav.renew()\n\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t} else {\n\t\t\t\tif _, err := remote(\"send load\"); err != nil {\n\t\t\t\t\tapp.ui.echoerrf(\"delete: %s\", err)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tlist, err := app.nav.currFileOrSelections()\n\t\t\tif err != nil {\n\t\t\t\tapp.ui.echoerrf(\"delete: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tnormal(app)\n\t\t\tif len(list) == 1 {\n\t\t\t\tapp.ui.cmdPrefix = \"delete '\" + list[0] + \"'? [y/N] \"\n\t\t\t} else {\n\t\t\t\tapp.ui.cmdPrefix = \"delete \" + strconv.Itoa(len(list)) + \" items? [y/N] \"\n\t\t\t}\n\t\t}\n\tcase \"rename\":\n\t\tif cmd, ok := gOpts.cmds[\"rename\"]; ok {\n\t\t\tcmd.eval(app, e.args)\n\t\t\tif gSingleMode {\n\t\t\t\tapp.nav.renew()\n\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t} else {\n\t\t\t\tif _, err := remote(\"send load\"); err != nil {\n\t\t\t\t\tapp.ui.echoerrf(\"rename: %s\", err)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tcurr := app.nav.currFile()\n\t\t\tif curr == nil {\n\t\t\t\tapp.ui.echoerr(\"rename: empty directory\")\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tnormal(app)\n\t\t\tapp.ui.cmdPrefix = \"rename: \"\n\t\t\textension := getFileExtension(curr)\n\t\t\tif len(extension) == 0 {\n\t\t\t\t// no extension or .hidden or is directory\n\t\t\t\tapp.ui.cmdAccLeft = curr.Name()\n\t\t\t} else {\n\t\t\t\tapp.ui.cmdAccLeft = strings.TrimSuffix(curr.Name(), extension)\n\t\t\t\tapp.ui.cmdAccRight = extension\n\t\t\t}\n\t\t}\n\tcase \"read\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.cmdPrefix = \":\"\n\tcase \"shell\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.cmdPrefix = \"$\"\n\tcase \"shell-pipe\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.cmdPrefix = \"%\"\n\tcase \"shell-wait\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.cmdPrefix = \"!\"\n\tcase \"shell-async\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.cmdPrefix = \"&\"\n\tcase \"find\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.cmdPrefix = \"find: \"\n\t\tapp.nav.findBack = false\n\tcase \"find-back\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.cmdPrefix = \"find-back: \"\n\t\tapp.nav.findBack = true\n\tcase \"find-next\":\n\t\tdir := app.nav.currDir()\n\t\told := dir.ind\n\t\tfor range e.count {\n\t\t\tif app.nav.findBack {\n\t\t\t\tapp.nav.findPrev()\n\t\t\t} else {\n\t\t\t\tapp.nav.findNext()\n\t\t\t}\n\t\t}\n\t\tif old != dir.ind {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"find-prev\":\n\t\tdir := app.nav.currDir()\n\t\told := dir.ind\n\t\tfor range e.count {\n\t\t\tif app.nav.findBack {\n\t\t\t\tapp.nav.findNext()\n\t\t\t} else {\n\t\t\t\tapp.nav.findPrev()\n\t\t\t}\n\t\t}\n\t\tif old != dir.ind {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"search\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.cmdPrefix = \"/\"\n\t\tdir := app.nav.currDir()\n\t\tapp.nav.searchInd = dir.ind\n\t\tapp.nav.searchPos = dir.pos\n\t\tapp.nav.searchBack = false\n\tcase \"search-back\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.cmdPrefix = \"?\"\n\t\tdir := app.nav.currDir()\n\t\tapp.nav.searchInd = dir.ind\n\t\tapp.nav.searchPos = dir.pos\n\t\tapp.nav.searchBack = true\n\tcase \"search-next\":\n\t\tfor range e.count {\n\t\t\tif app.nav.searchBack {\n\t\t\t\tif moved, err := app.nav.searchPrev(); err != nil {\n\t\t\t\t\tapp.ui.echoerrf(\"search-back: %s: %s\", err, app.nav.search)\n\t\t\t\t} else if moved {\n\t\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif moved, err := app.nav.searchNext(); err != nil {\n\t\t\t\t\tapp.ui.echoerrf(\"search: %s: %s\", err, app.nav.search)\n\t\t\t\t} else if moved {\n\t\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tcase \"search-prev\":\n\t\tfor range e.count {\n\t\t\tif app.nav.searchBack {\n\t\t\t\tif moved, err := app.nav.searchNext(); err != nil {\n\t\t\t\t\tapp.ui.echoerrf(\"search-back: %s: %s\", err, app.nav.search)\n\t\t\t\t} else if moved {\n\t\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif moved, err := app.nav.searchPrev(); err != nil {\n\t\t\t\t\tapp.ui.echoerrf(\"search: %s: %s\", err, app.nav.search)\n\t\t\t\t} else if moved {\n\t\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tcase \"filter\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.cmdPrefix = \"filter: \"\n\t\tdir := app.nav.currDir()\n\t\tapp.nav.prevFilter = dir.filter\n\t\tif len(e.args) == 0 {\n\t\t\tapp.ui.cmdAccLeft = strings.Join(dir.filter, \" \")\n\t\t} else {\n\t\t\tapp.ui.cmdAccLeft = strings.Join(e.args, \" \")\n\t\t}\n\tcase \"setfilter\":\n\t\tlog.Printf(\"filter: %s\", e.args)\n\t\tif err := app.nav.setFilter(e.args); err != nil {\n\t\t\tapp.ui.echoerrf(\"filter: %s\", err)\n\t\t}\n\t\tapp.ui.loadFile(app, true)\n\tcase \"mark-save\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.cmdPrefix = \"mark-save: \"\n\tcase \"mark-load\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.menu = listMarks(app.nav.marks)\n\t\tapp.ui.cmdPrefix = \"mark-load: \"\n\tcase \"mark-remove\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\t\tapp.ui.menu = listMarks(app.nav.marks)\n\t\tapp.ui.cmdPrefix = \"mark-remove: \"\n\tcase \"tag\":\n\t\ttag := \"*\"\n\t\tif len(e.args) != 0 {\n\t\t\ttag = e.args[0]\n\t\t}\n\n\t\tif err := app.nav.tag(tag); err != nil {\n\t\t\tapp.ui.echoerrf(\"tag: %s\", err)\n\t\t} else if err := app.nav.writeTags(); err != nil {\n\t\t\tapp.ui.echoerrf(\"tag: %s\", err)\n\t\t}\n\n\t\tif gSingleMode {\n\t\t\tif err := app.nav.sync(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"tag: %s\", err)\n\t\t\t}\n\t\t} else {\n\t\t\tif _, err := remote(\"send sync\"); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"tag: %s\", err)\n\t\t\t}\n\t\t}\n\tcase \"tag-toggle\":\n\t\ttag := \"*\"\n\t\tif len(e.args) != 0 {\n\t\t\ttag = e.args[0]\n\t\t}\n\n\t\tif err := app.nav.tagToggle(tag); err != nil {\n\t\t\tapp.ui.echoerrf(\"tag-toggle: %s\", err)\n\t\t} else if err := app.nav.writeTags(); err != nil {\n\t\t\tapp.ui.echoerrf(\"tag-toggle: %s\", err)\n\t\t}\n\n\t\tif gSingleMode {\n\t\t\tif err := app.nav.sync(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"tag-toggle: %s\", err)\n\t\t\t}\n\t\t} else {\n\t\t\tif _, err := remote(\"send sync\"); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"tag-toggle: %s\", err)\n\t\t\t}\n\t\t}\n\tcase \"echo\":\n\t\tapp.ui.echo(strings.Join(e.args, \" \"))\n\tcase \"echomsg\":\n\t\tapp.ui.echomsg(strings.Join(e.args, \" \"))\n\tcase \"echoerr\":\n\t\tapp.ui.echoerr(strings.Join(e.args, \" \"))\n\tcase \"cd\":\n\t\tpath := \"~\"\n\t\tif len(e.args) > 0 {\n\t\t\tpath = e.args[0]\n\t\t}\n\n\t\tif err := cd(app, path); err != nil {\n\t\t\tapp.ui.echoerrf(\"cd: %s\", err)\n\t\t}\n\tcase \"select\":\n\t\tif len(e.args) != 1 {\n\t\t\tapp.ui.echoerr(\"select: requires an argument\")\n\t\t\treturn\n\t\t}\n\n\t\tpath := replaceTilde(e.args[0])\n\t\tlstat, err := os.Lstat(path)\n\t\tif err != nil {\n\t\t\tapp.ui.echoerrf(\"select: %s\", err)\n\t\t\treturn\n\t\t}\n\n\t\tpath, err = filepath.Abs(replaceTilde(e.args[0]))\n\t\tif err != nil {\n\t\t\tapp.ui.echoerrf(\"select: %s\", err)\n\t\t\treturn\n\t\t}\n\n\t\tif err := cd(app, filepath.Dir(path)); err != nil {\n\t\t\tapp.ui.echoerrf(\"select: %s\", err)\n\t\t\treturn\n\t\t}\n\n\t\tdir := app.nav.currDir()\n\t\tapp.nav.checkDir(dir)\n\t\tif dir.loading {\n\t\t\tdir.files = append(dir.files, &file{FileInfo: lstat})\n\t\t}\n\t\tdir.sel(filepath.Base(path), app.nav.height)\n\t\tapp.ui.loadFile(app, true)\n\tcase \"source\":\n\t\tif len(e.args) != 1 {\n\t\t\tapp.ui.echoerr(\"source: requires an argument\")\n\t\t\treturn\n\t\t}\n\t\tapp.readFile(replaceTilde(e.args[0]))\n\tcase \"push\":\n\t\tif len(e.args) != 1 {\n\t\t\tapp.ui.echoerr(\"push: requires an argument\")\n\t\t\treturn\n\t\t}\n\t\tlog.Println(\"pushing keys\", e.args[0])\n\t\tfor _, val := range splitKeys(e.args[0]) {\n\t\t\tapp.ui.evChan <- parseKey(val)\n\t\t}\n\tcase \"addcustominfo\":\n\t\tvar k, v string\n\t\tswitch len(e.args) {\n\t\tcase 1:\n\t\t\tk, v = e.args[0], \"\"\n\t\tcase 2:\n\t\t\tk, v = e.args[0], e.args[1] // don't trim to allow for custom alignment\n\t\tdefault:\n\t\t\tapp.ui.echoerr(\"addcustominfo: requires either 1 or 2 arguments\")\n\t\t\treturn\n\t\t}\n\n\t\tpath, err := filepath.Abs(replaceTilde(k))\n\t\tif err != nil {\n\t\t\tapp.ui.echoerrf(\"addcustominfo: %s\", err)\n\t\t\treturn\n\t\t}\n\n\t\td := app.nav.getDir(filepath.Dir(path))\n\n\t\tvar f *file\n\t\tfor _, file := range d.allFiles {\n\t\t\tif file.path == path {\n\t\t\t\tf = file\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif f == nil {\n\t\t\tapp.ui.echoerrf(\"addcustominfo: file not found: %s\", path)\n\t\t\treturn\n\t\t}\n\n\t\tif f.customInfo != v {\n\t\t\tf.customInfo = v\n\t\t\t// only sort when order changes\n\t\t\tif getSortBy(d.path) == customSort {\n\t\t\t\td.sort()\n\t\t\t}\n\t\t}\n\tcase \"calcdirsize\":\n\t\terr := app.nav.calcDirSize()\n\t\tif err != nil {\n\t\t\tapp.ui.echoerrf(\"calcdirsize: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tapp.nav.sort()\n\tcase \"clearmaps\":\n\t\t// leave `:` and cmaps bound so the user can still exit using `:quit`\n\t\tclear(gOpts.nkeys)\n\t\tclear(gOpts.vkeys)\n\t\tgOpts.nkeys[\":\"] = &callExpr{\"read\", nil, 1}\n\t\tgOpts.vkeys[\":\"] = &callExpr{\"read\", nil, 1}\n\tcase \"tty-write\":\n\t\tif len(e.args) != 1 {\n\t\t\tapp.ui.echoerr(\"tty-write: requires an argument\")\n\t\t\treturn\n\t\t}\n\n\t\ttty, ok := app.ui.screen.Tty()\n\t\tif !ok {\n\t\t\tlog.Print(\"tty-write: failed to get tty\")\n\t\t\treturn\n\t\t}\n\n\t\ttty.Write([]byte(e.args[0]))\n\tcase \"visual\":\n\t\tdir := app.nav.currDir()\n\t\tdir.visualAnchor = dir.ind\n\t\tdir.visualWrap = 0\n\tcase \"visual-accept\":\n\t\tdir := app.nav.currDir()\n\t\tfor _, path := range dir.visualSelections() {\n\t\t\tif _, ok := app.nav.selections[path]; !ok {\n\t\t\t\tapp.nav.selections[path] = app.nav.selectionInd\n\t\t\t\tapp.nav.selectionInd++\n\t\t\t}\n\t\t}\n\t\t// resetting Visual mode here instead of inside `normal()`\n\t\t// allows us to use Visual mode inside search, find etc.\n\t\tdir.visualAnchor = -1\n\t\tnormal(app)\n\tcase \"visual-unselect\":\n\t\tdir := app.nav.currDir()\n\t\tfor _, path := range dir.visualSelections() {\n\t\t\tdelete(app.nav.selections, path)\n\t\t}\n\t\tif len(app.nav.selections) == 0 {\n\t\t\tapp.nav.selectionInd = 0\n\t\t}\n\t\tdir.visualAnchor = -1\n\t\tnormal(app)\n\tcase \"visual-discard\":\n\t\tdir := app.nav.currDir()\n\t\tdir.visualAnchor = -1\n\t\tnormal(app)\n\tcase \"visual-change\":\n\t\tif !app.nav.isVisualMode() {\n\t\t\treturn\n\t\t}\n\t\tdir := app.nav.currDir()\n\t\told := dir.ind\n\t\tbeg := max(dir.ind-dir.pos, 0)\n\t\tdir.ind, dir.visualAnchor = dir.visualAnchor, dir.ind\n\t\tdir.pos = dir.ind - beg\n\t\tdir.visualWrap = -dir.visualWrap\n\t\tdir.boundPos(app.nav.height)\n\t\tif old != dir.ind {\n\t\t\tapp.ui.loadFile(app, true)\n\t\t}\n\tcase \"cmd-insert\":\n\t\tif len(e.args) == 0 {\n\t\t\treturn\n\t\t}\n\t\tinsert(app, e.args[0])\n\tcase \"cmd-escape\":\n\t\tif app.ui.cmdPrefix == \">\" {\n\t\t\treturn\n\t\t}\n\t\tnormal(app)\n\tcase \"cmd-complete\":\n\t\tapp.doComplete()\n\tcase \"cmd-menu-complete\":\n\t\tapp.menuComplete(1)\n\tcase \"cmd-menu-complete-back\":\n\t\tapp.menuComplete(-1)\n\tcase \"cmd-menu-accept\":\n\t\texitCompMenu(app)\n\tcase \"cmd-menu-discard\":\n\t\tif app.menuCompActive {\n\t\t\tapp.ui.cmdAccLeft = strings.Join(app.menuCompTmp, \" \")\n\t\t}\n\t\texitCompMenu(app)\n\tcase \"cmd-enter\":\n\t\ts := app.ui.cmdAccLeft + app.ui.cmdAccRight\n\t\tif len(s) == 0 && app.ui.cmdPrefix != \"filter: \" && app.ui.cmdPrefix != \">\" {\n\t\t\treturn\n\t\t}\n\n\t\texitCompMenu(app)\n\n\t\tapp.ui.cmdAccLeft = \"\"\n\t\tapp.ui.cmdAccRight = \"\"\n\n\t\tswitch app.ui.cmdPrefix {\n\t\tcase \":\":\n\t\t\tlog.Printf(\"command: %s\", s)\n\t\t\tapp.cmdHistory = append(app.cmdHistory, app.ui.cmdPrefix+s)\n\t\t\tapp.ui.cmdPrefix = \"\"\n\t\t\tp := newParser(strings.NewReader(s))\n\t\t\tfor p.parse() {\n\t\t\t\tp.expr.eval(app, nil)\n\t\t\t}\n\t\t\tif p.err != nil {\n\t\t\t\tapp.ui.echoerrf(\"%s\", p.err)\n\t\t\t}\n\t\tcase \"$\":\n\t\t\tlog.Printf(\"shell: %s\", s)\n\t\t\tapp.cmdHistory = append(app.cmdHistory, app.ui.cmdPrefix+s)\n\t\t\tapp.ui.cmdPrefix = \"\"\n\t\t\tapp.runShell(s, nil, \"$\")\n\t\tcase \"%\":\n\t\t\tlog.Printf(\"shell-pipe: %s\", s)\n\t\t\tapp.cmdHistory = append(app.cmdHistory, app.ui.cmdPrefix+s)\n\t\t\tapp.runShell(s, nil, \"%\")\n\t\tcase \">\":\n\t\t\tio.WriteString(app.cmdIn, s+\"\\n\")\n\t\t\tapp.cmdOutBuf = nil\n\t\tcase \"!\":\n\t\t\tlog.Printf(\"shell-wait: %s\", s)\n\t\t\tapp.cmdHistory = append(app.cmdHistory, app.ui.cmdPrefix+s)\n\t\t\tapp.ui.cmdPrefix = \"\"\n\t\t\tapp.runShell(s, nil, \"!\")\n\t\tcase \"&\":\n\t\t\tlog.Printf(\"shell-async: %s\", s)\n\t\t\tapp.cmdHistory = append(app.cmdHistory, app.ui.cmdPrefix+s)\n\t\t\tapp.ui.cmdPrefix = \"\"\n\t\t\tapp.runShell(s, nil, \"&\")\n\t\tcase \"/\":\n\t\t\tdir := app.nav.currDir()\n\t\t\told := dir.ind\n\t\t\tif gOpts.incsearch {\n\t\t\t\tdir.ind = app.nav.searchInd\n\t\t\t\tdir.pos = app.nav.searchPos\n\t\t\t}\n\t\t\tlog.Printf(\"search: %s\", s)\n\t\t\tapp.ui.cmdPrefix = \"\"\n\t\t\tapp.nav.search = s\n\t\t\tif _, err := app.nav.searchNext(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"search: %s: %s\", err, app.nav.search)\n\t\t\t} else if old != dir.ind {\n\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t}\n\t\tcase \"?\":\n\t\t\tdir := app.nav.currDir()\n\t\t\told := dir.ind\n\t\t\tif gOpts.incsearch {\n\t\t\t\tdir.ind = app.nav.searchInd\n\t\t\t\tdir.pos = app.nav.searchPos\n\t\t\t}\n\t\t\tlog.Printf(\"search-back: %s\", s)\n\t\t\tapp.ui.cmdPrefix = \"\"\n\t\t\tapp.nav.search = s\n\t\t\tif _, err := app.nav.searchPrev(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"search-back: %s: %s\", err, app.nav.search)\n\t\t\t} else if old != dir.ind {\n\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t}\n\t\tcase \"filter: \":\n\t\t\tlog.Printf(\"filter: %s\", s)\n\t\t\tapp.ui.cmdPrefix = \"\"\n\t\t\tif err := app.nav.setFilter(strings.Split(s, \" \")); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"filter: %s\", err)\n\t\t\t}\n\t\t\tapp.ui.loadFile(app, true)\n\t\tcase \"find: \":\n\t\t\tapp.ui.cmdPrefix = \"\"\n\t\t\tif moved, found := app.nav.findNext(); !found {\n\t\t\t\tapp.ui.echoerrf(\"find: pattern not found: %s\", app.nav.find)\n\t\t\t} else if moved {\n\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t}\n\t\tcase \"find-back: \":\n\t\t\tapp.ui.cmdPrefix = \"\"\n\t\t\tif moved, found := app.nav.findPrev(); !found {\n\t\t\t\tapp.ui.echoerrf(\"find-back: pattern not found: %s\", app.nav.find)\n\t\t\t} else if moved {\n\t\t\t\tapp.ui.loadFile(app, true)\n\t\t\t}\n\t\tcase \"rename: \":\n\t\t\tapp.ui.cmdPrefix = \"\"\n\n\t\t\tcurr := app.nav.currFile()\n\t\t\tif curr == nil {\n\t\t\t\tapp.ui.echoerr(\"rename: empty directory\")\n\t\t\t\treturn\n\t\t\t}\n\t\t\twd, err := os.Getwd()\n\t\t\tif err != nil {\n\t\t\t\tlog.Printf(\"getting current directory: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\toldPath := filepath.Join(wd, curr.Name())\n\t\t\tnewPath := filepath.Clean(replaceTilde(s))\n\t\t\tif !filepath.IsAbs(newPath) {\n\t\t\t\tnewPath = filepath.Join(wd, newPath)\n\t\t\t}\n\t\t\tif oldPath == newPath {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tapp.nav.renameOldPath = oldPath\n\t\t\tapp.nav.renameNewPath = newPath\n\n\t\t\tnewDir := filepath.Dir(newPath)\n\t\t\tif _, err := os.Stat(newDir); os.IsNotExist(err) {\n\t\t\t\tapp.ui.cmdPrefix = \"create '\" + newDir + \"'? [y/N] \"\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\toldStat, err := os.Lstat(oldPath)\n\t\t\tif err != nil {\n\t\t\t\tapp.ui.echoerrf(\"rename: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif newStat, err := os.Lstat(newPath); !os.IsNotExist(err) && !os.SameFile(oldStat, newStat) {\n\t\t\t\tapp.ui.cmdPrefix = \"replace '\" + newPath + \"'? [y/N] \"\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif err := app.nav.rename(); err != nil {\n\t\t\t\tapp.ui.echoerrf(\"rename: %s\", err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif gSingleMode {\n\t\t\t\tapp.nav.renew()\n\t\t\t} else {\n\t\t\t\tif _, err := remote(\"send load\"); err != nil {\n\t\t\t\t\tapp.ui.echoerrf(\"rename: %s\", err)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t\tapp.ui.loadFile(app, true)\n\t\tdefault:\n\t\t\tlog.Printf(\"entering unknown execution prefix: %q\", app.ui.cmdPrefix)\n\t\t}\n\tcase \"cmd-interrupt\":\n\t\tif app.cmd != nil {\n\t\t\terr := shellKill(app.cmd)\n\t\t\tif err != nil {\n\t\t\t\tapp.ui.echoerrf(\"kill: %s\", err)\n\t\t\t} else {\n\t\t\t\tapp.ui.echoerr(\"process interrupt\")\n\t\t\t}\n\t\t}\n\t\tnormal(app)\n\tcase \"cmd-history-next\":\n\t\tif !slices.Contains([]string{\":\", \"$\", \"!\", \"%\", \"&\"}, app.ui.cmdPrefix) {\n\t\t\treturn\n\t\t}\n\t\tinput := app.ui.cmdPrefix + app.ui.cmdAccLeft\n\t\tif app.cmdHistoryInput == nil {\n\t\t\tapp.cmdHistoryInput = &input\n\t\t}\n\t\tfor i := app.cmdHistoryInd - 1; i >= 0; i-- {\n\t\t\tif i == 0 {\n\t\t\t\tif *app.cmdHistoryInput == \"\" {\n\t\t\t\t\tnormal(app)\n\t\t\t\t} else {\n\t\t\t\t\texitCompMenu(app)\n\t\t\t\t\tapp.ui.cmdAccLeft = \"\"\n\t\t\t\t\tapp.cmdHistoryInd = 0\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcmd := app.cmdHistory[len(app.cmdHistory)-i]\n\t\t\tif strings.HasPrefix(cmd, *app.cmdHistoryInput) && cmd != input {\n\t\t\t\texitCompMenu(app)\n\t\t\t\tapp.ui.cmdPrefix = cmd[:1]\n\t\t\t\tapp.ui.cmdAccLeft = cmd[1:]\n\t\t\t\tapp.cmdHistoryInd = i\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\tcase \"cmd-history-prev\":\n\t\tif !slices.Contains([]string{\":\", \"$\", \"!\", \"%\", \"&\", \"\"}, app.ui.cmdPrefix) {\n\t\t\treturn\n\t\t}\n\t\tinput := app.ui.cmdPrefix + app.ui.cmdAccLeft\n\t\tif app.cmdHistoryInput == nil {\n\t\t\tapp.cmdHistoryInput = &input\n\t\t}\n\t\tfor i := app.cmdHistoryInd + 1; i <= len(app.cmdHistory); i++ {\n\t\t\tcmd := app.cmdHistory[len(app.cmdHistory)-i]\n\t\t\tif strings.HasPrefix(cmd, *app.cmdHistoryInput) && cmd != input {\n\t\t\t\texitCompMenu(app)\n\t\t\t\tapp.ui.cmdPrefix = cmd[:1]\n\t\t\t\tapp.ui.cmdAccLeft = cmd[1:]\n\t\t\t\tapp.cmdHistoryInd = i\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\tcase \"cmd-left\":\n\t\tif app.ui.cmdAccLeft == \"\" {\n\t\t\treturn\n\t\t}\n\t\tlast := lastGraphemeCluster(app.ui.cmdAccLeft)\n\t\tapp.ui.cmdAccLeft = strings.TrimSuffix(app.ui.cmdAccLeft, last)\n\t\tapp.ui.cmdAccRight = last + app.ui.cmdAccRight\n\tcase \"cmd-right\":\n\t\tif app.ui.cmdAccRight == \"\" {\n\t\t\treturn\n\t\t}\n\t\tfirst := firstGraphemeCluster(app.ui.cmdAccRight)\n\t\tapp.ui.cmdAccLeft += first\n\t\tapp.ui.cmdAccRight = strings.TrimPrefix(app.ui.cmdAccRight, first)\n\tcase \"cmd-home\":\n\t\tapp.ui.cmdAccRight = app.ui.cmdAccLeft + app.ui.cmdAccRight\n\t\tapp.ui.cmdAccLeft = \"\"\n\tcase \"cmd-end\":\n\t\tapp.ui.cmdAccLeft += app.ui.cmdAccRight\n\t\tapp.ui.cmdAccRight = \"\"\n\tcase \"cmd-delete\":\n\t\tif app.ui.cmdAccRight == \"\" {\n\t\t\treturn\n\t\t}\n\t\tfirst := firstGraphemeCluster(app.ui.cmdAccRight)\n\t\tapp.ui.cmdAccRight = strings.TrimPrefix(app.ui.cmdAccRight, first)\n\t\tupdate(app)\n\tcase \"cmd-delete-back\":\n\t\tif app.ui.cmdAccLeft == \"\" {\n\t\t\tswitch app.ui.cmdPrefix {\n\t\t\tcase \"!\", \"$\", \"%\", \"&\":\n\t\t\t\tapp.ui.cmdPrefix = \":\"\n\t\t\t\tapp.cmdHistoryInd = 0\n\t\t\t\tapp.cmdHistoryInput = nil\n\t\t\tcase \">\", \"rename: \", \"filter: \":\n\t\t\t\t// Don't mess with programs waiting for input.\n\t\t\t\t// Exiting on backspace is also inconvenient for 'rename' and 'filter',\n\t\t\t\t// since the text field can start out nonempty.\n\t\t\tdefault:\n\t\t\t\tnormal(app)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tlast := lastGraphemeCluster(app.ui.cmdAccLeft)\n\t\tapp.ui.cmdAccLeft = strings.TrimSuffix(app.ui.cmdAccLeft, last)\n\t\tupdate(app)\n\tcase \"cmd-delete-home\":\n\t\tif app.ui.cmdAccLeft == \"\" {\n\t\t\treturn\n\t\t}\n\t\tapp.ui.cmdYankBuf = app.ui.cmdAccLeft\n\t\tapp.ui.cmdAccLeft = \"\"\n\t\tupdate(app)\n\tcase \"cmd-delete-end\":\n\t\tif app.ui.cmdAccRight == \"\" {\n\t\t\treturn\n\t\t}\n\t\tapp.ui.cmdYankBuf = app.ui.cmdAccRight\n\t\tapp.ui.cmdAccRight = \"\"\n\t\tupdate(app)\n\tcase \"cmd-delete-unix-word\":\n\t\tind := strings.LastIndex(strings.TrimRight(app.ui.cmdAccLeft, \" \"), \" \") + 1\n\t\tapp.ui.cmdYankBuf = app.ui.cmdAccLeft[ind:]\n\t\tapp.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]\n\t\tupdate(app)\n\tcase \"cmd-yank\":\n\t\tapp.ui.cmdAccLeft += app.ui.cmdYankBuf\n\t\tupdate(app)\n\tcase \"cmd-transpose\":\n\t\tvar c []string\n\t\tgr := uniseg.NewGraphemes(app.ui.cmdAccLeft)\n\t\tfor gr.Next() {\n\t\t\tc = append(c, gr.Str())\n\t\t}\n\n\t\tfirst := firstGraphemeCluster(app.ui.cmdAccRight)\n\t\tif first != \"\" {\n\t\t\tc = append(c, first)\n\t\t}\n\n\t\tif len(c) < 2 {\n\t\t\treturn\n\t\t}\n\n\t\tapp.ui.cmdAccRight = strings.TrimPrefix(app.ui.cmdAccRight, first)\n\n\t\tc[len(c)-1], c[len(c)-2] = c[len(c)-2], c[len(c)-1]\n\t\tapp.ui.cmdAccLeft = strings.Join(c, \"\")\n\t\tupdate(app)\n\tcase \"cmd-transpose-word\":\n\t\tif app.ui.cmdAccLeft == \"\" {\n\t\t\treturn\n\t\t}\n\n\t\tlocs := reWord.FindAllStringIndex(app.ui.cmdAccLeft, -1)\n\t\tif len(locs) < 2 {\n\t\t\treturn\n\t\t}\n\n\t\tif app.ui.cmdAccRight != \"\" {\n\t\t\tloc := reWordEnd.FindStringSubmatchIndex(app.ui.cmdAccRight)\n\t\t\tif loc != nil {\n\t\t\t\tind := loc[3]\n\t\t\t\tapp.ui.cmdAccLeft += app.ui.cmdAccRight[:ind]\n\t\t\t\tapp.ui.cmdAccRight = app.ui.cmdAccRight[ind:]\n\t\t\t}\n\t\t}\n\n\t\tlocs = reWord.FindAllStringIndex(app.ui.cmdAccLeft, -1)\n\n\t\tbeg1, end1 := locs[len(locs)-2][0], locs[len(locs)-2][1]\n\t\tbeg2, end2 := locs[len(locs)-1][0], locs[len(locs)-1][1]\n\n\t\tapp.ui.cmdAccLeft = app.ui.cmdAccLeft[:beg1] +\n\t\t\tapp.ui.cmdAccLeft[beg2:end2] +\n\t\t\tapp.ui.cmdAccLeft[end1:beg2] +\n\t\t\tapp.ui.cmdAccLeft[beg1:end1] +\n\t\t\tapp.ui.cmdAccLeft[end2:]\n\t\tupdate(app)\n\tcase \"cmd-word\":\n\t\tif app.ui.cmdAccRight == \"\" {\n\t\t\treturn\n\t\t}\n\t\tloc := reWordEnd.FindStringSubmatchIndex(app.ui.cmdAccRight)\n\t\tif loc == nil {\n\t\t\treturn\n\t\t}\n\t\tind := loc[3]\n\t\tapp.ui.cmdAccLeft += app.ui.cmdAccRight[:ind]\n\t\tapp.ui.cmdAccRight = app.ui.cmdAccRight[ind:]\n\tcase \"cmd-word-back\":\n\t\tif app.ui.cmdAccLeft == \"\" {\n\t\t\treturn\n\t\t}\n\t\tlocs := reWordBeg.FindAllStringSubmatchIndex(app.ui.cmdAccLeft, -1)\n\t\tif locs == nil {\n\t\t\treturn\n\t\t}\n\t\tind := locs[len(locs)-1][3]\n\t\tapp.ui.cmdAccRight = app.ui.cmdAccLeft[ind:] + app.ui.cmdAccRight\n\t\tapp.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]\n\tcase \"cmd-delete-word\":\n\t\tif app.ui.cmdAccRight == \"\" {\n\t\t\treturn\n\t\t}\n\t\tloc := reWordEnd.FindStringSubmatchIndex(app.ui.cmdAccRight)\n\t\tif loc == nil {\n\t\t\treturn\n\t\t}\n\t\tind := loc[3]\n\t\tapp.ui.cmdYankBuf = app.ui.cmdAccRight[:ind]\n\t\tapp.ui.cmdAccRight = app.ui.cmdAccRight[ind:]\n\t\tupdate(app)\n\tcase \"cmd-delete-word-back\":\n\t\tif app.ui.cmdAccLeft == \"\" {\n\t\t\treturn\n\t\t}\n\t\tlocs := reWordBeg.FindAllStringSubmatchIndex(app.ui.cmdAccLeft, -1)\n\t\tif locs == nil {\n\t\t\treturn\n\t\t}\n\t\tind := locs[len(locs)-1][3]\n\t\tapp.ui.cmdYankBuf = app.ui.cmdAccLeft[ind:]\n\t\tapp.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]\n\t\tupdate(app)\n\tcase \"cmd-capitalize-word\":\n\t\tif app.ui.cmdAccRight == \"\" {\n\t\t\treturn\n\t\t}\n\t\tloc := reWordEnd.FindStringSubmatchIndex(app.ui.cmdAccRight)\n\t\tif loc == nil {\n\t\t\treturn\n\t\t}\n\t\tind := loc[3]\n\t\tcapitalize := func(s string) string {\n\t\t\trunes := []rune(s)\n\t\t\tfor i, r := range runes {\n\t\t\t\tif !unicode.IsSpace(r) {\n\t\t\t\t\trunes[i] = unicode.ToUpper(r)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn string(runes)\n\t\t}\n\t\tapp.ui.cmdAccLeft += capitalize(app.ui.cmdAccRight[:ind])\n\t\tapp.ui.cmdAccRight = app.ui.cmdAccRight[ind:]\n\t\tupdate(app)\n\tcase \"cmd-uppercase-word\":\n\t\tif app.ui.cmdAccRight == \"\" {\n\t\t\treturn\n\t\t}\n\t\tloc := reWordEnd.FindStringSubmatchIndex(app.ui.cmdAccRight)\n\t\tif loc == nil {\n\t\t\treturn\n\t\t}\n\t\tind := loc[3]\n\t\tapp.ui.cmdAccLeft += strings.ToUpper(app.ui.cmdAccRight[:ind])\n\t\tapp.ui.cmdAccRight = app.ui.cmdAccRight[ind:]\n\t\tupdate(app)\n\tcase \"cmd-lowercase-word\":\n\t\tif app.ui.cmdAccRight == \"\" {\n\t\t\treturn\n\t\t}\n\t\tloc := reWordEnd.FindStringSubmatchIndex(app.ui.cmdAccRight)\n\t\tif loc == nil {\n\t\t\treturn\n\t\t}\n\t\tind := loc[3]\n\t\tapp.ui.cmdAccLeft += strings.ToLower(app.ui.cmdAccRight[:ind])\n\t\tapp.ui.cmdAccRight = app.ui.cmdAccRight[ind:]\n\t\tupdate(app)\n\tcase \"on-focus-gained\":\n\t\tonFocusGained(app)\n\tcase \"on-focus-lost\":\n\t\tonFocusLost(app)\n\tcase \"on-init\":\n\t\tonInit(app)\n\tdefault:\n\t\tcmd, ok := gOpts.cmds[e.name]\n\t\tif !ok {\n\t\t\tapp.ui.echoerrf(\"command not found: %s\", e.name)\n\t\t\treturn\n\t\t}\n\t\tcmd.eval(app, e.args)\n\t}\n}\n\nfunc (e *execExpr) eval(app *app, args []string) {\n\tswitch e.prefix {\n\tcase \"$\":\n\t\tlog.Printf(\"shell: %s -- %s\", e, args)\n\t\tapp.runShell(e.value, args, e.prefix)\n\tcase \"%\":\n\t\tlog.Printf(\"shell-pipe: %s -- %s\", e, args)\n\t\tapp.runShell(e.value, args, e.prefix)\n\tcase \"!\":\n\t\tlog.Printf(\"shell-wait: %s -- %s\", e, args)\n\t\tapp.runShell(e.value, args, e.prefix)\n\tcase \"&\":\n\t\tlog.Printf(\"shell-async: %s -- %s\", e, args)\n\t\tapp.runShell(e.value, args, e.prefix)\n\tdefault:\n\t\tlog.Printf(\"evaluating unknown execution prefix: %q\", e.prefix)\n\t}\n}\n\nfunc (e *listExpr) eval(app *app, _ []string) {\n\tfor range e.count {\n\t\tfor _, expr := range e.exprs {\n\t\t\texpr.eval(app, nil)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "eval_test.go",
    "content": "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  []string\n\texprs []expr\n}{\n\t{\n\t\t\"\",\n\t\t[]string{},\n\t\tnil,\n\t},\n\n\t{\n\t\t\"# comments start with '#'\",\n\t\t[]string{},\n\t\tnil,\n\t},\n\n\t{\n\t\t\"echo hello\",\n\t\t[]string{\"echo\", \"hello\", \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{\"hello\"}, 1}},\n\t},\n\n\t{\n\t\t\"echo hello world\",\n\t\t[]string{\"echo\", \"hello\", \"world\", \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{\"hello\", \"world\"}, 1}},\n\t},\n\n\t{\n\t\t\"echo 'hello world'\",\n\t\t[]string{\"echo\", \"hello world\", \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{\"hello world\"}, 1}},\n\t},\n\n\t{\n\t\t`echo \"hello world\"`,\n\t\t[]string{\"echo\", \"hello world\", \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{\"hello world\"}, 1}},\n\t},\n\n\t{\n\t\t`echo \"hello\\\"world\"`,\n\t\t[]string{\"echo\", `hello\"world`, \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{`hello\"world`}, 1}},\n\t},\n\n\t{\n\t\t`echo \"hello\\tworld\"`,\n\t\t[]string{\"echo\", \"hello\\tworld\", \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{\"hello\\tworld\"}, 1}},\n\t},\n\n\t{\n\t\t`echo \"hello\\nworld\"`,\n\t\t[]string{\"echo\", \"hello\\nworld\", \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{\"hello\\nworld\"}, 1}},\n\t},\n\n\t{\n\t\t`echo \"hello\\zworld\"`,\n\t\t[]string{\"echo\", `hello\\zworld`, \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{`hello\\zworld`}, 1}},\n\t},\n\n\t{\n\t\t`echo \"hello\\0world\"`,\n\t\t[]string{\"echo\", \"hello\\000world\", \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{\"hello\\000world\"}, 1}},\n\t},\n\n\t{\n\t\t`echo \"hello\\101world\"`,\n\t\t[]string{\"echo\", \"hello\\101world\", \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{\"hello\\101world\"}, 1}},\n\t},\n\n\t{\n\t\t`echo hello\\ world`,\n\t\t[]string{\"echo\", \"hello world\", \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{\"hello world\"}, 1}},\n\t},\n\n\t{\n\t\t\"echo hello\\\\\\tworld\",\n\t\t[]string{\"echo\", \"hello\\tworld\", \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{\"hello\\tworld\"}, 1}},\n\t},\n\n\t{\n\t\t\"echo hello\\\\\\nworld\",\n\t\t[]string{\"echo\", \"hello\\nworld\", \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{\"hello\\nworld\"}, 1}},\n\t},\n\n\t{\n\t\t`echo hello\\\\world`,\n\t\t[]string{\"echo\", `hello\\world`, \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{`hello\\world`}, 1}},\n\t},\n\n\t{\n\t\t`echo hello\\zworld`,\n\t\t[]string{\"echo\", \"hellozworld\", \"\\n\"},\n\t\t[]expr{&callExpr{\"echo\", []string{\"hellozworld\"}, 1}},\n\t},\n\n\t{\n\t\t\"set hidden # trailing comments are allowed\",\n\t\t[]string{\"set\", \"hidden\", \"\\n\"},\n\t\t[]expr{&setExpr{\"hidden\", \"\"}},\n\t},\n\n\t{\n\t\t\"set hidden; set preview\",\n\t\t[]string{\"set\", \"hidden\", \";\", \"set\", \"preview\", \"\\n\"},\n\t\t[]expr{&setExpr{\"hidden\", \"\"}, &setExpr{\"preview\", \"\"}},\n\t},\n\n\t{\n\t\t\"set hidden\\nset preview\",\n\t\t[]string{\"set\", \"hidden\", \"\\n\", \"set\", \"preview\", \"\\n\"},\n\t\t[]expr{&setExpr{\"hidden\", \"\"}, &setExpr{\"preview\", \"\"}},\n\t},\n\n\t{\n\t\t`set ifs \"\"`,\n\t\t[]string{\"set\", \"ifs\", \"\", \"\\n\"},\n\t\t[]expr{&setExpr{\"ifs\", \"\"}},\n\t},\n\n\t{\n\t\t`set ifs \"\\n\"`,\n\t\t[]string{\"set\", \"ifs\", \"\\n\", \"\\n\"},\n\t\t[]expr{&setExpr{\"ifs\", \"\\n\"}},\n\t},\n\n\t{\n\t\t\"set ratios 1:2:3\",\n\t\t[]string{\"set\", \"ratios\", \"1:2:3\", \"\\n\"},\n\t\t[]expr{&setExpr{\"ratios\", \"1:2:3\"}},\n\t},\n\n\t{\n\t\t\"set ratios 1:2:3;\",\n\t\t[]string{\"set\", \"ratios\", \"1:2:3\", \";\"},\n\t\t[]expr{&setExpr{\"ratios\", \"1:2:3\"}},\n\t},\n\n\t{\n\t\t\":set ratios 1:2:3\",\n\t\t[]string{\":\", \"set\", \"ratios\", \"1:2:3\", \"\\n\", \"\\n\"},\n\t\t[]expr{&listExpr{[]expr{&setExpr{\"ratios\", \"1:2:3\"}}, 1}},\n\t},\n\n\t{\n\t\t\":set ratios 1:2:3\\nset hidden\",\n\t\t[]string{\":\", \"set\", \"ratios\", \"1:2:3\", \"\\n\", \"\\n\", \"set\", \"hidden\", \"\\n\"},\n\t\t[]expr{&listExpr{[]expr{&setExpr{\"ratios\", \"1:2:3\"}}, 1}, &setExpr{\"hidden\", \"\"}},\n\t},\n\n\t{\n\t\t\":set ratios 1:2:3;\",\n\t\t[]string{\":\", \"set\", \"ratios\", \"1:2:3\", \";\", \"\\n\"},\n\t\t[]expr{&listExpr{[]expr{&setExpr{\"ratios\", \"1:2:3\"}}, 1}},\n\t},\n\n\t{\n\t\t\":set ratios 1:2:3;\\nset hidden\",\n\t\t[]string{\":\", \"set\", \"ratios\", \"1:2:3\", \";\", \"\\n\", \"set\", \"hidden\", \"\\n\"},\n\t\t[]expr{&listExpr{[]expr{&setExpr{\"ratios\", \"1:2:3\"}}, 1}, &setExpr{\"hidden\", \"\"}},\n\t},\n\n\t{\n\t\t\"set ratios 1:2:3\\n set hidden\",\n\t\t[]string{\"set\", \"ratios\", \"1:2:3\", \"\\n\", \"set\", \"hidden\", \"\\n\"},\n\t\t[]expr{&setExpr{\"ratios\", \"1:2:3\"}, &setExpr{\"hidden\", \"\"}},\n\t},\n\n\t{\n\t\t\"set ratios 1:2:3 \\nset hidden\",\n\t\t[]string{\"set\", \"ratios\", \"1:2:3\", \"\\n\", \"set\", \"hidden\", \"\\n\"},\n\t\t[]expr{&setExpr{\"ratios\", \"1:2:3\"}, &setExpr{\"hidden\", \"\"}},\n\t},\n\n\t{\n\t\t\"setlocal /foo/bar hidden # trailing comments are allowed\",\n\t\t[]string{\"setlocal\", \"/foo/bar\", \"hidden\", \"\\n\"},\n\t\t[]expr{&setLocalExpr{\"/foo/bar\", \"hidden\", \"\"}},\n\t},\n\n\t{\n\t\t\"setlocal /foo/bar hidden; setlocal /foo/bar reverse\",\n\t\t[]string{\"setlocal\", \"/foo/bar\", \"hidden\", \";\", \"setlocal\", \"/foo/bar\", \"reverse\", \"\\n\"},\n\t\t[]expr{&setLocalExpr{\"/foo/bar\", \"hidden\", \"\"}, &setLocalExpr{\"/foo/bar\", \"reverse\", \"\"}},\n\t},\n\n\t{\n\t\t\"setlocal /foo/bar hidden\\nsetlocal /foo/bar reverse\",\n\t\t[]string{\"setlocal\", \"/foo/bar\", \"hidden\", \"\\n\", \"setlocal\", \"/foo/bar\", \"reverse\", \"\\n\"},\n\t\t[]expr{&setLocalExpr{\"/foo/bar\", \"hidden\", \"\"}, &setLocalExpr{\"/foo/bar\", \"reverse\", \"\"}},\n\t},\n\n\t{\n\t\t`setlocal /foo/bar info \"\"`,\n\t\t[]string{\"setlocal\", \"/foo/bar\", \"info\", \"\", \"\\n\"},\n\t\t[]expr{&setLocalExpr{\"/foo/bar\", \"info\", \"\"}},\n\t},\n\n\t{\n\t\t`setlocal /foo/bar info \"size\"`,\n\t\t[]string{\"setlocal\", \"/foo/bar\", \"info\", \"size\", \"\\n\"},\n\t\t[]expr{&setLocalExpr{\"/foo/bar\", \"info\", \"size\"}},\n\t},\n\n\t{\n\t\t\"setlocal /foo/bar info size:time\",\n\t\t[]string{\"setlocal\", \"/foo/bar\", \"info\", \"size:time\", \"\\n\"},\n\t\t[]expr{&setLocalExpr{\"/foo/bar\", \"info\", \"size:time\"}},\n\t},\n\n\t{\n\t\t\"setlocal /foo/bar info size:time;\",\n\t\t[]string{\"setlocal\", \"/foo/bar\", \"info\", \"size:time\", \";\"},\n\t\t[]expr{&setLocalExpr{\"/foo/bar\", \"info\", \"size:time\"}},\n\t},\n\n\t{\n\t\t\":setlocal /foo/bar info size:time\",\n\t\t[]string{\":\", \"setlocal\", \"/foo/bar\", \"info\", \"size:time\", \"\\n\", \"\\n\"},\n\t\t[]expr{&listExpr{[]expr{&setLocalExpr{\"/foo/bar\", \"info\", \"size:time\"}}, 1}},\n\t},\n\n\t{\n\t\t\":setlocal /foo/bar info size:time\\nsetlocal /foo/bar hidden\",\n\t\t[]string{\":\", \"setlocal\", \"/foo/bar\", \"info\", \"size:time\", \"\\n\", \"\\n\", \"setlocal\", \"/foo/bar\", \"hidden\", \"\\n\"},\n\t\t[]expr{&listExpr{[]expr{&setLocalExpr{\"/foo/bar\", \"info\", \"size:time\"}}, 1}, &setLocalExpr{\"/foo/bar\", \"hidden\", \"\"}},\n\t},\n\n\t{\n\t\t\":setlocal /foo/bar info size:time;\",\n\t\t[]string{\":\", \"setlocal\", \"/foo/bar\", \"info\", \"size:time\", \";\", \"\\n\"},\n\t\t[]expr{&listExpr{[]expr{&setLocalExpr{\"/foo/bar\", \"info\", \"size:time\"}}, 1}},\n\t},\n\n\t{\n\t\t\":setlocal /foo/bar info size:time;\\nsetlocal /foo/bar hidden\",\n\t\t[]string{\":\", \"setlocal\", \"/foo/bar\", \"info\", \"size:time\", \";\", \"\\n\", \"setlocal\", \"/foo/bar\", \"hidden\", \"\\n\"},\n\t\t[]expr{&listExpr{[]expr{&setLocalExpr{\"/foo/bar\", \"info\", \"size:time\"}}, 1}, &setLocalExpr{\"/foo/bar\", \"hidden\", \"\"}},\n\t},\n\n\t{\n\t\t\"setlocal /foo/bar info size:time\\n setlocal /foo/bar hidden\",\n\t\t[]string{\"setlocal\", \"/foo/bar\", \"info\", \"size:time\", \"\\n\", \"setlocal\", \"/foo/bar\", \"hidden\", \"\\n\"},\n\t\t[]expr{&setLocalExpr{\"/foo/bar\", \"info\", \"size:time\"}, &setLocalExpr{\"/foo/bar\", \"hidden\", \"\"}},\n\t},\n\n\t{\n\t\t\"setlocal /foo/bar info size:time \\nsetlocal /foo/bar hidden\",\n\t\t[]string{\"setlocal\", \"/foo/bar\", \"info\", \"size:time\", \"\\n\", \"setlocal\", \"/foo/bar\", \"hidden\", \"\\n\"},\n\t\t[]expr{&setLocalExpr{\"/foo/bar\", \"info\", \"size:time\"}, &setLocalExpr{\"/foo/bar\", \"hidden\", \"\"}},\n\t},\n\n\t{\n\t\t\"map gh cd ~\",\n\t\t[]string{\"map\", \"gh\", \"cd\", \"~\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"gh\", &callExpr{\"cd\", []string{\"~\"}, 1}}},\n\t},\n\n\t{\n\t\t\"map gh cd ~;\",\n\t\t[]string{\"map\", \"gh\", \"cd\", \"~\", \";\"},\n\t\t[]expr{&mapExpr{\"gh\", &callExpr{\"cd\", []string{\"~\"}, 1}}},\n\t},\n\n\t{\n\t\t\"map gh :cd ~\",\n\t\t[]string{\"map\", \"gh\", \":\", \"cd\", \"~\", \"\\n\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"gh\", &listExpr{[]expr{&callExpr{\"cd\", []string{\"~\"}, 1}}, 1}}},\n\t},\n\n\t{\n\t\t\"map gh :cd ~;\",\n\t\t[]string{\"map\", \"gh\", \":\", \"cd\", \"~\", \";\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"gh\", &listExpr{[]expr{&callExpr{\"cd\", []string{\"~\"}, 1}}, 1}}},\n\t},\n\n\t{\n\t\t\"nmap <space> :toggle; down\",\n\t\t[]string{\"nmap\", \"<space>\", \":\", \"toggle\", \";\", \"down\", \"\\n\", \"\\n\"},\n\t\t[]expr{&nmapExpr{\"<space>\", &listExpr{[]expr{&callExpr{\"toggle\", nil, 1}, &callExpr{\"down\", nil, 1}}, 1}}},\n\t},\n\n\t{\n\t\t\"vmap <esc> visual-accept\",\n\t\t[]string{\"vmap\", \"<esc>\", \"visual-accept\", \"\\n\"},\n\t\t[]expr{&vmapExpr{\"<esc>\", &callExpr{\"visual-accept\", nil, 1}}},\n\t},\n\n\t{\n\t\t\"cmap <c-g> cmd-escape\",\n\t\t[]string{\"cmap\", \"<c-g>\", \"cmd-escape\", \"\\n\"},\n\t\t[]expr{&cmapExpr{\"<c-g>\", &callExpr{\"cmd-escape\", nil, 1}}},\n\t},\n\n\t{\n\t\t\"cmd usage $du -h . | less\",\n\t\t[]string{\"cmd\", \"usage\", \"$\", \"du -h . | less\", \"\\n\"},\n\t\t[]expr{&cmdExpr{\"usage\", &execExpr{\"$\", \"du -h . | less\"}}},\n\t},\n\n\t{\n\t\t\"cmd 世界 $echo 世界\",\n\t\t[]string{\"cmd\", \"世界\", \"$\", \"echo 世界\", \"\\n\"},\n\t\t[]expr{&cmdExpr{\"世界\", &execExpr{\"$\", \"echo 世界\"}}},\n\t},\n\n\t{\n\t\t\"map u usage\",\n\t\t[]string{\"map\", \"u\", \"usage\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"u\", &callExpr{\"usage\", nil, 1}}},\n\t},\n\n\t{\n\t\t\"map u usage;\",\n\t\t[]string{\"map\", \"u\", \"usage\", \";\"},\n\t\t[]expr{&mapExpr{\"u\", &callExpr{\"usage\", nil, 1}}},\n\t},\n\n\t{\n\t\t\"map u :usage\",\n\t\t[]string{\"map\", \"u\", \":\", \"usage\", \"\\n\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"u\", &listExpr{[]expr{&callExpr{\"usage\", nil, 1}}, 1}}},\n\t},\n\n\t{\n\t\t\"map u :usage;\",\n\t\t[]string{\"map\", \"u\", \":\", \"usage\", \";\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"u\", &listExpr{[]expr{&callExpr{\"usage\", nil, 1}}, 1}}},\n\t},\n\n\t{\n\t\t\"map r push :rename<space>\",\n\t\t[]string{\"map\", \"r\", \"push\", \":rename<space>\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"r\", &callExpr{\"push\", []string{\":rename<space>\"}, 1}}},\n\t},\n\n\t{\n\t\t\"map r push :rename<space>;\",\n\t\t[]string{\"map\", \"r\", \"push\", \":rename<space>;\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"r\", &callExpr{\"push\", []string{\":rename<space>;\"}, 1}}},\n\t},\n\n\t{\n\t\t\"map r push :rename<space> # trailing comments are allowed after a space\",\n\t\t[]string{\"map\", \"r\", \"push\", \":rename<space>\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"r\", &callExpr{\"push\", []string{\":rename<space>\"}, 1}}},\n\t},\n\n\t{\n\t\t\"map r :push :rename<space>\",\n\t\t[]string{\"map\", \"r\", \":\", \"push\", \":rename<space>\", \"\\n\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"r\", &listExpr{[]expr{&callExpr{\"push\", []string{\":rename<space>\"}, 1}}, 1}}},\n\t},\n\n\t{\n\t\t\"map r :push :rename<space> ; set hidden\",\n\t\t[]string{\"map\", \"r\", \":\", \"push\", \":rename<space>\", \";\", \"set\", \"hidden\", \"\\n\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"r\", &listExpr{[]expr{&callExpr{\"push\", []string{\":rename<space>\"}, 1}, &setExpr{\"hidden\", \"\"}}, 1}}},\n\t},\n\n\t{\n\t\t\"map u $du -h . | less\",\n\t\t[]string{\"map\", \"u\", \"$\", \"du -h . | less\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"u\", &execExpr{\"$\", \"du -h . | less\"}}},\n\t},\n\n\t{\n\t\t\"cmd usage $du -h $1 | less\",\n\t\t[]string{\"cmd\", \"usage\", \"$\", \"du -h $1 | less\", \"\\n\"},\n\t\t[]expr{&cmdExpr{\"usage\", &execExpr{\"$\", \"du -h $1 | less\"}}},\n\t},\n\n\t{\n\t\t\"map u usage /\",\n\t\t[]string{\"map\", \"u\", \"usage\", \"/\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"u\", &callExpr{\"usage\", []string{\"/\"}, 1}}},\n\t},\n\n\t{\n\t\t\"map ss :set sortby size; set info size\",\n\t\t[]string{\"map\", \"ss\", \":\", \"set\", \"sortby\", \"size\", \";\", \"set\", \"info\", \"size\", \"\\n\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"ss\", &listExpr{[]expr{&setExpr{\"sortby\", \"size\"}, &setExpr{\"info\", \"size\"}}, 1}}},\n\t},\n\n\t{\n\t\t\"map ss :set sortby size; set info size;\",\n\t\t[]string{\"map\", \"ss\", \":\", \"set\", \"sortby\", \"size\", \";\", \"set\", \"info\", \"size\", \";\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"ss\", &listExpr{[]expr{&setExpr{\"sortby\", \"size\"}, &setExpr{\"info\", \"size\"}}, 1}}},\n\t},\n\n\t{\n\t\t`cmd gohome :{{\n\t\t\tcd ~\n\t\t\tset hidden\n\t\t}}`,\n\t\t[]string{\n\t\t\t\"cmd\", \"gohome\", \":\", \"{{\",\n\t\t\t\"cd\", \"~\", \"\\n\",\n\t\t\t\"set\", \"hidden\", \"\\n\",\n\t\t\t\"}}\", \"\\n\",\n\t\t},\n\t\t[]expr{&cmdExpr{\n\t\t\t\"gohome\", &listExpr{[]expr{\n\t\t\t\t&callExpr{\"cd\", []string{\"~\"}, 1},\n\t\t\t\t&setExpr{\"hidden\", \"\"},\n\t\t\t}, 1},\n\t\t}},\n\t},\n\n\t{\n\t\t`map gh :{{\n\t\t\tcd ~\n\t\t\tset hidden\n\t\t}}`,\n\t\t[]string{\n\t\t\t\"map\", \"gh\", \":\", \"{{\",\n\t\t\t\"cd\", \"~\", \"\\n\",\n\t\t\t\"set\", \"hidden\", \"\\n\",\n\t\t\t\"}}\", \"\\n\",\n\t\t},\n\t\t[]expr{&mapExpr{\n\t\t\t\"gh\", &listExpr{[]expr{\n\t\t\t\t&callExpr{\"cd\", []string{\"~\"}, 1},\n\t\t\t\t&setExpr{\"hidden\", \"\"},\n\t\t\t}, 1},\n\t\t}},\n\t},\n\n\t{\n\t\t`map c ${{\n\t\t\tmkdir foo\n\t\t\tcp $fs foo\n\t\t\ttar -czvf foo.tar.gz foo\n\t\t\trm -rf foo\n\t\t}}`,\n\t\t[]string{\"map\", \"c\", \"$\", \"{{\", `\n\t\t\tmkdir foo\n\t\t\tcp $fs foo\n\t\t\ttar -czvf foo.tar.gz foo\n\t\t\trm -rf foo\n\t\t`, \"}}\", \"\\n\"},\n\t\t[]expr{&mapExpr{\"c\", &execExpr{\"$\", `\n\t\t\tmkdir foo\n\t\t\tcp $fs foo\n\t\t\ttar -czvf foo.tar.gz foo\n\t\t\trm -rf foo\n\t\t`}}},\n\t},\n\n\t{\n\t\t`cmd compress ${{\n\t\t\tmkdir $1\n\t\t\tcp $fs $1\n\t\t\ttar -czvf $1.tar.gz $1\n\t\t\trm -rf $1\n\t\t}}`,\n\t\t[]string{\"cmd\", \"compress\", \"$\", \"{{\", `\n\t\t\tmkdir $1\n\t\t\tcp $fs $1\n\t\t\ttar -czvf $1.tar.gz $1\n\t\t\trm -rf $1\n\t\t`, \"}}\", \"\\n\"},\n\t\t[]expr{&cmdExpr{\"compress\", &execExpr{\"$\", `\n\t\t\tmkdir $1\n\t\t\tcp $fs $1\n\t\t\ttar -czvf $1.tar.gz $1\n\t\t\trm -rf $1\n\t\t`}}},\n\t},\n}\n\nfunc TestScan(t *testing.T) {\n\tfor _, test := range gEvalTests {\n\t\ts := newScanner(strings.NewReader(test.inp))\n\n\t\tfor _, tok := range test.toks {\n\t\t\tif s.scan(); s.tok != tok {\n\t\t\t\tt.Errorf(\"at input '%s' expected '%s' but scanned '%s'\", test.inp, tok, s.tok)\n\t\t\t}\n\t\t}\n\n\t\tif s.scan() {\n\t\t\tt.Errorf(\"at input '%s' unexpected '%s'\", test.inp, s.tok)\n\t\t}\n\t}\n}\n\nfunc TestParse(t *testing.T) {\n\tfor _, test := range gEvalTests {\n\t\tp := newParser(strings.NewReader(test.inp))\n\n\t\tfor _, expr := range test.exprs {\n\t\t\tif p.parse(); !reflect.DeepEqual(p.expr, expr) {\n\t\t\t\tt.Errorf(\"at input '%s' expected '%s' but parsed '%s'\", test.inp, expr, p.expr)\n\t\t\t}\n\t\t}\n\n\t\tif p.parse(); p.expr != nil {\n\t\t\tt.Errorf(\"at input '%s' unexpected '%s'\", test.inp, p.expr)\n\t\t}\n\t}\n}\n\nfunc TestExprString(t *testing.T) {\n\ttests := []struct {\n\t\te   expr\n\t\texp string\n\t}{\n\t\t{&setExpr{\"hidden!\", \"\"}, \"set hidden!\"},\n\t\t{&setExpr{\"hidden\", \"true\"}, \"set hidden true\"},\n\t\t{&setLocalExpr{\"~\", \"hidden!\", \"\"}, \"setlocal ~ hidden!\"},\n\t\t{&setLocalExpr{\"~\", \"hidden\", \"true\"}, \"setlocal ~ hidden true\"},\n\t\t{&mapExpr{\"q\", nil}, \"map q\"},\n\t\t{&mapExpr{\"q\", &callExpr{\"quit\", nil, 1}}, \"map q quit\"},\n\t\t{&nmapExpr{\"q\", nil}, \"nmap q\"},\n\t\t{&nmapExpr{\"q\", &callExpr{\"quit\", nil, 1}}, \"nmap q quit\"},\n\t\t{&vmapExpr{\"q\", nil}, \"vmap q\"},\n\t\t{&vmapExpr{\"q\", &callExpr{\"quit\", nil, 1}}, \"vmap q quit\"},\n\t\t{&cmapExpr{\"q\", nil}, \"cmap q\"},\n\t\t{&cmapExpr{\"q\", &callExpr{\"quit\", nil, 1}}, \"cmap q quit\"},\n\t\t{&cmdExpr{\"foo\", nil}, \"cmd foo\"},\n\t\t{&cmdExpr{\"foo\", &callExpr{\"quit\", nil, 1}}, \"cmd foo quit\"},\n\t\t{&callExpr{\"quit\", nil, 1}, \"quit\"},\n\t\t{&callExpr{\"cd\", []string{\"~\"}, 1}, \"cd ~\"},\n\t\t{&execExpr{\"$\", \"du -h . | less\"}, \"${{ du -h . | less }}\"},\n\t\t{\n\t\t\t&execExpr{\"$\", `\n\t\t\t\tmkdir foo\n\t\t\t\tcp $fs foo\n\t\t\t\ttar -czvf foo.tar.gz foo\n\t\t\t\trm -rf foo\n\t\t\t`},\n\t\t\t\"${{ mkdir foo ... }}\",\n\t\t},\n\t\t{&listExpr{[]expr{&callExpr{\"toggle\", nil, 1}, &callExpr{\"down\", nil, 1}}, 1}, \":{{ toggle; down; }}\"},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := test.e.String(); got != test.exp {\n\t\t\tt.Errorf(\"at test '%#v' expected '%s' but got '%s'\", test.e, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestSplitKeys(t *testing.T) {\n\tinps := []struct {\n\t\ts    string\n\t\tkeys []string\n\t}{\n\t\t{\"\", nil},\n\t\t{\"j\", []string{\"j\"}},\n\t\t{\"jk\", []string{\"j\", \"k\"}},\n\t\t{\"1j\", []string{\"1\", \"j\"}},\n\t\t{\"42j\", []string{\"4\", \"2\", \"j\"}},\n\t\t{\"<space>\", []string{\"<space>\"}},\n\t\t{\"j<space>\", []string{\"j\", \"<space>\"}},\n\t\t{\"j<space>k\", []string{\"j\", \"<space>\", \"k\"}},\n\t\t{\"1j<space>k\", []string{\"1\", \"j\", \"<space>\", \"k\"}},\n\t\t{\"1j<space>1k\", []string{\"1\", \"j\", \"<space>\", \"1\", \"k\"}},\n\t\t{\"<>\", []string{\"<>\"}},\n\t\t{\"<space\", []string{\"<space\"}},\n\t\t{\"<space<\", []string{\"<space<\"}},\n\t\t{\"<space<>\", []string{\"<space<>\"}},\n\t\t{\"><space>\", []string{\">\", \"<space>\"}},\n\t\t{\"><space>>\", []string{\">\", \"<space>\", \">\"}},\n\t}\n\n\tfor _, inp := range inps {\n\t\tif keys := splitKeys(inp.s); !reflect.DeepEqual(keys, inp.keys) {\n\t\t\tt.Errorf(\"at input '%s' expected '%v' but got '%v'\", inp.s, inp.keys, keys)\n\t\t}\n\t}\n}\n\nfunc TestApplyBoolOpt(t *testing.T) {\n\ttests := []struct {\n\t\topt bool\n\t\te   setExpr\n\t\texp bool\n\t}{\n\t\t{true, setExpr{\"feature\", \"\"}, true},\n\t\t{true, setExpr{\"feature\", \"true\"}, true},\n\t\t{true, setExpr{\"feature\", \"false\"}, false},\n\t\t{false, setExpr{\"feature\", \"\"}, true},\n\t\t{false, setExpr{\"feature\", \"true\"}, true},\n\t\t{false, setExpr{\"feature\", \"false\"}, false},\n\t\t{true, setExpr{\"nofeature\", \"\"}, false},\n\t\t{false, setExpr{\"nofeature\", \"\"}, false},\n\t\t{true, setExpr{\"feature!\", \"\"}, false},\n\t\t{false, setExpr{\"feature!\", \"\"}, true},\n\t}\n\n\tfor _, test := range tests {\n\t\ttestStr := fmt.Sprintf(\"%v\", test)\n\t\tif err := applyBoolOpt(&test.opt, &test.e); err != nil {\n\t\t\tt.Errorf(\"at test '%s' expected '%t' but got an error '%s'\", testStr, test.exp, err)\n\t\t\tcontinue\n\t\t}\n\t\tif test.opt != test.exp {\n\t\t\tt.Errorf(\"at test '%s' expected '%t' but got '%t'\", testStr, test.exp, test.opt)\n\t\t}\n\t}\n}\n\nfunc TestApplyLocalBoolOpt(t *testing.T) {\n\ttests := []struct {\n\t\tlocalOpt  map[string]bool\n\t\tglobalOpt bool\n\t\te         setLocalExpr\n\t\texp       bool\n\t}{\n\t\t{map[string]bool{}, false, setLocalExpr{\"/\", \"feature\", \"\"}, true},\n\t\t{map[string]bool{}, false, setLocalExpr{\"/\", \"feature\", \"true\"}, true},\n\t\t{map[string]bool{}, false, setLocalExpr{\"/\", \"feature\", \"false\"}, false},\n\t\t{map[string]bool{}, false, setLocalExpr{\"/\", \"nofeature\", \"\"}, false},\n\t\t{map[string]bool{}, true, setLocalExpr{\"/\", \"feature!\", \"\"}, false},\n\t\t{map[string]bool{}, false, setLocalExpr{\"/\", \"feature!\", \"\"}, true},\n\t\t{map[string]bool{\"/\": true}, false, setLocalExpr{\"/\", \"feature\", \"\"}, true},\n\t\t{map[string]bool{\"/\": true}, false, setLocalExpr{\"/\", \"feature\", \"true\"}, true},\n\t\t{map[string]bool{\"/\": true}, false, setLocalExpr{\"/\", \"feature\", \"false\"}, false},\n\t\t{map[string]bool{\"/\": true}, false, setLocalExpr{\"/\", \"nofeature\", \"\"}, false},\n\t\t{map[string]bool{\"/\": true}, true, setLocalExpr{\"/\", \"feature!\", \"\"}, false},\n\t\t{map[string]bool{\"/\": true}, false, setLocalExpr{\"/\", \"feature!\", \"\"}, false},\n\t\t{map[string]bool{\"/\": false}, false, setLocalExpr{\"/\", \"feature\", \"\"}, true},\n\t\t{map[string]bool{\"/\": false}, false, setLocalExpr{\"/\", \"feature\", \"true\"}, true},\n\t\t{map[string]bool{\"/\": false}, false, setLocalExpr{\"/\", \"feature\", \"false\"}, false},\n\t\t{map[string]bool{\"/\": false}, false, setLocalExpr{\"/\", \"nofeature\", \"\"}, false},\n\t\t{map[string]bool{\"/\": false}, true, setLocalExpr{\"/\", \"feature!\", \"\"}, true},\n\t\t{map[string]bool{\"/\": false}, false, setLocalExpr{\"/\", \"feature!\", \"\"}, true},\n\t}\n\n\tfor _, test := range tests {\n\t\ttestStr := fmt.Sprintf(\"%v\", test)\n\t\tif err := applyLocalBoolOpt(test.localOpt, test.globalOpt, &test.e); err != nil {\n\t\t\tt.Errorf(\"at test '%s' expected '%t' but got an error '%s'\", testStr, test.exp, err)\n\t\t\tcontinue\n\t\t}\n\t\tresult := test.localOpt[test.e.path]\n\t\tif result != test.exp {\n\t\t\tt.Errorf(\"at test '%s' expected '%t' but got '%t'\", testStr, test.exp, result)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "gen/build.sh",
    "content": "#!/bin/sh\n# Builds a static stripped binary with version information.\n#\n# This script is used to build a binary for the current platform. Cgo is\n# disabled to make sure the binary is statically linked. Appropriate flags are\n# given to the go compiler to strip the binary. Current git tag is passed to\n# the compiler by default to be used as the version in the binary.\n\nset -o errexit -o nounset\n\n[ -z \"${version:-}\" ] && version=$(git describe --tags --abbrev=0)\n\nCGO_ENABLED=0 go build -ldflags=\"-s -w -X main.gVersion=$version\" \"$@\"\n\n# vim: tabstop=4 shiftwidth=4 textwidth=80 colorcolumn=80\n"
  },
  {
    "path": "gen/deflist.lua",
    "content": "local stringify = pandoc.utils.stringify\nlocal List = pandoc.List\nlocal DefinitionList = pandoc.DefinitionList\n\n-- We use bold paragraphs for flags (e.g. **-help**)\nlocal function is_term(b)\n\treturn b.tag == \"Para\" and b.content[1] and b.content[1].tag == \"Strong\"\nend\n\n-- GitHub-flavored markdown lacks native definition lists (i.e. \":\" syntax).\n-- Therefore, we generate them on the fly to get a better-looking \"OPTIONS\"\n-- section in man pages and plain-text help without changing the source file.\nfunction Blocks(blocks)\n\tlocal out = List()\n\tlocal i = 1\n\tlocal in_opts, lvl = false, nil\n\n\twhile blocks[i] do\n\t\tlocal b = blocks[i]\n\t\ti = i + 1\n\n\t\tif b.tag == \"Header\" then\n\t\t\t-- Apply definition lists inside \"OPTIONS\" only\n\t\t\tif stringify(b.content) == \"OPTIONS\" then\n\t\t\t\tin_opts, lvl = true, b.level\n\t\t\telse\n\t\t\t\tin_opts = in_opts and b.level > lvl\n\t\t\tend\n\t\t\tout:insert(b)\n\t\telseif in_opts and is_term(b) then\n\t\t\t-- Collect definition for current term\n\t\t\tlocal def = List()\n\t\t\twhile blocks[i] and blocks[i].tag ~= \"Header\" and not is_term(blocks[i]) do\n\t\t\t\tdef:insert(blocks[i])\n\t\t\t\ti = i + 1\n\t\t\tend\n\t\t\tout:insert(DefinitionList({ { b.content, { def } } }))\n\t\telse\n\t\t\t-- Pass through unchanged\n\t\t\tout:insert(b)\n\t\tend\n\tend\n\n\treturn out\nend\n"
  },
  {
    "path": "gen/doc.sh",
    "content": "#!/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 plain text conversion of the\n# markdown documentation using pandoc (https://pandoc.org/). GitHub Flavored\n# Markdown (GFM) (https://github.github.com/gfm/) is used for the markdown\n# input format. The markdown file is automatically rendered in the GitHub\n# repository (https://github.com/gokcehan/lf/blob/master/doc.md). The man page\n# file `lf.1` is meant to be used for installations on Unix systems. The plain\n# text file `doc.txt` is embedded in the binary to be displayed on request with\n# the `-doc` command line flag. Thus the same documentation is used for online\n# and terminal display.\n\nset -o errexit -o nounset\n\nget_version() {\n    printf \"r%s\" $(($(git describe --tags --abbrev=0 | tr -d r) + 1))\n}\n\n[ -z \"${version:-}\" ] && version=$(get_version)\n[ -z \"${date:-}\" ] && date=$(date +%F)\n\nPANDOC_IMAGE=pandoc/minimal:3.7\n\ngenerate_man_page() {\n    \"${OCI_PROGRAM?}\" run \\\n        --rm \\\n        --volume \"$PWD:/data\" \\\n        \"$@\" \"$PANDOC_IMAGE\" \\\n        --standalone \\\n        --lua-filter /data/gen/deflist.lua \\\n        --from gfm --to man \\\n        --metadata=title:\"LF\" \\\n        --metadata=section:\"1\" \\\n        --metadata=date:\"$date\" \\\n        --metadata=footer:\"$version\" \\\n        --metadata=header:\"DOCUMENTATION\" \\\n        doc.md -o lf.1\n}\n\ngenerate_plain_text() {\n    \"${OCI_PROGRAM?}\" run \\\n        --rm \\\n        --volume \"$PWD:/data\" \\\n        \"$@\" \"$PANDOC_IMAGE\" \\\n        --standalone \\\n        --lua-filter /data/gen/deflist.lua \\\n        --from gfm --to plain \\\n        doc.md -o doc.txt\n}\n\nis_rootless() {\n    case \"$OCI_PROGRAM\" in\n        podman) podman info -f '{{.Host.Security.Rootless}}' | grep -q true ;;\n        docker) docker info -f '{{.SecurityOptions}}' | grep -q rootless ;;\n        *) echo >&2 \\\n            \"Unknown OCI program \\\"$OCI_PROGRAM\\\", assuming rootless mode\" ;;\n    esac\n}\n\n# You can set your own OCI_PROGRAM, which assumes it runs in rootless mode.\nif [ -z \"${OCI_PROGRAM:-}\" ]; then\n    if command -v podman > /dev/null; then\n        OCI_PROGRAM=podman\n    elif command -v docker > /dev/null; then\n        OCI_PROGRAM=docker\n    fi\nfi\n\nif is_rootless; then\n    generate_man_page\nelse\n    generate_man_page --user \"$(id -u):$(id -g)\"\nfi\n\nif is_rootless; then\n    generate_plain_text\nelse\n    generate_plain_text --user \"$(id -u):$(id -g)\"\nfi\n\n# vim: tabstop=4 shiftwidth=4 textwidth=80 colorcolumn=80\n"
  },
  {
    "path": "gen/package.sh",
    "content": "#!/bin/sh\n# Compresses a binary into an archived form.\n#\n# This script is used to compress a binary built from `build.sh` into an\n# archive. `.zip` is used for Windows and `.tar.gz` otherwise. The archive is\n# placed inside a directory named `dist`.\n\nset -o errexit -o nounset\n\nmkdir -p dist\n\nif [ \"$GOOS\" = \"windows\" ]; then\n    zip \"dist/lf-${GOOS}-${GOARCH}.zip\" lf.exe\nelse\n    tar czf \"dist/lf-${GOOS}-${GOARCH}.tar.gz\" lf\nfi\n\n# vim: tabstop=4 shiftwidth=4 textwidth=80 colorcolumn=80\n"
  },
  {
    "path": "go.mod",
    "content": "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.0\n\tgithub.com/gdamore/tcell/v3 v3.1.2\n\tgithub.com/rivo/uniseg v0.4.7\n\tgolang.org/x/sys v0.42.0\n\tgolang.org/x/term v0.41.0\n)\n\nrequire (\n\tgithub.com/gdamore/encoding v1.0.1 // indirect\n\tgithub.com/lucasb-eyer/go-colorful v1.3.0 // indirect\n\tgolang.org/x/text v0.34.0 // indirect\n)\n"
  },
  {
    "path": "go.sum",
    "content": "github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=\ngithub.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=\ngithub.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=\ngithub.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=\ngithub.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw=\ngithub.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo=\ngithub.com/gdamore/tcell/v3 v3.1.2 h1:qEaXnDaYZpCIMDfa3XFHkxrwFBINUuDiePwj39vErZ8=\ngithub.com/gdamore/tcell/v3 v3.1.2/go.mod h1:MikpZpivMtggrw1kL999dI2VuXw6Wya4724VAh3DzIg=\ngithub.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=\ngithub.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=\ngithub.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=\ngithub.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=\ngithub.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=\ngolang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=\ngolang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=\ngolang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=\ngolang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=\ngolang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=\ngolang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=\ngolang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=\ngolang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=\ngolang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\ngolang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=\ngolang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=\ngolang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=\ngolang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=\ngolang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=\ngolang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU=\ngolang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A=\ngolang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=\ngolang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=\ngolang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=\ngolang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=\ngolang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=\ngolang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=\ngolang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=\ngolang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=\ngolang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=\ngolang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=\ngolang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=\ngolang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=\n"
  },
  {
    "path": "icons.go",
    "content": "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 {\n\ticon     string\n\thasStyle bool\n\tstyle    tcell.Style\n}\n\ntype iconMap struct {\n\ticons         map[string]iconDef\n\tuseLinkTarget bool\n}\n\nfunc iconWithoutStyle(icon string) iconDef {\n\treturn iconDef{icon, false, tcell.StyleDefault}\n}\n\nfunc iconWithStyle(icon string, style tcell.Style) iconDef {\n\treturn iconDef{icon, true, style}\n}\n\nfunc parseIcons() iconMap {\n\tim := iconMap{\n\t\ticons:         make(map[string]iconDef),\n\t\tuseLinkTarget: false,\n\t}\n\n\tdefaultIcons := []string{\n\t\t\"ln=l\",\n\t\t\"or=l\",\n\t\t\"tw=t\",\n\t\t\"ow=d\",\n\t\t\"st=t\",\n\t\t\"di=d\",\n\t\t\"pi=p\",\n\t\t\"so=s\",\n\t\t\"bd=b\",\n\t\t\"cd=c\",\n\t\t\"su=u\",\n\t\t\"sg=g\",\n\t\t\"ex=x\",\n\t\t\"fi=-\",\n\t}\n\n\tim.parseEnv(strings.Join(defaultIcons, \":\"))\n\n\tif env := os.Getenv(\"LF_ICONS\"); env != \"\" {\n\t\tim.parseEnv(env)\n\t}\n\n\tfor _, path := range gIconsPaths {\n\t\tif _, err := os.Stat(path); !os.IsNotExist(err) {\n\t\t\tim.parseFile(path)\n\t\t}\n\t}\n\n\treturn im\n}\n\nfunc (im *iconMap) parseFile(path string) {\n\tlog.Printf(\"reading file: %s\", path)\n\n\tf, err := os.Open(path)\n\tif err != nil {\n\t\tlog.Printf(\"opening icons file: %s\", err)\n\t\treturn\n\t}\n\tdefer f.Close()\n\n\tarrs, err := readArrays(f, 1, 3)\n\tif err != nil {\n\t\tlog.Printf(\"reading icons file: %s\", err)\n\t\treturn\n\t}\n\n\tfor _, arr := range arrs {\n\t\tim.parseArray(arr)\n\t}\n}\n\nfunc (im *iconMap) parseEnv(env string) {\n\tfor entry := range strings.SplitSeq(env, \":\") {\n\t\tif entry == \"\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tpair := strings.Split(entry, \"=\")\n\n\t\tif len(pair) != 2 {\n\t\t\tlog.Printf(\"invalid $LF_ICONS entry: %s\", entry)\n\t\t\treturn\n\t\t}\n\n\t\tim.parseArray(pair)\n\t}\n}\n\nfunc (im *iconMap) parseArray(arr []string) {\n\tkey := replaceTilde(arr[0])\n\n\tif filepath.IsAbs(key) {\n\t\tkey = filepath.Clean(key)\n\t}\n\n\tswitch len(arr) {\n\tcase 1:\n\t\tdelete(im.icons, key)\n\tcase 2:\n\t\ticon := arr[1]\n\t\tif key == \"ln\" && icon == \"target\" {\n\t\t\tim.useLinkTarget = true\n\t\t} else {\n\t\t\tim.icons[key] = iconWithoutStyle(icon)\n\t\t}\n\tcase 3:\n\t\ticon, color := arr[1], arr[2]\n\t\tim.icons[key] = iconWithStyle(icon, applySGR(color, tcell.StyleDefault))\n\t}\n}\n\nfunc (im iconMap) get(f *file) iconDef {\n\tif val, ok := im.icons[f.path]; ok {\n\t\treturn val\n\t}\n\n\tif f.IsDir() {\n\t\tif val, ok := im.icons[f.Name()+\"/\"]; ok {\n\t\t\treturn val\n\t\t}\n\t}\n\n\tvar key string\n\n\tswitch {\n\tcase f.linkState == working && !im.useLinkTarget:\n\t\tkey = \"ln\"\n\tcase f.linkState == broken:\n\t\tkey = \"or\"\n\tcase f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0o002 != 0:\n\t\tkey = \"tw\"\n\tcase f.IsDir() && f.Mode()&0o002 != 0:\n\t\tkey = \"ow\"\n\tcase f.IsDir() && f.Mode()&os.ModeSticky != 0:\n\t\tkey = \"st\"\n\tcase f.IsDir():\n\t\tkey = \"di\"\n\tcase f.Mode()&os.ModeNamedPipe != 0:\n\t\tkey = \"pi\"\n\tcase f.Mode()&os.ModeSocket != 0:\n\t\tkey = \"so\"\n\tcase f.Mode()&os.ModeCharDevice != 0:\n\t\tkey = \"cd\"\n\tcase f.Mode()&os.ModeDevice != 0:\n\t\tkey = \"bd\"\n\tcase f.Mode()&os.ModeSetuid != 0:\n\t\tkey = \"su\"\n\tcase f.Mode()&os.ModeSetgid != 0:\n\t\tkey = \"sg\"\n\tcase isExecutable(f.FileInfo):\n\t\tkey = \"ex\"\n\t}\n\n\tif val, ok := im.icons[key]; ok {\n\t\treturn val\n\t}\n\n\tif val, ok := im.icons[f.Name()+\"*\"]; ok {\n\t\treturn val\n\t}\n\n\tif val, ok := im.icons[\"*\"+f.Name()]; ok {\n\t\treturn val\n\t}\n\n\tif val, ok := im.icons[filepath.Base(f.Name())+\".*\"]; ok {\n\t\treturn val\n\t}\n\n\tif val, ok := im.icons[\"*\"+strings.ToLower(f.ext)]; ok {\n\t\treturn val\n\t}\n\n\tif val, ok := im.icons[\"fi\"]; ok {\n\t\treturn val\n\t}\n\n\treturn iconWithoutStyle(\" \")\n}\n"
  },
  {
    "path": "key.go",
    "content": "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{\n\ttcell.KeyEnter:     \"<enter>\",\n\ttcell.KeyBackspace: \"<backspace>\",\n\ttcell.KeyTab:       \"<tab>\",\n\ttcell.KeyBacktab:   \"<backtab>\",\n\ttcell.KeyEsc:       \"<esc>\",\n\ttcell.KeyDelete:    \"<delete>\",\n\ttcell.KeyInsert:    \"<insert>\",\n\ttcell.KeyUp:        \"<up>\",\n\ttcell.KeyDown:      \"<down>\",\n\ttcell.KeyLeft:      \"<left>\",\n\ttcell.KeyRight:     \"<right>\",\n\ttcell.KeyHome:      \"<home>\",\n\ttcell.KeyEnd:       \"<end>\",\n\ttcell.KeyUpLeft:    \"<upleft>\",\n\ttcell.KeyUpRight:   \"<upright>\",\n\ttcell.KeyDownLeft:  \"<downleft>\",\n\ttcell.KeyDownRight: \"<downright>\",\n\ttcell.KeyCenter:    \"<center>\",\n\ttcell.KeyPgDn:      \"<pgdn>\",\n\ttcell.KeyPgUp:      \"<pgup>\",\n\ttcell.KeyClear:     \"<clear>\",\n\ttcell.KeyExit:      \"<exit>\",\n\ttcell.KeyCancel:    \"<cancel>\",\n\ttcell.KeyPause:     \"<pause>\",\n\ttcell.KeyPrint:     \"<print>\",\n\ttcell.KeyF1:        \"<f-1>\",\n\ttcell.KeyF2:        \"<f-2>\",\n\ttcell.KeyF3:        \"<f-3>\",\n\ttcell.KeyF4:        \"<f-4>\",\n\ttcell.KeyF5:        \"<f-5>\",\n\ttcell.KeyF6:        \"<f-6>\",\n\ttcell.KeyF7:        \"<f-7>\",\n\ttcell.KeyF8:        \"<f-8>\",\n\ttcell.KeyF9:        \"<f-9>\",\n\ttcell.KeyF10:       \"<f-10>\",\n\ttcell.KeyF11:       \"<f-11>\",\n\ttcell.KeyF12:       \"<f-12>\",\n\ttcell.KeyF13:       \"<f-13>\",\n\ttcell.KeyF14:       \"<f-14>\",\n\ttcell.KeyF15:       \"<f-15>\",\n\ttcell.KeyF16:       \"<f-16>\",\n\ttcell.KeyF17:       \"<f-17>\",\n\ttcell.KeyF18:       \"<f-18>\",\n\ttcell.KeyF19:       \"<f-19>\",\n\ttcell.KeyF20:       \"<f-20>\",\n\ttcell.KeyF21:       \"<f-21>\",\n\ttcell.KeyF22:       \"<f-22>\",\n\ttcell.KeyF23:       \"<f-23>\",\n\ttcell.KeyF24:       \"<f-24>\",\n\ttcell.KeyF25:       \"<f-25>\",\n\ttcell.KeyF26:       \"<f-26>\",\n\ttcell.KeyF27:       \"<f-27>\",\n\ttcell.KeyF28:       \"<f-28>\",\n\ttcell.KeyF29:       \"<f-29>\",\n\ttcell.KeyF30:       \"<f-30>\",\n\ttcell.KeyF31:       \"<f-31>\",\n\ttcell.KeyF32:       \"<f-32>\",\n\ttcell.KeyF33:       \"<f-33>\",\n\ttcell.KeyF34:       \"<f-34>\",\n\ttcell.KeyF35:       \"<f-35>\",\n\ttcell.KeyF36:       \"<f-36>\",\n\ttcell.KeyF37:       \"<f-37>\",\n\ttcell.KeyF38:       \"<f-38>\",\n\ttcell.KeyF39:       \"<f-39>\",\n\ttcell.KeyF40:       \"<f-40>\",\n\ttcell.KeyF41:       \"<f-41>\",\n\ttcell.KeyF42:       \"<f-42>\",\n\ttcell.KeyF43:       \"<f-43>\",\n\ttcell.KeyF44:       \"<f-44>\",\n\ttcell.KeyF45:       \"<f-45>\",\n\ttcell.KeyF46:       \"<f-46>\",\n\ttcell.KeyF47:       \"<f-47>\",\n\ttcell.KeyF48:       \"<f-48>\",\n\ttcell.KeyF49:       \"<f-49>\",\n\ttcell.KeyF50:       \"<f-50>\",\n\ttcell.KeyF51:       \"<f-51>\",\n\ttcell.KeyF52:       \"<f-52>\",\n\ttcell.KeyF53:       \"<f-53>\",\n\ttcell.KeyF54:       \"<f-54>\",\n\ttcell.KeyF55:       \"<f-55>\",\n\ttcell.KeyF56:       \"<f-56>\",\n\ttcell.KeyF57:       \"<f-57>\",\n\ttcell.KeyF58:       \"<f-58>\",\n\ttcell.KeyF59:       \"<f-59>\",\n\ttcell.KeyF60:       \"<f-60>\",\n\ttcell.KeyF61:       \"<f-61>\",\n\ttcell.KeyF62:       \"<f-62>\",\n\ttcell.KeyF63:       \"<f-63>\",\n\ttcell.KeyF64:       \"<f-64>\",\n\ttcell.KeyCtrlA:     \"<c-a>\",\n\ttcell.KeyCtrlB:     \"<c-b>\",\n\ttcell.KeyCtrlC:     \"<c-c>\",\n\ttcell.KeyCtrlD:     \"<c-d>\",\n\ttcell.KeyCtrlE:     \"<c-e>\",\n\ttcell.KeyCtrlF:     \"<c-f>\",\n\ttcell.KeyCtrlG:     \"<c-g>\",\n\ttcell.KeyCtrlJ:     \"<c-j>\",\n\ttcell.KeyCtrlK:     \"<c-k>\",\n\ttcell.KeyCtrlL:     \"<c-l>\",\n\ttcell.KeyCtrlN:     \"<c-n>\",\n\ttcell.KeyCtrlO:     \"<c-o>\",\n\ttcell.KeyCtrlP:     \"<c-p>\",\n\ttcell.KeyCtrlQ:     \"<c-q>\",\n\ttcell.KeyCtrlR:     \"<c-r>\",\n\ttcell.KeyCtrlS:     \"<c-s>\",\n\ttcell.KeyCtrlT:     \"<c-t>\",\n\ttcell.KeyCtrlU:     \"<c-u>\",\n\ttcell.KeyCtrlV:     \"<c-v>\",\n\ttcell.KeyCtrlW:     \"<c-w>\",\n\ttcell.KeyCtrlX:     \"<c-x>\",\n\ttcell.KeyCtrlY:     \"<c-y>\",\n\ttcell.KeyCtrlZ:     \"<c-z>\",\n}\n\nvar gValKey map[string]tcell.Key\n\nfunc init() {\n\tgValKey = make(map[string]tcell.Key, len(gKeyVal))\n\tfor k, v := range gKeyVal {\n\t\tgValKey[v] = k\n\t}\n}\n\n// for simplicity, assume there will only be one modifier (ctrl, shift or alt)\nvar reModKey = regexp.MustCompile(`<(c|s|a)-(.+)>`)\n\nfunc wrapModifier(s string, mod string) string {\n\ts = strings.TrimPrefix(s, \"<\")\n\ts = strings.TrimSuffix(s, \">\")\n\treturn fmt.Sprintf(\"<%s-%s>\", mod, s)\n}\n\nfunc addKeyModifier(s string, mod tcell.ModMask) string {\n\tif reModKey.MatchString(s) {\n\t\treturn s\n\t}\n\n\tswitch {\n\tcase mod&tcell.ModCtrl != 0:\n\t\treturn wrapModifier(s, \"c\")\n\tcase mod&tcell.ModShift != 0:\n\t\treturn wrapModifier(s, \"s\")\n\tcase mod&tcell.ModAlt != 0:\n\t\treturn wrapModifier(s, \"a\")\n\tdefault:\n\t\treturn s\n\t}\n}\n\nfunc readKey(ev *tcell.EventKey) string {\n\tvar s string\n\tif ev.Key() == tcell.KeyRune {\n\t\tswitch ev.Str() {\n\t\tcase \"<\":\n\t\t\ts = \"<lt>\"\n\t\tcase \">\":\n\t\t\ts = \"<gt>\"\n\t\tcase \" \":\n\t\t\ts = \"<space>\"\n\t\tdefault:\n\t\t\ts = ev.Str()\n\t\t}\n\t} else {\n\t\ts = gKeyVal[ev.Key()]\n\t}\n\n\treturn addKeyModifier(s, ev.Modifiers())\n}\n\nfunc parseKeyModifier(s string) (tcell.ModMask, string) {\n\tmatches := reModKey.FindStringSubmatch(s)\n\tif matches == nil {\n\t\treturn tcell.ModNone, s\n\t}\n\n\tmod := tcell.ModNone\n\tswitch matches[1] {\n\tcase \"c\":\n\t\tmod = tcell.ModCtrl\n\tcase \"s\":\n\t\tmod = tcell.ModShift\n\tcase \"a\":\n\t\tmod = tcell.ModAlt\n\t}\n\n\ts = matches[2]\n\tif len(s) > 1 {\n\t\ts = \"<\" + s + \">\"\n\t}\n\n\treturn mod, s\n}\n\nfunc parseKey(s string) *tcell.EventKey {\n\tif key, ok := gValKey[s]; ok {\n\t\treturn tcell.NewEventKey(key, \"\", tcell.ModNone)\n\t}\n\n\tmod, s := parseKeyModifier(s)\n\n\tk := tcell.KeyRune\n\tif key, ok := gValKey[s]; ok {\n\t\tk = key\n\t\ts = \"\"\n\t} else {\n\t\tswitch s {\n\t\tcase \"<lt>\":\n\t\t\ts = \"<\"\n\t\tcase \"<gt>\":\n\t\t\ts = \">\"\n\t\tcase \"<space>\":\n\t\t\ts = \" \"\n\t\t}\n\t}\n\n\treturn tcell.NewEventKey(k, s, mod)\n}\n"
  },
  {
    "path": "key_test.go",
    "content": "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  string\n}{\n\t{tcell.NewEventKey(tcell.KeyRune, \"<\", tcell.ModNone), \"<lt>\"},\n\t{tcell.NewEventKey(tcell.KeyRune, \">\", tcell.ModNone), \"<gt>\"},\n\t{tcell.NewEventKey(tcell.KeyRune, \" \", tcell.ModNone), \"<space>\"},\n\t{tcell.NewEventKey(tcell.KeyRune, \"a\", tcell.ModNone), \"a\"},\n\t{tcell.NewEventKey(tcell.KeyCtrlA, \"\", tcell.ModNone), \"<c-a>\"},\n\t{tcell.NewEventKey(tcell.KeyRune, \"A\", tcell.ModNone), \"A\"},\n\t{tcell.NewEventKey(tcell.KeyRune, \"a\", tcell.ModAlt), \"<a-a>\"},\n\t{tcell.NewEventKey(tcell.KeyLeft, \"\", tcell.ModNone), \"<left>\"},\n\t{tcell.NewEventKey(tcell.KeyLeft, \"\", tcell.ModCtrl), \"<c-left>\"},\n\t{tcell.NewEventKey(tcell.KeyLeft, \"\", tcell.ModShift), \"<s-left>\"},\n\t{tcell.NewEventKey(tcell.KeyLeft, \"\", tcell.ModAlt), \"<a-left>\"},\n\t{tcell.NewEventKey(tcell.KeyEsc, \"\", tcell.ModNone), \"<esc>\"},\n\t{tcell.NewEventKey(tcell.KeyF1, \"\", tcell.ModNone), \"<f-1>\"},\n}\n\nfunc TestReadKey(t *testing.T) {\n\tfor _, test := range gKeyTests {\n\t\tif got := readKey(test.ev); got != test.s {\n\t\t\tt.Errorf(\"at input '%#v' expected '%s' but got '%s'\", test.ev, test.s, got)\n\t\t}\n\t}\n}\n\nfunc TestParseKey(t *testing.T) {\n\tkeyEqual := func(ev1, ev2 *tcell.EventKey) bool {\n\t\treturn ev1.Key() == ev2.Key() && ev1.Modifiers() == ev2.Modifiers() && ev1.Str() == ev2.Str()\n\t}\n\n\tfor _, test := range gKeyTests {\n\t\tif got := parseKey(test.s); !keyEqual(got, test.ev) {\n\t\t\tt.Errorf(\"at input '%s' expected '%#v' but got '%#v'\", test.s, test.ev, got)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "lf.1",
    "content": ".\\\" Automatically generated by Pandoc 3.7.0.2\n.\\\"\n.TH \"LF\" \"1\" \"2026\\-03\\-21\" \"r42\" \"DOCUMENTATION\"\n.SH NAME\nlf \\- terminal file manager\n.SH SYNOPSIS\n\\f[B]lf\\f[R] [\\f[B]\\-command\\f[R] \\f[I]command\\f[R]] [\\f[B]\\-config\\f[R]\n\\f[I]path\\f[R]] [\\f[B]\\-cpuprofile\\f[R] \\f[I]path\\f[R]]\n[\\f[B]\\-doc\\f[R]] [\\f[B]\\-help\\f[R]] [\\f[B]\\-last\\-dir\\-path\\f[R]\n\\f[I]path\\f[R]] [\\f[B]\\-log\\f[R] \\f[I]path\\f[R]] [\\f[B]\\-memprofile\\f[R]\n\\f[I]path\\f[R]] [\\f[B]\\-print\\-last\\-dir\\f[R]]\n[\\f[B]\\-print\\-selection\\f[R]] [\\f[B]\\-remote\\f[R] \\f[I]command\\f[R]]\n[\\f[B]\\-selection\\-path\\f[R] \\f[I]path\\f[R]] [\\f[B]\\-server\\f[R]]\n[\\f[B]\\-single\\f[R]] [\\f[B]\\-version\\f[R]]\n[\\f[I]cd\\-or\\-select\\-path\\f[R]]\n.SH DESCRIPTION\nlf is a terminal file manager.\n.PP\nThe source code can be found in the repository at \\c\n.UR https://github.com/gokcehan/lf\n.UE \\c\n.PP\nThis documentation can either be read from the terminal using\n\\f[CR]lf \\-doc\\f[R] or online at \\c\n.UR https://github.com/gokcehan/lf/blob/master/doc.md\n.UE \\c\n\\ You can also use the \\f[CR]help\\f[R] command (default\n\\f[CR]<f\\-1>\\f[R]) inside lf to view the documentation in a pager.\nA man page with the same content is also available in the repository at\n\\c\n.UR https://github.com/gokcehan/lf/blob/master/lf.1\n.UE \\c\n.SH OPTIONS\n.SS POSITIONAL ARGUMENTS\n.TP\n\\f[B]cd\\-or\\-select\\-path\\f[R]\nSet the starting location.\nIf \\f[I]path\\f[R] is a directory, start in there.\nIf it\\(aqs a file, start in the file\\(aqs parent directory and select\nthe file.\nWhen no \\f[I]path\\f[R] is supplied, lf uses the current directory.\nOnly accepts one argument.\n.SS META OPTIONS\n.TP\n\\f[B]\\-doc\\f[R]\nShow lf\\(aqs documentation (same content as this file) and exit.\n.TP\n\\f[B]\\-help\\f[R]\nShow command\\-line usage and exit.\n.TP\n\\f[B]\\-version\\f[R]\nShow version information and exit.\n.SS STARTUP & CONFIGURATION\n.TP\n\\f[B]\\-command\\f[R] \\f[I]command\\f[R]\nExecute \\f[I]command\\f[R] during client initialization (i.e.\nafter reading configuration, before \\f[CR]on\\-init\\f[R]).\nTo execute more than one command, you can either use the\n\\f[B]\\-command\\f[R] flag multiple times or pass multiple commands at\nonce by chaining them with \\(dq;\\(dq.\n.TP\n\\f[B]\\-config\\f[R] \\f[I]path\\f[R]\nUse the config file at \\f[I]path\\f[R] instead of the normal search\nlocations.\nThis only affects which \\f[CR]lfrc\\f[R] is read at startup.\n.SS SHELL INTEGRATION\n.TP\n\\f[B]\\-print\\-last\\-dir\\f[R]\nPrint the last directory to stdout when lf exits.\nThis can be used to let lf change your shells working directory.\nSee \\f[CR]CHANGING DIRECTORY\\f[R] for more details.\n.TP\n\\f[B]\\-last\\-dir\\-path\\f[R] \\f[I]path\\f[R]\nSame as \\f[B]\\-print\\-last\\-dir\\f[R], but write the directory to\n\\f[I]path\\f[R] instead of stdout.\n.TP\n\\f[B]\\-print\\-selection\\f[R]\nPrint selected files to stdout when opening a file in lf.\nThis can be used to use lf as an \\(dqopen file\\(dq dialog.\nFirst, select the files you want to pass to another program.\nThen, confirm the selection by opening a file.\nThis causes lf to quit and print out the selection.\nQuitting lf prematurely discards the selection.\n.TP\n\\f[B]\\-selection\\-path\\f[R] \\f[I]path\\f[R]\nSame as \\f[B]\\-print\\-selection\\f[R], but write the newline\\-separated\nlist to \\f[I]path\\f[R] instead of stdout.\n.SS SERVER\n.TP\n\\f[B]\\-remote\\f[R] \\f[I]command\\f[R]\nSend \\f[I]command\\f[R] to the running server (i.e.\n\\f[CR]send\\f[R], \\f[CR]query\\f[R], \\f[CR]list\\f[R], \\f[CR]quit\\f[R], or\n\\f[CR]quit!\\f[R]).\nSee \\f[CR]REMOTE COMMANDS\\f[R] for more details.\n.TP\n\\f[B]\\-server\\f[R]\nStart the (headless) server process explicitly.\nRuns in the foreground and writes server logs to stderr (or the file set\nwith \\f[B]\\-log\\f[R]).\nClients auto\\-start a server if none is running unless\n\\f[B]\\-single\\f[R] is used.\n.TP\n\\f[B]\\-single\\f[R]\nStart a stand\\-alone client without a server.\nDisables remote control.\n.SS DIAGNOSTICS\n.TP\n\\f[B]\\-log\\f[R] \\f[I]path\\f[R]\nAppend runtime log messages to \\f[I]path\\f[R].\n.TP\n\\f[B]\\-cpuprofile\\f[R] \\f[I]path\\f[R]\nWrite a CPU profile to \\f[I]path\\f[R].\nThe profile can be used by \\f[CR]go tool pprof\\f[R].\n.TP\n\\f[B]\\-memprofile\\f[R] \\f[I]path\\f[R]\nWrite a memory profile to \\f[I]path\\f[R].\nThe profile can be used by \\f[CR]go tool pprof\\f[R].\n.SS EXAMPLES\nUse \\f[CR]lf\\f[R] to select files (while hiding certain file types):\n.IP\n.EX\nlf \\-command \\(aqset nohidden\\(aq \\-command \\(aqset hiddenfiles \\(dq*mp4:*pdf:*txt\\(dq\\(aq \\-print\\-selection\n.EE\n.PP\nAnother sophisticated \\(dqopen file\\(dq dialog focusing on design:\n.IP\n.EX\nlf \\-command \\(aqset nopreview; set ratios 1; set drawbox; set promptfmt \\(dqSelect files [%w] %S q: cancel, l: confirm\\(dq\\(aq \\-print\\-selection\n.EE\n.PP\nOpen Downloads and set \\f[CR]sortby\\f[R] and \\f[CR]info\\f[R] to creation\ndate:\n.IP\n.EX\nlf \\-command \\(aqset sortby btime; set info btime\\(aq \\(ti/Downloads\n.EE\n.PP\nTemporarily prevent \\f[CR]lf\\f[R] from modifying the command history:\n.IP\n.EX\nlf \\-command \\(aqset nohistory\\(aq\n.EE\n.PP\nUse default settings and log current session:\n.IP\n.EX\nlf \\-config /dev/null \\-log /tmp/lf.log\n.EE\n.PP\nForce\\-quit the server:\n.IP\n.EX\nlf \\-remote \\(aqquit!\\(aq\n.EE\n.PP\nInherit lf\\(aqs working directory in your shell:\n.IP\n.EX\ncd \\(dq$(lf \\-print\\-last\\-dir)\\(dq\n.EE\n.SH QUICK REFERENCE\nThe following commands are provided by lf:\n.IP\n.EX\nquit                     (default \\(aqq\\(aq)\nup                       (default \\(aqk\\(aq and \\(aq<up>\\(aq)\nhalf\\-up                  (default \\(aq<c\\-u>\\(aq)\npage\\-up                  (default \\(aq<c\\-b>\\(aq and \\(aq<pgup>\\(aq)\nscroll\\-up                (default \\(aq<c\\-y>\\(aq)\ndown                     (default \\(aqj\\(aq and \\(aq<down>\\(aq)\nhalf\\-down                (default \\(aq<c\\-d>\\(aq)\npage\\-down                (default \\(aq<c\\-f>\\(aq and \\(aq<pgdn>\\(aq)\nscroll\\-down              (default \\(aq<c\\-e>\\(aq)\nupdir                    (default \\(aqh\\(aq and \\(aq<left>\\(aq)\nopen                     (default \\(aql\\(aq and \\(aq<right>\\(aq)\njump\\-next                (default \\(aq]\\(aq)\njump\\-prev                (default \\(aq[\\(aq)\ntop                      (default \\(aqgg\\(aq and \\(aq<home>\\(aq)\nbottom                   (default \\(aqG\\(aq and \\(aq<end>\\(aq)\nhigh                     (default \\(aqH\\(aq)\nmiddle                   (default \\(aqM\\(aq)\nlow                      (default \\(aqL\\(aq)\ntoggle\ninvert                   (default \\(aqv\\(aq)\nunselect                 (default \\(aqu\\(aq)\nglob\\-select\nglob\\-unselect\ncopy                     (default \\(aqy\\(aq)\ncut                      (default \\(aqd\\(aq)\npaste                    (default \\(aqp\\(aq)\nclear                    (default \\(aqc\\(aq)\nsync\ndraw\nredraw                   (default \\(aq<c\\-l>\\(aq)\nload\nreload                   (default \\(aq<c\\-r>\\(aq)\ndelete         (modal)\nrename         (modal)   (default \\(aqr\\(aq)\nread           (modal)   (default \\(aq:\\(aq)\nshell          (modal)   (default \\(aq$\\(aq)\nshell\\-pipe     (modal)   (default \\(aq%\\(aq)\nshell\\-wait     (modal)   (default \\(aq!\\(aq)\nshell\\-async    (modal)   (default \\(aq&\\(aq)\nfind           (modal)   (default \\(aqf\\(aq)\nfind\\-back      (modal)   (default \\(aqF\\(aq)\nfind\\-next                (default \\(aq;\\(aq)\nfind\\-prev                (default \\(aq,\\(aq)\nsearch         (modal)   (default \\(aq/\\(aq)\nsearch\\-back    (modal)   (default \\(aq?\\(aq)\nsearch\\-next              (default \\(aqn\\(aq)\nsearch\\-prev              (default \\(aqN\\(aq)\nfilter         (modal)\nsetfilter\nmark\\-save      (modal)   (default \\(aqm\\(aq)\nmark\\-load      (modal)   (default \\(dq\\(aq\\(dq)\nmark\\-remove    (modal)   (default \\(aq\\(dq\\(aq)\ntag\ntag\\-toggle               (default \\(aqt\\(aq)\necho\nechomsg\nechoerr\ncd\nselect\nsource\npush\naddcustominfo\ncalcdirsize\nclearmaps\ntty\\-write\nvisual                   (default \\(aqV\\(aq)\n.EE\n.PP\nThe following Visual mode commands are provided by lf:\n.IP\n.EX\nvisual\\-accept            (default \\(aqV\\(aq)\nvisual\\-unselect\nvisual\\-discard           (default \\(aq<esc>\\(aq)\nvisual\\-change            (default \\(aqo\\(aq)\n.EE\n.PP\nThe following Command\\-line mode commands are provided by lf:\n.IP\n.EX\ncmd\\-insert\ncmd\\-escape               (default \\(aq<esc>\\(aq)\ncmd\\-complete             (default \\(aq<tab>\\(aq)\ncmd\\-menu\\-complete\ncmd\\-menu\\-complete\\-back\ncmd\\-menu\\-accept\ncmd\\-menu\\-discard\ncmd\\-enter                (default \\(aq<c\\-j>\\(aq and \\(aq<enter>\\(aq)\ncmd\\-interrupt            (default \\(aq<c\\-c>\\(aq)\ncmd\\-history\\-next         (default \\(aq<c\\-n>\\(aq and \\(aq<down>\\(aq)\ncmd\\-history\\-prev         (default \\(aq<c\\-p>\\(aq and \\(aq<up>\\(aq)\ncmd\\-left                 (default \\(aq<c\\-b>\\(aq and \\(aq<left>\\(aq)\ncmd\\-right                (default \\(aq<c\\-f>\\(aq and \\(aq<right>\\(aq)\ncmd\\-home                 (default \\(aq<c\\-a>\\(aq and \\(aq<home>\\(aq)\ncmd\\-end                  (default \\(aq<c\\-e>\\(aq and \\(aq<end>\\(aq)\ncmd\\-delete               (default \\(aq<c\\-d>\\(aq and \\(aq<delete>\\(aq)\ncmd\\-delete\\-back          (default \\(aq<backspace>\\(aq)\ncmd\\-delete\\-home          (default \\(aq<c\\-u>\\(aq)\ncmd\\-delete\\-end           (default \\(aq<c\\-k>\\(aq)\ncmd\\-delete\\-unix\\-word     (default \\(aq<c\\-w>\\(aq)\ncmd\\-yank                 (default \\(aq<c\\-y>\\(aq)\ncmd\\-transpose            (default \\(aq<c\\-t>\\(aq)\ncmd\\-transpose\\-word       (default \\(aq<a\\-t>\\(aq)\ncmd\\-word                 (default \\(aq<a\\-f>\\(aq)\ncmd\\-word\\-back            (default \\(aq<a\\-b>\\(aq)\ncmd\\-delete\\-word          (default \\(aq<a\\-d>\\(aq)\ncmd\\-delete\\-word\\-back     (default \\(aq<a\\-backspace>\\(aq)\ncmd\\-capitalize\\-word      (default \\(aq<a\\-c>\\(aq)\ncmd\\-uppercase\\-word       (default \\(aq<a\\-u>\\(aq)\ncmd\\-lowercase\\-word       (default \\(aq<a\\-l>\\(aq)\n.EE\n.PP\nThe following options can be used to customize the behavior of lf:\n.IP\n.EX\nanchorfind        bool      (default true)\nautoquit          bool      (default true)\nborderfmt         string    (default \\(dq\\(rs033[0m\\(dq)\nborderstyle       string    (default \\(aqbox\\(aq)\ncleaner           string    (default \\(aq\\(aq)\ncopyfmt           string    (default \\(dq\\(rs033[7;33m\\(dq)\ncursoractivefmt   string    (default \\(dq\\(rs033[7m\\(dq)\ncursorparentfmt   string    (default \\(dq\\(rs033[7m\\(dq)\ncursorpreviewfmt  string    (default \\(dq\\(rs033[4m\\(dq)\ncutfmt            string    (default \\(dq\\(rs033[7;31m\\(dq)\ndircounts         bool      (default false)\ndirfirst          bool      (default true)\ndironly           bool      (default false)\ndirpreviews       bool      (default false)\ndrawbox           bool      (default false)\ndupfilefmt        string    (default \\(aq%f.\\(ti%n\\(ti\\(aq)\nerrorfmt          string    (default \\(dq\\(rs033[7;31;47m\\(dq)\nfilesep           string    (default \\(dq\\(rsn\\(dq)\nfiltermethod      string    (default \\(aqtext\\(aq)\nfindlen           int       (default 1)\nhidden            bool      (default false)\nhiddenfiles       []string  (default \\(aq.*\\(aq for Unix and \\(aq\\(aq for Windows)\nhistory           bool      (default true)\nicons             bool      (default false)\nifs               string    (default \\(aq\\(aq)\nignorecase        bool      (default true)\nignoredia         bool      (default true)\nincfilter         bool      (default false)\nincsearch         bool      (default false)\ninfo              []string  (default \\(aq\\(aq)\ninfotimefmtnew    string    (default \\(aqJan _2 15:04\\(aq)\ninfotimefmtold    string    (default \\(aqJan _2  2006\\(aq)\nmenufmt           string    (default \\(dq\\(rs033[0m\\(dq)\nmenuheaderfmt     string    (default \\(dq\\(rs033[1m\\(dq)\nmenuselectfmt     string    (default \\(dq\\(rs033[7m\\(dq)\nmergeindicators   bool      (default false)\nmouse             bool      (default false)\nnumber            bool      (default false)\nnumbercursorfmt   string    (default \\(aq\\(aq)\nnumberfmt         string    (default \\(dq\\(rs033[33m\\(dq)\nperiod            int       (default 0)\npreload           bool      (default false)\npreserve          []string  (default \\(dqmode\\(dq)\npreview           bool      (default true)\npreviewer         string    (default \\(aq\\(aq)\npromptfmt         string    (default \\(dq\\(rs033[32;1m%u\\(at%h\\(rs033[0m:\\(rs033[34;1m%d\\(rs033[0m\\(rs033[1m%f\\(rs033[0m\\(dq)\nratios            []int     (default \\(aq1:2:3\\(aq)\nrelativenumber    bool      (default false)\nreverse           bool      (default false)\nrulerfile         string    (default \\(dq\\(dq)\nrulerfmt          string    (default \\(dq\\(dq)\nscrolloff         int       (default 0)\nsearchmethod      string    (default \\(aqtext\\(aq)\nselectfmt         string    (default \\(dq\\(rs033[7;35m\\(dq)\nselmode           string    (default \\(aqall\\(aq)\nshell             string    (default \\(aqsh\\(aq for Unix and \\(aqcmd\\(aq for Windows)\nshellflag         string    (default \\(aq\\-c\\(aq for Unix and \\(aq/c\\(aq for Windows)\nshellopts         []string  (default \\(aq\\(aq)\nshowbinds         bool      (default true)\nsizeunits         string    (default \\(aqbinary\\(aq)\nsmartcase         bool      (default true)\nsmartdia          bool      (default false)\nsortby            string    (default \\(aqnatural\\(aq)\nstatfmt           string    (default \\(dq\\(rs033[36m%p\\(rs033[0m| %c| %u| %g| %S| %t| \\-> %l\\(dq)\ntabstop           int       (default 8)\ntagfmt            string    (default \\(dq\\(rs033[31m\\(dq)\ntempmarks         string    (default \\(aq\\(aq)\nterminalcursor    string    (default \\(aqdefault\\(aq)\ntimefmt           string    (default \\(aqMon Jan _2 15:04:05 2006\\(aq)\ntruncatechar      string    (default \\(aq\\(ti\\(aq)\ntruncatepct       int       (default 100)\nvisualfmt         string    (default \\(dq\\(rs033[7;36m\\(dq)\nwaitmsg           string    (default \\(aqPress any key to continue\\(aq)\nwatch             bool      (default false)\nwrapscan          bool      (default true)\nwrapscroll        bool      (default false)\nuser_{option}     string    (default none)\n.EE\n.PP\nThe following environment variables are exported for shell commands:\n.IP\n.EX\nf\nfs\nfv\nfx\nid\nPWD\nOLDPWD\nLF_LEVEL\nOPENER\nVISUAL\nEDITOR\nPAGER\nSHELL\nlf\nlf_{option}\nlf_user_{option}\nlf_flag_{flag}\nlf_width\nlf_height\nlf_count\nlf_mode\n.EE\n.PP\nThe following special shell commands are used to customize the behavior\nof lf when defined:\n.IP\n.EX\nopen\npaste\nrename\ndelete\npre\\-cd\non\\-cd\non\\-load\non\\-focus\\-gained\non\\-focus\\-lost\non\\-init\non\\-select\non\\-redraw\non\\-quit\n.EE\n.PP\nThe following commands/keybindings are provided by default:\n.IP\n.EX\nUnix\ncmd open &$OPENER \\(dq$f\\(dq\nmap e $$EDITOR \\(dq$f\\(dq\nmap i $$PAGER \\(dq$f\\(dq\nmap w $$SHELL\ncmd help $$lf \\-doc | $PAGER\nmap <f\\-1> help\ncmd maps $lf \\-remote \\(dqquery $id maps\\(dq | $PAGER\ncmd nmaps $lf \\-remote \\(dqquery $id nmaps\\(dq | $PAGER\ncmd vmaps $lf \\-remote \\(dqquery $id vmaps\\(dq | $PAGER\ncmd cmaps $lf \\-remote \\(dqquery $id cmaps\\(dq | $PAGER\ncmd cmds $lf \\-remote \\(dqquery $id cmds\\(dq | $PAGER\n\nWindows\ncmd open &%OPENER% %f%\nmap e $%EDITOR% %f%\nmap i !%PAGER% %f%\nmap w $%SHELL%\ncmd help !%lf% \\-doc | %PAGER%\nmap <f\\-1> help\ncmd maps !%lf% \\-remote \\(dqquery %id% maps\\(dq | %PAGER%\ncmd nmaps !%lf% \\-remote \\(dqquery %id% nmaps\\(dq | %PAGER%\ncmd vmaps !%lf% \\-remote \\(dqquery %id% vmaps\\(dq | %PAGER%\ncmd cmaps !%lf% \\-remote \\(dqquery %id% cmaps\\(dq | %PAGER%\ncmd cmds !%lf% \\-remote \\(dqquery %id% cmds\\(dq | %PAGER%\n.EE\n.PP\nThe defaults for Windows are using \\f[CR]cmd\\f[R] syntax.\nA \\f[CR]PowerShell\\f[R] compatible configuration file can be found at \\c\n.UR https://github.com/gokcehan/lf/blob/master/etc/lfrc.ps1.example\n.UE \\c\n.PP\nThe following additional keybindings are provided by default:\n.IP\n.EX\nmap zh set hidden!\nmap zr set reverse!\nmap zn set info\nmap zs set info size\nmap zt set info time\nmap za set info size:time\nmap sn :set sortby natural; set info\nmap ss :set sortby size; set info size\nmap st :set sortby time; set info time\nmap sa :set sortby atime; set info atime\nmap sb :set sortby btime; set info btime\nmap sc :set sortby ctime; set info ctime\nmap se :set sortby ext; set info\nmap gh cd \\(ti\nnmap <space> :toggle; down\n.EE\n.PP\nIf the \\f[CR]mouse\\f[R] option is enabled, mouse buttons have the\nfollowing default effects:\n.IP\n.EX\nLeft mouse button\n    Click on a file or directory to select it.\n\nRight mouse button\n    Enter a directory or open a file. Also works on the preview pane.\n\nScroll wheel\n    Move up or down. If Ctrl is pressed, scroll up or down.\n.EE\n.SH CONFIGURATION\nConfiguration files should be located at:\n.IP\n.EX\nOS       system\\-wide               user\\-specific\nUnix     /etc/lf/lfrc              \\(ti/.config/lf/lfrc\nWindows  C:\\(rsProgramData\\(rslf\\(rslfrc    C:\\(rsUsers\\(rs<user>\\(rsAppData\\(rsRoaming\\(rslf\\(rslfrc\n.EE\n.PP\nThe colors file should be located at:\n.IP\n.EX\nOS       system\\-wide               user\\-specific\nUnix     /etc/lf/colors            \\(ti/.config/lf/colors\nWindows  C:\\(rsProgramData\\(rslf\\(rscolors  C:\\(rsUsers\\(rs<user>\\(rsAppData\\(rsRoaming\\(rslf\\(rscolors\n.EE\n.PP\nThe icons file should be located at:\n.IP\n.EX\nOS       system\\-wide               user\\-specific\nUnix     /etc/lf/icons             \\(ti/.config/lf/icons\nWindows  C:\\(rsProgramData\\(rslf\\(rsicons   C:\\(rsUsers\\(rs<user>\\(rsAppData\\(rsRoaming\\(rslf\\(rsicons\n.EE\n.PP\nThe selection file should be located at:\n.IP\n.EX\nUnix     \\(ti/.local/share/lf/files\nWindows  C:\\(rsUsers\\(rs<user>\\(rsAppData\\(rsLocal\\(rslf\\(rsfiles\n.EE\n.PP\nThe marks file should be located at:\n.IP\n.EX\nUnix     \\(ti/.local/share/lf/marks\nWindows  C:\\(rsUsers\\(rs<user>\\(rsAppData\\(rsLocal\\(rslf\\(rsmarks\n.EE\n.PP\nThe tags file should be located at:\n.IP\n.EX\nUnix     \\(ti/.local/share/lf/tags\nWindows  C:\\(rsUsers\\(rs<user>\\(rsAppData\\(rsLocal\\(rslf\\(rstags\n.EE\n.PP\nThe history file should be located at:\n.IP\n.EX\nUnix     \\(ti/.local/share/lf/history\nWindows  C:\\(rsUsers\\(rs<user>\\(rsAppData\\(rsLocal\\(rslf\\(rshistory\n.EE\n.PP\nYou can configure these locations with the following variables given\nwith their order of precedences and their default values:\n.IP\n.EX\nUnix\n    $LF_CONFIG_HOME\n    $XDG_CONFIG_HOME\n    \\(ti/.config\n\n    $LF_DATA_HOME\n    $XDG_DATA_HOME\n    \\(ti/.local/share\n\nWindows\n    %LF_CONFIG_HOME%\n    %XDG_CONFIG_HOME%\n    %APPDATA%\n\n    %LF_DATA_HOME%\n    %XDG_DATA_HOME%\n    %LOCALAPPDATA%\n.EE\n.PP\nA sample configuration file can be found at \\c\n.UR https://github.com/gokcehan/lf/blob/master/etc/lfrc.example\n.UE \\c\n.SH COMMANDS\nThis section shows information about built\\-in commands.\nModal commands do not take any arguments, but instead change the\noperation mode to read their input conveniently, and so they are meant\nto be assigned to keybindings.\n.SS quit (default \\f[CR]q\\f[R])\nQuit lf and return to the shell.\n.SS up (default \\f[CR]k\\f[R] and \\f[CR]<up>\\f[R]), half\\-up (default \\f[CR]<c\\-u>\\f[R]), page\\-up (default \\f[CR]<c\\-b>\\f[R] and \\f[CR]<pgup>\\f[R]), scroll\\-up (default \\f[CR]<c\\-y>\\f[R]), down (default \\f[CR]j\\f[R] and \\f[CR]<down>\\f[R]), half\\-down (default \\f[CR]<c\\-d>\\f[R]), page\\-down (default \\f[CR]<c\\-f>\\f[R] and \\f[CR]<pgdn>\\f[R]), scroll\\-down (default \\f[CR]<c\\-e>\\f[R])\nMove/scroll the current file selection upwards/downwards by one/half a\npage/full page.\n.SS updir (default \\f[CR]h\\f[R] and \\f[CR]<left>\\f[R])\nChange the current working directory to the parent directory.\n.SS open (default \\f[CR]l\\f[R] and \\f[CR]<right>\\f[R])\nIf the current file is a directory, then change the current directory to\nit, otherwise, execute the \\f[CR]open\\f[R] command.\nA default \\f[CR]open\\f[R] command is provided to call the default system\nopener asynchronously with the current file as the argument.\nA custom \\f[CR]open\\f[R] command can be defined to override this\ndefault.\n.SS jump\\-next (default \\f[CR]]\\f[R]), jump\\-prev (default \\f[CR][\\f[R])\nChange the current working directory to the next/previous jumplist item.\n.SS top (default \\f[CR]gg\\f[R] and \\f[CR]<home>\\f[R]), bottom (default \\f[CR]G\\f[R] and \\f[CR]<end>\\f[R])\nMove the current file selection to the top/bottom of the directory.\nA count can be specified to move to a specific line, for example, use\n\\f[CR]3G\\f[R] to move to the third line.\n.SS high (default \\f[CR]H\\f[R]), middle (default \\f[CR]M\\f[R]), low (default \\f[CR]L\\f[R])\nMove the current file selection to the high/middle/low of the screen.\n.SS toggle\nToggle the selection of the current file or files given as arguments.\n.SS invert (default \\f[CR]v\\f[R])\nReverse the selection of all files in the current directory (i.e.\n\\f[CR]toggle\\f[R] all files).\nSelections in other directories are not affected by this command.\nYou can define a new command to select all files in the directory by\ncombining \\f[CR]invert\\f[R] with \\f[CR]unselect\\f[R] (i.e.\n\\f[CR]cmd select\\-all :unselect; invert\\f[R]), though this will also\nremove selections in other directories.\n.SS unselect (default \\f[CR]u\\f[R])\nRemove the selection of all files in all directories.\n.SS glob\\-select, glob\\-unselect\nSelect/unselect files that match the given glob.\n.SS copy (default \\f[CR]y\\f[R])\nSave the paths of selected files to the clipboard as files to be copied.\nIf there are no selected files, the path of the current file is used\ninstead.\n.SS cut (default \\f[CR]d\\f[R])\nSave the paths of selected files to the clipboard as files to be moved.\nIf there are no selected files, the path of the current file is used\ninstead.\n.SS paste (default \\f[CR]p\\f[R])\nCopy/Move files in the clipboard to the current working directory.\nA custom \\f[CR]paste\\f[R] command can be defined to override this\ndefault.\n.SS clear (default \\f[CR]c\\f[R])\nClear file paths in the clipboard.\n.SS sync\nSynchronize copied/cut files with the server.\nThis command is automatically called when required.\n.SS draw\nDraw the screen.\nThis command is automatically called when required.\n.SS redraw (default \\f[CR]<c\\-l>\\f[R])\nSynchronize the terminal and redraw the screen.\n.SS load\nLoad modified files and directories.\nThis command is automatically called when required.\n.SS reload (default \\f[CR]<c\\-r>\\f[R])\nFlush the cache and reload all files and directories.\n.SS delete (modal)\nRemove the current file or selected file(s).\nA custom \\f[CR]delete\\f[R] command can be defined to override this\ndefault.\n.SS rename (modal) (default \\f[CR]r\\f[R])\nRename the current file using the built\\-in method.\nA custom \\f[CR]rename\\f[R] command can be defined to override this\ndefault.\n.SS read (modal) (default \\f[CR]:\\f[R])\nRead a command to evaluate.\n.SS shell (modal) (default \\f[CR]$\\f[R])\nRead a shell command to execute.\n.SS shell\\-pipe (modal) (default \\f[CR]%\\f[R])\nRead a shell command to execute piping its standard I/O to the bottom\nstatline.\n.SS shell\\-wait (modal) (default \\f[CR]!\\f[R])\nRead a shell command to execute and wait for a key press at the end.\n.SS shell\\-async (modal) (default \\f[CR]&\\f[R])\nRead a shell command to execute asynchronously without standard I/O.\n.SS find (modal) (default \\f[CR]f\\f[R]), find\\-back (modal) (default \\f[CR]F\\f[R]), find\\-next (default \\f[CR];\\f[R]), find\\-prev (default \\f[CR],\\f[R])\nRead key(s) to find the appropriate filename match in the\nforward/backward direction and jump to the next/previous match.\n.SS search (default \\f[CR]/\\f[R]), search\\-back (default \\f[CR]?\\f[R]), search\\-next (default \\f[CR]n\\f[R]), search\\-prev (default \\f[CR]N\\f[R])\nRead a pattern to search for a filename match in the forward/backward\ndirection and jump to the next/previous match.\n.SS filter (modal), setfilter\nCommand \\f[CR]filter\\f[R] reads a pattern to filter out and only view\nfiles matching the pattern.\nCommand \\f[CR]setfilter\\f[R] does the same but uses an argument to set\nthe filter immediately.\nYou can supply an argument to \\f[CR]filter\\f[R] to use as the starting\nprompt.\n.SS mark\\-save (modal) (default \\f[CR]m\\f[R])\nSave the current directory as a bookmark assigned to the given key.\n.SS mark\\-load (modal) (default \\f[CR]\\(aq\\f[R])\nChange the current directory to the bookmark assigned to the given key.\nA special bookmark \\f[CR]\\(aq\\f[R] holds the previous directory after a\n\\f[CR]mark\\-load\\f[R], \\f[CR]cd\\f[R], or \\f[CR]select\\f[R] command.\n.SS mark\\-remove (modal) (default \\f[CR]\\(dq\\f[R])\nRemove a bookmark assigned to the given key.\n.SS tag\nTag a file with \\f[CR]*\\f[R] or a single\\-width character given in the\nargument.\nYou can define a new tag\\-clearing command by combining \\f[CR]tag\\f[R]\nwith \\f[CR]tag\\-toggle\\f[R] (i.e.\n\\f[CR]cmd tag\\-clear :tag; tag\\-toggle\\f[R]).\n.SS tag\\-toggle (default \\f[CR]t\\f[R])\nTag a file with \\f[CR]*\\f[R] or a single\\-width character given in the\nargument if the file is untagged, otherwise remove the tag.\n.SS echo\nPrint the given arguments to the message line at the bottom.\n.SS echomsg\nPrint the given arguments to the message line at the bottom and also to\nthe log file.\n.SS echoerr\nPrint given arguments to the message line at the bottom as\n\\f[CR]errorfmt\\f[R] and also to the log file.\n.SS cd\nChange the working directory to the given argument.\n.SS select\nChange the current file selection to the given argument.\n.SS source\nRead the configuration file given in the argument.\n.SS push\nSimulate key pushes given in the argument.\n.SS addcustominfo\nUpdate the \\f[CR]custom\\f[R] info and \\f[CR].Stat.CustomInfo\\f[R] field\nof the given file with the given string.\nThe info string may contain ANSI escape codes to further customize its\nappearance.\nIf no info is provided, clear the file\\(aqs info instead.\n.SS calcdirsize\nCalculate the total size for each of the selected directories.\nOption \\f[CR]info\\f[R] should include \\f[CR]size\\f[R] and option\n\\f[CR]dircounts\\f[R] should be disabled to show this size.\nIf the total size of a directory is not calculated, it will be shown as\n\\f[CR]\\-\\f[R].\n.SS clearmaps\nRemove all keybindings associated with the \\f[CR]map\\f[R],\n\\f[CR]nmap\\f[R] and \\f[CR]vmap\\f[R] command.\nThis command can be used in the config file to remove the default\nkeybindings.\nFor safety purposes, \\f[CR]:\\f[R] is left mapped to the \\f[CR]read\\f[R]\ncommand, and \\f[CR]cmap\\f[R] keybindings are retained so that it is\nstill possible to exit \\f[CR]lf\\f[R] using \\f[CR]:quit\\f[R].\n.SS tty\\-write\nWrite the given string to the tty.\nThis is useful for sending escape sequences to the terminal to control\nits behavior (e.g.\nOSC 0 to set the window title).\nUsing \\f[CR]tty\\-write\\f[R] is preferred over directly writing to\n\\f[CR]/dev/tty\\f[R] because the latter is not synchronized and can\ninterfere with drawing the UI.\n.SS visual (default \\f[CR]V\\f[R])\nSwitch to Visual mode.\nIf already in Visual mode, discard the visual selection and stay in\nVisual mode.\n.SH VISUAL MODE COMMANDS\n.SS visual\\-accept (default \\f[CR]V\\f[R])\nAdd the visual selection to the selection list, quit Visual mode and\nreturn to Normal mode.\n.SS visual\\-unselect\nRemove the visual selection from the selection list, quit Visual mode\nand return to Normal mode.\n.SS visual\\-discard (default \\f[CR]<esc>\\f[R])\nDiscard the visual selection, quit Visual mode and return to Normal\nmode.\n.SS visual\\-change (default \\f[CR]o\\f[R])\nGo to the other end of the current Visual mode selection.\n.SH COMMAND\\-LINE MODE COMMANDS\nThe prompt character specifies which of the several Command\\-line modes\nyou are in.\nFor example, the \\f[CR]read\\f[R] command takes you to the \\f[CR]:\\f[R]\nmode.\n.PP\nWhen the cursor is at the first character in \\f[CR]:\\f[R] mode, pressing\none of the keys \\f[CR]!\\f[R], \\f[CR]$\\f[R], \\f[CR]%\\f[R], or\n\\f[CR]&\\f[R] takes you to the corresponding mode.\nYou can go back with \\f[CR]cmd\\-delete\\-back\\f[R]\n(\\f[CR]<backspace>\\f[R] by default).\n.PP\nThe command line commands should be mostly compatible with readline\nkeybindings.\nA character refers to a Unicode code point, a word consists of letters\nand digits, and a Unix word consists of any non\\-blank characters.\n.SS cmd\\-insert\nInsert the character given in the argument.\nThis command is automatically called when required.\n.SS cmd\\-escape (default \\f[CR]<esc>\\f[R])\nQuit Command\\-line mode and return to Normal mode.\n.SS cmd\\-complete (default \\f[CR]<tab>\\f[R])\nAutocomplete the current word.\n.SS cmd\\-menu\\-complete, cmd\\-menu\\-complete\\-back\nAutocomplete the current word with the menu selection.\nYou need to assign keys to these commands (e.g.\n\\f[CR]cmap <tab> cmd\\-menu\\-complete; cmap <backtab> cmd\\-menu\\-complete\\-back\\f[R]).\nYou can use the assigned keys to display the menu and then cycle through\ncompletion options.\n.SS cmd\\-menu\\-accept\nAccept the currently selected match in menu completion and close the\nmenu.\n.SS cmd\\-menu\\-discard\nDiscard the currently selected match in menu completion and close the\nmenu.\n.SS cmd\\-enter (default \\f[CR]<c\\-j>\\f[R] and \\f[CR]<enter>\\f[R])\nExecute the current line.\n.SS cmd\\-interrupt (default \\f[CR]<c\\-c>\\f[R])\nInterrupt the current shell\\-pipe command and return to the Normal mode.\n.SS cmd\\-history\\-next (default \\f[CR]<c\\-n>\\f[R] and \\f[CR]<down>\\f[R]), cmd\\-history\\-prev (default \\f[CR]<c\\-p>\\f[R] and \\f[CR]<up>\\f[R])\nGo to the next/previous entry in the command history.\nIf part of the command is already typed, then only matching entries will\nbe considered, and consecutive duplicate entries are skipped.\n.SS cmd\\-left (default \\f[CR]<c\\-b>\\f[R] and \\f[CR]<left>\\f[R]), cmd\\-right (default \\f[CR]<c\\-f>\\f[R] and \\f[CR]<right>\\f[R])\nMove the cursor to the left/right.\n.SS cmd\\-home (default \\f[CR]<c\\-a>\\f[R] and \\f[CR]<home>\\f[R]), cmd\\-end (default \\f[CR]<c\\-e>\\f[R] and \\f[CR]<end>\\f[R])\nMove the cursor to the beginning/end of the line.\n.SS cmd\\-delete (default \\f[CR]<c\\-d>\\f[R] and \\f[CR]<delete>\\f[R])\nDelete the next character.\n.SS cmd\\-delete\\-back (default \\f[CR]<backspace>\\f[R])\nDelete the previous character.\nWhen at the beginning of a prompt, returns either to Normal mode or to\n\\f[CR]:\\f[R] mode.\n.SS cmd\\-delete\\-home (default \\f[CR]<c\\-u>\\f[R]), cmd\\-delete\\-end (default \\f[CR]<c\\-k>\\f[R])\nDelete everything up to the beginning/end of the line.\n.SS cmd\\-delete\\-unix\\-word (default \\f[CR]<c\\-w>\\f[R])\nDelete the previous Unix word.\n.SS cmd\\-yank (default \\f[CR]<c\\-y>\\f[R])\nPaste the buffer content containing the last deleted item.\n.SS cmd\\-transpose (default \\f[CR]<c\\-t>\\f[R])\nSwap the characters before and after the cursor, then move the cursor\nforward.\nIf there is no character after the cursor, swap the previous two\ncharacters instead.\n.SS cmd\\-transpose\\-word (default \\f[CR]<a\\-t>\\f[R])\nSwap the words before and after the cursor, then move the cursor\nforward.\nIf there is no word after the cursor, swap the previous two words\ninstead.\n.SS cmd\\-word (default \\f[CR]<a\\-f>\\f[R]), cmd\\-word\\-back (default \\f[CR]<a\\-b>\\f[R])\nMove the cursor by one word in the forward/backward direction.\n.SS cmd\\-delete\\-word (default \\f[CR]<a\\-d>\\f[R])\nDelete the next word in the forward direction.\n.SS cmd\\-delete\\-word\\-back (default \\f[CR]<a\\-backspace>\\f[R])\nDelete the previous word in the backward direction.\n.SS cmd\\-capitalize\\-word (default \\f[CR]<a\\-c>\\f[R]), cmd\\-uppercase\\-word (default \\f[CR]<a\\-u>\\f[R]), cmd\\-lowercase\\-word (default \\f[CR]<a\\-l>\\f[R])\nCapitalize/uppercase/lowercase the current word and jump to the next\nword.\n.SH SETTINGS\nThis section shows information about options to customize the behavior.\nCharacter \\f[CR]:\\f[R] is used as the separator for list options\n\\f[CR][]int\\f[R] and \\f[CR][]string\\f[R].\n.SS anchorfind (bool) (default true)\nWhen this option is enabled, the find command starts matching patterns\nfrom the beginning of filenames, otherwise, it can match at an arbitrary\nposition.\n.SS autoquit (bool) (default true)\nAutomatically quit the server when there are no clients left connected.\n.SS borderfmt (string) (default \\f[CR]\\(rs033[0m\\f[R])\nFormat string of border characters.\n.SS borderstyle (string) (default \\f[CR]box\\f[R])\nBorder style used by \\f[CR]drawbox\\f[R].\n.PP\nThe following styles are supported:\n.IP\n.EX\nbox           outline around all panes and separators between them\nroundbox      like \\(gabox\\(ga, but with rounded outer corners\noutline       outline around all panes\nroundoutline  like \\(gaoutline\\(ga, but with rounded outer corners\nseparators    separators between panes\n.EE\n.SS cleaner (string) (default \\(ga\\(ga) (not called if empty)\nSet the path of a cleaner file.\nThe file should be executable.\nThis file is called if previewing is enabled, the previewer is set, and\nthe previously selected file has its preview cache disabled.\nThe following arguments are passed to the file, (1) current filename,\n(2) width, (3) height, (4) horizontal position, (5) vertical position of\npreview pane and (6) next filename to be previewed respectively.\nPreview cleaning is disabled when the value of this option is left\nempty.\n.SS copyfmt (string) (default \\f[CR]\\(rs033[7;33m\\f[R])\nFormat string of the indicator for files to be copied.\n.SS cursoractivefmt (string) (default \\f[CR]\\(rs033[7m\\f[R]), cursorparentfmt (string) (default \\f[CR]\\(rs033[7m\\f[R]), cursorpreviewfmt (string) (default \\f[CR]\\(rs033[4m\\f[R])\nFormat strings for highlighting the cursor.\n\\f[CR]cursoractivefmt\\f[R] applies in the current directory pane,\n\\f[CR]cursorparentfmt\\f[R] applies in panes that show parents of the\ncurrent directory, and \\f[CR]cursorpreviewfmt\\f[R] applies in panes that\npreview directories.\n.PP\nThe default is to make the active cursor and the parent directory cursor\ninverted.\nThe preview cursor is underlined.\n.PP\nSome other possibilities to consider for the preview or parent cursors:\nan empty string for no cursor, \\f[CR]\\(rs033[7;2m\\f[R] for dimmed\ninverted text (visibility varies by terminal), \\f[CR]\\(rs033[7;90m\\f[R]\nfor inverted text with grey (aka \\(dqbrightblack\\(dq) background.\n.PP\nIf the format string contains the characters \\f[CR]%s\\f[R], it is\ninterpreted as a format string for \\f[CR]fmt.Sprintf\\f[R].\nSuch a string should end with the terminal reset sequence.\nFor example, \\f[CR]\\(rs033[4m%s\\(rs033[0m\\f[R] has the same effect as\n\\f[CR]\\(rs033[4m\\f[R].\n.SS cutfmt (string) (default \\f[CR]\\(rs033[7;31m\\f[R])\nFormat string of the indicator for files to be cut.\n.SS dircounts (bool) (default false)\nWhen this option is enabled, directory sizes show the number of items\ninside instead of the total size of the directory, which needs to be\ncalculated for each directory using \\f[CR]calcdirsize\\f[R].\nThis information needs to be calculated by reading the directory and\ncounting the items inside.\nTherefore, this option is disabled by default for performance reasons.\nThis option only has an effect when \\f[CR]info\\f[R] has a\n\\f[CR]size\\f[R] field and the pane is wide enough to show the\ninformation.\n999 items are counted per directory at most, and bigger directories are\nshown as \\f[CR]999+\\f[R].\n.SS dirfirst (bool) (default true)\nShow directories first above regular files.\nWith \\f[CR]dircounts\\f[R] enabled, sorting by \\f[CR]size\\f[R] always\nseparates directories and files, regardless of \\f[CR]dirfirst\\f[R].\n.SS dironly (bool) (default false)\nShow only directories.\n.SS dirpreviews (bool) (default false)\nIf enabled, directories will also be passed to the previewer script.\nThis allows custom previews for directories.\n.SS drawbox (bool) (default false)\nDraw borders around panes using box drawing characters.\n.SS dupfilefmt (string) (default \\f[CR]%f.\\(ti%n\\(ti\\f[R])\nFormat string of filename when creating duplicate files.\nWith the default format, copying a file \\f[CR]abc.txt\\f[R] to the same\ndirectory will result in a duplicate file called\n\\f[CR]abc.txt.\\(ti1\\(ti\\f[R].\nSpecial expansions are provided, \\f[CR]%f\\f[R] as the file name,\n\\f[CR]%b\\f[R] for the base name (file name without extension),\n\\f[CR]%e\\f[R] as the extension (including the dot) and \\f[CR]%n\\f[R] as\nthe number of duplicates.\n.SS errorfmt (string) (default \\f[CR]\\(rs033[7;31;47m\\f[R])\nFormat string of error messages shown in the bottom message line.\n.PP\nIf the format string contains the characters \\f[CR]%s\\f[R], it is\ninterpreted as a format string for \\f[CR]fmt.Sprintf\\f[R].\nSuch a string should end with the terminal reset sequence.\nFor example, \\f[CR]\\(rs033[4m%s\\(rs033[0m\\f[R] has the same effect as\n\\f[CR]\\(rs033[4m\\f[R].\n.SS filesep (string) (default \\f[CR]\\(rsn\\f[R])\nFile separator used in environment variables \\f[CR]fs\\f[R],\n\\f[CR]fv\\f[R] and \\f[CR]fx\\f[R].\n.SS filtermethod (string) (default \\f[CR]text\\f[R])\nHow filter command patterns are treated.\nCurrently supported methods are \\f[CR]text\\f[R] (i.e.\nstring literals), \\f[CR]glob\\f[R] (i.e.\nshell globs) and \\f[CR]regex\\f[R] (i.e.\nregular expressions).\nSee \\f[CR]SEARCHING FILES\\f[R] for more details.\n.SS findlen (int) (default 1)\nNumber of characters prompted for the find command.\nWhen this value is set to 0, find command prompts until there is only a\nsingle match left.\n.SS hidden (bool) (default false)\nShow hidden files.\nOn Unix systems, hidden files are determined by the value of\n\\f[CR]hiddenfiles\\f[R].\nOn Windows, files with hidden attributes are also considered hidden\nfiles.\n.SS hiddenfiles ([]string) (default \\f[CR].*\\f[R] for Unix and \\(ga\\(ga for Windows)\nList of hidden file glob patterns.\nPatterns can be given as relative or absolute paths.\nGlobbing supports the usual special characters, \\f[CR]*\\f[R] to match\nany sequence, \\f[CR]?\\f[R] to match any character, and \\f[CR][...]\\f[R]\nor \\f[CR][\\(ha...]\\f[R] to match character sets or ranges.\nIn addition, if a pattern starts with \\f[CR]!\\f[R], then its matches are\nexcluded from hidden files.\nTo add multiple patterns, use \\f[CR]:\\f[R] as a separator.\nExample: \\f[CR].*:lost+found:*.bak\\f[R]\n.SS history (bool) (default true)\nSave command history.\n.SS icons (bool) (default false)\nShow icons before each item in the list.\n.SS ifs (string) (default \\(ga\\(ga)\nSets \\f[CR]IFS\\f[R] variable in shell commands.\nIt works by adding the assignment to the beginning of the command string\nas \\f[CR]IFS=...; ...\\f[R].\nThe reason is that \\f[CR]IFS\\f[R] variable is not inherited by the shell\nfor security reasons.\nThis method assumes a POSIX shell syntax so it can fail for non\\-POSIX\nshells.\nThis option has no effect when the value is left empty.\nThis option does not have any effect on Windows.\n.SS ignorecase (bool) (default true)\nIgnore case in sorting and search patterns.\n.SS ignoredia (bool) (default true)\nIgnore diacritics in sorting and search patterns.\n.SS incfilter (bool) (default false)\nApply filter pattern after each keystroke during filtering.\n.SS incsearch (bool) (default false)\nJump to the first match after each keystroke during searching.\n.SS info ([]string) (default \\(ga\\(ga)\nA list of information that is shown for directory items at the right\nside of the pane.\n.PP\nThe following information types are supported:\n.IP\n.EX\nperm      file permission\nuser      user name\ngroup     group name\nsize      file size\ntime      time of last data modification\natime     time of last access\nbtime     time of file birth\nctime     time of last status (inode) change\ncustom    property defined via \\(gaaddcustominfo\\(ga (empty by default)\n.EE\n.PP\nInformation is only shown when the pane width is more than twice the\nwidth of information.\n.SS infotimefmtnew (string) (default \\f[CR]Jan _2 15:04\\f[R])\nFormat string of the file time shown in the info column when it matches\nthis year.\n.SS infotimefmtold (string) (default \\f[CR]Jan _2  2006\\f[R])\nFormat string of the file time shown in the info column when it\ndoesn\\(aqt match this year.\n.SS menufmt (string) (default \\f[CR]\\(rs033[0m\\f[R])\nFormat string of the menu.\n.SS menuheaderfmt (string) (default \\f[CR]\\(rs033[1m\\f[R])\nFormat string of the header row in the menu.\n.SS menuselectfmt (string) (default \\f[CR]\\(rs033[7m\\f[R])\nFormat string of the currently selected item in the menu.\n.SS mergeindicators (bool) (default false)\nWhen \\f[CR]mergeindicators\\f[R] is enabled, tag and selection indicators\nare drawn in a single column to reduce the gap before filenames.\nIf a file is both tagged and selected, the tag uses the selection format\n(e.g.\n\\f[CR]copyfmt\\f[R]) instead of \\f[CR]tagfmt\\f[R].\n.SS mouse (bool) (default false)\nSend mouse events as input.\n.SS number (bool) (default false)\nShow the position number for directory items on the left side of the\npane.\nWhen the \\f[CR]relativenumber\\f[R] option is enabled, only the current\nline shows the absolute position and relative positions are shown for\nthe rest.\n.SS numberfmt (string) (default \\f[CR]\\(rs033[33m\\f[R]), numbercursorfmt (string) (default \\(ga\\(ga)\nFormat strings for highlighting line numbers.\n\\f[CR]numberfmt\\f[R] applies to all lines.\n\\f[CR]numbercursorfmt\\f[R] applies to the cursor line and falls back to\n\\f[CR]numberfmt\\f[R] when left empty.\n.SS period (int) (default 0)\nSet the interval in seconds for periodic checks of directory updates.\nThis works by periodically calling the \\f[CR]load\\f[R] command.\nNote that directories are already updated automatically in many cases.\nThis option can be useful when there is an external process changing the\ndisplayed directory and you are not doing anything in lf.\nPeriodic checks are disabled when the value of this option is set to\nzero.\n.SS preload (bool) (default false)\nAllow previews to be generated in advance using the \\f[CR]previewer\\f[R]\nscript as the user navigates through the filesystem.\n.SS preserve ([]string) (default \\f[CR]mode\\f[R])\nList of attributes that are preserved when copying files.\nCurrently supported attributes are \\f[CR]mode\\f[R] (i.e.\naccess mode) and \\f[CR]timestamps\\f[R] (i.e.\nmodification time and access time).\nNote that preserving other attributes like ownership of change/birth\ntimestamp is desirable, but not portably supported in Go.\n.SS preview (bool) (default true)\nShow previews of files and directories at the rightmost pane.\nIf the file has more lines than the preview pane, the rest of the lines\nare not read.\nFiles containing the null character (U+0000) in the read portion are\nconsidered binary files and displayed as \\f[CR]binary\\f[R].\n.SS previewer (string) (default \\(ga\\(ga) (not filtered if empty)\nSet the path of a previewer file to filter the content of regular files\nfor previewing.\nThe file should be executable.\nThe following arguments are passed to the file, (1) current filename,\n(2) width, (3) height, (4) horizontal position, (5) vertical position,\nand (6) mode (\\(dqpreview\\(dq or \\(dqpreload\\(dq).\nSIGPIPE signal is sent when enough lines are read.\nIf the previewer returns a non\\-zero exit code, then the preview cache\nfor the given file is disabled.\nThis means that if the file is selected in the future, the previewer is\ncalled once again.\nPreview filtering is disabled and files are displayed as they are when\nthe value of this option is left empty.\nIf the \\f[CR]preload\\f[R] option is enabled, then this will be called\nwith \\f[CR]preload\\f[R] as the mode when preloading file previews.\nRefer to the \\c\n.UR https://github.com/gokcehan/lf/blob/master/doc.md#previewing-files\nPREVIEWING FILES section\n.UE \\c\n\\ for more information about how to configure custom previews.\n.SS promptfmt (string) (default \\f[CR]\\(rs033[32;1m%u\\(at%h\\(rs033[0m:\\(rs033[34;1m%d\\(rs033[0m\\(rs033[1m%f\\(rs033[0m\\f[R])\nFormat string of the prompt shown in the top line.\n.PP\nThe following special expansions are supported:\n.IP\n.EX\n%f        file name\n%h        host name\n%u        user name\n%w        working directory\n%d        working directory (with trailing path separator)\n%F        current filter\n%S        spacer to right\\-align the following parts (can be used once)\n.EE\n.PP\nThe home folder is shown as \\f[CR]\\(ti\\f[R] in the working directory\nexpansion.\nDirectory names are automatically shortened to a single character\nstarting from the leftmost parent when the prompt does not fit the\nscreen.\n.SS ratios ([]int) (default \\f[CR]1:2:3\\f[R])\nList of ratios of pane widths.\nNumber of items in the list determines the number of panes in the UI.\nWhen the \\f[CR]preview\\f[R] option is enabled, the rightmost number is\nused for the width of the preview pane.\n.SS relativenumber (bool) (default false)\nShow the position number relative to the current line.\nWhen \\f[CR]number\\f[R] is enabled, the current line shows the absolute\nposition, otherwise nothing is shown.\n.SS reverse (bool) (default false)\nReverse the direction of sort.\n.SS rulerfile (string) (default \\(ga\\(ga)\nSet the path of the ruler file.\nIf not set, then a default template will be used for the ruler.\nRefer to the \\c\n.UR https://github.com/gokcehan/lf/blob/master/doc.md#ruler\nRULER section\n.UE \\c\n\\ for more information about how the ruler file works.\n.SS rulerfmt (string) (default \\(ga\\(ga)\nFormat string of the ruler shown in the bottom right corner.\nWhen set, it will be used along with \\f[CR]statfmt\\f[R] to draw the\nruler, and \\f[CR]rulerfile\\f[R] will be ignored.\nHowever, using \\f[CR]rulerfile\\f[R] is preferred and this option is\nprovided for backwards compatibility.\n.PP\nThe following special expansions are supported:\n.IP\n.EX\n%a        pressed keys\n%p        progress of file operations\n%m        number of files to be cut (moved)\n%c        number of files to be copied\n%s        number of selected files\n%v        number of visually selected files\n%t        number of shown files in the current directory\n%h        number of hidden files in the current directory\n%f        current filter\n%i        cursor position\n%P        scroll percentage\n%d        amount of free disk space\n.EE\n.PP\nAdditional expansions are provided for environment variables exported by\nlf, in the form \\f[CR]%{lf_<name>}\\f[R] (e.g.\n\\f[CR]%{lf_selmode}\\f[R]).\nThis is useful for displaying the current settings.\nExpansions are also provided for user\\-defined options, in the form\n\\f[CR]%{lf_user_<name>}\\f[R] (e.g.\n\\f[CR]%{lf_user_foo}\\f[R]).\nThe \\f[CR]|\\f[R] character splits the format string into sections.\nAny section containing a failed expansion (result is a blank string) is\ndiscarded and not shown.\n.SS scrolloff (int) (default 0)\nMinimum number of offset lines shown at all times at the top and bottom\nof the screen when scrolling.\nThe current line is kept in the middle when this option is set to a\nlarge value that is bigger than half the number of lines.\nA smaller offset can be used when the current file is close to the\nbeginning or end of the list to show the maximum number of items.\n.SS searchmethod (string) (default \\f[CR]text\\f[R])\nHow search command patterns are treated.\nCurrently supported methods are \\f[CR]text\\f[R] (i.e.\nstring literals), \\f[CR]glob\\f[R] (i.e.\nshell globs) and \\f[CR]regex\\f[R] (i.e.\nregular expressions).\nSee \\f[CR]SEARCHING FILES\\f[R] for more details.\n.SS selectfmt (string) (default \\f[CR]\\(rs033[7;35m\\f[R])\nFormat string of the indicator for files that are selected.\n.SS selmode (string) (default \\f[CR]all\\f[R])\nSelection mode for commands.\nWhen set to \\f[CR]all\\f[R] it will use the selected files from all\ndirectories.\nWhen set to \\f[CR]dir\\f[R] it will only use the selected files in the\ncurrent directory.\n.SS shell (string) (default \\f[CR]sh\\f[R] for Unix and \\f[CR]cmd\\f[R] for Windows)\nShell executable to use for shell commands.\nShell commands are executed as\n\\f[CR]shell shellopts shellflag command \\-\\- arguments\\f[R].\n.SS shellflag (string) (default \\f[CR]\\-c\\f[R] for Unix and \\f[CR]/c\\f[R] for Windows)\nCommand line flag used to pass shell commands.\n.SS shellopts ([]string) (default \\(ga\\(ga)\nList of shell options to pass to the shell executable.\n.SS showbinds (bool) (default true)\nShow bindings associated with pressed keys.\n.SS sizeunits (string) (default \\f[CR]binary\\f[R])\nDetermines whether file sizes are displayed using binary units\n(\\f[CR]1K\\f[R] is 1024 bytes) or decimal units (\\f[CR]1K\\f[R] is 1000\nbytes).\n.SS smartcase (bool) (default true)\nOverride \\f[CR]ignorecase\\f[R] option when the pattern contains an\nuppercase character.\nThis option has no effect when \\f[CR]ignorecase\\f[R] is disabled.\n.SS smartdia (bool) (default false)\nOverride \\f[CR]ignoredia\\f[R] option when the pattern contains a\ncharacter with diacritic.\nThis option has no effect when \\f[CR]ignoredia\\f[R] is disabled.\n.SS sortby (string) (default \\f[CR]natural\\f[R])\nSort type for directories.\n.PP\nThe following sort types are supported:\n.IP\n.EX\nnatural   file name (track_2.flac comes before track_10.flac)\nname      file name (track_10.flac comes before track_2.flac)\next       file extension\nsize      file size\ntime      time of last data modification\natime     time of last access\nbtime     time of file birth\nctime     time of last status (inode) change\ncustom    property defined via \\(gaaddcustominfo\\(ga (empty by default)\n.EE\n.SS statfmt (string) (default \\f[CR]\\(rs033[36m%p\\(rs033[0m| %c| %u| %g| %S| %t| \\-> %l\\f[R])\nFormat string of the file info shown in the bottom left corner.\nThis option has no effect unless \\f[CR]rulerfmt\\f[R] is also set.\nUsing \\f[CR]rulerfile\\f[R] is preferred and this option is provided for\nbackwards compatibility.\n.PP\nThe following special expansions are supported:\n.IP\n.EX\n%p        file permission\n%c        link count\n%u        user name\n%g        group name\n%s        file size\n%S        file size (left\\-padded with spaces to a fixed width of 5 characters)\n%t        time of last data modification\n%l        link target\n%m        current mode\n%M        current mode (displaying \\(gaNORMAL\\(ga instead of a blank string in Normal mode)\n.EE\n.PP\nThe \\f[CR]|\\f[R] character splits the format string into sections.\nAny section containing a failed expansion (result is a blank string) is\ndiscarded and not shown.\n.SS tabstop (int) (default 8)\nNumber of space characters to show for horizontal tabulation (U+0009)\ncharacter.\n.SS tagfmt (string) (default \\f[CR]\\(rs033[31m\\f[R])\nFormat string of the tags.\n.PP\nIf the format string contains the characters \\f[CR]%s\\f[R], it is\ninterpreted as a format string for \\f[CR]fmt.Sprintf\\f[R].\nSuch a string should end with the terminal reset sequence.\nFor example, \\f[CR]\\(rs033[4m%s\\(rs033[0m\\f[R] has the same effect as\n\\f[CR]\\(rs033[4m\\f[R].\n.SS tempmarks (string) (default \\(ga\\(ga)\nMarks to be considered temporary (e.g.\n\\f[CR]abc\\f[R] refers to marks \\f[CR]a\\f[R], \\f[CR]b\\f[R], and\n\\f[CR]c\\f[R]).\nThese marks are not synced to other clients and they are not saved in\nthe bookmarks file.\nNote that the special bookmark \\f[CR]\\(aq\\f[R] is always treated as\ntemporary and it does not need to be specified.\n.SS terminalcursor (string) (default \\f[CR]default\\f[R])\nSet the appearance of the terminal cursor for prompts shown in the\nbottom line.\nCurrently supported values are \\f[CR]default\\f[R], \\f[CR]block\\f[R],\n\\f[CR]underline\\f[R], \\f[CR]bar\\f[R], \\f[CR]blinkblock\\f[R],\n\\f[CR]blinkunderline\\f[R] and \\f[CR]blinkbar\\f[R].\n.SS timefmt (string) (default \\f[CR]Mon Jan _2 15:04:05 2006\\f[R])\nFormat string of the file modification time shown in the bottom line.\n.SS truncatechar (string) (default \\f[CR]\\(ti\\f[R])\nThe truncate character that is shown at the end when the filename does\nnot fit into the pane.\n.SS truncatepct (int) (default 100)\nWhen a filename is too long to be shown completely, the available space\nwill be partitioned into two parts.\n\\f[CR]truncatepct\\f[R] is a percentage value between 0 and 100 that\ndetermines the size of the first part, which will be shown at the\nbeginning of the filename.\nThe second part uses the rest of the available space, and will be shown\nat the end of the filename.\nBoth parts are separated by the truncation character\n(\\f[CR]truncatechar\\f[R]).\nTruncation is not applied to the file extension.\n.PP\nFor example, with the filename \\f[CR]very_long_filename.txt\\f[R]:\n.IP \\(bu 2\n\\f[CR]set truncatepct 100\\f[R] \\-> \\f[CR]very_long_filena\\(ti.txt\\f[R]\n(default)\n.IP \\(bu 2\n\\f[CR]set truncatepct 50\\f[R] \\-> \\f[CR]very_lon\\(tifilename.txt\\f[R]\n.IP \\(bu 2\n\\f[CR]set truncatepct 0\\f[R] \\-> \\f[CR]\\(tiry_long_filename.txt\\f[R]\n.SS visualfmt (string) (default \\f[CR]\\(rs033[7;36m\\f[R])\nFormat string of the indicator for files that are visually selected.\n.SS waitmsg (string) (default \\f[CR]Press any key to continue\\f[R])\nString shown after commands of shell\\-wait type.\n.SS watch (bool) (default false)\nWatch the filesystem for changes using \\f[CR]fsnotify\\f[R] to\nautomatically refresh file information.\nFUSE is currently not supported due to limitations in\n\\f[CR]fsnotify\\f[R].\n.SS wrapscan (bool) (default true)\nSearching can wrap around the file list.\n.SS wrapscroll (bool) (default false)\nScrolling can wrap around the file list.\n.SS user_{option} (string) (default none)\nAny option that is prefixed with \\f[CR]user_\\f[R] is a user\\-defined\noption and can be set to any string.\nInside a user\\-defined command, the value will be provided in the\n\\f[CR]lf_user_{option}\\f[R] environment variable.\nThese options are not used by lf and are not persisted.\n.SH ENVIRONMENT VARIABLES\nThe following variables are exported for shell commands: These are\nreferred to with a \\f[CR]$\\f[R] prefix on POSIX shells (e.g.\n\\f[CR]$f\\f[R]), between \\f[CR]%\\f[R] characters on Windows cmd (e.g.\n\\f[CR]%f%\\f[R]), and with a \\f[CR]$env:\\f[R] prefix on Windows\nPowerShell (e.g.\n\\f[CR]$env:f\\f[R]).\n.SS f\nCurrent file selection as a full path.\n.SS fs\nSelected file(s) separated with the value of \\f[CR]filesep\\f[R] option\nas full path(s).\n.SS fv\nVisually selected file(s) separated with the value of \\f[CR]filesep\\f[R]\noption as full path(s).\n.SS fx\nSelected file(s) (i.e.\n\\f[CR]fs\\f[R], never \\f[CR]fv\\f[R]) if there are any selected files,\notherwise current file selection (i.e.\n\\f[CR]f\\f[R]).\n.SS id\nId of the running client.\n.SS PWD\nPresent working directory.\n.SS OLDPWD\nInitial working directory.\n.SS LF_LEVEL\nThe value of this variable is set to the current nesting level when you\nrun lf from a shell spawned inside lf.\nYou can add the value of this variable to your shell prompt to make it\nclear that your shell runs inside lf.\nFor example, with POSIX shells, you can use\n\\f[CR][ \\-n \\(dq$LF_LEVEL\\(dq ] && PS1=\\(dq$PS1\\(dq\\(dq(lf level: $LF_LEVEL) \\(dq\\f[R]\nin your shell configuration file (e.g.\n\\f[CR]\\(ti/.bashrc\\f[R]).\n.SS OPENER\nIf this variable is set in the environment, use the same value.\nOtherwise, this is set to \\f[CR]start\\f[R] in Windows, \\f[CR]open\\f[R]\nin macOS, \\f[CR]xdg\\-open\\f[R] in others.\n.SS EDITOR\nIf VISUAL is set in the environment, use its value.\nOtherwise, use the value of the environment variable EDITOR.\nIf neither variable is set, this is set to \\f[CR]vi\\f[R] on Unix,\n\\f[CR]notepad\\f[R] in Windows.\n.SS PAGER\nIf this variable is set in the environment, use the same value.\nOtherwise, this is set to \\f[CR]less\\f[R] on Unix, \\f[CR]more\\f[R] in\nWindows.\n.SS SHELL\nIf this variable is set in the environment, use the same value.\nOtherwise, this is set to \\f[CR]sh\\f[R] on Unix, \\f[CR]cmd\\f[R] in\nWindows.\n.SS lf\nAbsolute path to the currently running lf binary, if it can be found.\nOtherwise, this is set to the string \\f[CR]lf\\f[R].\n.SS lf_{option}\nValue of the {option}.\n.SS lf_user_{option}\nValue of the user_{option}.\n.SS lf_flag_{flag}\nValue of the command line {flag}.\n.SS lf_width, lf_height\nWidth/Height of the terminal.\n.SS lf_count\nValue of the count associated with the current command.\n.SS lf_mode\nCurrent mode that \\f[CR]lf\\f[R] is operating in.\nThis is useful for customizing keybindings depending on what the current\nmode is.\nPossible values are \\f[CR]compmenu\\f[R], \\f[CR]delete\\f[R],\n\\f[CR]rename\\f[R], \\f[CR]filter\\f[R], \\f[CR]find\\f[R], \\f[CR]mark\\f[R],\n\\f[CR]search\\f[R], \\f[CR]command\\f[R], \\f[CR]shell\\f[R], \\f[CR]pipe\\f[R]\n(when running a shell\\-pipe command), \\f[CR]normal\\f[R],\n\\f[CR]visual\\f[R] and \\f[CR]unknown\\f[R].\n.SH SPECIAL COMMANDS\nThis section shows information about special shell commands.\n.SS open\nThis shell command can be defined to override the default\n\\f[CR]open\\f[R] command when the current file is not a directory.\n.SS paste\nThis shell command can be defined to override the default\n\\f[CR]paste\\f[R] command.\n.SS rename\nThis shell command can be defined to override the default\n\\f[CR]rename\\f[R] command.\n.SS delete\nThis shell command can be defined to override the default\n\\f[CR]delete\\f[R] command.\n.SS pre\\-cd\nThis shell command can be defined to be executed before changing a\ndirectory.\n.SS on\\-cd\nThis shell command can be defined to be executed after changing a\ndirectory.\n.SS on\\-load\nThis shell command can be defined to be executed after loading a\ndirectory.\nIt provides the files inside the directory as arguments.\n.SS on\\-focus\\-gained\nThis shell command can be defined to be executed when the terminal gains\nfocus.\n.SS on\\-focus\\-lost\nThis shell command can be defined to be executed when the terminal loses\nfocus.\n.SS on\\-init\nThis shell command can be defined to be executed after initializing and\nconnecting to the server.\n.SS on\\-select\nThis shell command can be defined to be executed after the selection\nchanges.\n.SS on\\-redraw\nThis shell command can be defined to be executed after the screen is\nredrawn or if the terminal is resized.\n.SS on\\-quit\nThis shell command can be defined to be executed before quitting.\n.SH PREFIXES\nThe following command prefixes are used by lf:\n.IP\n.EX\n:  read (default)  built\\-in/custom command\n$  shell           shell command\n%  shell\\-pipe      shell command running with the UI\n!  shell\\-wait      shell command waiting for a key press\n&  shell\\-async     shell command running asynchronously\n.EE\n.PP\nThe same evaluator is used for the command line and the configuration\nfile for reading shell commands.\nThe difference is that prefixes are not necessary in the command line.\nInstead, different modes are provided to read corresponding commands.\nThese modes are mapped to the prefix keys above by default.\nVisual mode mappings are defined the same way Normal mode mappings are\ndefined.\n.SH SYNTAX\nCharacters from \\f[CR]#\\f[R] to newline are comments and ignored:\n.IP\n.EX\n# comments start with \\(ga#\\(ga\n.EE\n.PP\nThe following commands (\\f[CR]set\\f[R], \\f[CR]setlocal\\f[R],\n\\f[CR]map\\f[R], \\f[CR]nmap\\f[R], \\f[CR]vmap\\f[R], \\f[CR]cmap\\f[R], and\n\\f[CR]cmd\\f[R]) are used for configuration.\n.PP\nCommand \\f[CR]set\\f[R] is used to set an option which can be a boolean,\ninteger, or string:\n.IP\n.EX\nset hidden         # boolean enable\nset hidden true    # boolean enable\nset nohidden       # boolean disable\nset hidden false   # boolean disable\nset hidden!        # boolean toggle\nset scrolloff 10   # integer value\nset sortby time    # string value without quotes\nset sortby \\(aqtime\\(aq  # string value with single quotes (whitespace)\nset sortby \\(dqtime\\(dq  # string value with double quotes (backslash escapes)\n.EE\n.PP\nCommand \\f[CR]setlocal\\f[R] is used to set a local option for a\ndirectory which can be a boolean or string.\nCurrently supported local options are \\f[CR]dircounts\\f[R],\n\\f[CR]dirfirst\\f[R], \\f[CR]dironly\\f[R], \\f[CR]hidden\\f[R],\n\\f[CR]info\\f[R], \\f[CR]reverse\\f[R] and \\f[CR]sortby\\f[R].\n.IP\n.EX\nsetlocal /foo/bar hidden         # boolean enable\nsetlocal /foo/bar hidden true    # boolean enable\nsetlocal /foo/bar nohidden       # boolean disable\nsetlocal /foo/bar hidden false   # boolean disable\nsetlocal /foo/bar hidden!        # boolean toggle\nsetlocal /foo/bar sortby time    # string value without quotes\nsetlocal /foo/bar sortby \\(aqtime\\(aq  # string value with single quotes (whitespace)\nsetlocal /foo/bar sortby \\(dqtime\\(dq  # string value with double quotes (backslash escapes)\n.EE\n.PP\nCommand \\f[CR]map\\f[R] is used to bind a key in Normal and Visual mode\nto a command which can be a built\\-in command, custom command, or shell\ncommand:\n.IP\n.EX\nmap gh cd \\(ti        # built\\-in command\nmap D trash        # custom command\nmap i $less $f     # shell command\nmap U !du \\-csh *   # waiting shell command\n.EE\n.PP\nCommand \\f[CR]nmap\\f[R] does the same but for Normal mode only.\n.PP\nCommand \\f[CR]vmap\\f[R] does the same but for Visual mode only.\n.PP\nOverview of which map command works in which mode:\n.IP\n.EX\nmap                Normal, Visual\nnmap               Normal\nvmap               Visual\ncmap               Command\\-line\n.EE\n.PP\nCommand \\f[CR]cmap\\f[R] is used to bind a key on the command line to a\ncommand line command or any other command:\n.IP\n.EX\ncmap <c\\-g> cmd\\-escape\ncmap <a\\-i> set incsearch!\n.EE\n.PP\nYou can delete an existing binding by leaving the expression empty:\n.IP\n.EX\nmap gh             # deletes \\(aqgh\\(aq mapping in Normal and Visual mode\nnmap v             # deletes \\(aqv\\(aq mapping in Normal mode\nvmap o             # deletes \\(aqo\\(aq mapping in Visual mode\ncmap <c\\-g>         # deletes \\(aq<c\\-g>\\(aq mapping\n.EE\n.PP\nCommand \\f[CR]cmd\\f[R] is used to define a custom command:\n.IP\n.EX\ncmd usage $du \\-h \\-d1 | less\n.EE\n.PP\nYou can delete an existing command by leaving the expression empty:\n.IP\n.EX\ncmd trash          # deletes \\(aqtrash\\(aq command\n.EE\n.PP\nIf there is no prefix then \\f[CR]:\\f[R] is assumed:\n.IP\n.EX\nmap zt set info time\n.EE\n.PP\nAn explicit \\f[CR]:\\f[R] can be provided to group statements until a\nnewline which is especially useful for \\f[CR]map\\f[R] and \\f[CR]cmd\\f[R]\ncommands:\n.IP\n.EX\nmap st :set sortby time; set info time\n.EE\n.PP\nIf you need multiline you can wrap statements in \\f[CR]{{\\f[R] and\n\\f[CR]}}\\f[R] after the proper prefix.\n.IP\n.EX\nmap st :{{\n    set sortby time\n    set info time\n}}\n.EE\n.SH KEY MAPPINGS\nRegular keys are assigned to a command with the usual syntax:\n.IP\n.EX\nmap a down\n.EE\n.PP\nKeys combined with the Shift key simply use the uppercase letter:\n.IP\n.EX\nmap A down\n.EE\n.PP\nSpecial keys are written in between \\f[CR]<\\f[R] and \\f[CR]>\\f[R]\ncharacters and always use lowercase letters:\n.IP\n.EX\nmap <enter> down\n.EE\n.PP\nAngle brackets can be assigned with their special names:\n.IP\n.EX\nmap <lt> down\nmap <gt> down\n.EE\n.PP\nFunction keys are prefixed with an \\f[CR]f\\f[R] character:\n.IP\n.EX\nmap <f\\-1> down\n.EE\n.PP\nKeys combined with the Ctrl key are prefixed with a \\f[CR]c\\f[R]\ncharacter:\n.IP\n.EX\nmap <c\\-a> down\n.EE\n.PP\nKeys combined with the Alt key are assigned in two different ways\ndepending on the behavior of your terminal.\nOlder terminals (e.g.\nxterm) may set the 8th bit of a character when the Alt key is pressed.\nOn these terminals, you can use the corresponding byte for the mapping:\n.IP\n.EX\nmap á down\n.EE\n.PP\nNewer terminals (e.g.\ngnome\\-terminal) may prefix the key with an escape character when the\nAlt key is pressed.\nlf uses the escape delaying mechanism to recognize Alt keys in these\nterminals (delay is 100ms).\nOn these terminals, keys combined with the Alt key are prefixed with an\n\\f[CR]a\\f[R] character:\n.IP\n.EX\nmap <a\\-a> down\n.EE\n.PP\nIt is possible to combine special keys with modifiers:\n.IP\n.EX\nmap <a\\-enter> down\n.EE\n.PP\nCombining multiple modifiers (e.g.\n\\f[CR]Ctrl+Shift+Space\\f[R]) is not supported.\n.PP\nNote that lf\\(aqs key mapping syntax is similar to Vim\\(aqs, but not\nidentical.\nSome special keys and modifiers use different names and separators, and\nkey names are matched literally (i.e.\nno case\\-folding, no aliases), so some familiar forms will not work:\n.IP\n.EX\nmap <enter> down  # not <Enter>, <Return> or <CR>\nmap <f\\-1> down    # not <F1>\nmap <a\\-j> down    # not <A\\-j> or <M\\-j> (Meta)\nmap <m\\-2> down    # not <RightMouse>\nmap <m\\-up> down   # not <ScrollWheelUp>\n.EE\n.PP\nWARNING: Some key combinations will likely be intercepted by your OS,\nwindow manager, or terminal.\nOther key combinations cannot be recognized by lf due to the way\nterminals work (e.g.\n\\f[CR]Ctrl+h\\f[R] combination sends a backspace key instead).\nThe easiest way to find out the name of a key combination and whether it\nwill work on your system is to press the key while lf is running and\nread the name from the \\f[CR]unknown mapping\\f[R] error.\n.PP\nMouse buttons are prefixed with an \\f[CR]m\\f[R] character:\n.IP\n.EX\nmap <m\\-1> down  # primary\nmap <m\\-2> down  # secondary\nmap <m\\-3> down  # middle\nmap <m\\-4> down  # thumb next\nmap <m\\-5> down  # thumb prev\nmap <m\\-6> down\nmap <m\\-7> down\nmap <m\\-8> down\n.EE\n.PP\nMouse wheel events are also prefixed with an \\f[CR]m\\f[R] character:\n.IP\n.EX\nmap <m\\-up>    down\nmap <m\\-down>  down\nmap <m\\-left>  down\nmap <m\\-right> down\n.EE\n.SH PUSH MAPPINGS\nThe usual way to map a key sequence is to assign it to a named or\nunnamed command.\nWhile this provides a clean way to remap built\\-in keys as well as other\ncommands, it can be limiting at times.\nFor this reason, the \\f[CR]push\\f[R] command is provided by lf.\nThis command is used to simulate key pushes given as its arguments.\nYou can \\f[CR]map\\f[R] a key to a \\f[CR]push\\f[R] command with an\nargument to create various keybindings.\n.PP\nThis is mainly useful for two purposes.\nFirst, it can be used to map a command with a command count:\n.IP\n.EX\nmap <c\\-j> push 10j\n.EE\n.PP\nSecond, it can be used to avoid typing the name when a command takes\narguments:\n.IP\n.EX\nmap r push :rename<space>\n.EE\n.PP\nOne thing to be careful of is that since the \\f[CR]push\\f[R] command\nworks with keys instead of commands it is possible to accidentally\ncreate recursive bindings:\n.IP\n.EX\nmap j push 2j\n.EE\n.PP\nThese types of bindings create a deadlock when executed.\n.SH SHELL COMMANDS\nRegular shell commands are the most basic command type that is useful\nfor many purposes.\nFor example, we can write a shell command to move the selected file(s)\nto trash.\nA first attempt to write such a command may look like this:\n.IP\n.EX\ncmd trash ${{\n    mkdir \\-p \\(ti/.trash\n    if [ \\-z \\(dq$fs\\(dq ]; then\n        mv \\(dq$f\\(dq \\(ti/.trash\n    else\n        IFS=\\(dq$(printf \\(aq\\(rsn\\(rst\\(aq)\\(dq; mv $fs \\(ti/.trash\n    fi\n}}\n.EE\n.PP\nWe check \\f[CR]$fs\\f[R] to see if there are any selected files.\nOtherwise, we just delete the current file.\nSince this is such a common pattern, a separate \\f[CR]$fx\\f[R] variable\nis provided.\nWe can use this variable to get rid of the conditional:\n.IP\n.EX\ncmd trash ${{\n    mkdir \\-p \\(ti/.trash\n    IFS=\\(dq$(printf \\(aq\\(rsn\\(rst\\(aq)\\(dq; mv $fx \\(ti/.trash\n}}\n.EE\n.PP\nThe trash directory is checked each time the command is executed.\nWe can move it outside of the command so it would only run once at\nstartup:\n.IP\n.EX\n${{ mkdir \\-p \\(ti/.trash }}\n\ncmd trash ${{ IFS=\\(dq$(printf \\(aq\\(rsn\\(rst\\(aq)\\(dq; mv $fx \\(ti/.trash }}\n.EE\n.PP\nSince these are one\\-liners, we can drop \\f[CR]{{\\f[R] and\n\\f[CR]}}\\f[R]:\n.IP\n.EX\n$mkdir \\-p \\(ti/.trash\n\ncmd trash $IFS=\\(dq$(printf \\(aq\\(rsn\\(rst\\(aq)\\(dq; mv $fx \\(ti/.trash\n.EE\n.PP\nFinally, note that we set the \\f[CR]IFS\\f[R] variable manually in these\ncommands.\nInstead, we could use the \\f[CR]ifs\\f[R] option to set it for all shell\ncommands (i.e.\n\\f[CR]set ifs \\(dq\\(rsn\\(dq\\f[R]).\nThis can be especially useful for interactive use (e.g.\n\\f[CR]$rm $f\\f[R] or \\f[CR]$rm $fs\\f[R] would simply work).\nThis option is not set by default as it can behave unexpectedly for new\nusers.\nHowever, use of this option is highly recommended and it is assumed in\nthe rest of the documentation.\n.SH PIPING SHELL COMMANDS\nRegular shell commands have some limitations in some cases.\nWhen an output or error message is given and the command exits\nafterwards, the UI is immediately resumed and there is no way to see the\nmessage without dropping to shell again.\nAlso, even when there is no output or error, the UI still needs to be\npaused while the command is running.\nThis can cause flickering on the screen for short commands and similar\ndistractions for longer commands.\n.PP\nInstead of pausing the UI, piping shell commands connect stdin, stdout,\nand stderr of the command to the statline at the bottom of the UI.\nThis can be useful for programs following the Unix philosophy to give no\noutput in the success case, and brief error messages or prompts in other\ncases.\n.PP\nFor example, the following rename command prompts for overwrite in the\nstatline if there is an existing file with the given name:\n.IP\n.EX\ncmd rename %mv \\-i $f $1\n.EE\n.PP\nYou can also output error messages in the command and they will show up\nin the statline.\nFor example, an alternative rename command may look like this:\n.IP\n.EX\ncmd rename %[ \\-e $1 ] && printf \\(dqfile exists\\(dq || mv $f $1\n.EE\n.PP\nNote that input is line buffered and output and error are byte buffered.\n.SH WAITING SHELL COMMANDS\nWaiting shell commands are similar to regular shell commands except that\nthey wait for a key press when the command is finished.\nThese can be useful to see the output of a program before the UI is\nresumed.\nWaiting shell commands are more appropriate than piping shell commands\nwhen the command is verbose and the output is best displayed as\nmultiline.\n.SH ASYNCHRONOUS SHELL COMMANDS\nAsynchronous shell commands are used to start a command in the\nbackground and then resume operation without waiting for the command to\nfinish.\nStdin, stdout, and stderr of the command are neither connected to the\nterminal nor the UI.\n.SH REMOTE COMMANDS\nOne of the more advanced features in lf is remote commands.\nAll clients connect to a server on startup.\nIt is possible to send commands to all or any of the connected clients\nover the common server.\nThis is used internally to notify file selection changes to other\nclients.\n.PP\nTo use this feature, you need to use a client which supports\ncommunicating with a Unix domain socket.\nOpenBSD implementation of netcat (nc) is one such example.\nYou can use it to send a command to the socket file:\n.IP\n.EX\necho \\(aqsend echo hello world\\(aq | nc \\-U ${XDG_RUNTIME_DIR:\\-/tmp}/lf.${USER}.sock\n.EE\n.PP\nSince such a client may not be available everywhere, lf comes bundled\nwith a command line flag to be used as such.\nWhen using lf, you do not need to specify the address of the socket\nfile.\nThis is the recommended way of using remote commands since it is shorter\nand immune to socket file address changes:\n.IP\n.EX\nlf \\-remote \\(aqsend echo hello world\\(aq\n.EE\n.PP\nIn this command \\f[CR]send\\f[R] is used to send the rest of the string\nas a command to all connected clients.\nYou can optionally give it an ID number to send a command to a single\nclient:\n.IP\n.EX\nlf \\-remote \\(aqsend 1234 echo hello world\\(aq\n.EE\n.PP\nAll clients have a unique ID number but you may not be aware of the ID\nnumber when you are writing a command.\nFor this purpose, an \\f[CR]$id\\f[R] variable is exported to the\nenvironment for shell commands.\nThe value of this variable is set to the process ID of the client.\nYou can use it to send a remote command from a client to the server\nwhich in return sends a command back to itself.\nSo now you can display a message in the current client by calling the\nfollowing in a shell command:\n.IP\n.EX\nlf \\-remote \\(dqsend $id echo hello world\\(dq\n.EE\n.PP\nSince lf does not have control flow syntax, remote commands are used for\nsuch needs.\nFor example, you can configure the number of columns in the UI with\nrespect to the terminal width as follows:\n.IP\n.EX\ncmd recol %{{\n    if [ $lf_width \\-le 80 ]; then\n        lf \\-remote \\(dqsend $id set ratios 1:2\\(dq\n    elif [ $lf_width \\-le 160 ]; then\n        lf \\-remote \\(dqsend $id set ratios 1:2:3\\(dq\n    else\n        lf \\-remote \\(dqsend $id set ratios 1:2:3:5\\(dq\n    fi\n}}\n.EE\n.PP\nIn addition, the \\f[CR]query\\f[R] command can be used to obtain\ninformation about a specific lf instance by providing its ID:\n.IP\n.EX\nlf \\-remote \\(dqquery $id maps\\(dq\n.EE\n.PP\nThe following types of information are supported:\n.IP\n.EX\nmaps     list of mappings created by the \\(aqmap\\(aq, \\(aqnmap\\(aq and \\(aqvmap\\(aq command\nnmaps    list of mappings created by the \\(aqnmap\\(aq and \\(aqmap\\(aq command\nvmaps    list of mappings created by the \\(aqvmap\\(aq and \\(aqmap\\(aq command\ncmaps    list of mappings created by the \\(aqcmap\\(aq command\ncmds     list of commands created by the \\(aqcmd\\(aq command\njumps    contents of the jump list, showing previously visited locations\nhistory  list of previously executed commands on the command line\nfiles    list of files in the currently open directory as displayed by lf, empty if dir is still loading\n.EE\n.PP\nWhen listing mappings the characters in the first column are:\n.IP\n.EX\nn  Normal\nv  Visual\nc  Command\\-line\n.EE\n.PP\nThis is useful for scripting actions based on the internal state of lf.\nFor example, to select a previous command using fzf and execute it:\n.IP\n.EX\nmap <a\\-h> ${{\n    clear\n    cmd=$(\n        lf \\-remote \\(dqquery $id history\\(dq |\n        awk \\-F\\(aq\\(rst\\(aq \\(aqNR > 1 { print $NF}\\(aq |\n        sort \\-u |\n        fzf \\-\\-reverse \\-\\-prompt=\\(aqExecute command: \\(aq\n    )\n    lf \\-remote \\(dqsend $id $cmd\\(dq\n}}\n.EE\n.PP\nThe \\f[CR]list\\f[R] command prints the IDs of all currently connected\nclients:\n.IP\n.EX\nlf \\-remote \\(aqlist\\(aq\n.EE\n.PP\nThere is also a \\f[CR]quit\\f[R] command to quit the server when there\nare no connected clients left, and a \\f[CR]quit!\\f[R] command to force\nquit the server by closing client connections first:\n.IP\n.EX\nlf \\-remote \\(aqquit\\(aq\nlf \\-remote \\(aqquit!\\(aq\n.EE\n.PP\nLastly, the commands \\f[CR]conn\\f[R] and \\f[CR]drop\\f[R] connect or\ndisconnect ID to/from the server:\n.IP\n.EX\nlf \\-remote \\(aqconn $id\\(aq\nlf \\-remote \\(aqdrop $id\\(aq\n.EE\n.PP\nThese are internal and generally not needed by users.\n.SH FILE OPERATIONS\nlf uses its own built\\-in copy and move operations by default.\nThese are implemented as asynchronous operations and progress is shown\nin the bottom ruler.\nThese commands do not overwrite existing files or directories with the\nsame name.\nInstead, a suffix that is compatible with the\n\\f[CR]\\-\\-backup=numbered\\f[R] option in GNU cp is added to the new\nfiles or directories.\nOnly file modes and (some) timestamps can be preserved (see\n\\f[CR]preserve\\f[R] option), all other attributes are ignored including\nownership, context, and xattr.\nSpecial files such as character and block devices, named pipes, and\nsockets are skipped and links are not followed.\nMoving is performed using the rename operation of the underlying OS.\nFor cross\\-device moving, lf falls back to copying and then deletes the\noriginal files if there are no errors.\nOperation errors are shown in the message line as well as the log file\nand they do not prematurely terminate the corresponding file operation.\n.PP\nFile operations can be performed on the currently selected file or on\nmultiple files by selecting them first.\nWhen you \\f[CR]copy\\f[R] a file, lf doesn\\(aqt actually copy the file on\nthe disk, but only records its name to a file.\nThe actual file copying takes place when you \\f[CR]paste\\f[R].\nSimilarly \\f[CR]paste\\f[R] after a \\f[CR]cut\\f[R] operation moves the\nfile.\n.PP\nYou can customize copy and move operations by defining a\n\\f[CR]paste\\f[R] command.\nThis is a special command that is called when it is defined instead of\nthe built\\-in implementation.\nYou can use the following example as a starting point:\n.IP\n.EX\ncmd paste %{{\n    load=$(cat \\(ti/.local/share/lf/files)\n    mode=$(echo \\(dq$load\\(dq | sed \\-n \\(aq1p\\(aq)\n    list=$(echo \\(dq$load\\(dq | sed \\(aq1d\\(aq)\n    if [ $mode = \\(aqcopy\\(aq ]; then\n        cp \\-R $list .\n    elif [ $mode = \\(aqmove\\(aq ]; then\n        mv $list .\n        rm \\(ti/.local/share/lf/files\n        lf \\-remote \\(aqsend clear\\(aq\n    fi\n}}\n.EE\n.PP\nSome useful things to be considered are to use the backup\n(\\f[CR]\\-\\-backup\\f[R]) and/or preserve attributes (\\f[CR]\\-a\\f[R])\noptions with \\f[CR]cp\\f[R] and \\f[CR]mv\\f[R] commands if they support it\n(i.e.\nGNU implementation), change the command type to asynchronous, or use\n\\f[CR]rsync\\f[R] command with progress bar option for copying and feed\nthe progress to the client periodically with remote \\f[CR]echo\\f[R]\ncalls.\n.PP\nBy default, lf does not assign \\f[CR]delete\\f[R] command to a key to\nprotect new users.\nYou can customize file deletion by defining a \\f[CR]delete\\f[R] command.\nYou can also assign a key to this command if you like.\nAn example command to move selected files to a trash folder and remove\nfiles completely after a prompt is provided in the example configuration\nfile.\n.SH SEARCHING FILES\nThere are two mechanisms implemented in lf to search a file in the\ncurrent directory.\nSearching is the traditional method to move the selection to a file\nmatching a given pattern.\nFinding is an alternative way to search for a pattern possibly using\nfewer keystrokes.\n.PP\nThe searching mechanism is implemented with commands \\f[CR]search\\f[R]\n(default \\f[CR]/\\f[R]), \\f[CR]search\\-back\\f[R] (default \\f[CR]?\\f[R]),\n\\f[CR]search\\-next\\f[R] (default \\f[CR]n\\f[R]), and\n\\f[CR]search\\-prev\\f[R] (default \\f[CR]N\\f[R]).\nYou can set \\f[CR]searchmethod\\f[R] to \\f[CR]glob\\f[R] to match using a\nglob pattern.\nGlobbing supports \\f[CR]*\\f[R] to match any sequence, \\f[CR]?\\f[R] to\nmatch any character, and \\f[CR][...]\\f[R] or \\f[CR][\\(ha...]\\f[R] to\nmatch character sets or ranges.\nYou can set \\f[CR]searchmethod\\f[R] to \\f[CR]regex\\f[R] to match using a\nregex pattern.\nFor a full overview of Go\\(aqs RE2 syntax, see \\c\n.UR https://pkg.go.dev/regexp/syntax\n.UE \\c\n\\&.\nYou can enable \\f[CR]incsearch\\f[R] option to jump to the current match\nat each keystroke while typing.\nIn this mode, you can either use \\f[CR]cmd\\-enter\\f[R] to accept the\nsearch or use \\f[CR]cmd\\-escape\\f[R] to cancel the search.\nYou can also map some other commands with \\f[CR]cmap\\f[R] to accept the\nsearch and execute the command immediately afterwards.\nFor example, you can use the right arrow key to finish the search and\nopen the selected file with the following mapping:\n.IP\n.EX\ncmap <right> :cmd\\-enter; open\n.EE\n.PP\nThe finding mechanism is implemented with commands \\f[CR]find\\f[R]\n(default \\f[CR]f\\f[R]), \\f[CR]find\\-back\\f[R] (default \\f[CR]F\\f[R]),\n\\f[CR]find\\-next\\f[R] (default \\f[CR];\\f[R]), \\f[CR]find\\-prev\\f[R]\n(default \\f[CR],\\f[R]).\nYou can disable \\f[CR]anchorfind\\f[R] option to match a pattern at an\narbitrary position in the filename instead of the beginning.\nYou can set the number of keys to match using \\f[CR]findlen\\f[R] option.\nIf you set this value to zero, then the keys are read until there is\nonly a single match.\nThe default values of these two options are set to jump to the first\nfile with the given initial.\n.PP\nSome options affect both searching and finding.\nYou can disable \\f[CR]wrapscan\\f[R] option to prevent searches from\nbeing wrapped around at the end of the file list.\nYou can disable \\f[CR]ignorecase\\f[R] option to match cases in the\npattern and the filename.\nThis option is already automatically overridden if the pattern contains\nuppercase characters.\nYou can disable \\f[CR]smartcase\\f[R] option to disable this behavior.\nTwo similar options \\f[CR]ignoredia\\f[R] and \\f[CR]smartdia\\f[R] are\nprovided to control matching diacritics in Latin letters.\n.SH OPENING FILES\nYou can define an \\f[CR]open\\f[R] command (default \\f[CR]l\\f[R] and\n\\f[CR]<right>\\f[R]) to configure file opening.\nThis command is only called when the current file is not a directory,\notherwise, the directory is entered instead.\nYou can define it just as you would define any other command:\n.IP\n.EX\ncmd open $vi $fx\n.EE\n.PP\nIt is possible to use different command types:\n.IP\n.EX\ncmd open &xdg\\-open $f\n.EE\n.PP\nYou may want to use either file extensions or MIME types from\n\\f[CR]file\\f[R] command:\n.IP\n.EX\ncmd open ${{\n    case $(file \\-\\-mime\\-type \\-Lb $f) in\n        text/*) vi $fx;;\n        *) for f in $fx; do xdg\\-open $f > /dev/null 2> /dev/null & done;;\n    esac\n}}\n.EE\n.PP\nYou may want to use \\f[CR]setsid\\f[R] before your opener command to have\npersistent processes that continue to run after lf quits.\n.PP\nRegular shell commands (i.e.\n\\f[CR]$\\f[R]) drop to the terminal which results in a flicker for\ncommands that finish immediately (e.g.\n\\f[CR]xdg\\-open\\f[R] in the above example).\nIf you want to use asynchronous shell commands (i.e.\n\\f[CR]&\\f[R]) but also want to use the terminal when necessary (e.g.\n\\f[CR]vi\\f[R] in the above example), you can use a remote command:\n.IP\n.EX\ncmd open &{{\n    case $(file \\-\\-mime\\-type \\-Lb $f) in\n        text/*) lf \\-remote \\(dqsend $id \\(rs$vi \\(rs$fx\\(dq;;\n        *) for f in $fx; do xdg\\-open $f > /dev/null 2> /dev/null & done;;\n    esac\n}}\n.EE\n.PP\nNote that asynchronous shell commands run in their own process group by\ndefault so they do not require the manual use of \\f[CR]setsid\\f[R].\n.PP\nThe following command is provided by default:\n.IP\n.EX\ncmd open &$OPENER $f\n.EE\n.PP\nYou may also use any other existing file openers as you like.\nPossible options are \\f[CR]libfile\\-mimeinfo\\-perl\\f[R] (executable name\nis \\f[CR]mimeopen\\f[R]), \\f[CR]rifle\\f[R] (ranger\\(aqs default file\nopener), or \\f[CR]mimeo\\f[R] to name a few.\n.SH PREVIEWING FILES\nlf previews files on the preview pane by printing the file until the end\nor until the preview pane is filled.\nThis output can be enhanced by providing a custom preview script for\nfiltering.\nThis can be used to highlight source code, list contents of archive\nfiles or view PDF or image files to name a few.\nFor coloring lf recognizes ANSI escape codes.\n.PP\nTo use this feature, you need to set the value of \\f[CR]previewer\\f[R]\noption to the path of an executable file.\nThe following arguments are passed to the file, (1) current filename,\n(2) width, (3) height, (4) horizontal position, (5) vertical position,\nand (6) mode (\\(dqpreview\\(dq or \\(dqpreload\\(dq).\nThe output of the execution is printed in the preview pane.\n.PP\nDifferent types of files can be handled by matching by extension (or\nMIME type from the \\f[CR]file\\f[R] command):\n.IP\n.EX\n#!/bin/sh\n\ncase \\(dq$1\\(dq in\n    *.tar*) tar tf \\(dq$1\\(dq;;\n    *.zip) unzip \\-l \\(dq$1\\(dq;;\n    *.rar) unrar l \\(dq$1\\(dq;;\n    *.7z) 7z l \\(dq$1\\(dq;;\n    *.pdf) pdftotext \\(dq$1\\(dq \\-;;\n    *) highlight \\-O ansi \\(dq$1\\(dq;;\nesac\n.EE\n.PP\nBecause files can be large, lf automatically closes the previewer script\noutput pipe with a SIGPIPE when enough lines are read.\nNote that some programs may not respond well to SIGPIPE and will exit\nwith a non\\-zero return code, which avoids caching.\nYou may add a trailing \\f[CR]|| true\\f[R] command to avoid such errors:\n.IP\n.EX\nhighlight \\-O ansi \\(dq$1\\(dq || true\n.EE\n.PP\nYou may also want to use the same script in your pager mapping as well:\n.IP\n.EX\nset previewer \\(ti/.config/lf/pv.sh\nmap i $\\(ti/.config/lf/pv.sh $f | less \\-R\n.EE\n.PP\nFor \\f[CR]less\\f[R] pager, you may instead utilize \\f[CR]LESSOPEN\\f[R]\nmechanism so that useful information about the file such as the full\npath of the file can still be displayed in the statusline below:\n.IP\n.EX\nset previewer \\(ti/.config/lf/pv.sh\nmap i $LESSOPEN=\\(aq| \\(ti/.config/lf/pv.sh %s\\(aq less \\-R $f\n.EE\n.PP\nSince the preview script is called for each file selection change, it\nmay not generate previews fast enough if the user scrolls through files\nquickly.\nTo deal with this, the \\f[CR]preload\\f[R] option can be set to enable\nfile previews to be preloaded in advance.\nIf enabled, the preview script will be run on files in advance as the\nuser navigates through them.\nIn this case, if the exit code of the preview script is zero, then the\noutput will be cached in memory and displayed by lf (useful for text or\nsixel previews).\nOtherwise, it will fallback to calling the preview script again when the\nfile is actually selected (useful for previews managed by an external\nprogram).\n.SH CHANGING DIRECTORY\nlf changes the working directory of the process to the current directory\nso that shell commands always work in the displayed directory.\nAfter quitting, it returns to the original directory where it is first\nlaunched like all shell programs.\nIf you want to stay in the current directory after quitting, you can use\none of the example lfcd wrapper shell scripts provided in the repository\nat \\c\n.UR https://github.com/gokcehan/lf/tree/master/etc\n.UE \\c\n.PP\nThere is a special command \\f[CR]on\\-cd\\f[R] that runs a shell command\nwhen it is defined and the directory is changed.\nYou can define it just as you would define any other command:\n.IP\n.EX\ncmd on\\-cd &{{\n    bash \\-c \\(aq\n    # display git repository status in your prompt\n    source /usr/share/git/completion/git\\-prompt.sh\n    GIT_PS1_SHOWDIRTYSTATE=auto\n    GIT_PS1_SHOWSTASHSTATE=auto\n    GIT_PS1_SHOWUNTRACKEDFILES=auto\n    GIT_PS1_SHOWUPSTREAM=auto\n    git=$(__git_ps1 \\(dq (%s)\\(dq)\n    fmt=\\(dq\\(rs033[32;1m%u\\(at%h\\(rs033[0m:\\(rs033[34;1m%d\\(rs033[0m\\(rs033[1m%f$git\\(rs033[0m\\(dq\n    lf \\-remote \\(dqsend $id set promptfmt \\(rs\\(dq$fmt\\(rs\\(dq\\(dq\n    \\(aq\n}}\n.EE\n.PP\nIf you want to send escape sequences to the terminal, you can use the\n\\f[CR]tty\\-write\\f[R] command to do so.\nThe following xterm\\-specific escape sequence sets the terminal title to\nthe working directory:\n.IP\n.EX\ncmd on\\-cd &{{\n    lf \\-remote \\(dqsend $id tty\\-write \\(rs\\(dq\\(rs033]0;$PWD\\(rs007\\(rs\\(dq\\(dq\n}}\n.EE\n.PP\nThis command runs whenever you change the directory but not on startup.\nYou can add an extra call to make it run on startup as well:\n.IP\n.EX\ncmd on\\-cd &{{ ... }}\non\\-cd\n.EE\n.PP\nNote that all shell commands are possible but \\f[CR]%\\f[R] and\n\\f[CR]&\\f[R] are usually more appropriate as \\f[CR]$\\f[R] and\n\\f[CR]!\\f[R] causes flickers and pauses respectively.\n.PP\nThere is also a \\f[CR]pre\\-cd\\f[R] command, that works like\n\\f[CR]on\\-cd\\f[R], but is run before the directory is actually changed.\nAnother related command is \\f[CR]on\\-load\\f[R] which gets executed when\nloading a directory.\n.SH LOADING DIRECTORY\nSimilar to \\f[CR]on\\-cd\\f[R] there also is \\f[CR]on\\-load\\f[R] that when\ndefined runs a shell command after loading a directory.\nIt works well when combined with \\f[CR]addcustominfo\\f[R].\n.PP\nThe following example can be used to display git indicators in the info\ncolumn:\n.IP\n.EX\ncmd on\\-load &{{\n    cd \\(dq$(dirname \\(dq$1\\(dq)\\(dq || exit 1\n    [ \\(dq$(git rev\\-parse \\-\\-is\\-inside\\-git\\-dir 2>/dev/null)\\(dq = false ] || exit 0\n\n    cmds=\\(dq\\(dq\n\n    for file in \\(dq$\\(at\\(dq; do\n        case \\(dq$file\\(dq in\n            */.git|*/.git/*) continue;;\n        esac\n\n        status=$(git status \\-\\-porcelain \\-\\-ignored \\-\\- \\(dq$file\\(dq | cut \\-c1\\-2 | head \\-n1)\n\n        if [ \\-n \\(dq$status\\(dq ]; then\n            cmds=\\(dq${cmds}addcustominfo \\(rs\\(dq${file}\\(rs\\(dq \\(rs\\(dq$status\\(rs\\(dq; \\(dq\n        else\n            cmds=\\(dq${cmds}addcustominfo \\(rs\\(dq${file}\\(rs\\(dq \\(aq\\(aq; \\(dq\n        fi\n    done\n\n    if [ \\-n \\(dq$cmds\\(dq ]; then\n        lf \\-remote \\(dqsend $id :$cmds\\(dq\n    fi\n}}\n.EE\n.PP\nAnother use case could be showing the dimensions of images and videos:\n.IP\n.EX\ncmd on\\-load &{{\n    cmds=\\(dq\\(dq\n\n    for file in \\(dq$\\(at\\(dq; do\n        mime=$(file \\-\\-mime\\-type \\-Lb \\-\\- \\(dq$file\\(dq)\n        case \\(dq$mime\\(dq in\n            # vector images cause problems\n            image/svg+xml)\n                ;;\n            image/*|video/*)\n                dimensions=$(exiftool \\-s3 \\-imagesize \\-\\- \\(dq$file\\(dq)\n                cmds=\\(dq${cmds}addcustominfo \\(rs\\(dq${file}\\(rs\\(dq \\(rs\\(dq$dimensions\\(rs\\(dq; \\(dq\n                ;;\n        esac\n    done\n\n    if [ \\-n \\(dq$cmds\\(dq ]; then\n        lf \\-remote \\(dqsend $id :$cmds\\(dq\n    fi\n}}\n.EE\n.SH COLORS\nlf tries to automatically adapt its colors to the environment.\nIt starts with a default color scheme and updates colors using values of\nexisting environment variables possibly by overwriting its previous\nvalues.\nColors are set in the following order:\n.IP \"1.\" 3\ndefault\n.IP \"2.\" 3\nLSCOLORS (macOS/BSD ls)\n.IP \"3.\" 3\nLS_COLORS (GNU ls)\n.IP \"4.\" 3\nLF_COLORS (lf specific)\n.IP \"5.\" 3\ncolors file (lf specific)\n.PP\nPlease refer to the corresponding man pages for more information about\n\\f[CR]LSCOLORS\\f[R] and \\f[CR]LS_COLORS\\f[R].\n\\f[CR]LF_COLORS\\f[R] is provided with the same syntax as\n\\f[CR]LS_COLORS\\f[R] in case you want to configure colors only for lf\nbut not ls.\nThis can be useful since there are some differences between ls and lf,\nthough one should expect the same behavior for common cases.\nThe colors file (refer to the \\c\n.UR https://github.com/gokcehan/lf/blob/master/doc.md#configuration\nCONFIGURATION section\n.UE \\c\n) is provided for easier configuration without environment variables.\nThis file should consist of whitespace\\-separated pairs with a\n\\f[CR]#\\f[R] character to start comments until the end of the line.\n.PP\nYou can configure lf colors in two different ways.\nFirst, you can only configure 8 basic colors used by your terminal and\nlf should pick up those colors automatically.\nDepending on your terminal, you should be able to select your colors\nfrom a 24\\-bit palette.\nThis is the recommended approach as colors used by other programs will\nalso match each other.\n.PP\nSecond, you can set the values of environment variables or colors file\nmentioned above for fine\\-grained customization.\nNote that \\f[CR]LS_COLORS/LF_COLORS\\f[R] are more powerful than\n\\f[CR]LSCOLORS\\f[R] and they can be used even when GNU programs are not\ninstalled on the system.\nYou can combine this second method with the first method for the best\nresults.\n.PP\nLastly, you may also want to configure the colors of the prompt line to\nmatch the rest of the colors.\nColors of the prompt line can be configured using the\n\\f[CR]promptfmt\\f[R] option which can include hardcoded colors as ANSI\nescapes.\nSee the default value of this option to have an idea about how to color\nthis line.\n.PP\nIt is worth noting that lf uses as many colors advertised by your\nterminal\\(aqs entry in terminfo or infocmp databases on your system.\nIf an entry is not present, it falls back to an internal database.\nIf your terminal supports 24\\-bit colors but either does not have a\ndatabase entry or does not advertise all capabilities, you can enable\nsupport by setting the \\f[CR]$COLORTERM\\f[R] variable to\n\\f[CR]truecolor\\f[R] or ensuring \\f[CR]$TERM\\f[R] is set to a value that\nends with \\f[CR]\\-truecolor\\f[R].\n.PP\nDefault lf colors are mostly taken from GNU dircolors defaults.\nThese defaults use 8 basic colors and bold attribute.\nDefault dircolors entries with background colors are simplified to avoid\nconfusion with current file selection in lf.\nSimilarly, there are only file type matchings and extension matchings\nare left out for simplicity.\nDefault values are as follows given with their matching order in lf:\n.IP\n.EX\nln  01;36\nor  31;01\ntw  01;34\now  01;34\nst  01;34\ndi  01;34\npi  33\nso  01;35\nbd  33;01\ncd  33;01\nsu  01;32\nsg  01;32\nex  01;32\nfi  00\n.EE\n.PP\nNote that lf first tries matching file names and then falls back to file\ntypes.\nThe full order of matchings from most specific to least are as follows:\n.IP \"1.\" 3\nFull Path (e.g.\n\\f[CR]\\(ti/.config/lf/lfrc\\f[R])\n.IP \"2.\" 3\nDir Name (e.g.\n\\f[CR].git/\\f[R]) (only matches dirs with a trailing slash at the end)\n.IP \"3.\" 3\nFile Type (e.g.\n\\f[CR]ln\\f[R]) (except \\f[CR]fi\\f[R])\n.IP \"4.\" 3\nFile Name (e.g.\n\\f[CR]README*\\f[R])\n.IP \"5.\" 3\nFile Name (e.g.\n\\f[CR]*README\\f[R])\n.IP \"6.\" 3\nBase Name (e.g.\n\\f[CR]README.*\\f[R])\n.IP \"7.\" 3\nExtension (e.g.\n\\f[CR]*.txt\\f[R])\n.IP \"8.\" 3\nDefault (i.e.\n\\f[CR]fi\\f[R])\n.PP\nFor example, given a regular text file \\f[CR]/path/to/README.txt\\f[R],\nthe following entries are checked in the configuration and the first one\nto match is used:\n.IP \"1.\" 3\n\\f[CR]/path/to/README.txt\\f[R]\n.IP \"2.\" 3\n(skipped since the file is not a directory)\n.IP \"3.\" 3\n(skipped since the file is of type \\f[CR]fi\\f[R])\n.IP \"4.\" 3\n\\f[CR]README.txt*\\f[R]\n.IP \"5.\" 3\n\\f[CR]*README.txt\\f[R]\n.IP \"6.\" 3\n\\f[CR]README.*\\f[R]\n.IP \"7.\" 3\n\\f[CR]*.txt\\f[R]\n.IP \"8.\" 3\n\\f[CR]fi\\f[R]\n.PP\nGiven a regular directory \\f[CR]/path/to/example.d\\f[R], the following\nentries are checked in the configuration and the first one to match is\nused:\n.IP \"1.\" 3\n\\f[CR]/path/to/example.d\\f[R]\n.IP \"2.\" 3\n\\f[CR]example.d/\\f[R]\n.IP \"3.\" 3\n\\f[CR]di\\f[R]\n.IP \"4.\" 3\n\\f[CR]example.d*\\f[R]\n.IP \"5.\" 3\n\\f[CR]*example.d\\f[R]\n.IP \"6.\" 3\n\\f[CR]example.*\\f[R]\n.IP \"7.\" 3\n\\f[CR]*.d\\f[R]\n.IP \"8.\" 3\n\\f[CR]fi\\f[R]\n.PP\nNote that glob\\-like patterns do not perform glob matching for\nperformance reasons.\n.PP\nFor example, you can set a variable as follows:\n.IP\n.EX\nexport LF_COLORS=\\(dq\\(ti/Documents=01;31:\\(ti/Downloads=01;31:\\(ti/.local/share=01;31:\\(ti/.config/lf/lfrc=31:.git/=01;32:.git*=32:*.gitignore=32:*Makefile=32:README.*=33:*.txt=34:*.md=34:ln=01;36:di=01;34:ex=01;32:\\(dq\n.EE\n.PP\nHaving all entries on a single line can make it hard to read.\nYou may instead divide it into multiple lines in between double quotes\nby escaping newlines with backslashes as follows:\n.IP\n.EX\nexport LF_COLORS=\\(dq\\(rs\n\\(ti/Documents=01;31:\\(rs\n\\(ti/Downloads=01;31:\\(rs\n\\(ti/.local/share=01;31:\\(rs\n\\(ti/.config/lf/lfrc=31:\\(rs\n\\&.git/=01;32:\\(rs\n\\&.git*=32:\\(rs\n*.gitignore=32:\\(rs\n*Makefile=32:\\(rs\nREADME.*=33:\\(rs\n*.txt=34:\\(rs\n*.md=34:\\(rs\nln=01;36:\\(rs\ndi=01;34:\\(rs\nex=01;32:\\(rs\n\\(dq\n.EE\n.PP\nThe \\f[CR]ln\\f[R] entry supports the special value \\f[CR]target\\f[R],\nwhich will use the link target to select a style.\nFilename rules will still apply based on the link\\(aqs name \\-\\- this\nmirrors GNU\\(aqs \\f[CR]ls\\f[R] and \\f[CR]dircolors\\f[R] behavior.\nHaving such a long variable definition in a shell configuration file\nmight be undesirable.\nYou may instead use the colors file (refer to the \\c\n.UR https://github.com/gokcehan/lf/blob/master/doc.md#configuration\nCONFIGURATION section\n.UE \\c\n) for configuration.\nA sample colors file can be found at \\c\n.UR https://github.com/gokcehan/lf/blob/master/etc/colors.example\n.UE \\c\n\\ You may also see the wiki page for ANSI escape codes \\c\n.UR https://en.wikipedia.org/wiki/ANSI_escape_code\n.UE \\c\n.SH ICONS\nIcons are configured using \\f[CR]LF_ICONS\\f[R] environment variable or\nan icons file (refer to the \\c\n.UR https://github.com/gokcehan/lf/blob/master/doc.md#configuration\nCONFIGURATION section\n.UE \\c\n).\nThe variable uses the same syntax as \\f[CR]LS_COLORS/LF_COLORS\\f[R].\nInstead of colors, you should use single characters or symbols as\nvalues.\nThe \\f[CR]ln\\f[R] entry supports the special value \\f[CR]target\\f[R],\nwhich will use the link target to select a icon.\nFilename rules will still apply based on the link\\(aqs name \\-\\- this\nmirrors GNU\\(aqs \\f[CR]ls\\f[R] and \\f[CR]dircolors\\f[R] behavior.\nThe icons file (refer to the \\c\n.UR https://github.com/gokcehan/lf/blob/master/doc.md#configuration\nCONFIGURATION section\n.UE \\c\n) should consist of whitespace\\-separated arrays with a \\f[CR]#\\f[R]\ncharacter to start comments until the end of the line.\nEach line should contain 1\\-3 columns: a file type or file name pattern,\nthe icon, and an optional icon color.\nUsing only one column disables all rules for that type or name.\nDo not forget to add \\f[CR]set icons true\\f[R] to your \\f[CR]lfrc\\f[R]\nto see the icons.\nDefault values are listed below in the order lf matches them:\n.IP\n.EX\nln  l\nor  l\ntw  t\now  d\nst  t\ndi  d\npi  p\nso  s\nbd  b\ncd  c\nsu  u\nsg  g\nex  x\nfi  \\-\n.EE\n.PP\nA sample icons file can be found at \\c\n.UR https://github.com/gokcehan/lf/blob/master/etc/icons.example\n.UE \\c\n.PP\nA sample colored icons file can be found at \\c\n.UR https://github.com/gokcehan/lf/blob/master/etc/icons_colored.example\n.UE \\c\n.SH RULER\nThe ruler can be configured using the \\f[CR]rulerfile\\f[R] option (refer\nto the \\c\n.UR https://github.com/gokcehan/lf/blob/master/doc.md#configuration\nCONFIGURATION section\n.UE \\c\n).\nThe contents of the ruler file should be a Go template which is then\nrendered to create the actual output (refer to \\c\n.UR https://pkg.go.dev/text/template\n.UE \\c\n\\ for more details on the syntax).\n.PP\nThe following data fields are exported:\n.IP\n.EX\n\\&.Message          string              Includes internal messages, errors, and messages generated by the \\(gaecho\\(ga/\\(gaechomsg\\(ga/\\(gaechoerr\\(ga commands\n\\&.Keys             string              Keys pressed by the user\n\\&.Progress         []string            Progress indicators for copied, moved and deleted files\n\\&.Copy             []string            List of files in the clipboard to be copied\n\\&.Cut              []string            List of files in the clipboard to be moved\n\\&.Select           []string            Selection list\n\\&.Visual           []string            Visual selection\n\\&.Index            int                 Index of the cursor\n\\&.Total            int                 Number of visible files in the current working directory\n\\&.Hidden           int                 Number of hidden files in the current working directory\n\\&.All              int                 Number of all files in the current working directory\n\\&.LinePercentage   string              Line percentage (analogous to \\(ga%p\\(ga for the \\(gastatusline\\(ga option in Vim)\n\\&.ScrollPercentage string              Scroll percentage (analogous to \\(ga%P\\(ga for the \\(gastatusline\\(ga option in Vim)\n\\&.Filter           []string            Filter currently being applied\n\\&.Mode             string              Current mode (\\(dqNORMAL\\(dq for Normal mode, and \\(dqVISUAL\\(dq for Visual mode)\n\\&.Options          map[string]string   The value of options (e.g. \\(ga{{.Options.hidden}}\\(ga)\n\\&.UserOptions      map[string]string   The value of user\\-defined options (e.g. \\(ga{{.UserOptions.foo}}\\(ga)\n\\&.Stat.Path        string              Path of the current file\n\\&.Stat.Name        string              Name of the current file\n\\&.Stat.Extension   string              Extension of the current file\n\\&.Stat.Size        int64               Size of the current file\n\\&.Stat.DirSize     int64               Total size of the current directory if calculated via \\(gacalcdirsize\\(ga (\\(ga\\-1\\(ga if not calculated)\n\\&.Stat.DirCount    int                 Number of items in the current directory if the \\(gadircounts\\(ga option is enabled (\\(ga\\-1\\(ga if the directory cannot be read)\n\\&.Stat.Permissions string              Permissions of the current file\n\\&.Stat.ModTime     string              Last modified time of the current file (formatted based on the \\(gatimefmt\\(ga option)\n\\&.Stat.AccessTime  string              Last access time of the current file (formatted based on the \\(gatimefmt\\(ga option)\n\\&.Stat.BirthTime   string              Birth time of the current file (formatted based on the \\(gatimefmt\\(ga option)\n\\&.Stat.ChangeTime  string              Last status (inode) change time of the current file (formatted based on the \\(gatimefmt\\(ga option)\n\\&.Stat.LinkCount   string              Number of hard links for the current file\n\\&.Stat.User        string              User of the current file\n\\&.Stat.Group       string              Group of the current file\n\\&.Stat.Target      string              Target if the current file is a symbolic link, otherwise a blank string\n\\&.Stat.CustomInfo  string              Custom property if defined via \\(gaaddcustominfo\\(ga, otherwise a blank string\n.EE\n.PP\nThe following functions are exported:\n.IP\n.EX\ndf       func() string                   Get an indicator representing the amount of free disk space available\nenv      func(string) string             Get the value of an environment variable\nhumanize func(int64) string              Express a file size in a human\\-readable format\njoin     func([]string, string) string   Join a string array by a separator\nlower    func(string) string             Convert a string to lowercase\nsubstr   func(string, int, int) string   Get a substring based on starting index and length\nupper    func(string) string             Convert a string to uppercase\n.EE\n.PP\nThe special identifier \\f[CR]{{.SPACER}}\\f[R] can be used to divide the\nruler into sections that are spaced evenly from each other.\n.PP\nThe default ruler file can be found at \\c\n.UR https://github.com/gokcehan/lf/blob/master/etc/ruler.default\n.UE \\c\n"
  },
  {
    "path": "lf.desktop",
    "content": "[Desktop Entry]\nType=Application\nName=lf\nComment=Launches the lf file manager\nIcon=utilities-terminal\nTerminal=true\nExec=lf\nCategories=ConsoleOnly;System;FileTools;FileManager\nMimeType=inode/directory;\n"
  },
  {
    "path": "main.go",
    "content": "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\"runtime/pprof\"\n\t\"strconv\"\n\t\"strings\"\n\n\t_ \"embed\"\n)\n\n//go:embed doc.txt\nvar genDocString string\n\nvar (\n\tenvPath  = os.Getenv(\"PATH\")\n\tenvLevel = os.Getenv(\"LF_LEVEL\")\n)\n\ntype arrayFlag []string\n\nvar (\n\tgSingleMode     bool\n\tgPrintLastDir   bool\n\tgPrintSelection bool\n\tgClientID       int\n\tgHostname       string\n\tgLastDirPath    string\n\tgSelectionPath  string\n\tgSocketProt     string\n\tgSocketPath     string\n\tgLogPath        string\n\tgSelect         string\n\tgConfigPath     string\n\tgCommands       arrayFlag\n\tgVersion        string\n)\n\nfunc (a *arrayFlag) Set(v string) error {\n\t*a = append(*a, v)\n\treturn nil\n}\n\nfunc (a *arrayFlag) String() string {\n\treturn strings.Join(*a, \", \")\n}\n\nfunc init() {\n\th, err := os.Hostname()\n\tif err != nil {\n\t\tlog.Printf(\"hostname: %s\", err)\n\t}\n\tgHostname = h\n\n\tif envLevel == \"\" {\n\t\tenvLevel = \"0\"\n\t}\n}\n\nfunc exportEnvVars() {\n\tos.Setenv(\"id\", strconv.Itoa(gClientID))\n\n\tos.Setenv(\"OPENER\", envOpener)\n\tos.Setenv(\"EDITOR\", envEditor)\n\tos.Setenv(\"PAGER\", envPager)\n\tos.Setenv(\"SHELL\", envShell)\n\n\tdir, err := os.Getwd()\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"getting current directory: %s\\n\", err)\n\t}\n\tos.Setenv(\"OLDPWD\", dir)\n\n\tlevel, err := strconv.Atoi(envLevel)\n\tif err != nil {\n\t\tlog.Printf(\"reading lf level: %s\", err)\n\t}\n\n\tlevel++\n\n\tos.Setenv(\"LF_LEVEL\", strconv.Itoa(level))\n}\n\nfunc exportFlags() {\n\tos.Setenv(\"lf_flag_config\", gConfigPath)\n\tos.Setenv(\"lf_flag_last_dir_path\", gLastDirPath)\n\tos.Setenv(\"lf_flag_log\", gLogPath)\n\tos.Setenv(\"lf_flag_print_last_dir\", strconv.FormatBool(gPrintLastDir))\n\tos.Setenv(\"lf_flag_print_selection\", strconv.FormatBool(gPrintSelection))\n\tos.Setenv(\"lf_flag_selection_path\", gSelectionPath)\n\tos.Setenv(\"lf_flag_single\", strconv.FormatBool(gSingleMode))\n}\n\n// used by exportOpts below\nfunc fieldToString(field reflect.Value) string {\n\t// prevent returning <main.borderStyle Value>\n\tif field.Type() == reflect.TypeFor[borderStyle]() {\n\t\treturn borderStyle(field.Uint()).String()\n\t}\n\n\tvar value string\n\tswitch field.Kind() {\n\tcase reflect.Int:\n\t\tvalue = strconv.Itoa(int(field.Int()))\n\tcase reflect.Bool:\n\t\tvalue = strconv.FormatBool(field.Bool())\n\tcase reflect.Slice:\n\t\tfor i := range field.Len() {\n\t\t\telement := field.Index(i)\n\n\t\t\tif i == 0 {\n\t\t\t\tvalue = fieldToString(element)\n\t\t\t} else {\n\t\t\t\tvalue += \":\" + fieldToString(element)\n\t\t\t}\n\t\t}\n\tdefault:\n\t\tvalue = field.String()\n\t}\n\n\treturn value\n}\n\nfunc getOptsMap() map[string]string {\n\topts := make(map[string]string)\n\tv := reflect.ValueOf(gOpts)\n\tt := v.Type()\n\n\tfor i := range v.NumField() {\n\t\t// Get field name and prefix it with lf_\n\t\tname := \"lf_\" + t.Field(i).Name\n\n\t\tswitch name {\n\t\tcase \"lf_nkeys\", \"lf_vkeys\", \"lf_cmdkeys\", \"lf_cmds\":\n\t\t\t// Skip maps\n\t\t\tcontinue\n\t\tcase \"lf_user\":\n\t\t\t// set each user option\n\t\t\tfor key, value := range gOpts.user {\n\t\t\t\topts[name+\"_\"+key] = value\n\t\t\t}\n\t\tdefault:\n\t\t\topts[name] = fieldToString(v.Field(i))\n\t\t}\n\t}\n\n\treturn opts\n}\n\nfunc exportLfPath() {\n\tlfPath, err := os.Executable()\n\tif err != nil {\n\t\tlog.Printf(\"getting path to lf binary: %s\", err)\n\t\tlfPath = \"lf\"\n\t}\n\tos.Setenv(\"lf\", quoteString(lfPath))\n}\n\nfunc exportOpts() {\n\tfor key, value := range getOptsMap() {\n\t\tos.Setenv(key, value)\n\t}\n}\n\nfunc startServer() {\n\tcmd := detachedCommand(os.Args[0], \"-server\")\n\tif err := cmd.Start(); err != nil {\n\t\tlog.Printf(\"starting server: %s\", err)\n\t}\n}\n\nfunc checkServer() {\n\tif gSocketProt == \"unix\" {\n\t\tif _, err := os.Stat(gSocketPath); os.IsNotExist(err) {\n\t\t\tstartServer()\n\t\t} else if _, err := net.Dial(gSocketProt, gSocketPath); err != nil {\n\t\t\tif err := os.Remove(gSocketPath); err != nil {\n\t\t\t\tlog.Print(err)\n\t\t\t}\n\t\t\tstartServer()\n\t\t}\n\t} else {\n\t\tif _, err := net.Dial(gSocketProt, gSocketPath); err != nil {\n\t\t\tstartServer()\n\t\t}\n\t}\n}\n\nfunc printVersion() {\n\tif gVersion != \"\" {\n\t\tfmt.Println(gVersion)\n\t\treturn\n\t}\n\n\tbuildInfo, ok := debug.ReadBuildInfo()\n\tif !ok {\n\t\treturn\n\t}\n\n\tvar vcsRevision, vcsTime, vcsModified string\n\tfor _, setting := range buildInfo.Settings {\n\t\tswitch setting.Key {\n\t\tcase \"vcs.revision\":\n\t\t\tvcsRevision = setting.Value\n\t\tcase \"vcs.time\":\n\t\t\tvcsTime = setting.Value\n\t\tcase \"vcs.modified\":\n\t\t\tif setting.Value == \"true\" {\n\t\t\t\tvcsModified = \" (dirty)\"\n\t\t\t}\n\t\t}\n\t}\n\n\tif vcsRevision != \"\" {\n\t\tfmt.Printf(\"Built at commit: %s%s %s\\n\", vcsRevision, vcsModified, vcsTime)\n\t}\n\tfmt.Printf(\"Go version: %s\\n\", buildInfo.GoVersion)\n}\n\nfunc main() {\n\tflag.Usage = func() {\n\t\tf := flag.CommandLine.Output()\n\t\tfmt.Fprintf(f, `lf - Terminal file manager\n\nUsage:  %s [options] [cd-or-select-path]\n\n  cd-or-select-path\n        set the initial dir or file selection to the given argument\n\nOptions:\n`, os.Args[0])\n\t\tflag.PrintDefaults()\n\t}\n\n\tshowDoc := flag.Bool(\n\t\t\"doc\",\n\t\tfalse,\n\t\t\"show documentation\")\n\n\tshowHelp := flag.Bool(\n\t\t\"help\",\n\t\tfalse,\n\t\t\"show help\")\n\n\tshowVersion := flag.Bool(\n\t\t\"version\",\n\t\tfalse,\n\t\t\"show version\")\n\n\tserverMode := flag.Bool(\n\t\t\"server\",\n\t\tfalse,\n\t\t\"start server (automatic)\")\n\n\tsingleMode := flag.Bool(\n\t\t\"single\",\n\t\tfalse,\n\t\t\"start a client without server\")\n\n\tprintLastDir := flag.Bool(\n\t\t\"print-last-dir\",\n\t\tfalse,\n\t\t\"print the last dir to stdout on exit (to use for cd)\")\n\n\tprintSelection := flag.Bool(\n\t\t\"print-selection\",\n\t\tfalse,\n\t\t\"print the selected files to stdout on open (to use as open file dialog)\")\n\n\tremoteCmd := flag.String(\n\t\t\"remote\",\n\t\t\"\",\n\t\t\"send remote `command` to server\")\n\n\tcpuprofile := flag.String(\n\t\t\"cpuprofile\",\n\t\t\"\",\n\t\t\"`path` to the file to write the CPU profile\")\n\n\tmemprofile := flag.String(\n\t\t\"memprofile\",\n\t\t\"\",\n\t\t\"`path` to the file to write the memory profile\")\n\n\tflag.StringVar(&gLastDirPath,\n\t\t\"last-dir-path\",\n\t\t\"\",\n\t\t\"`path` to the file to write the last dir on exit (to use for cd)\")\n\n\tflag.StringVar(&gSelectionPath,\n\t\t\"selection-path\",\n\t\t\"\",\n\t\t\"`path` to the file to write selected files on open (to use as open file dialog)\")\n\n\tflag.StringVar(&gConfigPath,\n\t\t\"config\",\n\t\t\"\",\n\t\t\"`path` to the config file (instead of the usual paths)\")\n\n\tflag.Var(&gCommands,\n\t\t\"command\",\n\t\t\"`command` to execute on client initialization\")\n\n\tflag.StringVar(&gLogPath,\n\t\t\"log\",\n\t\t\"\",\n\t\t\"`path` to the log file to write messages\")\n\n\tflag.Parse()\n\n\tgSocketProt = gDefaultSocketProt\n\tgSocketPath = gDefaultSocketPath\n\n\tif gLogPath != \"\" {\n\t\tpath, err := filepath.Abs(gLogPath)\n\t\tif err != nil {\n\t\t\tlog.Fatalf(\"getting log path: %s\", err)\n\t\t}\n\t\tgLogPath = path\n\t}\n\n\tif *cpuprofile != \"\" {\n\t\tf, err := os.Create(*cpuprofile)\n\t\tif err != nil {\n\t\t\tlog.Fatalf(\"could not create CPU profile: %s\", err)\n\t\t}\n\t\tif err := pprof.StartCPUProfile(f); err != nil {\n\t\t\tlog.Fatalf(\"could not start CPU profile: %s\", err)\n\t\t}\n\t\tdefer pprof.StopCPUProfile()\n\t}\n\n\tswitch {\n\tcase *showDoc:\n\t\tfmt.Print(genDocString)\n\tcase *showHelp:\n\t\tflag.Usage()\n\tcase *showVersion:\n\t\tprintVersion()\n\tcase *remoteCmd != \"\":\n\t\tresp, err := remote(*remoteCmd)\n\t\tif err != nil {\n\t\t\tlog.Fatalf(\"remote command: %s\", err)\n\t\t\treturn\n\t\t}\n\t\tfmt.Print(resp)\n\tcase *serverMode:\n\t\tif err := os.Chdir(gUser.HomeDir); err != nil {\n\t\t\tlog.Print(err)\n\t\t}\n\t\tserve()\n\tdefault:\n\t\tgSingleMode = *singleMode\n\t\tgPrintLastDir = *printLastDir\n\t\tgPrintSelection = *printSelection\n\n\t\tif !gSingleMode {\n\t\t\tcheckServer()\n\t\t}\n\n\t\tgClientID = os.Getpid()\n\n\t\tswitch flag.NArg() {\n\t\tcase 0:\n\t\t\t_, err := os.Getwd()\n\t\t\tif err != nil {\n\t\t\t\tfmt.Fprintf(os.Stderr, \"getting current directory: %s\\n\", err)\n\t\t\t\tos.Exit(2)\n\t\t\t}\n\t\tcase 1:\n\t\t\tgSelect = flag.Arg(0)\n\t\tdefault:\n\t\t\tfmt.Fprintln(os.Stderr, \"only single file or directory is allowed\")\n\t\t\tos.Exit(2)\n\t\t}\n\n\t\texportEnvVars()\n\t\texportFlags()\n\n\t\trun()\n\t}\n\n\tif *memprofile != \"\" {\n\t\tf, err := os.Create(*memprofile)\n\t\tif err != nil {\n\t\t\tlog.Fatal(\"could not create memory profile: \", err)\n\t\t}\n\t\truntime.GC()\n\t\tif err := pprof.WriteHeapProfile(f); err != nil {\n\t\t\tlog.Fatal(\"could not write memory profile: \", err)\n\t\t}\n\t\tf.Close()\n\t}\n}\n"
  },
  {
    "path": "misc.go",
    "content": "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\"slices\"\n\t\"strconv\"\n\t\"strings\"\n\t\"unicode\"\n\n\t\"github.com/rivo/uniseg\"\n)\n\nvar (\n\treRulerSub  = regexp.MustCompile(`%[apmcsvfithPd]|%\\{[^}]+\\}`)\n\treSixelSize = regexp.MustCompile(`\"1;1;(\\d+);(\\d+)`)\n)\n\nvar (\n\treWord    = regexp.MustCompile(`(\\pL|\\pN)+`)\n\treWordBeg = regexp.MustCompile(`([^\\pL\\pN]|^)(\\pL|\\pN)`)\n\treWordEnd = regexp.MustCompile(`(\\pL|\\pN)([^\\pL\\pN]|$)`)\n)\n\nfunc isRoot(name string) bool { return filepath.Dir(name) == name }\n\nfunc replaceTilde(s string) string {\n\tif strings.HasPrefix(s, \"~\") {\n\t\treturn gUser.HomeDir + s[1:]\n\t}\n\treturn s\n}\n\n// firstGraphemeCluster returns the string containing the first grapheme cluster\n// of the input.\nfunc firstGraphemeCluster(s string) string {\n\tgr := uniseg.NewGraphemes(s)\n\tgr.Next()\n\treturn gr.Str()\n}\n\n// lastGraphemeCluster returns the string containing the last grapheme cluster\n// of the input.\nfunc lastGraphemeCluster(s string) string {\n\tgr := uniseg.NewGraphemes(s)\n\tvar last string\n\tfor gr.Next() {\n\t\tlast = gr.Str()\n\t}\n\treturn last\n}\n\n// truncateRight truncates a string from the right based on Unicode widths,\n// taking into account grapheme clusters.\nfunc truncateRight(s string, maxWidth int) string {\n\tbuf := make([]byte, 0, len(s))\n\twidth := 0\n\n\tgr := uniseg.NewGraphemes(s)\n\tfor gr.Next() {\n\t\twidth += gr.Width()\n\t\tif width > maxWidth {\n\t\t\tbreak\n\t\t}\n\n\t\tbuf = append(buf, gr.Bytes()...)\n\t}\n\n\treturn string(buf)\n}\n\n// truncateLeft truncates a string from the left based on Unicode widths,\n// taking into account grapheme clusters.\nfunc truncateLeft(s string, maxWidth int) string {\n\ttype cluster struct {\n\t\tbytes []byte\n\t\twidth int\n\t}\n\n\tvar clusters []cluster\n\ttotalWidth := 0\n\tgr := uniseg.NewGraphemes(s)\n\tfor gr.Next() {\n\t\tclusters = append(clusters, cluster{slices.Clone(gr.Bytes()), gr.Width()})\n\t\ttotalWidth += gr.Width()\n\t}\n\n\tbuf := make([]byte, 0, len(s))\n\twidth := 0\n\tfor _, cluster := range clusters {\n\t\tif totalWidth-width <= maxWidth {\n\t\t\tbuf = append(buf, cluster.bytes...)\n\t\t}\n\n\t\twidth += cluster.width\n\t}\n\n\treturn string(buf)\n}\n\n// cmdEscape is used to escape whitespace and special characters with\n// backslashes in a given string.\nfunc cmdEscape(s string) string {\n\tbuf := make([]rune, 0, len(s))\n\tfor _, r := range s {\n\t\tif unicode.IsSpace(r) || r == '\\\\' || r == ';' || r == '#' {\n\t\t\tbuf = append(buf, '\\\\')\n\t\t}\n\t\tbuf = append(buf, r)\n\t}\n\treturn string(buf)\n}\n\n// cmdUnescape is used to remove backslashes that are used to escape\n// whitespace and special characters in a given string.\nfunc cmdUnescape(s string) string {\n\tesc := false\n\tbuf := make([]rune, 0, len(s))\n\tfor _, r := range s {\n\t\tif esc {\n\t\t\tif !unicode.IsSpace(r) && r != '\\\\' && r != ';' && r != '#' {\n\t\t\t\tbuf = append(buf, '\\\\')\n\t\t\t}\n\t\t\tbuf = append(buf, r)\n\t\t\tesc = false\n\t\t\tcontinue\n\t\t}\n\t\tif r == '\\\\' {\n\t\t\tesc = true\n\t\t\tcontinue\n\t\t}\n\t\tesc = false\n\t\tbuf = append(buf, r)\n\t}\n\tif esc {\n\t\tbuf = append(buf, '\\\\')\n\t}\n\treturn string(buf)\n}\n\n// tokenize splits the given string by whitespace. It is aware of escaped\n// and quoted whitespace so that they are not split unintentionally.\nfunc tokenize(s string) []string {\n\tesc := false\n\tquote := false\n\tvar buf []rune\n\tvar toks []string\n\tfor _, r := range s {\n\t\tswitch {\n\t\tcase esc:\n\t\t\tesc = false\n\t\t\tbuf = append(buf, r)\n\t\tcase r == '\\\\':\n\t\t\tesc = true\n\t\t\tbuf = append(buf, r)\n\t\tcase r == '\"':\n\t\t\tquote = !quote\n\t\t\tbuf = append(buf, r)\n\t\tcase unicode.IsSpace(r) && !quote:\n\t\t\ttoks = append(toks, string(buf))\n\t\t\tbuf = nil\n\t\tdefault:\n\t\t\tbuf = append(buf, r)\n\t\t}\n\t}\n\treturn append(toks, string(buf))\n}\n\n// splitWord splits the first word of a string delimited by whitespace from\n// the rest. This is used to tokenize a string one by one without touching the\n// rest. Whitespace on the left side of both the word and the rest are trimmed.\nfunc splitWord(s string) (word, rest string) {\n\ts = strings.TrimLeftFunc(s, unicode.IsSpace)\n\tind := len(s)\n\tfor i, c := range s {\n\t\tif unicode.IsSpace(c) {\n\t\t\tind = i\n\t\t\tbreak\n\t\t}\n\t}\n\tword = s[0:ind]\n\trest = strings.TrimLeftFunc(s[ind:], unicode.IsSpace)\n\treturn\n}\n\n// readArrays reads whitespace-separated string arrays on each line. Single\n// or double quotes can be used to escape whitespace. Hash characters can be\n// used to add a comment until the end of line. Leading and trailing space is\n// trimmed. Empty lines are skipped.\nfunc readArrays(r io.Reader, minCols, maxCols int) ([][]string, error) {\n\tvar arrays [][]string\n\ts := bufio.NewScanner(r)\n\tfor s.Scan() {\n\t\tline := s.Text()\n\n\t\tsquote, dquote := false, false\n\t\tfor i := range len(line) {\n\t\t\tif line[i] == '\\'' && !dquote {\n\t\t\t\tsquote = !squote\n\t\t\t} else if line[i] == '\"' && !squote {\n\t\t\t\tdquote = !dquote\n\t\t\t}\n\t\t\tif !squote && !dquote && line[i] == '#' {\n\t\t\t\tline = line[:i]\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tline = strings.TrimSpace(line)\n\n\t\tif line == \"\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tsquote, dquote = false, false\n\t\tarr := strings.FieldsFunc(line, func(r rune) bool {\n\t\t\tif r == '\\'' && !dquote {\n\t\t\t\tsquote = !squote\n\t\t\t} else if r == '\"' && !squote {\n\t\t\t\tdquote = !dquote\n\t\t\t}\n\t\t\treturn !squote && !dquote && unicode.IsSpace(r)\n\t\t})\n\t\tarrlen := len(arr)\n\n\t\tif arrlen < minCols || arrlen > maxCols {\n\t\t\tif minCols == maxCols {\n\t\t\t\treturn nil, fmt.Errorf(\"expected %d columns but found: %s\", minCols, s.Text())\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"expected %d~%d columns but found: %s\", minCols, maxCols, s.Text())\n\t\t}\n\n\t\tfor i := range arrlen {\n\t\t\tsquote, dquote = false, false\n\t\t\tbuf := make([]rune, 0, len(arr[i]))\n\t\t\tfor _, r := range arr[i] {\n\t\t\t\tif r == '\\'' && !dquote {\n\t\t\t\t\tsquote = !squote\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif r == '\"' && !squote {\n\t\t\t\t\tdquote = !dquote\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tbuf = append(buf, r)\n\t\t\t}\n\t\t\tarr[i] = string(buf)\n\t\t}\n\n\t\tarrays = append(arrays, arr)\n\t}\n\n\treturn arrays, s.Err()\n}\n\nfunc readPairs(r io.Reader) ([][]string, error) {\n\treturn readArrays(r, 2, 2)\n}\n\n// humanize converts a size in bytes to a human-readable form using\n// prefixes for either binary (1 KiB = 1024 B) or decimal (1 KB = 1000 B)\n// multiples. The output should be no more than 5 characters long.\nfunc humanize(size int64) string {\n\tvar base int64 = 1024\n\tif gOpts.sizeunits == \"decimal\" {\n\t\tbase = 1000\n\t}\n\n\tif size < base {\n\t\treturn fmt.Sprintf(\"%dB\", size)\n\t}\n\n\t// Note: due to [fs.FileInfo.Size] being `int64`, the maximum\n\t// possible representable value would be 8 EiB or 9.2 EB.\n\tprefixes := []string{\n\t\t\"K\", // kibi (2^10) or kilo (10^3)\n\t\t\"M\", // mebi (2^20) or mega (10^6)\n\t\t\"G\", // gibi (2^30) or giga (10^9)\n\t\t\"T\", // tebi (2^40) or tera (10^2)\n\t\t\"P\", // pebi (2^50) or peta (10^15)\n\t\t\"E\", // exbi (2^60) or exa (10^18)\n\t\t\"Z\", // zebi (2^70) or zetta (10^21)\n\t\t\"Y\", // yobi (2^80) or yotta (10^24)\n\t\t\"R\", // robi (2^90) or ronna (10^27)\n\t\t\"Q\", // quebi (2^100) or quetta (10^30)\n\t}\n\n\tcurr := big.NewRat(size, base)\n\n\tfor _, prefix := range prefixes {\n\t\t// if curr < 99.95 then round to 1 decimal place\n\t\tif curr.Cmp(big.NewRat(9995, 100)) < 0 {\n\t\t\treturn fmt.Sprintf(\"%s%s\", curr.FloatString(1), prefix)\n\t\t}\n\n\t\t// if curr < base-0.5 then round to the nearest integer\n\t\tif curr.Cmp(new(big.Rat).Sub(big.NewRat(base, 1), big.NewRat(1, 2))) < 0 {\n\t\t\treturn fmt.Sprintf(\"%s%s\", curr.FloatString(0), prefix)\n\t\t}\n\n\t\tcurr.Quo(curr, big.NewRat(base, 1))\n\t}\n\n\treturn fmt.Sprintf(\"+999%s\", prefixes[len(prefixes)-1])\n}\n\n// permString returns an ls(1)-style string representation of the given file\n// mode, to avoid using [fs.FileMode.String], which differs slightly.\nfunc permString(m os.FileMode) string {\n\t// re-use Perm()'s \"-rwxrwxrwx\" output and write type into b[0]\n\tb := []byte(m.Perm().String())\n\tswitch {\n\tcase m&os.ModeSymlink != 0:\n\t\tb[0] = 'l'\n\tcase m&os.ModeDir != 0:\n\t\tb[0] = 'd'\n\tcase m&os.ModeNamedPipe != 0:\n\t\tb[0] = 'p'\n\tcase m&os.ModeSocket != 0:\n\t\tb[0] = 's'\n\tcase m&os.ModeCharDevice != 0:\n\t\tb[0] = 'c'\n\tcase m&os.ModeDevice != 0:\n\t\tb[0] = 'b'\n\tdefault:\n\t\tb[0] = '-'\n\t}\n\t// patch exec slots with suid/sgid/sticky flags\n\tif m&os.ModeSetuid != 0 {\n\t\tif b[3] == 'x' {\n\t\t\tb[3] = 's'\n\t\t} else {\n\t\t\tb[3] = 'S'\n\t\t}\n\t}\n\tif m&os.ModeSetgid != 0 {\n\t\tif b[6] == 'x' {\n\t\t\tb[6] = 's'\n\t\t} else {\n\t\t\tb[6] = 'S'\n\t\t}\n\t}\n\tif m&os.ModeSticky != 0 {\n\t\tif b[9] == 'x' {\n\t\t\tb[9] = 't'\n\t\t} else {\n\t\t\tb[9] = 'T'\n\t\t}\n\t}\n\n\treturn string(b)\n}\n\n// naturalCmp compares two strings for natural sorting which takes into\n// account the values of numbers in strings. For example, '2' is ordered before\n// '10', and similarly 'foo2bar' ordered before 'foo10bar'. When comparing\n// numbers, if they have the same value then the length of the string is also\n// compared, so '0' is ordered before '00'.\nfunc naturalCmp(s1, s2 string) int {\n\ts1len := len(s1)\n\ts2len := len(s2)\n\n\tvar lo1, lo2, hi1, hi2 int\n\tfor {\n\t\tswitch {\n\t\tcase hi1 >= s1len && hi2 >= s2len:\n\t\t\treturn 0\n\t\tcase hi1 >= s1len && hi2 < s2len:\n\t\t\treturn -1\n\t\tcase hi1 < s1len && hi2 >= s2len:\n\t\t\treturn 1\n\t\t}\n\n\t\tlo1 = hi1\n\t\tisDigit1 := isDigit(s1[hi1])\n\t\tfor hi1 < s1len && isDigit(s1[hi1]) == isDigit1 {\n\t\t\thi1++\n\t\t}\n\t\ttok1 := s1[lo1:hi1]\n\n\t\tlo2 = hi2\n\t\tisDigit2 := isDigit(s2[hi2])\n\t\tfor hi2 < s2len && isDigit(s2[hi2]) == isDigit2 {\n\t\t\thi2++\n\t\t}\n\t\ttok2 := s2[lo2:hi2]\n\n\t\tif isDigit1 && isDigit2 {\n\t\t\tnum1, err1 := strconv.Atoi(tok1)\n\t\t\tnum2, err2 := strconv.Atoi(tok2)\n\t\t\tif err1 == nil && err2 == nil {\n\t\t\t\tif num1 != num2 {\n\t\t\t\t\treturn cmp.Compare(num1, num2)\n\t\t\t\t} else if len(tok1) != len(tok2) {\n\t\t\t\t\treturn cmp.Compare(len(tok1), len(tok2))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif tok1 != tok2 {\n\t\t\treturn cmp.Compare(tok1, tok2)\n\t\t}\n\t}\n}\n\n// getFileExtension returns the extension of a file with a leading dot.\n// It returns an empty string if extension could not be determined\n// i.e. directories, filenames without extensions\nfunc getFileExtension(file fs.FileInfo) string {\n\tif file.IsDir() {\n\t\treturn \"\"\n\t}\n\tif strings.Count(file.Name(), \".\") == 1 && file.Name()[0] == '.' {\n\t\t// hidden file without extension\n\t\treturn \"\"\n\t}\n\treturn filepath.Ext(file.Name())\n}\n\n// truncateFilename truncates a filename at a given position.\n// The position is specified as percentage indicating where the truncation\n// character will appear (0 means left, 50 means middle, 100 means right).\n// The file extension is not affected by truncation, however it will be clipped\n// if it exceeds the allowed width.\nfunc truncateFilename(file fs.FileInfo, maxWidth, truncatePct int, truncateChar string) string {\n\tfilename := file.Name()\n\tif uniseg.StringWidth(filename) <= maxWidth {\n\t\treturn filename\n\t}\n\n\text := getFileExtension(file)\n\tavail := maxWidth - uniseg.StringWidth(truncateChar) - uniseg.StringWidth(ext)\n\tif avail < 0 {\n\t\treturn truncateRight(truncateChar+ext, maxWidth)\n\t}\n\n\tbasename := strings.TrimSuffix(filename, ext)\n\tleft := truncateRight(basename, avail*truncatePct/100)\n\tright := truncateLeft(basename, avail-uniseg.StringWidth(left))\n\treturn left + truncateChar + right + ext\n}\n\n// deletePathRecursive deletes entries from a map if the key is either the given\n// path or a subpath of it.\n// This is useful for clearing cached data when a directory is moved or deleted.\nfunc deletePathRecursive[T any](m map[string]T, path string) {\n\tdelete(m, path)\n\tprefix := path + string(filepath.Separator)\n\tfor k := range m {\n\t\tif strings.HasPrefix(k, prefix) {\n\t\t\tdelete(m, k)\n\t\t}\n\t}\n}\n\n// readLines reads lines from a file to be displayed as a preview.\n// The number of lines to read is capped since files can be very large.\n// Lines are split on `\\n` characters, and `\\r` characters are discarded.\n// Sixel images are also detected and stored as separate lines.\n// The presence of a null byte outside a sixel image indicates a binary file.\nfunc readLines(reader io.ByteReader, maxLines int) (lines []string, binary bool, sixel bool) {\n\tvar buf bytes.Buffer\n\tvar last byte\n\tinSixel := false\n\n\tfor {\n\t\tb, err := reader.ReadByte()\n\t\tif err != nil {\n\t\t\tif buf.Len() > 0 {\n\t\t\t\tlines = append(lines, buf.String())\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\tif inSixel {\n\t\t\tbuf.WriteByte(b)\n\t\t\tif b == '\\\\' && last == '\\033' {\n\t\t\t\tlines = append(lines, buf.String())\n\t\t\t\tbuf.Reset()\n\t\t\t\tif len(lines) >= maxLines {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tinSixel = false\n\t\t\t}\n\t\t} else {\n\t\t\tswitch {\n\t\t\tcase b == 0:\n\t\t\t\treturn nil, true, false\n\t\t\tcase b == '\\033':\n\t\t\t\t// withhold as it could be the start of a sixel image\n\t\t\tcase b == 'P' && last == '\\033':\n\t\t\t\tif buf.Len() > 0 {\n\t\t\t\t\tlines = append(lines, buf.String())\n\t\t\t\t\tbuf.Reset()\n\t\t\t\t\tif len(lines) >= maxLines {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbuf.WriteByte(last)\n\t\t\t\tbuf.WriteByte(b)\n\t\t\t\tinSixel = true\n\t\t\t\tsixel = true\n\t\t\tcase last == '\\033':\n\t\t\t\t// not a sixel image\n\t\t\t\tbuf.WriteByte(last)\n\t\t\t\tbuf.WriteByte(b)\n\t\t\tcase b == '\\r':\n\t\t\tcase b == '\\n':\n\t\t\t\tlines = append(lines, buf.String())\n\t\t\t\tbuf.Reset()\n\t\t\t\tif len(lines) >= maxLines {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\tbuf.WriteByte(b)\n\t\t\t}\n\t\t}\n\n\t\tlast = b\n\t}\n}\n\n// getWidths calculates the widths of windows as the result of applying the\n// `ratios` option to the screen width. One column is allocated for each divider\n// between windows. When `drawbox` is enabled and `borderstyle` includes an outline,\n// getWidths reserves two additional columns for the left and right borders.\nfunc getWidths(wtot int, ratios []int, drawbox bool, borderstyle borderStyle) []int {\n\trlen := len(ratios)\n\twtot -= rlen - 1\n\tif drawbox && borderstyle&borderOutline != 0 {\n\t\twtot -= 2\n\t}\n\twtot = max(wtot, 0)\n\n\trtot := 0\n\tfor _, r := range ratios {\n\t\trtot += r\n\t}\n\n\tdivround := func(x, y int) int {\n\t\treturn (x + y/2) / y\n\t}\n\n\twidths := make([]int, rlen)\n\trsum := 0\n\twsum := 0\n\tfor i, r := range ratios {\n\t\trsum += r\n\t\twidths[i] = divround(wtot*rsum, rtot) - wsum\n\t\twsum += widths[i]\n\t}\n\n\treturn widths\n}\n\n// We don't need no generic code\n// We don't need no type control\n// No dark templates in compiler\n// Haskell leave them kids alone\n// Hey Bjarne leave them kids alone\n// All in all it's just another brick in the code\n// All in all you're just another brick in the code\n//\n// -- Pink Trolled --\n"
  },
  {
    "path": "misc_test.go",
    "content": "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 := string(os.PathSeparator)\n\tif !isRoot(sep) {\n\t\tt.Errorf(`\"%s\" is root`, sep)\n\t}\n\n\tpaths := []string{\n\t\t\"\",\n\t\t\"~\",\n\t\t\"foo\",\n\t\t\"foo/bar\",\n\t\t\"foo/bar\",\n\t\t\"/home\",\n\t\t\"/home/user\",\n\t}\n\n\tfor _, p := range paths {\n\t\tif isRoot(p) {\n\t\t\tt.Errorf(\"'%s' is not root\", p)\n\t\t}\n\t}\n}\n\nfunc TestFirstGraphemeCluster(t *testing.T) {\n\ttests := []struct {\n\t\ts   string\n\t\texp string\n\t}{\n\t\t{\"\", \"\"},\n\t\t{\"a\", \"a\"},\n\t\t{\"世界\", \"世\"},\n\t\t{\"🏳️a\", \"🏳️\"},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := firstGraphemeCluster(test.s); got != test.exp {\n\t\t\tt.Errorf(\"at input '%v' expected '%v' but got '%v'\", test.s, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestLastGraphemeCluster(t *testing.T) {\n\ttests := []struct {\n\t\ts   string\n\t\texp string\n\t}{\n\t\t{\"\", \"\"},\n\t\t{\"a\", \"a\"},\n\t\t{\"世界\", \"界\"},\n\t\t{\"a🏳️\", \"🏳️\"},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := lastGraphemeCluster(test.s); got != test.exp {\n\t\t\tt.Errorf(\"at input '%v' expected '%v' but got '%v'\", test.s, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestTruncateRight(t *testing.T) {\n\ttests := []struct {\n\t\ts        string\n\t\tmaxWidth int\n\t\texp      string\n\t}{\n\t\t{\"\", 0, \"\"},\n\t\t{\"\", 1, \"\"},\n\t\t{\"a\", 0, \"\"},\n\t\t{\"a\", 1, \"a\"},\n\t\t{\"ab\", 1, \"a\"},\n\t\t{\"世\", 0, \"\"},\n\t\t{\"世\", 1, \"\"},\n\t\t{\"世界\", 2, \"世\"},\n\t\t{\"世界\", 3, \"世\"},\n\t\t{\"a🏳️b\", 2, \"a\"},\n\t\t{\"a🏳️b\", 3, \"a🏳️\"},\n\t\t{\"a🏳️b\", 4, \"a🏳️b\"},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := truncateRight(test.s, test.maxWidth); got != test.exp {\n\t\t\tt.Errorf(\"at input ('%v', %v) expected '%v' but got '%v'\", test.s, test.maxWidth, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestTruncateLeft(t *testing.T) {\n\ttests := []struct {\n\t\ts        string\n\t\tmaxWidth int\n\t\texp      string\n\t}{\n\t\t{\"\", 0, \"\"},\n\t\t{\"\", 1, \"\"},\n\t\t{\"a\", 0, \"\"},\n\t\t{\"a\", 1, \"a\"},\n\t\t{\"ab\", 1, \"b\"},\n\t\t{\"世\", 0, \"\"},\n\t\t{\"世\", 1, \"\"},\n\t\t{\"世界\", 2, \"界\"},\n\t\t{\"世界\", 3, \"界\"},\n\t\t{\"a🏳️b\", 2, \"b\"},\n\t\t{\"a🏳️b\", 3, \"🏳️b\"},\n\t\t{\"a🏳️b\", 4, \"a🏳️b\"},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := truncateLeft(test.s, test.maxWidth); got != test.exp {\n\t\t\tt.Errorf(\"at input ('%v', %v) expected '%v' but got '%v'\", test.s, test.maxWidth, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestCmdEscape(t *testing.T) {\n\ttests := []struct {\n\t\ts   string\n\t\texp string\n\t}{\n\t\t{\"\", \"\"},\n\t\t{\"foo\", \"foo\"},\n\t\t{\"foo bar\", `foo\\ bar`},\n\t\t{\"foo  bar\", `foo\\ \\ bar`},\n\t\t{`foo\\bar`, `foo\\\\bar`},\n\t\t{`foo\\ bar`, `foo\\\\\\ bar`},\n\t\t{`foo;bar`, `foo\\;bar`},\n\t\t{`foo#bar`, `foo\\#bar`},\n\t\t{`foo\\tbar`, `foo\\\\tbar`},\n\t\t{\"foo\\tbar\", \"foo\\\\\\tbar\"},\n\t\t{`foo\\`, `foo\\\\`},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := cmdEscape(test.s); !reflect.DeepEqual(got, test.exp) {\n\t\t\tt.Errorf(\"at input '%v' expected '%v' but got '%v'\", test.s, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestCmdUnescape(t *testing.T) {\n\ttests := []struct {\n\t\ts   string\n\t\texp string\n\t}{\n\t\t{\"\", \"\"},\n\t\t{\"foo\", \"foo\"},\n\t\t{`foo\\ bar`, \"foo bar\"},\n\t\t{`foo\\ \\ bar`, \"foo  bar\"},\n\t\t{`foo\\\\bar`, `foo\\bar`},\n\t\t{`foo\\\\\\ bar`, `foo\\ bar`},\n\t\t{`foo\\;bar`, `foo;bar`},\n\t\t{`foo\\#bar`, `foo#bar`},\n\t\t{`foo\\\\tbar`, `foo\\tbar`},\n\t\t{\"foo\\\\\\tbar\", \"foo\\tbar\"},\n\t\t{`foo\\`, `foo\\`},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := cmdUnescape(test.s); !reflect.DeepEqual(got, test.exp) {\n\t\t\tt.Errorf(\"at input '%v' expected '%v' but got '%v'\", test.s, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestTokenize(t *testing.T) {\n\ttests := []struct {\n\t\ts   string\n\t\texp []string\n\t}{\n\t\t{\"\", []string{\"\"}},\n\t\t{\"foo\", []string{\"foo\"}},\n\t\t{`foo\\`, []string{`foo\\`}},\n\t\t{`foo\"`, []string{`foo\"`}},\n\t\t{\"foo bar\", []string{\"foo\", \"bar\"}},\n\t\t{`foo\\ bar`, []string{`foo\\ bar`}},\n\t\t{`\"foo bar\"`, []string{`\"foo bar\"`}},\n\t\t{`\"foo\" \"bar\"`, []string{`\"foo\"`, `\"bar\"`}},\n\t\t{`\"foo \"bar\"`, []string{`\"foo \"bar\"`}},\n\t\t{`\"foo\\\" bar\"`, []string{`\"foo\\\" bar\"`}},\n\t\t{`\\\"foo bar\\\"`, []string{`\\\"foo`, `bar\\\"`}},\n\t\t{`:rename foo\\ bar`, []string{\":rename\", `foo\\ bar`}},\n\t\t{`!dir \"C:\\Program Files\"`, []string{\"!dir\", `\"C:\\Program Files\"`}},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := tokenize(test.s); !reflect.DeepEqual(got, test.exp) {\n\t\t\tt.Errorf(\"at input '%v' expected '%v' but got '%v'\", test.s, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestSplitWord(t *testing.T) {\n\ttests := []struct {\n\t\ts    string\n\t\tword string\n\t\trest string\n\t}{\n\t\t{\"\", \"\", \"\"},\n\t\t{\"foo\", \"foo\", \"\"},\n\t\t{\"  foo\", \"foo\", \"\"},\n\t\t{\"foo  \", \"foo\", \"\"},\n\t\t{\"  foo  \", \"foo\", \"\"},\n\t\t{\"foo bar baz\", \"foo\", \"bar baz\"},\n\t\t{\"  foo bar baz\", \"foo\", \"bar baz\"},\n\t\t{\"foo   bar baz\", \"foo\", \"bar baz\"},\n\t\t{\"  foo   bar baz\", \"foo\", \"bar baz\"},\n\t}\n\n\tfor _, test := range tests {\n\t\tif w, r := splitWord(test.s); w != test.word || r != test.rest {\n\t\t\tt.Errorf(\"at input '%s' expected '%s' and '%s' but got '%s' and '%s'\", test.s, test.word, test.rest, w, r)\n\t\t}\n\t}\n}\n\nfunc TestReadArrays(t *testing.T) {\n\ttests := []struct {\n\t\ts       string\n\t\tminCols int\n\t\tmaxCols int\n\t\texp     [][]string\n\t}{\n\t\t{\"foo bar\", 2, 2, [][]string{{\"foo\", \"bar\"}}},\n\t\t{\"foo bar \", 2, 2, [][]string{{\"foo\", \"bar\"}}},\n\t\t{\" foo bar\", 2, 2, [][]string{{\"foo\", \"bar\"}}},\n\t\t{\" foo bar \", 2, 2, [][]string{{\"foo\", \"bar\"}}},\n\t\t{\"foo bar#baz\", 2, 2, [][]string{{\"foo\", \"bar\"}}},\n\t\t{\"foo bar #baz\", 2, 2, [][]string{{\"foo\", \"bar\"}}},\n\t\t{`'foo#baz' bar`, 2, 2, [][]string{{\"foo#baz\", \"bar\"}}},\n\t\t{`\"foo#baz\" bar`, 2, 2, [][]string{{\"foo#baz\", \"bar\"}}},\n\t\t{\"foo bar baz\", 3, 3, [][]string{{\"foo\", \"bar\", \"baz\"}}},\n\t\t{`\"foo bar baz\"`, 1, 1, [][]string{{\"foo bar baz\"}}},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got, _ := readArrays(strings.NewReader(test.s), test.minCols, test.maxCols); !reflect.DeepEqual(got, test.exp) {\n\t\t\tt.Errorf(\"at input '%v' expected '%v' but got '%v'\", test.s, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestHumanize(t *testing.T) {\n\ttests := []struct {\n\t\tsize     int64\n\t\texpected string\n\t}{\n\t\t{0, \"0B\"},\n\t\t{1, \"1B\"},\n\t\t{2, \"2B\"},\n\t\t{10, \"10B\"},\n\t\t{100, \"100B\"},\n\t\t{1000, \"1000B\"},\n\t\t{1023, \"1023B\"},\n\t\t{1024, \"1.0K\"},\n\t\t{1025, \"1.0K\"},                // 1.000976563 KiB\n\t\t{10188, \"9.9K\"},               // 9.94921875 KiB\n\t\t{10189, \"10.0K\"},              // 9.950195313 KiB\n\t\t{10240, \"10.0K\"},              // 10 KiB\n\t\t{10291, \"10.0K\"},              // 10.049804688 KiB\n\t\t{10292, \"10.1K\"},              // 10.05078125 KiB\n\t\t{10342, \"10.1K\"},              // 10.099609375 KiB\n\t\t{102348, \"99.9K\"},             // 99.94921875 KiB\n\t\t{102349, \"100K\"},              // 99.950195313 KiB\n\t\t{1023487, \"999K\"},             // 999.499023438 KiB\n\t\t{1023488, \"1000K\"},            // 999.5 KiB\n\t\t{1048063, \"1023K\"},            // 1023.499023438 KiB\n\t\t{1048064, \"1.0M\"},             // 1023.5 KiB\n\t\t{1072693248, \"1023M\"},         // 1023 MiB\n\t\t{1073217535, \"1023M\"},         // 1023.499999046 MiB\n\t\t{1073217536, \"1.0G\"},          // 1023.5 MiB\n\t\t{1073741824, \"1.0G\"},          // 1 GiB\n\t\t{1610612736, \"1.5G\"},          // 1.5 GiB\n\t\t{1319413953332, \"1.2T\"},       // 1.2 TiB\n\t\t{1463669878895412, \"1.3P\"},    // 1.3 PiB\n\t\t{7955158381787244544, \"6.9E\"}, // 6.9 EiB\n\t\t{math.MaxInt64, \"8.0E\"},       // 8 EiB\n\t}\n\n\tgOpts.sizeunits = \"binary\"\n\tfor _, test := range tests {\n\t\tif got := humanize(test.size); got != test.expected {\n\t\t\tt.Errorf(\"at input ('%d', '%s') expected '%s' but got '%s'\", test.size, gOpts.sizeunits, test.expected, got)\n\t\t}\n\t}\n\n\ttests = []struct {\n\t\tsize     int64\n\t\texpected string\n\t}{\n\t\t{0, \"0B\"},\n\t\t{1, \"1B\"},\n\t\t{2, \"2B\"},\n\t\t{10, \"10B\"},\n\t\t{100, \"100B\"},\n\t\t{999, \"999B\"},\n\t\t{1000, \"1.0K\"},\n\t\t{1001, \"1.0K\"},\n\t\t{1049, \"1.0K\"},\n\t\t{1050, \"1.1K\"},\n\t\t{1051, \"1.1K\"},\n\t\t{9949, \"9.9K\"},\n\t\t{9950, \"10.0K\"},\n\t\t{9951, \"10.0K\"},\n\t\t{9999, \"10.0K\"},\n\t\t{10000, \"10.0K\"},\n\t\t{10001, \"10.0K\"},\n\t\t{99949, \"99.9K\"},\n\t\t{99950, \"100K\"},\n\t\t{99951, \"100K\"},\n\t\t{999499, \"999K\"},\n\t\t{999500, \"1.0M\"},\n\t\t{999501, \"1.0M\"},\n\t\t{999999, \"1.0M\"},\n\t\t{1000000, \"1.0M\"},\n\t\t{1000001, \"1.0M\"},\n\t\t{999499999, \"999M\"},\n\t\t{999500000, \"1.0G\"},\n\t\t{999500001, \"1.0G\"},\n\t\t{999999999, \"1.0G\"},\n\t\t{1000000000, \"1.0G\"},\n\t\t{1000000001, \"1.0G\"},\n\t\t{math.MaxInt64, \"9.2E\"},\n\t}\n\n\tgOpts.sizeunits = \"decimal\"\n\tfor _, test := range tests {\n\t\tif got := humanize(test.size); got != test.expected {\n\t\t\tt.Errorf(\"at input ('%d', '%s') expected '%s' but got '%s'\", test.size, gOpts.sizeunits, test.expected, got)\n\t\t}\n\t}\n}\n\nfunc TestPermString(t *testing.T) {\n\ttests := []struct {\n\t\tname string\n\t\tm    os.FileMode\n\t\texp  string\n\t}{\n\t\t{\"none\", 0, \"----------\"},\n\t\t{\"regular file\", 0o644, \"-rw-r--r--\"},\n\t\t{\"executable\", 0o755, \"-rwxr-xr-x\"},\n\t\t{\"directory\", 0o755 | os.ModeDir, \"drwxr-xr-x\"},\n\t\t{\"symbolic link\", 0o777 | os.ModeSymlink, \"lrwxrwxrwx\"},\n\t\t{\"named pipe\", 0o644 | os.ModeNamedPipe, \"prw-r--r--\"},\n\t\t{\"socket\", 0o777 | os.ModeSocket, \"srwxrwxrwx\"},\n\t\t{\"character device\", 0o660 | os.ModeCharDevice, \"crw-rw----\"},\n\t\t{\"block device\", 0o660 | os.ModeDevice, \"brw-rw----\"},\n\t\t{\"setuid\", 0o644 | os.ModeSetuid, \"-rwSr--r--\"},\n\t\t{\"setuid executable\", 0o755 | os.ModeSetuid, \"-rwsr-xr-x\"},\n\t\t{\"setgid\", 0o644 | os.ModeSetgid, \"-rw-r-Sr--\"},\n\t\t{\"setgid executable\", 0o755 | os.ModeSetgid, \"-rwxr-sr-x\"},\n\t\t{\"sticky\", 0o644 | os.ModeSticky, \"-rw-r--r-T\"},\n\t\t{\"sticky executable\", 0o755 | os.ModeSticky, \"-rwxr-xr-t\"},\n\t\t{\"sticky directory\", 0o777 | os.ModeDir | os.ModeSticky, \"drwxrwxrwt\"},\n\t}\n\n\tfor _, test := range tests {\n\t\tt.Run(test.name, func(t *testing.T) {\n\t\t\tif got := permString(test.m); got != test.exp {\n\t\t\t\tt.Errorf(\"at input '%#o' expected '%s' but got '%s'\", test.m, test.exp, got)\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc TestNaturalCmp(t *testing.T) {\n\ttests := []struct {\n\t\ts1  string\n\t\ts2  string\n\t\texp int\n\t}{\n\t\t{\"\", \"\", 0},\n\t\t{\"a\", \"a\", 0},\n\t\t{\"\", \"a\", -1},\n\t\t{\"a\", \"b\", -1},\n\t\t{\"a\", \"ab\", -1},\n\t\t{\"0\", \"0\", 0},\n\t\t{\"0\", \"00\", -1},\n\t\t{\"1\", \"1\", 0},\n\t\t{\"1\", \"01\", -1},\n\t\t{\"2\", \"10\", -1},\n\t\t{\"123\", \"foo\", -1},\n\t\t{\"foo\", \"foo1\", -1},\n\t\t{\"foo1\", \"foobar\", -1},\n\t\t{\"foo1\", \"foobar1\", -1},\n\t\t{\"foo2\", \"foo10\", -1},\n\t\t{\"foo2bar\", \"foo10bar\", -1},\n\t\t{\"foo0\", \"foo00\", -1},\n\t\t{\"foo0bar\", \"foo00bar\", -1},\n\t\t{\"foo1\", \"foo01\", -1},\n\t\t{\"foo1bar\", \"foo01bar\", -1},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := naturalCmp(test.s1, test.s2); got != test.exp {\n\t\t\tt.Errorf(\"at input '%s' and '%s' expected '%d' but got '%d'\", test.s1, test.s2, test.exp, got)\n\t\t}\n\n\t\tif got := naturalCmp(test.s2, test.s1); got != -test.exp {\n\t\t\tt.Errorf(\"at input '%s' and '%s' expected '%d' but got '%d'\", test.s2, test.s1, -test.exp, got)\n\t\t}\n\t}\n}\n\ntype fakeFileInfo struct {\n\tname  string\n\tisDir bool\n}\n\nfunc (fileinfo fakeFileInfo) Name() string       { return fileinfo.name }\nfunc (fileinfo fakeFileInfo) Size() int64        { return 0 }\nfunc (fileinfo fakeFileInfo) Mode() os.FileMode  { return os.FileMode(0o000) }\nfunc (fileinfo fakeFileInfo) ModTime() time.Time { return time.Unix(0, 0) }\nfunc (fileinfo fakeFileInfo) IsDir() bool        { return fileinfo.isDir }\nfunc (fileinfo fakeFileInfo) Sys() any           { return nil }\n\nfunc TestGetFileExtension(t *testing.T) {\n\ttests := []struct {\n\t\tname              string\n\t\tfileName          string\n\t\tisDir             bool\n\t\texpectedExtension string\n\t}{\n\t\t{\"normal file\", \"file.txt\", false, \".txt\"},\n\t\t{\"file without extension\", \"file\", false, \"\"},\n\t\t{\"hidden file\", \".gitignore\", false, \"\"},\n\t\t{\"hidden file with extension\", \".file.txt\", false, \".txt\"},\n\t\t{\"directory\", \"dir\", true, \"\"},\n\t\t{\"hidden directory\", \".git\", true, \"\"},\n\t\t{\"directory with dot\", \"profile.d\", true, \"\"},\n\t}\n\n\tfor _, test := range tests {\n\t\tt.Run(test.name, func(t *testing.T) {\n\t\t\tif got := getFileExtension(fakeFileInfo{test.fileName, test.isDir}); got != test.expectedExtension {\n\t\t\t\tt.Errorf(\"at input '%s' expected '%s' but got '%s'\", test.fileName, test.expectedExtension, got)\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc TestTruncateFilename(t *testing.T) {\n\ttests := []struct {\n\t\tfile        fakeFileInfo\n\t\tmaxWidth    int\n\t\ttruncatePct int\n\t\texp         string\n\t}{\n\t\t{fakeFileInfo{\"foo\", false}, 0, 0, \"\"},\n\t\t{fakeFileInfo{\"foo\", false}, 0, 100, \"\"},\n\t\t{fakeFileInfo{\"foo\", false}, 1, 0, \"~\"},\n\t\t{fakeFileInfo{\"foo\", false}, 1, 100, \"~\"},\n\t\t{fakeFileInfo{\"foo\", false}, 2, 0, \"~o\"},\n\t\t{fakeFileInfo{\"foo\", false}, 2, 100, \"f~\"},\n\t\t{fakeFileInfo{\"foo\", false}, 3, 0, \"foo\"},\n\t\t{fakeFileInfo{\"foo\", false}, 3, 100, \"foo\"},\n\t\t{fakeFileInfo{\"foo\", false}, 4, 0, \"foo\"},\n\t\t{fakeFileInfo{\"foo\", false}, 4, 100, \"foo\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 0, 0, \"\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 0, 100, \"\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 1, 0, \"~\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 1, 100, \"~\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 2, 0, \"~.\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 2, 100, \"~.\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 3, 0, \"~.t\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 3, 100, \"~.t\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 4, 0, \"~.tx\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 4, 100, \"~.tx\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 5, 0, \"~.txt\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 5, 100, \"~.txt\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 6, 0, \"~o.txt\"},\n\t\t{fakeFileInfo{\"foo.txt\", false}, 6, 100, \"f~.txt\"},\n\t\t{fakeFileInfo{\"foobarbaz\", false}, 7, 0, \"~barbaz\"},\n\t\t{fakeFileInfo{\"foobarbaz\", false}, 7, 50, \"foo~baz\"},\n\t\t{fakeFileInfo{\"foobarbaz\", false}, 7, 100, \"foobar~\"},\n\t\t{fakeFileInfo{\"foobarbaz.txt\", false}, 11, 0, \"~barbaz.txt\"},\n\t\t{fakeFileInfo{\"foobarbaz.txt\", false}, 11, 50, \"foo~baz.txt\"},\n\t\t{fakeFileInfo{\"foobarbaz.txt\", false}, 11, 100, \"foobar~.txt\"},\n\t\t{fakeFileInfo{\"foobarbaz.d\", true}, 9, 0, \"~barbaz.d\"},\n\t\t{fakeFileInfo{\"foobarbaz.d\", true}, 9, 50, \"foob~az.d\"},\n\t\t{fakeFileInfo{\"foobarbaz.d\", true}, 9, 100, \"foobarba~\"},\n\t\t{fakeFileInfo{\"世界世界.txt\", false}, 10, 0, \"~世界.txt\"},\n\t\t{fakeFileInfo{\"世界世界.txt\", false}, 10, 50, \"世~界.txt\"},\n\t\t{fakeFileInfo{\"世界世界.txt\", false}, 10, 100, \"世界~.txt\"},\n\t\t{fakeFileInfo{\"世界世界.txt\", false}, 11, 0, \"~界世界.txt\"},\n\t\t{fakeFileInfo{\"世界世界.txt\", false}, 11, 50, \"世~世界.txt\"},\n\t\t{fakeFileInfo{\"世界世界.txt\", false}, 11, 100, \"世界世~.txt\"},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := truncateFilename(test.file, test.maxWidth, test.truncatePct, \"~\"); got != test.exp {\n\t\t\tt.Errorf(\"at input (%v, %v, %v) expected '%s' but got '%s'\", test.file, test.maxWidth, test.truncatePct, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestReadLines(t *testing.T) {\n\ttests := []struct {\n\t\ts        string\n\t\tmaxLines int\n\t\tlines    []string\n\t\tbinary   bool\n\t\tsixel    bool\n\t}{\n\t\t{\"\", 10, nil, false, false},\n\t\t{\"\\r\", 10, nil, false, false},\n\t\t{\"\\r\\n\", 10, []string{\"\"}, false, false},\n\t\t{\"\\r\\r\\n\", 10, []string{\"\"}, false, false},\n\t\t{\"\\n\\n\", 10, []string{\"\", \"\"}, false, false},\n\t\t{\"foo\", 10, []string{\"foo\"}, false, false},\n\t\t{\"foo\\n\", 10, []string{\"foo\"}, false, false},\n\t\t{\"foo\\r\\n\", 10, []string{\"foo\"}, false, false},\n\t\t{\"foo\\nbar\", 10, []string{\"foo\", \"bar\"}, false, false},\n\t\t{\"foo\\nbar\\n\", 10, []string{\"foo\", \"bar\"}, false, false},\n\t\t{\"foo\\r\\nbar\", 10, []string{\"foo\", \"bar\"}, false, false},\n\t\t{\"foo\\r\\nbar\\r\\n\", 10, []string{\"foo\", \"bar\"}, false, false},\n\t\t{\"\\033[31mfoo\\033[0m\", 10, []string{\"\\033[31mfoo\\033[0m\"}, false, false},\n\t\t{\"\\000\", 10, nil, true, false},\n\t\t{\"foo\\r\\n\\000\\r\\nbar\\r\\n\", 10, nil, true, false},\n\t\t{\"\\033P\\033\\\\\", 10, []string{\"\\033P\\033\\\\\"}, false, true},\n\t\t{\"\\033Pq\\\"1;1;1;1#0@\\033\\\\\", 10, []string{\"\\033Pq\\\"1;1;1;1#0@\\033\\\\\"}, false, true},\n\t\t{\"\\033P\\000\\033\\\\\", 10, []string{\"\\033P\\000\\033\\\\\"}, false, true},\n\t\t{\"\\033P\\n\\033\\\\\", 10, []string{\"\\033P\\n\\033\\\\\"}, false, true},\n\t\t{\"\\033P\\r\\n\\033\\\\\", 10, []string{\"\\033P\\r\\n\\033\\\\\"}, false, true},\n\t\t{\"\\033P\\033\\\\\\033P\\033\\\\\", 10, []string{\"\\033P\\033\\\\\", \"\\033P\\033\\\\\"}, false, true},\n\t\t{\"foo\\033P\\033\\\\bar\", 10, []string{\"foo\", \"\\033P\\033\\\\\", \"bar\"}, false, true},\n\t\t{\"foo\\033P\\033\\\\bar\\033P\\033\\\\baz\", 10, []string{\"foo\", \"\\033P\\033\\\\\", \"bar\", \"\\033P\\033\\\\\", \"baz\"}, false, true},\n\t\t{\"foo\\nbar\\nbaz\", 2, []string{\"foo\", \"bar\"}, false, false},\n\t\t{\"foo\\nbar\\nbaz\\n\", 2, []string{\"foo\", \"bar\"}, false, false},\n\t\t{\"foo\\nbar\\033P\\033\\\\\", 2, []string{\"foo\", \"bar\"}, false, false},\n\t\t{\"foo\\nbar\\nbaz\", 3, []string{\"foo\", \"bar\", \"baz\"}, false, false},\n\t\t{\"foo\\nbar\\nbaz\\n\", 3, []string{\"foo\", \"bar\", \"baz\"}, false, false},\n\t\t{\"foo\\nbar\\033P\\033\\\\\", 3, []string{\"foo\", \"bar\", \"\\033P\\033\\\\\"}, false, true},\n\t}\n\n\tfor _, test := range tests {\n\t\tlines, binary, sixel := readLines(strings.NewReader(test.s), test.maxLines)\n\t\tif !reflect.DeepEqual(lines, test.lines) || binary != test.binary || sixel != test.sixel {\n\t\t\tt.Errorf(\n\t\t\t\t\"at input (%q, %v) expected (%#v, %v, %v) but got (%#v, %v, %v)\",\n\t\t\t\ttest.s, test.maxLines,\n\t\t\t\ttest.lines, test.binary, test.sixel,\n\t\t\t\tlines, binary, sixel,\n\t\t\t)\n\t\t}\n\t}\n}\n\nfunc TestGetWidths(t *testing.T) {\n\ttests := []struct {\n\t\twtot        int\n\t\tratios      []int\n\t\tdrawbox     bool\n\t\tborderstyle borderStyle\n\t\texp         []int\n\t}{\n\t\t{0, []int{1}, false, borderBox, []int{0}},\n\t\t{0, []int{1}, true, borderBox, []int{0}},\n\t\t{0, []int{1, 3, 2}, false, borderBox, []int{0, 0, 0}},\n\t\t{0, []int{1, 3, 2}, true, borderBox, []int{0, 0, 0}},\n\n\t\t{14, []int{1, 3, 2}, false, borderBox, []int{2, 6, 4}},\n\t\t{16, []int{1, 3, 2}, true, borderBox, []int{2, 6, 4}},\n\n\t\t{16, []int{1, 3, 2}, true, borderSeparators, []int{2, 7, 5}},\n\t\t{16, []int{1, 3, 2}, true, borderOutline, []int{2, 6, 4}},\n\t\t{16, []int{1, 3, 2}, true, borderRoundOutline, []int{2, 6, 4}},\n\t\t{16, []int{1, 3, 2}, true, borderRoundBox, []int{2, 6, 4}},\n\n\t\t{23, []int{1, 3, 2, 4}, false, borderBox, []int{2, 6, 4, 8}}, // windows end at 2.0, 8.0, 12.0, 20.0 respectively\n\t\t{24, []int{1, 3, 2, 4}, false, borderBox, []int{2, 6, 5, 8}}, // windows end at 2.1, 8.4, 12.6, 21.0 respectively\n\t\t{25, []int{1, 3, 2, 4}, false, borderBox, []int{2, 7, 4, 9}}, // windows end at 2.2, 8.8, 13.2, 22.0 respectively\n\t\t{26, []int{1, 3, 2, 4}, false, borderBox, []int{2, 7, 5, 9}}, // windows end at 2.3, 9.2, 13.8, 23.0 respectively\n\t}\n\n\tfor _, test := range tests {\n\t\twidths := getWidths(test.wtot, test.ratios, test.drawbox, test.borderstyle)\n\t\tif !reflect.DeepEqual(widths, test.exp) {\n\t\t\tt.Errorf(\"at input (%v, %v, %v, %v) expected %v but got %v\", test.wtot, test.ratios, test.drawbox, test.borderstyle, test.exp, widths)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "nav.go",
    "content": "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\t\"reflect\"\n\t\"regexp\"\n\t\"slices\"\n\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/djherbis/times\"\n)\n\n// A linkState describes whether a file is a symlink and whether its target exists.\ntype linkState byte\n\nconst (\n\tnotLink linkState = iota // Not a symbolic link.\n\tworking                  // Symbolic link with an existing target.\n\tbroken                   // Symbolic link with a missing target.\n)\n\ntype file struct {\n\tos.FileInfo           // stat information\n\tlinkState   linkState // symlink state\n\tlinkTarget  string    // path a symlink points to\n\tpath        string    // full path including the name\n\tdirCount    int       // number of items inside the directory\n\tdirSize     int64     // total directory size (needs to be calculated via `calcdirsize`)\n\taccessTime  time.Time // time of last access\n\tbirthTime   time.Time // time of file birth\n\tchangeTime  time.Time // time of last status (inode) change\n\tcustomInfo  string    // property defined via `addcustominfo`\n\text         string    // file extension (including the dot)\n\terr         error     // potential error returned by [os.Lstat]\n}\n\nfunc newFile(path string) *file {\n\tlstat, err := os.Lstat(path)\n\tif err != nil {\n\t\tlog.Printf(\"getting file information: %s\", err)\n\t\treturn &file{\n\t\t\tFileInfo:   &fakeStat{name: filepath.Base(path)},\n\t\t\tlinkState:  notLink,\n\t\t\tpath:       path,\n\t\t\tdirCount:   -1,\n\t\t\tdirSize:    -1,\n\t\t\taccessTime: time.Unix(0, 0),\n\t\t\tbirthTime:  time.Unix(0, 0),\n\t\t\tchangeTime: time.Unix(0, 0),\n\t\t\terr:        err,\n\t\t}\n\t}\n\n\tvar linkState linkState\n\tvar linkTarget string\n\n\tif lstat.Mode()&os.ModeSymlink != 0 {\n\t\tstat, err := os.Stat(path)\n\t\tif err == nil {\n\t\t\tlinkState = working\n\t\t\tlstat = stat\n\t\t} else {\n\t\t\tlinkState = broken\n\t\t}\n\t\tlinkTarget, err = os.Readlink(path)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"reading link target: %s\", err)\n\t\t}\n\t}\n\n\tts := times.Get(lstat)\n\tat := ts.AccessTime()\n\t// from [times.Timespec] docs:\n\t// ChangeTime() panics unless HasChangeTime() is true and\n\t// BirthTime() panics unless HasBirthTime() is true.\n\n\t// default to ModTime if BirthTime cannot be determined\n\tbt := lstat.ModTime()\n\tif ts.HasBirthTime() {\n\t\tbt = ts.BirthTime()\n\t}\n\t// default to ModTime if ChangeTime cannot be determined\n\tct := lstat.ModTime()\n\tif ts.HasChangeTime() {\n\t\tct = ts.ChangeTime()\n\t}\n\n\tdirCount := -1\n\tif lstat.IsDir() && getDirCounts(filepath.Dir(path)) {\n\t\td, err := os.Open(path)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"opening file: %s\", err)\n\t\t} else {\n\t\t\tnames, err := d.Readdirnames(10000)\n\t\t\td.Close()\n\n\t\t\tif names == nil && err != io.EOF {\n\t\t\t\tlog.Printf(\"reading directory: %s\", err)\n\t\t\t} else {\n\t\t\t\tdirCount = len(names)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn &file{\n\t\tFileInfo:   lstat,\n\t\tlinkState:  linkState,\n\t\tlinkTarget: linkTarget,\n\t\tpath:       path,\n\t\tdirCount:   dirCount,\n\t\tdirSize:    -1,\n\t\taccessTime: at,\n\t\tbirthTime:  bt,\n\t\tchangeTime: ct,\n\t\text:        getFileExtension(lstat),\n\t}\n}\n\nfunc (file *file) isPreviewable() bool {\n\treturn !file.IsDir() || gOpts.dirpreviews\n}\n\ntype fakeStat struct {\n\tname string\n}\n\nfunc (fs *fakeStat) Name() string       { return fs.name }\nfunc (fs *fakeStat) Size() int64        { return 0 }\nfunc (fs *fakeStat) Mode() os.FileMode  { return os.FileMode(0o000) }\nfunc (fs *fakeStat) ModTime() time.Time { return time.Unix(0, 0) }\nfunc (fs *fakeStat) IsDir() bool        { return false }\nfunc (fs *fakeStat) Sys() any           { return nil }\n\nfunc readdir(path string) ([]*file, error) {\n\tf, err := os.Open(path)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tnames, err := f.Readdirnames(-1)\n\tf.Close()\n\n\tfiles := make([]*file, 0, len(names))\n\tfor _, fname := range names {\n\t\tfile := newFile(filepath.Join(path, fname))\n\t\tif !os.IsNotExist(file.err) {\n\t\t\tfiles = append(files, file)\n\t\t}\n\t}\n\n\treturn files, err\n}\n\ntype dir struct {\n\tloading      bool       // whether directory is loading from disk\n\tloadTime     time.Time  // last load time\n\tind          int        // 0-based index of current entry in dir.files\n\tpos          int        // 0-based cursor row in directory window\n\tpath         string     // full path of directory\n\tfiles        []*file    // displayed files in directory including or excluding hidden ones\n\tallFiles     []*file    // all files in directory including hidden ones (same array as files)\n\tsortby       sortMethod // sortby value from last sort\n\tdircounts    bool       // dircounts value from last sort\n\tdirfirst     bool       // dirfirst value from last sort\n\tdironly      bool       // dironly value from last sort\n\thidden       bool       // hidden value from last sort\n\treverse      bool       // reverse value from last sort\n\tvisualAnchor int        // index where Visual mode was initiated\n\tvisualWrap   int        // wrap direction in Visual mode (0: none, +: bottom->top, -: top->bottom)\n\thiddenfiles  []string   // hiddenfiles value from last sort\n\tfilter       []string   // last filter for this directory\n\tignorecase   bool       // ignorecase value from last sort\n\tignoredia    bool       // ignoredia value from last sort\n\tnoPerm       bool       // whether lf has no permission to open the directory\n}\n\nfunc newDir(path string) *dir {\n\tfiles, err := readdir(path)\n\tif err != nil {\n\t\tlog.Printf(\"reading directory: %s\", err)\n\t}\n\n\treturn &dir{\n\t\tloadTime:     time.Now(),\n\t\tpath:         path,\n\t\tfiles:        files,\n\t\tallFiles:     files,\n\t\tvisualAnchor: -1,\n\t\tnoPerm:       os.IsPermission(err),\n\t}\n}\n\nfunc (dir *dir) sort() {\n\tdir.sortby = getSortBy(dir.path)\n\tdir.dircounts = getDirCounts(dir.path)\n\tdir.dirfirst = getDirFirst(dir.path)\n\tdir.dironly = getDirOnly(dir.path)\n\tdir.hidden = getHidden(dir.path)\n\tdir.reverse = getReverse(dir.path)\n\tdir.hiddenfiles = gOpts.hiddenfiles\n\tdir.ignorecase = gOpts.ignorecase\n\tdir.ignoredia = gOpts.ignoredia\n\n\tdir.files = dir.allFiles\n\n\t// When applying a filter, move all files not satisfying the predicate to\n\t// the beginning, then take the subslice starting from the first file that\n\t// does satisfy the predicate\n\tapplyFilter := func(fn func(f *file) bool) {\n\t\tslices.SortStableFunc(dir.files, func(i, j *file) int {\n\t\t\tswitch {\n\t\t\tcase !fn(i) && fn(j):\n\t\t\t\treturn -1\n\t\t\tcase fn(i) && !fn(j):\n\t\t\t\treturn 1\n\t\t\tdefault:\n\t\t\t\treturn 0\n\t\t\t}\n\t\t})\n\n\t\ti := slices.IndexFunc(dir.files, fn)\n\t\tif i == -1 {\n\t\t\ti = len(dir.files)\n\t\t}\n\t\tdir.files = dir.files[i:]\n\t}\n\n\tif dir.dironly {\n\t\tapplyFilter(func(f *file) bool { return f.IsDir() })\n\t}\n\n\tif !dir.hidden {\n\t\tapplyFilter(func(f *file) bool { return !isHidden(f, dir.path, dir.hiddenfiles) })\n\t}\n\n\tif len(dir.filter) != 0 {\n\t\tapplyFilter(func(f *file) bool { return !isFiltered(f, dir.filter) })\n\t}\n\n\tapplySort := func(fn func(f1, f2 *file) int) {\n\t\tif !dir.reverse {\n\t\t\tslices.SortStableFunc(dir.files, fn)\n\t\t} else {\n\t\t\tslices.SortStableFunc(dir.files, func(f1, f2 *file) int { return fn(f2, f1) })\n\t\t}\n\t}\n\n\tnormalize := func(s string) string {\n\t\tif dir.ignorecase {\n\t\t\ts = strings.ToLower(s)\n\t\t}\n\t\tif dir.ignoredia {\n\t\t\ts = removeDiacritics(s)\n\t\t}\n\t\treturn s\n\t}\n\n\tswitch dir.sortby {\n\tcase naturalSort:\n\t\tapplySort(func(f1, f2 *file) int {\n\t\t\treturn naturalCmp(normalize(f1.Name()), normalize(f2.Name()))\n\t\t})\n\tcase nameSort:\n\t\tapplySort(func(f1, f2 *file) int {\n\t\t\treturn cmp.Compare(normalize(f1.Name()), normalize(f2.Name()))\n\t\t})\n\tcase sizeSort:\n\t\tsizeVal := func(f *file) int64 {\n\t\t\tif f.IsDir() && dir.dircounts {\n\t\t\t\treturn int64(f.dirCount)\n\t\t\t}\n\t\t\tif f.dirSize >= 0 {\n\t\t\t\treturn f.dirSize\n\t\t\t}\n\t\t\treturn f.Size()\n\t\t}\n\t\tapplySort(func(f1, f2 *file) int {\n\t\t\treturn cmp.Compare(sizeVal(f1), sizeVal(f2))\n\t\t})\n\tcase timeSort:\n\t\tapplySort(func(f1, f2 *file) int {\n\t\t\treturn f1.ModTime().Compare(f2.ModTime())\n\t\t})\n\tcase atimeSort:\n\t\tapplySort(func(f1, f2 *file) int {\n\t\t\treturn f1.accessTime.Compare(f2.accessTime)\n\t\t})\n\tcase btimeSort:\n\t\tapplySort(func(f1, f2 *file) int {\n\t\t\treturn f1.birthTime.Compare(f2.birthTime)\n\t\t})\n\tcase ctimeSort:\n\t\tapplySort(func(f1, f2 *file) int {\n\t\t\treturn f1.changeTime.Compare(f2.changeTime)\n\t\t})\n\tcase extSort:\n\t\tapplySort(func(f1, f2 *file) int {\n\t\t\text1 := normalize(f1.ext)\n\t\t\text2 := normalize(f2.ext)\n\t\t\tif ext1 != ext2 {\n\t\t\t\treturn cmp.Compare(ext1, ext2)\n\t\t\t}\n\t\t\treturn cmp.Compare(normalize(f1.Name()), normalize(f2.Name()))\n\t\t})\n\tcase customSort:\n\t\tapplySort(func(f1, f2 *file) int {\n\t\t\ts1 := normalize(stripTermSequence(f1.customInfo))\n\t\t\ts2 := normalize(stripTermSequence(f2.customInfo))\n\t\t\treturn naturalCmp(s1, s2)\n\t\t})\n\t}\n\n\t// when sorting by size while also showing dircounts, we always display files\n\t// and directories separately to avoid mixing file sizes and file counts\n\tif dir.dirfirst || (dir.sortby == sizeSort && dir.dircounts) {\n\t\tslices.SortStableFunc(dir.files, func(f1, f2 *file) int {\n\t\t\tswitch {\n\t\t\tcase f1.IsDir() && !f2.IsDir():\n\t\t\t\treturn -1\n\t\t\tcase !f1.IsDir() && f2.IsDir():\n\t\t\t\treturn 1\n\t\t\tdefault:\n\t\t\t\treturn 0\n\t\t\t}\n\t\t})\n\t}\n\n\tdir.ind = max(dir.ind, 0)\n\tdir.ind = min(dir.ind, len(dir.files)-1)\n}\n\nfunc (dir *dir) name() string {\n\tif len(dir.files) == 0 {\n\t\treturn \"\"\n\t}\n\n\treturn dir.files[dir.ind].Name()\n}\n\nfunc (nav *nav) isVisualMode() bool {\n\treturn nav.currDir().visualAnchor != -1\n}\n\nfunc (dir *dir) visualSelections() []string {\n\tpaths := []string{}\n\tif dir.visualAnchor == -1 || len(dir.files) == 0 {\n\t\treturn paths\n\t}\n\n\tvar beg, end int\n\tswitch {\n\tcase dir.visualWrap == 0:\n\t\tbeg = min(dir.ind, dir.visualAnchor)\n\t\tend = max(dir.ind, dir.visualAnchor)\n\tcase dir.visualWrap < 0:\n\t\tbeg = dir.ind\n\t\tend = dir.visualAnchor - dir.visualWrap*len(dir.files)\n\tcase dir.visualWrap > 0:\n\t\tbeg = dir.visualAnchor\n\t\tend = dir.ind + dir.visualWrap*len(dir.files)\n\t}\n\n\tfor i := beg; i < min(end+1, beg+len(dir.files)); i++ {\n\t\tpaths = append(paths, dir.files[i%len(dir.files)].path)\n\t}\n\n\treturn paths\n}\n\nfunc (dir *dir) sel(name string, height int) {\n\tif len(dir.files) == 0 {\n\t\tdir.ind, dir.pos = 0, 0\n\t\treturn\n\t}\n\n\tdir.ind = max(dir.ind, 0)\n\tdir.ind = min(dir.ind, len(dir.files)-1)\n\n\tif dir.files[dir.ind].Name() != name {\n\t\tfor i, f := range dir.files {\n\t\t\tif f.Name() == name {\n\t\t\t\tdir.ind = i\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tdir.boundPos(height)\n}\n\nfunc (dir *dir) boundPos(height int) {\n\tif len(dir.files) <= height {\n\t\tdir.pos = dir.ind\n\t\treturn\n\t}\n\n\tedge := min(height/2, gOpts.scrolloff)\n\tdir.pos = max(dir.pos, edge)\n\n\t// use a smaller value for half when the height is even and scrolloff is\n\t// maxed in order to stay at the same row while scrolling up and down\n\tif height%2 == 0 {\n\t\tedge = min(height/2-1, gOpts.scrolloff)\n\t}\n\tdir.pos = min(dir.pos, height-1-edge)\n\n\tdir.pos = min(dir.pos, dir.ind)\n\tdir.pos = max(dir.pos, height-(len(dir.files)-dir.ind))\n}\n\n// clipboardMode controls the clipboard's behavior when pasting.\ntype clipboardMode byte\n\nconst (\n\tclipboardCopy clipboardMode = iota // Copy on paste.\n\tclipboardCut                       // Move on paste.\n)\n\ntype clipboard struct {\n\tpaths []string\n\tmode  clipboardMode\n}\n\ntype nav struct {\n\tdirPaths        []string\n\tcopyJobs        int\n\tcopyBytes       int64\n\tcopyTotal       int64\n\tcopyUpdate      int\n\tmoveCount       int\n\tmoveTotal       int\n\tmoveUpdate      int\n\tdeleteCount     int\n\tdeleteTotal     int\n\tdeleteUpdate    int\n\tcopyJobsChan    chan int\n\tcopyBytesChan   chan int64\n\tcopyTotalChan   chan int64\n\tmoveCountChan   chan int\n\tmoveTotalChan   chan int\n\tdeleteCountChan chan int\n\tdeleteTotalChan chan int\n\tpreloadChan     chan string\n\tpreviewChan     chan string\n\tdirChan         chan *dir\n\tregChan         chan *reg\n\tfileChan        chan *file\n\tdelChan         chan string\n\tdirCache        map[string]*dir\n\tregCache        map[string]*reg\n\tclipboard       clipboard\n\tmarks           map[string]string\n\trenameOldPath   string\n\trenameNewPath   string\n\tselections      map[string]int\n\ttags            map[string]string\n\tselectionInd    int\n\theight          int\n\tpreviewWidth    int\n\tfind            string\n\tfindBack        bool\n\tsearch          string\n\tsearchBack      bool\n\tsearchInd       int\n\tsearchPos       int\n\tprevFilter      []string\n\tvolatilePreview bool\n\tpreviewTimer    *time.Timer\n\tpreloadTimer    *time.Timer\n\tjumpList        []string\n\tjumpListInd     int\n}\n\nfunc (nav *nav) getDir(path string) *dir {\n\tif d, ok := nav.dirCache[path]; ok {\n\t\treturn d\n\t}\n\n\tgo func() {\n\t\tnav.dirChan <- newDir(path)\n\t}()\n\n\td := &dir{\n\t\tloading:      true,\n\t\tloadTime:     time.Now(),\n\t\tpath:         path,\n\t\tsortby:       getSortBy(path),\n\t\tdircounts:    getDirCounts(path),\n\t\tdirfirst:     getDirFirst(path),\n\t\tdironly:      getDirOnly(path),\n\t\thidden:       getHidden(path),\n\t\treverse:      getReverse(path),\n\t\tvisualAnchor: -1,\n\t\thiddenfiles:  gOpts.hiddenfiles,\n\t\tignorecase:   gOpts.ignorecase,\n\t\tignoredia:    gOpts.ignoredia,\n\t}\n\tnav.dirCache[path] = d\n\treturn d\n}\n\nfunc (nav *nav) checkDir(dir *dir) {\n\tif dir.loading {\n\t\treturn\n\t}\n\n\ts, err := os.Stat(dir.path)\n\tif err != nil {\n\t\tlog.Printf(\"getting directory info: %s\", err)\n\t\treturn\n\t}\n\n\tswitch {\n\tcase s.ModTime().After(dir.loadTime):\n\t\t// XXX: Linux builtin exFAT drivers are able to predict modifications in the future\n\t\t// https://bugs.launchpad.net/ubuntu/+source/ubuntu-meta/+bug/1872504\n\t\tif s.ModTime().After(time.Now()) {\n\t\t\treturn\n\t\t}\n\n\t\tdir.loading = true\n\t\tgo func() {\n\t\t\tnav.dirChan <- newDir(dir.path)\n\t\t}()\n\tcase dir.dircounts != getDirCounts(dir.path):\n\t\tdir.loading = true\n\t\tgo func() {\n\t\t\tnav.dirChan <- newDir(dir.path)\n\t\t}()\n\t// Although toggling dircounts can affect sorting, it is already handled by\n\t// reloading the directory which should sort the files anyway, so it is not\n\t// checked below.\n\tcase dir.sortby != getSortBy(dir.path) ||\n\t\tdir.dirfirst != getDirFirst(dir.path) ||\n\t\tdir.dironly != getDirOnly(dir.path) ||\n\t\tdir.hidden != getHidden(dir.path) ||\n\t\tdir.reverse != getReverse(dir.path) ||\n\t\t!reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) ||\n\t\tdir.ignorecase != gOpts.ignorecase ||\n\t\tdir.ignoredia != gOpts.ignoredia:\n\t\tdir.loading = true\n\t\tsd := *dir\n\t\tgo func() {\n\t\t\tsd.sort()\n\t\t\tsd.loading = false\n\t\t\tnav.dirChan <- &sd\n\t\t}()\n\t}\n}\n\nfunc (nav *nav) loadDirs(wd string) {\n\tvar dirPaths []string\n\n\tfor curr, base := wd, \"\"; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {\n\t\tdirPaths = append(dirPaths, curr)\n\n\t\tdir := nav.getDir(curr)\n\t\tif base != \"\" {\n\t\t\tdir.sel(base, nav.height)\n\t\t}\n\t}\n\n\tslices.Reverse(dirPaths)\n\tnav.dirPaths = dirPaths\n}\n\nfunc newNav(ui *ui) *nav {\n\tnav := &nav{\n\t\tcopyJobsChan:    make(chan int, 1024),\n\t\tcopyBytesChan:   make(chan int64, 1024),\n\t\tcopyTotalChan:   make(chan int64, 1024),\n\t\tmoveCountChan:   make(chan int, 1024),\n\t\tmoveTotalChan:   make(chan int, 1024),\n\t\tdeleteCountChan: make(chan int, 1024),\n\t\tdeleteTotalChan: make(chan int, 1024),\n\t\tpreloadChan:     make(chan string, 1024),\n\t\tpreviewChan:     make(chan string, 1024),\n\t\tdirChan:         make(chan *dir),\n\t\tregChan:         make(chan *reg),\n\t\tfileChan:        make(chan *file),\n\t\tdelChan:         make(chan string),\n\t\tdirCache:        make(map[string]*dir),\n\t\tregCache:        make(map[string]*reg),\n\t\tmarks:           make(map[string]string),\n\t\tselections:      make(map[string]int),\n\t\ttags:            make(map[string]string),\n\t\tselectionInd:    0,\n\t\tpreviewTimer:    time.NewTimer(0),\n\t\tpreloadTimer:    time.NewTimer(0),\n\t\tjumpList:        make([]string, 0),\n\t\tjumpListInd:     -1,\n\t}\n\n\tnav.resize(ui)\n\treturn nav\n}\n\nfunc (nav *nav) addJumpList() {\n\tcurrPath := nav.currDir().path\n\tif nav.jumpListInd >= 0 && nav.jumpListInd < len(nav.jumpList)-1 {\n\t\tif nav.jumpList[nav.jumpListInd] == currPath {\n\t\t\t// walking the jumpList\n\t\t\treturn\n\t\t}\n\t\tnav.jumpList = nav.jumpList[:nav.jumpListInd+1]\n\t}\n\tif len(nav.jumpList) == 0 || nav.jumpList[len(nav.jumpList)-1] != currPath {\n\t\tnav.jumpList = append(nav.jumpList, currPath)\n\t}\n\tnav.jumpListInd = len(nav.jumpList) - 1\n}\n\nfunc (nav *nav) cdJumpListPrev() {\n\tif nav.jumpListInd > 0 {\n\t\tnav.jumpListInd--\n\t\tif err := nav.cd(nav.jumpList[nav.jumpListInd]); err != nil {\n\t\t\tlog.Print(err)\n\t\t}\n\t}\n}\n\nfunc (nav *nav) cdJumpListNext() {\n\tif nav.jumpListInd < len(nav.jumpList)-1 {\n\t\tnav.jumpListInd++\n\t\tif err := nav.cd(nav.jumpList[nav.jumpListInd]); err != nil {\n\t\t\tlog.Print(err)\n\t\t}\n\t}\n}\n\nfunc (nav *nav) renew() {\n\tfor _, path := range nav.dirPaths {\n\t\tdir := nav.getDir(path)\n\t\tnav.checkDir(dir)\n\t}\n\n\tfor m := range nav.selections {\n\t\tif _, err := os.Lstat(m); os.IsNotExist(err) {\n\t\t\tdelete(nav.selections, m)\n\t\t}\n\t}\n\n\tif len(nav.selections) == 0 {\n\t\tnav.selectionInd = 0\n\t}\n}\n\nfunc (nav *nav) reload() {\n\twd := nav.currDir().path\n\tcurr := nav.currFile()\n\n\tclear(nav.dirCache)\n\tclear(nav.regCache)\n\n\tnav.loadDirs(wd)\n\n\tif curr != nil {\n\t\tdir := nav.currDir()\n\t\tdir.files = append(dir.files, curr)\n\t}\n}\n\nfunc (nav *nav) resize(ui *ui) {\n\tpreviewWin := ui.wins[len(ui.wins)-1]\n\tif previewWin.h == nav.height && previewWin.w == nav.previewWidth {\n\t\treturn\n\t}\n\n\tnav.height = previewWin.h\n\tnav.previewWidth = previewWin.w\n\n\tfor _, path := range nav.dirPaths {\n\t\tnav.getDir(path).boundPos(nav.height)\n\t}\n\n\tclear(nav.regCache)\n\tnav.preloadTimer.Reset(200 * time.Millisecond)\n}\n\nfunc (nav *nav) position() {\n\tvar path string\n\tvar base string\n\n\tfor i := len(nav.dirPaths) - 1; i >= 0; i-- {\n\t\tpath = nav.dirPaths[i]\n\t\tif i < len(nav.dirPaths)-1 {\n\t\t\tnav.getDir(path).sel(base, nav.height)\n\t\t}\n\n\t\tbase = filepath.Base(path)\n\t}\n}\n\nfunc (nav *nav) exportFiles() {\n\tvar currFile string\n\tif curr := nav.currFile(); curr != nil {\n\t\tcurrFile = quoteString(curr.path)\n\t}\n\n\tvar selections []string\n\tfor _, selection := range nav.currSelections() {\n\t\tselections = append(selections, quoteString(selection))\n\t}\n\tcurrSelections := strings.Join(selections, gOpts.filesep)\n\n\tvar vSelections []string\n\tfor _, selection := range nav.currDir().visualSelections() {\n\t\tvSelections = append(vSelections, quoteString(selection))\n\t}\n\tcurrVSelections := strings.Join(vSelections, gOpts.filesep)\n\n\tos.Setenv(\"f\", currFile)\n\tos.Setenv(\"fs\", currSelections)\n\tos.Setenv(\"fv\", currVSelections)\n\tos.Setenv(\"PWD\", quoteString(nav.currDir().path))\n\n\tif len(selections) == 0 {\n\t\tos.Setenv(\"fx\", currFile)\n\t} else {\n\t\tos.Setenv(\"fx\", currSelections)\n\t}\n}\n\nfunc (nav *nav) preloadLoop(ui *ui) {\n\tstack := []string{}\n\n\tpush := func(path string) {\n\t\tstack = slices.DeleteFunc(stack, func(s string) bool { return s == path })\n\t\tstack = append(stack, path)\n\t}\n\n\tpop := func() string {\n\t\tpath := stack[len(stack)-1]\n\t\tstack = stack[:len(stack)-1]\n\t\treturn path\n\t}\n\n\tfor {\n\t\tif len(stack) == 0 {\n\t\t\tpush(<-nav.preloadChan)\n\t\t} else {\n\t\t\tselect {\n\t\t\tcase path := <-nav.preloadChan:\n\t\t\t\tpush(path)\n\t\t\tdefault:\n\t\t\t\tpath := pop()\n\t\t\t\tnav.preview(path, ui.wins[len(ui.wins)-1], \"preload\")\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc (nav *nav) previewLoop(ui *ui) {\n\tvar prev string\n\tfor path := range nav.previewChan {\n\t\tisClear := len(path) == 0\n\tloop:\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase path = <-nav.previewChan:\n\t\t\t\tisClear = isClear || len(path) == 0\n\t\t\tdefault:\n\t\t\t\tbreak loop\n\t\t\t}\n\t\t}\n\t\twin := ui.wins[len(ui.wins)-1]\n\t\tif isClear && len(gOpts.previewer) != 0 && len(gOpts.cleaner) != 0 && nav.volatilePreview {\n\t\t\tcmd := exec.Command(\n\t\t\t\tgOpts.cleaner,\n\t\t\t\tprev,\n\t\t\t\tstrconv.Itoa(win.w),\n\t\t\t\tstrconv.Itoa(win.h),\n\t\t\t\tstrconv.Itoa(win.x),\n\t\t\t\tstrconv.Itoa(win.y),\n\t\t\t\tpath,\n\t\t\t)\n\t\t\tvar stderr bytes.Buffer\n\t\t\tcmd.Stderr = &stderr\n\n\t\t\tif err := cmd.Run(); err != nil {\n\t\t\t\tvar exitErr *exec.ExitError\n\t\t\t\tif !errors.As(err, &exitErr) {\n\t\t\t\t\tlog.Printf(\"cleaning preview: %s\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif s := strings.TrimSpace(stderr.String()); s != \"\" {\n\t\t\t\ts = strings.Join(strings.Fields(s), \" \")\n\t\t\t\tlog.Printf(\"cleaning preview (stderr): %s\", s)\n\t\t\t}\n\t\t\tnav.volatilePreview = false\n\t\t}\n\t\tif len(path) != 0 {\n\t\t\tnav.preview(path, win, \"preview\")\n\t\t\tprev = path\n\t\t}\n\t}\n}\n\nfunc matchPattern(pattern, name, path string) bool {\n\ts := name\n\n\tpattern = replaceTilde(pattern)\n\n\tif filepath.IsAbs(pattern) {\n\t\ts = filepath.Join(path, name)\n\t}\n\n\t// pattern errors are checked when 'hiddenfiles' option is set\n\tmatched, _ := filepath.Match(pattern, s)\n\n\treturn matched\n}\n\nfunc (nav *nav) preload() {\n\tif !gOpts.preview || !gOpts.preload {\n\t\treturn\n\t}\n\n\tdir := nav.currDir()\n\tdoPreload := func(i int) {\n\t\tif i < 0 || i >= len(dir.files) {\n\t\t\treturn\n\t\t}\n\n\t\tfile := dir.files[i]\n\t\tif !file.isPreviewable() {\n\t\t\treturn\n\t\t}\n\n\t\tif _, ok := nav.regCache[file.path]; ok {\n\t\t\treturn\n\t\t}\n\n\t\tnav.regCache[file.path] = &reg{loading: true, loadTime: time.Now(), path: file.path}\n\t\tselect {\n\t\tcase nav.preloadChan <- file.path:\n\t\tdefault:\n\t\t}\n\t}\n\n\tfor i := nav.height / 2; i >= 1; i-- {\n\t\tdoPreload(dir.ind - i)\n\t\tdoPreload(dir.ind + i)\n\t}\n\tdoPreload(dir.ind)\n}\n\nfunc (nav *nav) preview(path string, win *win, mode string) {\n\treg := &reg{loadTime: time.Now(), path: path}\n\tdefer func() {\n\t\tif (gOpts.preload && mode == \"preview\") || (!gOpts.preload && reg.volatile) {\n\t\t\tnav.volatilePreview = true\n\t\t}\n\n\t\tif gOpts.preload == (mode == \"preload\") {\n\t\t\tnav.regChan <- reg\n\t\t}\n\t}()\n\n\tvar reader *bufio.Reader\n\n\tif len(gOpts.previewer) != 0 {\n\t\tcmd := exec.Command(\n\t\t\tgOpts.previewer,\n\t\t\tpath,\n\t\t\tstrconv.Itoa(win.w),\n\t\t\tstrconv.Itoa(win.h),\n\t\t\tstrconv.Itoa(win.x),\n\t\t\tstrconv.Itoa(win.y),\n\t\t\tmode,\n\t\t)\n\t\tvar stderr bytes.Buffer\n\t\tcmd.Stderr = &stderr\n\n\t\tout, err := cmd.StdoutPipe()\n\t\tif err != nil {\n\t\t\tlog.Printf(\"previewing file: %s\", err)\n\t\t\treturn\n\t\t}\n\n\t\tif err := cmd.Start(); err != nil {\n\t\t\tlog.Printf(\"previewing file: %s\", err)\n\t\t\tout.Close()\n\t\t\treturn\n\t\t}\n\n\t\tdefer func() {\n\t\t\tif err := cmd.Wait(); err != nil {\n\t\t\t\tvar exitErr *exec.ExitError\n\t\t\t\tif errors.As(err, &exitErr) {\n\t\t\t\t\treg.volatile = true\n\t\t\t\t} else {\n\t\t\t\t\tlog.Printf(\"loading file: %s\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif s := strings.TrimSpace(stderr.String()); s != \"\" {\n\t\t\t\ts = strings.Join(strings.Fields(s), \" \")\n\t\t\t\tlog.Printf(\"loading file (stderr): %s\", s)\n\t\t\t}\n\t\t}()\n\t\tdefer out.Close()\n\t\treader = bufio.NewReader(out)\n\t} else {\n\t\tlstat, err := os.Lstat(path)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"lstat: %s\", err)\n\t\t\treturn\n\t\t}\n\n\t\tif !lstat.Mode().IsRegular() {\n\t\t\treturn\n\t\t}\n\n\t\tf, err := os.Open(path)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"opening file: %s\", err)\n\t\t\treturn\n\t\t}\n\n\t\tdefer f.Close()\n\t\treader = bufio.NewReader(f)\n\t}\n\n\tlines, binary, sixel := readLines(reader, win.h)\n\tif binary {\n\t\tlines = []string{\"\\033[7mbinary\\033[0m\"}\n\t}\n\treg.lines = lines\n\treg.sixel = sixel\n}\n\nfunc (nav *nav) loadReg(path string, volatile bool) *reg {\n\tr, ok := nav.regCache[path]\n\tif !ok || (!gOpts.preload && r.loading) {\n\t\tr = &reg{loading: true, loadTime: time.Now(), path: path}\n\t\tnav.regCache[path] = r\n\t\tif gOpts.preload {\n\t\t\tselect {\n\t\t\tcase nav.preloadChan <- path:\n\t\t\tdefault:\n\t\t\t}\n\t\t} else {\n\t\t\tnav.previewChan <- path\n\t\t}\n\t\treturn r\n\t}\n\n\tif volatile && r.volatile {\n\t\tif !gOpts.preload {\n\t\t\tr.loadTime = time.Now()\n\t\t\tr.loading = true\n\t\t}\n\t\tnav.previewChan <- path\n\t}\n\n\tnav.checkReg(r)\n\treturn r\n}\n\nfunc (nav *nav) checkReg(reg *reg) {\n\ts, err := os.Stat(reg.path)\n\tif err != nil {\n\t\treturn\n\t}\n\n\tnow := time.Now()\n\n\t// XXX: Linux builtin exFAT drivers are able to predict modifications in the future\n\t// https://bugs.launchpad.net/ubuntu/+source/ubuntu-meta/+bug/1872504\n\tif s.ModTime().After(now) {\n\t\treturn\n\t}\n\n\tif s.ModTime().After(reg.loadTime) {\n\t\treg.loadTime = now\n\t\tnav.previewChan <- reg.path\n\t}\n}\n\nfunc (nav *nav) sort() {\n\tfor _, path := range nav.dirPaths {\n\t\tdir := nav.getDir(path)\n\t\tname := dir.name()\n\t\tdir.sort()\n\t\tdir.sel(name, nav.height)\n\t}\n\n\tif curr := nav.currFile(); curr != nil && curr.IsDir() {\n\t\tdir := nav.getDir(curr.path)\n\t\tname := dir.name()\n\t\tdir.sort()\n\t\tdir.sel(name, nav.height)\n\t}\n}\n\nfunc (nav *nav) setFilter(filter []string) error {\n\tnewfilter := []string{}\n\tfor _, tok := range filter {\n\t\tif tok == \"\" {\n\t\t\tcontinue\n\t\t}\n\n\t\t// check if filter is valid by applying it to a dummy string\n\t\tif _, err := searchMatch(\"a\", strings.TrimPrefix(tok, \"!\"), gOpts.filtermethod); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tnewfilter = append(newfilter, tok)\n\t}\n\n\tdir := nav.currDir()\n\tdir.filter = newfilter\n\n\t// Apply filter, by sorting current dir (see nav.sort())\n\tname := dir.name()\n\tdir.sort()\n\tdir.sel(name, nav.height)\n\treturn nil\n}\n\nfunc (nav *nav) up(dist int) bool {\n\tdir := nav.currDir()\n\n\told := dir.ind\n\n\tif dir.ind == 0 {\n\t\tif gOpts.wrapscroll {\n\t\t\tnav.bottom()\n\t\t\tdir.visualWrap--\n\t\t}\n\t\treturn old != dir.ind\n\t}\n\n\tdir.ind -= dist\n\tdir.ind = max(0, dir.ind)\n\n\tdir.pos -= dist\n\tdir.boundPos(nav.height)\n\n\treturn old != dir.ind\n}\n\nfunc (nav *nav) down(dist int) bool {\n\tdir := nav.currDir()\n\n\told := dir.ind\n\n\tmaxind := len(dir.files) - 1\n\n\tif dir.ind >= maxind {\n\t\tif gOpts.wrapscroll {\n\t\t\tnav.top()\n\t\t\tdir.visualWrap++\n\t\t}\n\t\treturn old != dir.ind\n\t}\n\n\tdir.ind += dist\n\tdir.ind = min(maxind, dir.ind)\n\n\tdir.pos += dist\n\tdir.boundPos(nav.height)\n\n\treturn old != dir.ind\n}\n\nfunc (nav *nav) scrollUp(dist int) bool {\n\tdir := nav.currDir()\n\n\told := dir.ind\n\n\toldPos := dir.pos\n\tdir.pos += dist\n\tdir.boundPos(nav.height)\n\n\tdir.ind -= dist - (dir.pos - oldPos)\n\tdir.ind = max(dir.ind, dir.pos)\n\n\treturn old != dir.ind\n}\n\nfunc (nav *nav) scrollDown(dist int) bool {\n\tdir := nav.currDir()\n\n\told := dir.ind\n\n\toldPos := dir.pos\n\tdir.pos -= dist\n\tdir.boundPos(nav.height)\n\n\tdir.ind += dist - (oldPos - dir.pos)\n\tdir.ind = min(dir.ind, dir.pos+max(len(dir.files)-nav.height, 0))\n\n\treturn old != dir.ind\n}\n\nfunc (nav *nav) updir() error {\n\tif len(nav.dirPaths) < 2 {\n\t\treturn nil\n\t}\n\n\tif err := os.Chdir(nav.dirPaths[len(nav.dirPaths)-2]); err != nil {\n\t\treturn fmt.Errorf(\"updir: %w\", err)\n\t}\n\n\tnav.dirPaths = nav.dirPaths[:len(nav.dirPaths)-1]\n\treturn nil\n}\n\nfunc (nav *nav) open() error {\n\tcurr := nav.currFile()\n\tif curr == nil {\n\t\treturn nil\n\t}\n\n\tif err := os.Chdir(curr.path); err != nil {\n\t\treturn fmt.Errorf(\"open: %w\", err)\n\t}\n\n\tnav.dirPaths = append(nav.dirPaths, curr.path)\n\treturn nil\n}\n\nfunc (nav *nav) top() bool {\n\tdir := nav.currDir()\n\n\told := dir.ind\n\n\tdir.ind = 0\n\tdir.pos = 0\n\n\treturn old != dir.ind\n}\n\nfunc (nav *nav) bottom() bool {\n\tdir := nav.currDir()\n\n\told := dir.ind\n\n\tdir.ind = max(len(dir.files)-1, 0)\n\tdir.pos = min(dir.ind, nav.height-1)\n\n\treturn old != dir.ind\n}\n\nfunc (nav *nav) high() bool {\n\tdir := nav.currDir()\n\n\told := dir.ind\n\tbeg := max(dir.ind-dir.pos, 0)\n\toffs := min(nav.height/2, gOpts.scrolloff)\n\tif beg == 0 {\n\t\toffs = 0\n\t}\n\n\tdir.ind = beg + offs\n\tdir.pos = offs\n\n\treturn old != dir.ind\n}\n\nfunc (nav *nav) middle() bool {\n\tdir := nav.currDir()\n\n\told := dir.ind\n\tbeg := max(dir.ind-dir.pos, 0)\n\tend := min(beg+nav.height, len(dir.files))\n\n\thalf := (end - beg) / 2\n\tdir.ind = beg + half\n\tdir.pos = half\n\n\treturn old != dir.ind\n}\n\nfunc (nav *nav) low() bool {\n\tdir := nav.currDir()\n\n\told := dir.ind\n\tbeg := max(dir.ind-dir.pos, 0)\n\tend := min(beg+nav.height, len(dir.files))\n\n\toffs := min(nav.height/2, gOpts.scrolloff)\n\t// use a smaller value for half when the height is even and scrolloff is\n\t// maxed in order to stay at the same row when using both high and low\n\tif nav.height%2 == 0 {\n\t\toffs = min(nav.height/2-1, gOpts.scrolloff)\n\t}\n\n\tif end == len(dir.files) {\n\t\toffs = 0\n\t}\n\n\tdir.ind = end - 1 - offs\n\tdir.pos = end - beg - 1 - offs\n\n\treturn old != dir.ind\n}\n\nfunc (nav *nav) move(index int) bool {\n\told := nav.currDir().ind\n\n\tswitch {\n\tcase index < old:\n\t\treturn nav.up(old - index)\n\tcase index > old:\n\t\treturn nav.down(index - old)\n\tdefault:\n\t\treturn false\n\t}\n}\n\nfunc (nav *nav) toggleSelection(path string) {\n\tif _, ok := nav.selections[path]; ok {\n\t\tdelete(nav.selections, path)\n\t\tif len(nav.selections) == 0 {\n\t\t\tnav.selectionInd = 0\n\t\t}\n\t} else {\n\t\tnav.selections[path] = nav.selectionInd\n\t\tnav.selectionInd++\n\t}\n}\n\nfunc (nav *nav) toggle() {\n\tif curr := nav.currFile(); curr != nil {\n\t\tnav.toggleSelection(curr.path)\n\t}\n}\n\nfunc (nav *nav) tagToggleSelection(path, tag string) {\n\tif _, ok := nav.tags[path]; ok {\n\t\tdelete(nav.tags, path)\n\t} else {\n\t\tnav.tags[path] = tag\n\t}\n}\n\nfunc (nav *nav) tagToggle(tag string) error {\n\tlist, err := nav.currFileOrSelections()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif printLength(tag) != 1 {\n\t\treturn errors.New(\"tag should be single width character\")\n\t}\n\n\tfor _, path := range list {\n\t\tnav.tagToggleSelection(path, tag)\n\t}\n\n\treturn nil\n}\n\nfunc (nav *nav) tag(tag string) error {\n\tlist, err := nav.currFileOrSelections()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif printLength(tag) != 1 {\n\t\treturn errors.New(\"tag should be single width character\")\n\t}\n\n\tfor _, path := range list {\n\t\tnav.tags[path] = tag\n\t}\n\n\treturn nil\n}\n\nfunc (nav *nav) invert() {\n\tfor _, file := range nav.currDir().files {\n\t\tnav.toggleSelection(file.path)\n\t}\n}\n\nfunc (nav *nav) unselect() {\n\tclear(nav.selections)\n\tnav.selectionInd = 0\n}\n\nfunc (nav *nav) save(mode clipboardMode) error {\n\tlist, err := nav.currFileOrSelections()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tclipboard := clipboard{list, mode}\n\tif err := saveFiles(clipboard); err != nil {\n\t\treturn err\n\t}\n\n\tnav.clipboard = clipboard\n\treturn nil\n}\n\nfunc (nav *nav) copyAsync(app *app, srcs []string, dstDir string) {\n\terrCount := 0\n\tsendErr := func(format string, a ...any) {\n\t\terrCount++\n\t\tmsg := fmt.Sprintf(\"copy [%d]: %s\", errCount, fmt.Sprintf(format, a...))\n\t\tapp.ui.exprChan <- &callExpr{\"echoerr\", []string{msg}, 1}\n\t}\n\n\t_, err := os.Stat(dstDir)\n\tif os.IsNotExist(err) {\n\t\tsendErr(\"%v\", err)\n\t\treturn\n\t}\n\n\t// Indicate that a copy operation is in progress. Using the total bytes to\n\t// determine this instead will mean that it is possible for copySize to take\n\t// a while, but not be reflected in the UI until it has finished.\n\tnav.copyJobsChan <- 1\n\n\ttotal, err := copySize(srcs)\n\tif err != nil {\n\t\tsendErr(\"%v\", err)\n\t\tnav.copyJobsChan <- -1\n\t\treturn\n\t}\n\n\tnav.copyTotalChan <- total\n\n\tnums, errs := copyAll(srcs, dstDir, gOpts.preserve)\n\nloop:\n\tfor {\n\t\tselect {\n\t\tcase n := <-nums:\n\t\t\tnav.copyBytesChan <- n\n\t\tcase err, ok := <-errs:\n\t\t\tif !ok {\n\t\t\t\tbreak loop\n\t\t\t}\n\t\t\tsendErr(\"%v\", err)\n\t\t}\n\t}\n\n\tnav.copyJobsChan <- -1\n\tnav.copyTotalChan <- -total\n\n\tif gSingleMode {\n\t\tnav.renew()\n\t\tapp.ui.loadFile(app, true)\n\t} else {\n\t\tif _, err := remote(\"send load\"); err != nil {\n\t\t\tsendErr(\"%v\", err)\n\t\t}\n\t}\n\n\tif errCount == 0 {\n\t\tapp.ui.exprChan <- &callExpr{\"echo\", []string{\"\\033[0;32mCopied successfully\\033[0m\"}, 1}\n\t}\n}\n\nfunc (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {\n\terrCount := 0\n\tsendErr := func(format string, a ...any) {\n\t\terrCount++\n\t\tmsg := fmt.Sprintf(\"move [%d]: %s\", errCount, fmt.Sprintf(format, a...))\n\t\tapp.ui.exprChan <- &callExpr{\"echoerr\", []string{msg}, 1}\n\t}\n\n\t_, err := os.Stat(dstDir)\n\tif os.IsNotExist(err) {\n\t\tsendErr(\"%v\", err)\n\t\treturn\n\t}\n\n\tnav.moveTotalChan <- len(srcs)\n\n\tfor _, src := range srcs {\n\t\tnav.moveCountChan <- 1\n\n\t\tsrcStat, err := os.Lstat(src)\n\t\tif err != nil {\n\t\t\tsendErr(\"%v\", err)\n\t\t\tcontinue\n\t\t}\n\n\t\tfile := filepath.Base(src)\n\t\tdst := filepath.Join(dstDir, file)\n\n\t\tif dstStat, err := os.Stat(dst); err == nil {\n\t\t\tif os.SameFile(srcStat, dstStat) {\n\t\t\t\tsendErr(\"rename %s %s: source and destination are the same file\", src, dst)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\text := getFileExtension(dstStat)\n\t\t\tbasename := file[:len(file)-len(ext)]\n\t\t\tvar newPath string\n\t\t\tfor i := 1; !os.IsNotExist(err); i++ {\n\t\t\t\tfile = strings.ReplaceAll(gOpts.dupfilefmt, \"%f\", basename+ext)\n\t\t\t\tfile = strings.ReplaceAll(file, \"%b\", basename)\n\t\t\t\tfile = strings.ReplaceAll(file, \"%e\", ext)\n\t\t\t\tfile = strings.ReplaceAll(file, \"%n\", strconv.Itoa(i))\n\t\t\t\tnewPath = filepath.Join(dstDir, file)\n\t\t\t\t_, err = os.Lstat(newPath)\n\t\t\t}\n\t\t\tdst = newPath\n\t\t}\n\n\t\tif err := os.Rename(src, dst); err != nil {\n\t\t\tif errCrossDevice(err) {\n\t\t\t\tnav.copyJobsChan <- 1\n\n\t\t\t\ttotal, err := copySize([]string{src})\n\t\t\t\tif err != nil {\n\t\t\t\t\tsendErr(\"%v\", err)\n\t\t\t\t\tnav.copyJobsChan <- -1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tnav.copyTotalChan <- total\n\n\t\t\t\tnums, errs := copyAll([]string{src}, dstDir, []string{\"mode\", \"timestamps\"})\n\n\t\t\t\toldCount := errCount\n\t\t\tloop:\n\t\t\t\tfor {\n\t\t\t\t\tselect {\n\t\t\t\t\tcase n := <-nums:\n\t\t\t\t\t\tnav.copyBytesChan <- n\n\t\t\t\t\tcase err, ok := <-errs:\n\t\t\t\t\t\tif !ok {\n\t\t\t\t\t\t\tbreak loop\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsendErr(\"%v\", err)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tnav.copyJobsChan <- -1\n\t\t\t\tnav.copyTotalChan <- -total\n\n\t\t\t\tif errCount == oldCount {\n\t\t\t\t\tif err := os.RemoveAll(src); err != nil {\n\t\t\t\t\t\tsendErr(\"%v\", err)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tsendErr(\"%v\", err)\n\t\t\t}\n\t\t}\n\t}\n\n\tnav.moveTotalChan <- -len(srcs)\n\n\tif gSingleMode {\n\t\tnav.renew()\n\t\tapp.ui.loadFile(app, true)\n\t} else {\n\t\tif _, err := remote(\"send load\"); err != nil {\n\t\t\tsendErr(\"%v\", err)\n\t\t}\n\t}\n\n\tif errCount == 0 {\n\t\tapp.ui.exprChan <- &callExpr{\"clear\", nil, 1}\n\t\tapp.ui.exprChan <- &callExpr{\"echo\", []string{\"\\033[0;32mMoved successfully\\033[0m\"}, 1}\n\t}\n}\n\nfunc (nav *nav) paste(app *app) error {\n\tclipboard, err := loadFiles()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif len(clipboard.paths) == 0 {\n\t\treturn errors.New(\"no files in clipboard\")\n\t}\n\n\tdstDir := nav.currDir().path\n\n\tif clipboard.mode == clipboardCopy {\n\t\tgo nav.copyAsync(app, clipboard.paths, dstDir)\n\t} else {\n\t\tgo nav.moveAsync(app, clipboard.paths, dstDir)\n\t}\n\n\treturn nil\n}\n\nfunc (nav *nav) del(app *app) error {\n\tlist, err := nav.currFileOrSelections()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tgo func() {\n\t\techo := &callExpr{\"echoerr\", []string{\"\"}, 1}\n\t\terrCount := 0\n\n\t\tnav.deleteTotalChan <- len(list)\n\n\t\tfor _, path := range list {\n\t\t\tnav.deleteCountChan <- 1\n\n\t\t\tif err := os.RemoveAll(path); err != nil {\n\t\t\t\terrCount++\n\t\t\t\techo.args[0] = fmt.Sprintf(\"[%d] %s\", errCount, err)\n\t\t\t\tapp.ui.exprChan <- echo\n\t\t\t}\n\t\t}\n\n\t\tnav.deleteTotalChan <- -len(list)\n\n\t\tif gSingleMode {\n\t\t\tnav.renew()\n\t\t\tapp.ui.loadFile(app, true)\n\t\t} else {\n\t\t\tif _, err := remote(\"send load\"); err != nil {\n\t\t\t\terrCount++\n\t\t\t\techo.args[0] = fmt.Sprintf(\"[%d] %s\", errCount, err)\n\t\t\t\tapp.ui.exprChan <- echo\n\t\t\t}\n\t\t}\n\t}()\n\n\treturn nil\n}\n\nfunc (nav *nav) rename() error {\n\toldPath := nav.renameOldPath\n\tnewPath := nav.renameNewPath\n\n\tif err := os.Rename(oldPath, newPath); err != nil {\n\t\treturn err\n\t}\n\n\tlstat, err := os.Lstat(newPath)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// It is possible for newPath to already have cache entries if it previously\n\t// existed and was deleted. In this case the cache entries should be deleted\n\t// before loading newPath to prevent displaying a stale preview. However,\n\t// this clears only the current instance of lf, and not any other instances.\n\tdeletePathRecursive(nav.regCache, newPath)\n\tdeletePathRecursive(nav.dirCache, newPath)\n\tdir := nav.getDir(filepath.Dir(newPath))\n\tnav.checkDir(dir)\n\n\tif dir.loading {\n\t\tfor i := range dir.allFiles {\n\t\t\tif dir.allFiles[i].path == oldPath {\n\t\t\t\tdir.allFiles[i] = &file{FileInfo: lstat}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tdir.sort()\n\t}\n\n\tdir.sel(lstat.Name(), nav.height)\n\n\treturn nil\n}\n\nfunc (nav *nav) sync() error {\n\tclipboard, err := loadFiles()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tnav.clipboard = clipboard\n\n\ttempmarks := make(map[string]string)\n\tfor _, ch := range gOpts.tempmarks {\n\t\tk := string(ch)\n\t\tif v, ok := nav.marks[k]; ok {\n\t\t\ttempmarks[k] = v\n\t\t}\n\t}\n\terrMarks := nav.readMarks()\n\tmaps.Copy(nav.marks, tempmarks)\n\n\terr = nav.readTags()\n\n\tif errMarks != nil {\n\t\treturn errMarks\n\t}\n\treturn err\n}\n\nfunc (nav *nav) cd(path string) error {\n\tif err := os.Chdir(path); err != nil {\n\t\treturn err\n\t}\n\n\tnav.loadDirs(path)\n\tnav.addJumpList()\n\treturn nil\n}\n\nfunc (nav *nav) globSel(pattern string, invert bool) error {\n\tdir := nav.currDir()\n\tanyMatched := false\n\n\tfor i := range dir.files {\n\t\tmatched, err := filepath.Match(pattern, dir.files[i].Name())\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"glob-select: %w\", err)\n\t\t}\n\t\tif matched {\n\t\t\tanyMatched = true\n\t\t\tfpath := filepath.Join(dir.path, dir.files[i].Name())\n\t\t\tif _, ok := nav.selections[fpath]; ok == invert {\n\t\t\t\tnav.toggleSelection(fpath)\n\t\t\t}\n\t\t}\n\t}\n\n\tif !anyMatched {\n\t\treturn fmt.Errorf(\"glob-select: pattern not found: %s\", pattern)\n\t}\n\n\treturn nil\n}\n\nfunc findMatch(name, pattern string) bool {\n\tif gOpts.ignorecase {\n\t\tlpattern := strings.ToLower(pattern)\n\t\tif !gOpts.smartcase || lpattern == pattern {\n\t\t\tpattern = lpattern\n\t\t\tname = strings.ToLower(name)\n\t\t}\n\t}\n\tif gOpts.ignoredia {\n\t\tlpattern := removeDiacritics(pattern)\n\t\tif !gOpts.smartdia || lpattern == pattern {\n\t\t\tpattern = lpattern\n\t\t\tname = removeDiacritics(name)\n\t\t}\n\t}\n\tif gOpts.anchorfind {\n\t\treturn strings.HasPrefix(name, pattern)\n\t}\n\treturn strings.Contains(name, pattern)\n}\n\nfunc (nav *nav) findSingle() int {\n\tcount := 0\n\tindex := 0\n\tdir := nav.currDir()\n\tfor i := range dir.files {\n\t\tif findMatch(dir.files[i].Name(), nav.find) {\n\t\t\tcount++\n\t\t\tif count > 1 {\n\t\t\t\treturn count\n\t\t\t}\n\t\t\tindex = i\n\t\t}\n\t}\n\tif count == 1 {\n\t\tif index > dir.ind {\n\t\t\tnav.down(index - dir.ind)\n\t\t} else {\n\t\t\tnav.up(dir.ind - index)\n\t\t}\n\t}\n\treturn count\n}\n\nfunc (nav *nav) findNext() (bool, bool) {\n\tdir := nav.currDir()\n\tfor i := dir.ind + 1; i < len(dir.files); i++ {\n\t\tif findMatch(dir.files[i].Name(), nav.find) {\n\t\t\treturn nav.down(i - dir.ind), true\n\t\t}\n\t}\n\tif gOpts.wrapscan {\n\t\tfor i := range dir.ind {\n\t\t\tif findMatch(dir.files[i].Name(), nav.find) {\n\t\t\t\tdir.visualWrap++\n\t\t\t\treturn nav.up(dir.ind - i), true\n\t\t\t}\n\t\t}\n\t}\n\treturn false, false\n}\n\nfunc (nav *nav) findPrev() (bool, bool) {\n\tdir := nav.currDir()\n\tfor i := dir.ind - 1; i >= 0; i-- {\n\t\tif findMatch(dir.files[i].Name(), nav.find) {\n\t\t\treturn nav.up(dir.ind - i), true\n\t\t}\n\t}\n\tif gOpts.wrapscan {\n\t\tfor i := len(dir.files) - 1; i > dir.ind; i-- {\n\t\t\tif findMatch(dir.files[i].Name(), nav.find) {\n\t\t\t\tdir.visualWrap--\n\t\t\t\treturn nav.down(i - dir.ind), true\n\t\t\t}\n\t\t}\n\t}\n\treturn false, false\n}\n\nfunc searchMatch(name, pattern string, method searchMethod) (matched bool, err error) {\n\tif gOpts.ignorecase {\n\t\tlpattern := strings.ToLower(pattern)\n\t\tif !gOpts.smartcase || lpattern == pattern {\n\t\t\tpattern = lpattern\n\t\t\tname = strings.ToLower(name)\n\t\t}\n\t}\n\tif gOpts.ignoredia {\n\t\tlpattern := removeDiacritics(pattern)\n\t\tif !gOpts.smartdia || lpattern == pattern {\n\t\t\tpattern = lpattern\n\t\t\tname = removeDiacritics(name)\n\t\t}\n\t}\n\tswitch method {\n\tcase textSearch:\n\t\treturn strings.Contains(name, pattern), nil\n\tcase globSearch:\n\t\treturn filepath.Match(pattern, name)\n\tcase regexSearch:\n\t\treturn regexp.MatchString(pattern, name)\n\tdefault:\n\t\treturn false, errors.New(\"searchMatch: invalid searchMethod\")\n\t}\n}\n\nfunc (nav *nav) searchNext() (bool, error) {\n\tdir := nav.currDir()\n\tfor i := dir.ind + 1; i < len(dir.files); i++ {\n\t\tif matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.searchmethod); err != nil {\n\t\t\treturn false, err\n\t\t} else if matched {\n\t\t\treturn nav.down(i - dir.ind), nil\n\t\t}\n\t}\n\tif gOpts.wrapscan {\n\t\tfor i := range dir.ind {\n\t\t\tif matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.searchmethod); err != nil {\n\t\t\t\treturn false, err\n\t\t\t} else if matched {\n\t\t\t\tdir.visualWrap++\n\t\t\t\treturn nav.up(dir.ind - i), nil\n\t\t\t}\n\t\t}\n\t}\n\treturn false, nil\n}\n\nfunc (nav *nav) searchPrev() (bool, error) {\n\tdir := nav.currDir()\n\tfor i := dir.ind - 1; i >= 0; i-- {\n\t\tif matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.searchmethod); err != nil {\n\t\t\treturn false, err\n\t\t} else if matched {\n\t\t\treturn nav.up(dir.ind - i), nil\n\t\t}\n\t}\n\tif gOpts.wrapscan {\n\t\tfor i := len(dir.files) - 1; i > dir.ind; i-- {\n\t\t\tif matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.searchmethod); err != nil {\n\t\t\t\treturn false, err\n\t\t\t} else if matched {\n\t\t\t\tdir.visualWrap--\n\t\t\t\treturn nav.down(i - dir.ind), nil\n\t\t\t}\n\t\t}\n\t}\n\treturn false, nil\n}\n\nfunc isFiltered(f os.FileInfo, filter []string) bool {\n\tfor _, pattern := range filter {\n\t\tmatched, err := searchMatch(f.Name(), strings.TrimPrefix(pattern, \"!\"), gOpts.filtermethod)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Filter Error: %s\", err)\n\t\t\treturn false\n\t\t}\n\t\tif strings.HasPrefix(pattern, \"!\") && matched {\n\t\t\treturn true\n\t\t} else if !strings.HasPrefix(pattern, \"!\") && !matched {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc (nav *nav) removeMark(mark string) error {\n\tif _, ok := nav.marks[mark]; ok {\n\t\tdelete(nav.marks, mark)\n\t\treturn nil\n\t}\n\treturn errors.New(\"no such mark\")\n}\n\nfunc (nav *nav) readMarks() error {\n\tclear(nav.marks)\n\tf, err := os.Open(gMarksPath)\n\tif os.IsNotExist(err) {\n\t\treturn nil\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"opening marks file: %w\", err)\n\t}\n\tdefer f.Close()\n\n\tscanner := bufio.NewScanner(f)\n\tfor scanner.Scan() {\n\t\tmark, path, found := strings.Cut(scanner.Text(), \":\")\n\t\tif !found {\n\t\t\treturn fmt.Errorf(\"invalid marks file entry: %s\", scanner.Text())\n\t\t}\n\t\tif _, ok := nav.marks[mark]; !ok {\n\t\t\tnav.marks[mark] = path\n\t\t}\n\t}\n\n\tif err := scanner.Err(); err != nil {\n\t\treturn fmt.Errorf(\"reading marks file: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (nav *nav) writeMarks() error {\n\tif err := os.MkdirAll(filepath.Dir(gMarksPath), os.ModePerm); err != nil {\n\t\treturn fmt.Errorf(\"creating data directory: %w\", err)\n\t}\n\n\tf, err := os.Create(gMarksPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating marks file: %w\", err)\n\t}\n\tdefer f.Close()\n\n\tvar keys []string\n\tfor k := range nav.marks {\n\t\tif !strings.Contains(gOpts.tempmarks, k) {\n\t\t\tkeys = append(keys, k)\n\t\t}\n\t}\n\tsort.Strings(keys)\n\n\tfor _, k := range keys {\n\t\t_, err = fmt.Fprintf(f, \"%s:%s\\n\", k, nav.marks[k])\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"writing marks file: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (nav *nav) readTags() error {\n\tclear(nav.tags)\n\tf, err := os.Open(gTagsPath)\n\tif os.IsNotExist(err) {\n\t\treturn nil\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"opening tags file: %w\", err)\n\t}\n\tdefer f.Close()\n\n\tscanner := bufio.NewScanner(f)\n\tfor scanner.Scan() {\n\t\ttext := scanner.Text()\n\n\t\tind := strings.LastIndex(text, \":\")\n\t\tif ind == -1 {\n\t\t\treturn fmt.Errorf(\"invalid tags file entry: %s\", text)\n\t\t}\n\n\t\tpath := text[0:ind]\n\t\ttag := text[ind+1:]\n\t\tif _, ok := nav.tags[path]; !ok {\n\t\t\tnav.tags[path] = tag\n\t\t}\n\t}\n\n\tif err := scanner.Err(); err != nil {\n\t\treturn fmt.Errorf(\"reading tags file: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (nav *nav) writeTags() error {\n\tif err := os.MkdirAll(filepath.Dir(gTagsPath), os.ModePerm); err != nil {\n\t\treturn fmt.Errorf(\"creating data directory: %w\", err)\n\t}\n\n\tf, err := os.Create(gTagsPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating tags file: %w\", err)\n\t}\n\tdefer f.Close()\n\n\tvar keys []string\n\tfor k := range nav.tags {\n\t\tkeys = append(keys, k)\n\t}\n\tsort.Strings(keys)\n\n\tfor _, k := range keys {\n\t\t_, err = fmt.Fprintf(f, \"%s:%s\\n\", k, nav.tags[k])\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"writing tags file: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (nav *nav) currDir() *dir {\n\tif len(nav.dirPaths) == 0 {\n\t\twd, err := os.Getwd()\n\t\tif err != nil {\n\t\t\tlog.Printf(\"getting current directory: %s\", err)\n\t\t}\n\t\tnav.loadDirs(wd)\n\t}\n\n\tpath := nav.dirPaths[len(nav.dirPaths)-1]\n\treturn nav.getDir(path)\n}\n\nfunc (nav *nav) currFile() *file {\n\tdir := nav.currDir()\n\n\tif len(dir.files) == 0 {\n\t\treturn nil\n\t}\n\n\treturn dir.files[dir.ind]\n}\n\ntype indexedSelections struct {\n\tpaths   []string\n\tindices []int\n}\n\nfunc (m indexedSelections) Len() int { return len(m.paths) }\n\nfunc (m indexedSelections) Swap(i, j int) {\n\tm.paths[i], m.paths[j] = m.paths[j], m.paths[i]\n\tm.indices[i], m.indices[j] = m.indices[j], m.indices[i]\n}\n\nfunc (m indexedSelections) Less(i, j int) bool { return m.indices[i] < m.indices[j] }\n\nfunc (nav *nav) currSelections() []string {\n\tcurrDirOnly := gOpts.selmode == \"dir\"\n\tcurrDirPath := \"\"\n\tif currDirOnly {\n\t\t// select only from this directory\n\t\tcurrDirPath = nav.currDir().path\n\t}\n\n\tpaths := make([]string, 0, len(nav.selections))\n\tindices := make([]int, 0, len(nav.selections))\n\tfor path, index := range nav.selections {\n\t\tif !currDirOnly || filepath.Dir(path) == currDirPath {\n\t\t\tpaths = append(paths, path)\n\t\t\tindices = append(indices, index)\n\t\t}\n\t}\n\tsort.Sort(indexedSelections{paths: paths, indices: indices})\n\treturn paths\n}\n\nfunc (nav *nav) currFileOrSelections() (list []string, err error) {\n\tif sel := nav.currSelections(); len(sel) > 0 {\n\t\treturn sel, nil\n\t}\n\n\tif curr := nav.currFile(); curr != nil {\n\t\treturn []string{curr.path}, nil\n\t}\n\n\treturn nil, errors.New(\"no file selected\")\n}\n\nfunc (nav *nav) calcDirSize() error {\n\tcalc := func(f *file) error {\n\t\tif f.IsDir() {\n\t\t\ttotal, err := copySize([]string{f.path})\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tf.dirSize = total\n\t\t}\n\t\treturn nil\n\t}\n\n\tif len(nav.selections) == 0 {\n\t\tcurr := nav.currFile()\n\t\tif curr == nil {\n\t\t\treturn errors.New(\"no file selected\")\n\t\t}\n\t\treturn calc(curr)\n\t}\n\n\tfor sel := range nav.selections {\n\t\tlstat, err := os.Lstat(sel)\n\t\tif err != nil || !lstat.IsDir() {\n\t\t\tcontinue\n\t\t}\n\t\tpath, name := filepath.Dir(sel), filepath.Base(sel)\n\t\tdir := nav.getDir(path)\n\n\t\tfor _, f := range dir.files {\n\t\t\tif f.Name() == name {\n\t\t\t\terr := calc(f)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n"
  },
  {
    "path": "opts.go",
    "content": "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\ntype sortMethod string\n\nconst (\n\tnaturalSort sortMethod = \"natural\"\n\tnameSort    sortMethod = \"name\"\n\tsizeSort    sortMethod = \"size\"\n\ttimeSort    sortMethod = \"time\"\n\tatimeSort   sortMethod = \"atime\"\n\tbtimeSort   sortMethod = \"btime\"\n\tctimeSort   sortMethod = \"ctime\"\n\textSort     sortMethod = \"ext\"\n\tcustomSort  sortMethod = \"custom\"\n)\n\nfunc isValidSortMethod(method sortMethod) bool {\n\tswitch method {\n\tcase naturalSort, nameSort, sizeSort, timeSort, atimeSort, btimeSort, ctimeSort, extSort, customSort:\n\t\treturn true\n\t}\n\treturn false\n}\n\nconst invalidSortErrorMessage = `sortby: value should either be 'natural', 'name', 'size', 'time', 'atime', 'btime', 'ctime', 'ext' or 'custom'`\n\ntype searchMethod string\n\nconst (\n\ttextSearch  searchMethod = \"text\"\n\tglobSearch  searchMethod = \"glob\"\n\tregexSearch searchMethod = \"regex\"\n)\n\ntype cursorStyle string\n\nconst (\n\tdefaultCursor        cursorStyle = \"default\"\n\tblockCursor          cursorStyle = \"block\"\n\tunderlineCursor      cursorStyle = \"underline\"\n\tbarCursor            cursorStyle = \"bar\"\n\tblinkBlockCursor     cursorStyle = \"blinkblock\"\n\tblinkUnderlineCursor cursorStyle = \"blinkunderline\"\n\tblinkBarCursor       cursorStyle = \"blinkbar\"\n)\n\ntype borderStyle byte\n\nconst (\n\tborderOutline borderStyle = 1 << iota\n\tborderSeparators\n\tborderRound\n\n\tborderBox          = borderOutline | borderSeparators\n\tborderRoundOutline = borderOutline | borderRound\n\tborderRoundBox     = borderBox | borderRound\n)\n\nfunc (s borderStyle) String() string {\n\tswitch s {\n\tcase borderBox:\n\t\treturn \"box\"\n\tcase borderRoundBox:\n\t\treturn \"roundbox\"\n\tcase borderOutline:\n\t\treturn \"outline\"\n\tcase borderRoundOutline:\n\t\treturn \"roundoutline\"\n\tcase borderSeparators:\n\t\treturn \"separators\"\n\tdefault:\n\t\treturn fmt.Sprintf(\"borderStyle(%d)\", s)\n\t}\n}\n\nvar gOpts struct {\n\tanchorfind       bool\n\tautoquit         bool\n\tborderfmt        string\n\tborderstyle      borderStyle\n\tcleaner          string\n\tcopyfmt          string\n\tcursoractivefmt  string\n\tcursorparentfmt  string\n\tcursorpreviewfmt string\n\tcutfmt           string\n\tdircounts        bool\n\tdirfirst         bool\n\tdironly          bool\n\tdirpreviews      bool\n\tdrawbox          bool\n\tdupfilefmt       string\n\terrorfmt         string\n\tfilesep          string\n\tfiltermethod     searchMethod\n\tfindlen          int\n\thidden           bool\n\thiddenfiles      []string\n\thistory          bool\n\ticons            bool\n\tifs              string\n\tignorecase       bool\n\tignoredia        bool\n\tincfilter        bool\n\tincsearch        bool\n\tinfo             []string\n\tinfotimefmtnew   string\n\tinfotimefmtold   string\n\tmenufmt          string\n\tmenuheaderfmt    string\n\tmenuselectfmt    string\n\tmergeindicators  bool\n\tmouse            bool\n\tnumber           bool\n\tnumbercursorfmt  string\n\tnumberfmt        string\n\tperiod           int\n\tpreload          bool\n\tpreserve         []string\n\tpreview          bool\n\tpreviewer        string\n\tpromptfmt        string\n\tratios           []int\n\trelativenumber   bool\n\treverse          bool\n\trulerfile        string\n\trulerfmt         string\n\tscrolloff        int\n\tsearchmethod     searchMethod\n\tselectfmt        string\n\tselmode          string\n\tshell            string\n\tshellflag        string\n\tshellopts        []string\n\tshowbinds        bool\n\tsizeunits        string\n\tsmartcase        bool\n\tsmartdia         bool\n\tsortby           sortMethod\n\tstatfmt          string\n\ttabstop          int\n\ttagfmt           string\n\ttempmarks        string\n\tterminalcursor   cursorStyle\n\ttimefmt          string\n\ttruncatechar     string\n\ttruncatepct      int\n\tvisualfmt        string\n\twaitmsg          string\n\twatch            bool\n\twrapscan         bool\n\twrapscroll       bool\n\tnkeys            map[string]expr\n\tvkeys            map[string]expr\n\tcmdkeys          map[string]expr\n\tcmds             map[string]expr\n\tuser             map[string]string\n}\n\nvar gLocalOpts struct {\n\tdircounts map[string]bool\n\tdirfirst  map[string]bool\n\tdironly   map[string]bool\n\thidden    map[string]bool\n\tinfo      map[string][]string\n\treverse   map[string]bool\n\tsortby    map[string]sortMethod\n}\n\nfunc getDirCounts(path string) bool {\n\tif val, ok := gLocalOpts.dircounts[path]; ok {\n\t\treturn val\n\t}\n\treturn gOpts.dircounts\n}\n\nfunc getDirFirst(path string) bool {\n\tif val, ok := gLocalOpts.dirfirst[path]; ok {\n\t\treturn val\n\t}\n\treturn gOpts.dirfirst\n}\n\nfunc getDirOnly(path string) bool {\n\tif val, ok := gLocalOpts.dironly[path]; ok {\n\t\treturn val\n\t}\n\treturn gOpts.dironly\n}\n\nfunc getHidden(path string) bool {\n\tif val, ok := gLocalOpts.hidden[path]; ok {\n\t\treturn val\n\t}\n\treturn gOpts.hidden\n}\n\nfunc getInfo(path string) []string {\n\tif val, ok := gLocalOpts.info[path]; ok {\n\t\treturn val\n\t}\n\treturn gOpts.info\n}\n\nfunc getReverse(path string) bool {\n\tif val, ok := gLocalOpts.reverse[path]; ok {\n\t\treturn val\n\t}\n\treturn gOpts.reverse\n}\n\nfunc getSortBy(path string) sortMethod {\n\tif val, ok := gLocalOpts.sortby[path]; ok {\n\t\treturn val\n\t}\n\treturn gOpts.sortby\n}\n\nfunc init() {\n\tgOpts.anchorfind = true\n\tgOpts.autoquit = true\n\tgOpts.borderfmt = \"\\033[0m\"\n\tgOpts.borderstyle = borderBox\n\tgOpts.cleaner = \"\"\n\tgOpts.copyfmt = \"\\033[7;33m\"\n\tgOpts.cursoractivefmt = \"\\033[7m\"\n\tgOpts.cursorparentfmt = \"\\033[7m\"\n\tgOpts.cursorpreviewfmt = \"\\033[4m\"\n\tgOpts.cutfmt = \"\\033[7;31m\"\n\tgOpts.dircounts = false\n\tgOpts.dirfirst = true\n\tgOpts.dironly = false\n\tgOpts.dirpreviews = false\n\tgOpts.drawbox = false\n\tgOpts.dupfilefmt = \"%f.~%n~\"\n\tgOpts.errorfmt = \"\\033[7;31;47m\"\n\tgOpts.filesep = \"\\n\"\n\tgOpts.filtermethod = textSearch\n\tgOpts.findlen = 1\n\tgOpts.hidden = false\n\tgOpts.hiddenfiles = gDefaultHiddenFiles\n\tgOpts.history = true\n\tgOpts.icons = false\n\tgOpts.ifs = \"\"\n\tgOpts.ignorecase = true\n\tgOpts.ignoredia = true\n\tgOpts.incfilter = false\n\tgOpts.incsearch = false\n\tgOpts.info = nil\n\tgOpts.infotimefmtnew = \"Jan _2 15:04\"\n\tgOpts.infotimefmtold = \"Jan _2  2006\"\n\tgOpts.menufmt = \"\\033[0m\"\n\tgOpts.menuheaderfmt = \"\\033[1m\"\n\tgOpts.menuselectfmt = \"\\033[7m\"\n\tgOpts.mergeindicators = false\n\tgOpts.mouse = false\n\tgOpts.number = false\n\tgOpts.numbercursorfmt = \"\"\n\tgOpts.numberfmt = \"\\033[33m\"\n\tgOpts.period = 0\n\tgOpts.preload = false\n\tgOpts.preserve = []string{\"mode\"}\n\tgOpts.preview = true\n\tgOpts.previewer = \"\"\n\tgOpts.promptfmt = \"\\033[32;1m%u@%h\\033[0m:\\033[34;1m%d\\033[0m\\033[1m%f\\033[0m\"\n\tgOpts.ratios = []int{1, 2, 3}\n\tgOpts.relativenumber = false\n\tgOpts.reverse = false\n\tgOpts.rulerfile = \"\"\n\tgOpts.rulerfmt = \"\"\n\tgOpts.scrolloff = 0\n\tgOpts.searchmethod = textSearch\n\tgOpts.selectfmt = \"\\033[7;35m\"\n\tgOpts.selmode = \"all\"\n\tgOpts.shell = gDefaultShell\n\tgOpts.shellflag = gDefaultShellFlag\n\tgOpts.shellopts = nil\n\tgOpts.showbinds = true\n\tgOpts.sizeunits = \"binary\"\n\tgOpts.smartcase = true\n\tgOpts.smartdia = false\n\tgOpts.sortby = naturalSort\n\tgOpts.statfmt = \"\\033[36m%p\\033[0m| %c| %u| %g| %S| %t| -> %l\"\n\tgOpts.tabstop = 8\n\tgOpts.tagfmt = \"\\033[31m\"\n\tgOpts.tempmarks = \"'\"\n\tgOpts.terminalcursor = defaultCursor\n\tgOpts.timefmt = time.ANSIC\n\tgOpts.truncatechar = \"~\"\n\tgOpts.truncatepct = 100\n\tgOpts.visualfmt = \"\\033[7;36m\"\n\tgOpts.waitmsg = \"Press any key to continue\"\n\tgOpts.watch = false\n\tgOpts.wrapscan = true\n\tgOpts.wrapscroll = false\n\n\t// Normal and Visual mode\n\tkeys := map[string]expr{\n\t\t\"k\":          &callExpr{\"up\", nil, 1},\n\t\t\"<up>\":       &callExpr{\"up\", nil, 1},\n\t\t\"<m-up>\":     &callExpr{\"up\", nil, 1},\n\t\t\"<c-u>\":      &callExpr{\"half-up\", nil, 1},\n\t\t\"<c-b>\":      &callExpr{\"page-up\", nil, 1},\n\t\t\"<pgup>\":     &callExpr{\"page-up\", nil, 1},\n\t\t\"<c-y>\":      &callExpr{\"scroll-up\", nil, 1},\n\t\t\"<c-m-up>\":   &callExpr{\"scroll-up\", nil, 1},\n\t\t\"j\":          &callExpr{\"down\", nil, 1},\n\t\t\"<down>\":     &callExpr{\"down\", nil, 1},\n\t\t\"<m-down>\":   &callExpr{\"down\", nil, 1},\n\t\t\"<c-d>\":      &callExpr{\"half-down\", nil, 1},\n\t\t\"<c-f>\":      &callExpr{\"page-down\", nil, 1},\n\t\t\"<pgdn>\":     &callExpr{\"page-down\", nil, 1},\n\t\t\"<c-e>\":      &callExpr{\"scroll-down\", nil, 1},\n\t\t\"<c-m-down>\": &callExpr{\"scroll-down\", nil, 1},\n\t\t\"h\":          &callExpr{\"updir\", nil, 1},\n\t\t\"<left>\":     &callExpr{\"updir\", nil, 1},\n\t\t\"l\":          &callExpr{\"open\", nil, 1},\n\t\t\"<right>\":    &callExpr{\"open\", nil, 1},\n\t\t\"q\":          &callExpr{\"quit\", nil, 1},\n\t\t\"gg\":         &callExpr{\"top\", nil, 1},\n\t\t\"<home>\":     &callExpr{\"top\", nil, 1},\n\t\t\"G\":          &callExpr{\"bottom\", nil, 1},\n\t\t\"<end>\":      &callExpr{\"bottom\", nil, 1},\n\t\t\"H\":          &callExpr{\"high\", nil, 1},\n\t\t\"M\":          &callExpr{\"middle\", nil, 1},\n\t\t\"L\":          &callExpr{\"low\", nil, 1},\n\t\t\"[\":          &callExpr{\"jump-prev\", nil, 1},\n\t\t\"]\":          &callExpr{\"jump-next\", nil, 1},\n\t\t\"t\":          &callExpr{\"tag-toggle\", nil, 1},\n\t\t\"u\":          &callExpr{\"unselect\", nil, 1},\n\t\t\"y\":          &callExpr{\"copy\", nil, 1},\n\t\t\"d\":          &callExpr{\"cut\", nil, 1},\n\t\t\"c\":          &callExpr{\"clear\", nil, 1},\n\t\t\"p\":          &callExpr{\"paste\", nil, 1},\n\t\t\"<c-l>\":      &callExpr{\"redraw\", nil, 1},\n\t\t\"<c-r>\":      &callExpr{\"reload\", nil, 1},\n\t\t\":\":          &callExpr{\"read\", nil, 1},\n\t\t\"$\":          &callExpr{\"shell\", nil, 1},\n\t\t\"%\":          &callExpr{\"shell-pipe\", nil, 1},\n\t\t\"!\":          &callExpr{\"shell-wait\", nil, 1},\n\t\t\"&\":          &callExpr{\"shell-async\", nil, 1},\n\t\t\"f\":          &callExpr{\"find\", nil, 1},\n\t\t\"F\":          &callExpr{\"find-back\", nil, 1},\n\t\t\";\":          &callExpr{\"find-next\", nil, 1},\n\t\t\",\":          &callExpr{\"find-prev\", nil, 1},\n\t\t\"/\":          &callExpr{\"search\", nil, 1},\n\t\t\"?\":          &callExpr{\"search-back\", nil, 1},\n\t\t\"n\":          &callExpr{\"search-next\", nil, 1},\n\t\t\"N\":          &callExpr{\"search-prev\", nil, 1},\n\t\t\"m\":          &callExpr{\"mark-save\", nil, 1},\n\t\t\"'\":          &callExpr{\"mark-load\", nil, 1},\n\t\t`\"`:          &callExpr{\"mark-remove\", nil, 1},\n\t\t`r`:          &callExpr{\"rename\", nil, 1},\n\t\t\"<c-n>\":      &callExpr{\"cmd-history-next\", nil, 1},\n\t\t\"<c-p>\":      &callExpr{\"cmd-history-prev\", nil, 1},\n\n\t\t\"zh\": &setExpr{\"hidden!\", \"\"},\n\t\t\"zr\": &setExpr{\"reverse!\", \"\"},\n\t\t\"zn\": &setExpr{\"info\", \"\"},\n\t\t\"zs\": &setExpr{\"info\", \"size\"},\n\t\t\"zt\": &setExpr{\"info\", \"time\"},\n\t\t\"za\": &setExpr{\"info\", \"size:time\"},\n\t\t\"sn\": &listExpr{[]expr{&setExpr{\"sortby\", \"natural\"}, &setExpr{\"info\", \"\"}}, 1},\n\t\t\"ss\": &listExpr{[]expr{&setExpr{\"sortby\", \"size\"}, &setExpr{\"info\", \"size\"}}, 1},\n\t\t\"st\": &listExpr{[]expr{&setExpr{\"sortby\", \"time\"}, &setExpr{\"info\", \"time\"}}, 1},\n\t\t\"sa\": &listExpr{[]expr{&setExpr{\"sortby\", \"atime\"}, &setExpr{\"info\", \"atime\"}}, 1},\n\t\t\"sb\": &listExpr{[]expr{&setExpr{\"sortby\", \"btime\"}, &setExpr{\"info\", \"btime\"}}, 1},\n\t\t\"sc\": &listExpr{[]expr{&setExpr{\"sortby\", \"ctime\"}, &setExpr{\"info\", \"ctime\"}}, 1},\n\t\t\"se\": &listExpr{[]expr{&setExpr{\"sortby\", \"ext\"}, &setExpr{\"info\", \"\"}}, 1},\n\t\t\"gh\": &callExpr{\"cd\", []string{\"~\"}, 1},\n\t}\n\n\t// insert bindings that apply to both Normal & Visual mode first\n\tgOpts.nkeys = maps.Clone(keys)\n\t// now add Normal mode specific ones\n\tgOpts.nkeys[\"<space>\"] = &listExpr{[]expr{&callExpr{\"toggle\", nil, 1}, &callExpr{\"down\", nil, 1}}, 1}\n\tgOpts.nkeys[\"V\"] = &callExpr{\"visual\", nil, 1}\n\tgOpts.nkeys[\"v\"] = &callExpr{\"invert\", nil, 1}\n\n\t// now do the same for Visual mode\n\tgOpts.vkeys = maps.Clone(keys)\n\tgOpts.vkeys[\"<esc>\"] = &callExpr{\"visual-discard\", nil, 1}\n\tgOpts.vkeys[\"V\"] = &callExpr{\"visual-accept\", nil, 1}\n\tgOpts.vkeys[\"o\"] = &callExpr{\"visual-change\", nil, 1}\n\n\t// Command-line mode bindings can be assigned directly\n\tgOpts.cmdkeys = map[string]expr{\n\t\t\"<space>\":       &callExpr{\"cmd-insert\", []string{\" \"}, 1},\n\t\t\"<esc>\":         &callExpr{\"cmd-escape\", nil, 1},\n\t\t\"<tab>\":         &callExpr{\"cmd-complete\", nil, 1},\n\t\t\"<enter>\":       &callExpr{\"cmd-enter\", nil, 1},\n\t\t\"<c-j>\":         &callExpr{\"cmd-enter\", nil, 1},\n\t\t\"<down>\":        &callExpr{\"cmd-history-next\", nil, 1},\n\t\t\"<c-n>\":         &callExpr{\"cmd-history-next\", nil, 1},\n\t\t\"<up>\":          &callExpr{\"cmd-history-prev\", nil, 1},\n\t\t\"<c-p>\":         &callExpr{\"cmd-history-prev\", nil, 1},\n\t\t\"<delete>\":      &callExpr{\"cmd-delete\", nil, 1},\n\t\t\"<c-d>\":         &callExpr{\"cmd-delete\", nil, 1},\n\t\t\"<backspace>\":   &callExpr{\"cmd-delete-back\", nil, 1},\n\t\t\"<left>\":        &callExpr{\"cmd-left\", nil, 1},\n\t\t\"<c-b>\":         &callExpr{\"cmd-left\", nil, 1},\n\t\t\"<right>\":       &callExpr{\"cmd-right\", nil, 1},\n\t\t\"<c-f>\":         &callExpr{\"cmd-right\", nil, 1},\n\t\t\"<home>\":        &callExpr{\"cmd-home\", nil, 1},\n\t\t\"<c-a>\":         &callExpr{\"cmd-home\", nil, 1},\n\t\t\"<end>\":         &callExpr{\"cmd-end\", nil, 1},\n\t\t\"<c-e>\":         &callExpr{\"cmd-end\", nil, 1},\n\t\t\"<c-u>\":         &callExpr{\"cmd-delete-home\", nil, 1},\n\t\t\"<c-k>\":         &callExpr{\"cmd-delete-end\", nil, 1},\n\t\t\"<c-w>\":         &callExpr{\"cmd-delete-unix-word\", nil, 1},\n\t\t\"<c-y>\":         &callExpr{\"cmd-yank\", nil, 1},\n\t\t\"<c-t>\":         &callExpr{\"cmd-transpose\", nil, 1},\n\t\t\"<c-c>\":         &callExpr{\"cmd-interrupt\", nil, 1},\n\t\t\"<a-f>\":         &callExpr{\"cmd-word\", nil, 1},\n\t\t\"<a-b>\":         &callExpr{\"cmd-word-back\", nil, 1},\n\t\t\"<a-c>\":         &callExpr{\"cmd-capitalize-word\", nil, 1},\n\t\t\"<a-d>\":         &callExpr{\"cmd-delete-word\", nil, 1},\n\t\t\"<a-backspace>\": &callExpr{\"cmd-delete-word-back\", nil, 1},\n\t\t\"<a-u>\":         &callExpr{\"cmd-uppercase-word\", nil, 1},\n\t\t\"<a-l>\":         &callExpr{\"cmd-lowercase-word\", nil, 1},\n\t\t\"<a-t>\":         &callExpr{\"cmd-transpose-word\", nil, 1},\n\t}\n\n\tgOpts.cmds = make(map[string]expr)\n\tgOpts.user = make(map[string]string)\n\n\tgLocalOpts.dircounts = make(map[string]bool)\n\tgLocalOpts.dirfirst = make(map[string]bool)\n\tgLocalOpts.dironly = make(map[string]bool)\n\tgLocalOpts.hidden = make(map[string]bool)\n\tgLocalOpts.info = make(map[string][]string)\n\tgLocalOpts.reverse = make(map[string]bool)\n\tgLocalOpts.sortby = make(map[string]sortMethod)\n\n\tsetDefaults()\n}\n"
  },
  {
    "path": "os.go",
    "content": "//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\"\n\t\"strconv\"\n\t\"strings\"\n\t\"syscall\"\n\n\t\"golang.org/x/sys/unix\"\n)\n\nvar (\n\tenvOpener = os.Getenv(\"OPENER\")\n\tenvEditor = os.Getenv(\"VISUAL\")\n\tenvPager  = os.Getenv(\"PAGER\")\n\tenvShell  = os.Getenv(\"SHELL\")\n)\n\nvar (\n\tgDefaultShell       = \"sh\"\n\tgDefaultShellFlag   = \"-c\"\n\tgDefaultSocketProt  = \"unix\"\n\tgDefaultSocketPath  string\n\tgDefaultHiddenFiles = []string{\".*\"}\n)\n\nvar (\n\tgUser        *user.User\n\tgConfigPaths []string\n\tgColorsPaths []string\n\tgIconsPaths  []string\n\tgFilesPath   string\n\tgMarksPath   string\n\tgTagsPath    string\n\tgHistoryPath string\n)\n\nfunc init() {\n\tif envOpener == \"\" {\n\t\tif runtime.GOOS == \"darwin\" {\n\t\t\tenvOpener = \"open\"\n\t\t} else {\n\t\t\tenvOpener = \"xdg-open\"\n\t\t}\n\t}\n\n\tif envEditor == \"\" {\n\t\tenvEditor = cmp.Or(os.Getenv(\"EDITOR\"), \"vi\")\n\t}\n\n\tif envPager == \"\" {\n\t\tenvPager = \"less\"\n\t}\n\n\tif envShell == \"\" {\n\t\tenvShell = \"sh\"\n\t}\n\n\tu, err := user.Current()\n\tif err != nil {\n\t\t// When the user is not in /etc/passwd (for e.g. LDAP) and CGO_ENABLED=1 in go env,\n\t\t// the cgo implementation of user.Current() fails even when HOME and USER are set.\n\n\t\tlog.Printf(\"user: %s\", err)\n\t\tif os.Getenv(\"HOME\") == \"\" {\n\t\t\tpanic(\"$HOME variable is empty or not set\")\n\t\t}\n\t\tif os.Getenv(\"USER\") == \"\" {\n\t\t\tpanic(\"$USER variable is empty or not set\")\n\t\t}\n\t\tu = &user.User{\n\t\t\tUsername: os.Getenv(\"USER\"),\n\t\t\tHomeDir:  os.Getenv(\"HOME\"),\n\t\t}\n\t}\n\tgUser = u\n\n\tconfig := cmp.Or(\n\t\tos.Getenv(\"LF_CONFIG_HOME\"),\n\t\tos.Getenv(\"XDG_CONFIG_HOME\"),\n\t\tfilepath.Join(gUser.HomeDir, \".config\"),\n\t)\n\n\tgConfigPaths = []string{\n\t\tfilepath.Join(\"/etc\", \"lf\", \"lfrc\"),\n\t\tfilepath.Join(config, \"lf\", \"lfrc\"),\n\t}\n\n\tgColorsPaths = []string{\n\t\tfilepath.Join(\"/etc\", \"lf\", \"colors\"),\n\t\tfilepath.Join(config, \"lf\", \"colors\"),\n\t}\n\n\tgIconsPaths = []string{\n\t\tfilepath.Join(\"/etc\", \"lf\", \"icons\"),\n\t\tfilepath.Join(config, \"lf\", \"icons\"),\n\t}\n\n\tdata := cmp.Or(\n\t\tos.Getenv(\"LF_DATA_HOME\"),\n\t\tos.Getenv(\"XDG_DATA_HOME\"),\n\t\tfilepath.Join(gUser.HomeDir, \".local\", \"share\"),\n\t)\n\n\tgFilesPath = filepath.Join(data, \"lf\", \"files\")\n\tgMarksPath = filepath.Join(data, \"lf\", \"marks\")\n\tgTagsPath = filepath.Join(data, \"lf\", \"tags\")\n\tgHistoryPath = filepath.Join(data, \"lf\", \"history\")\n\n\truntime := cmp.Or(os.Getenv(\"XDG_RUNTIME_DIR\"), os.TempDir())\n\n\tgDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf(\"lf.%s.sock\", gUser.Username))\n}\n\nfunc detachedCommand(name string, arg ...string) *exec.Cmd {\n\tcmd := exec.Command(name, arg...)\n\tcmd.SysProcAttr = &unix.SysProcAttr{Setsid: true}\n\treturn cmd\n}\n\nfunc shellCommand(s string, args []string) *exec.Cmd {\n\tif len(gOpts.ifs) != 0 {\n\t\ts = fmt.Sprintf(\"IFS='%s'; %s\", gOpts.ifs, s)\n\t}\n\n\targs = append([]string{gOpts.shellflag, s, \"--\"}, args...)\n\n\targs = append(gOpts.shellopts, args...)\n\n\treturn exec.Command(gOpts.shell, args...)\n}\n\nfunc shellSetPG(cmd *exec.Cmd) {\n\tcmd.SysProcAttr = &unix.SysProcAttr{Setpgid: true}\n}\n\nfunc shellKill(cmd *exec.Cmd) error {\n\tpgid, err := unix.Getpgid(cmd.Process.Pid)\n\tif err == nil && cmd.Process.Pid == pgid {\n\t\t// kill the process group\n\t\terr = unix.Kill(-pgid, syscall.SIGTERM)\n\t\tif err == nil {\n\t\t\treturn nil\n\t\t}\n\t}\n\treturn cmd.Process.Kill()\n}\n\nfunc setDefaults() {\n\tgOpts.cmds[\"open\"] = &execExpr{\"&\", `$OPENER \"$f\"`}\n\tgOpts.nkeys[\"e\"] = &execExpr{\"$\", `$EDITOR \"$f\"`}\n\tgOpts.vkeys[\"e\"] = &execExpr{\"$\", `$EDITOR \"$f\"`}\n\tgOpts.nkeys[\"i\"] = &execExpr{\"$\", `$PAGER \"$f\"`}\n\tgOpts.vkeys[\"i\"] = &execExpr{\"$\", `$PAGER \"$f\"`}\n\tgOpts.nkeys[\"w\"] = &execExpr{\"$\", \"$SHELL\"}\n\tgOpts.vkeys[\"w\"] = &execExpr{\"$\", \"$SHELL\"}\n\n\tgOpts.cmds[\"help\"] = &execExpr{\"$\", `\"$lf\" -doc | $PAGER`}\n\tgOpts.nkeys[\"<f-1>\"] = &callExpr{\"help\", nil, 1}\n\tgOpts.vkeys[\"<f-1>\"] = &callExpr{\"help\", nil, 1}\n\n\tgOpts.cmds[\"maps\"] = &execExpr{\"$\", `\"$lf\" -remote \"query $id maps\" | $PAGER`}\n\tgOpts.cmds[\"nmaps\"] = &execExpr{\"$\", `\"$lf\" -remote \"query $id nmaps\" | $PAGER`}\n\tgOpts.cmds[\"vmaps\"] = &execExpr{\"$\", `\"$lf\" -remote \"query $id vmaps\" | $PAGER`}\n\tgOpts.cmds[\"cmaps\"] = &execExpr{\"$\", `\"$lf\" -remote \"query $id cmaps\" | $PAGER`}\n\tgOpts.cmds[\"cmds\"] = &execExpr{\"$\", `\"$lf\" -remote \"query $id cmds\" | $PAGER`}\n}\n\nfunc setUserUmask() {\n\tunix.Umask(0o077)\n}\n\nfunc isExecutable(f os.FileInfo) bool {\n\treturn f.Mode()&0o111 != 0\n}\n\nfunc isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {\n\thidden := false\n\tfor _, pattern := range hiddenfiles {\n\t\tif matchPattern(strings.TrimPrefix(pattern, \"!\"), f.Name(), path) {\n\t\t\thidden = !strings.HasPrefix(pattern, \"!\")\n\t\t}\n\t}\n\treturn hidden\n}\n\nfunc userName(f os.FileInfo) string {\n\tif stat, ok := f.Sys().(*syscall.Stat_t); ok {\n\t\tuid := strconv.FormatUint(uint64(stat.Uid), 10)\n\t\tif u, err := user.LookupId(uid); err == nil {\n\t\t\treturn u.Username\n\t\t}\n\t\treturn uid\n\t}\n\treturn \"\"\n}\n\nfunc groupName(f os.FileInfo) string {\n\tif stat, ok := f.Sys().(*syscall.Stat_t); ok {\n\t\tgid := strconv.FormatUint(uint64(stat.Gid), 10)\n\t\tif g, err := user.LookupGroupId(gid); err == nil {\n\t\t\treturn g.Name\n\t\t}\n\t\treturn gid\n\t}\n\treturn \"\"\n}\n\nfunc linkCount(f os.FileInfo) string {\n\tif stat, ok := f.Sys().(*syscall.Stat_t); ok {\n\t\treturn strconv.FormatUint(uint64(stat.Nlink), 10)\n\t}\n\treturn \"\"\n}\n\nfunc errCrossDevice(err error) bool {\n\treturn err.(*os.LinkError).Err.(unix.Errno) == unix.EXDEV\n}\n\nfunc quoteString(s string) string {\n\treturn s\n}\n\nfunc shellEscape(s string) string {\n\tbuf := make([]rune, 0, len(s))\n\tfor _, r := range s {\n\t\tif strings.ContainsRune(\" !\\\"$&'()*,:;<=>?@[\\\\]^`{|}\", r) {\n\t\t\tbuf = append(buf, '\\\\')\n\t\t}\n\t\tbuf = append(buf, r)\n\t}\n\treturn string(buf)\n}\n\nfunc shellUnescape(s string) string {\n\tesc := false\n\tbuf := make([]rune, 0, len(s))\n\tfor _, r := range s {\n\t\tif r == '\\\\' && !esc {\n\t\t\tesc = true\n\t\t\tcontinue\n\t\t}\n\t\tesc = false\n\t\tbuf = append(buf, r)\n\t}\n\tif esc {\n\t\tbuf = append(buf, '\\\\')\n\t}\n\treturn string(buf)\n}\n"
  },
  {
    "path": "os_windows.go",
    "content": "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/sys/windows\"\n)\n\nvar (\n\tenvOpener = os.Getenv(\"OPENER\")\n\tenvEditor = os.Getenv(\"VISUAL\")\n\tenvPager  = os.Getenv(\"PAGER\")\n\tenvShell  = os.Getenv(\"SHELL\")\n)\n\nvar envPathExts []string\n\nvar (\n\tgDefaultShell       = \"cmd\"\n\tgDefaultShellFlag   = \"/c\"\n\tgDefaultSocketProt  = \"unix\"\n\tgDefaultSocketPath  string\n\tgDefaultHiddenFiles []string\n)\n\nvar (\n\tgUser        *user.User\n\tgConfigPaths []string\n\tgColorsPaths []string\n\tgIconsPaths  []string\n\tgFilesPath   string\n\tgTagsPath    string\n\tgMarksPath   string\n\tgHistoryPath string\n)\n\nfunc init() {\n\tif envOpener == \"\" {\n\t\tenvOpener = `start \"\"`\n\t}\n\n\tif envEditor == \"\" {\n\t\tenvEditor = cmp.Or(os.Getenv(\"EDITOR\"), \"notepad\")\n\t}\n\n\tif envPager == \"\" {\n\t\tenvPager = \"more\"\n\t}\n\n\tif envShell == \"\" {\n\t\tenvShell = \"cmd\"\n\t}\n\n\thomeDir, err := os.UserHomeDir()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tusername := os.Getenv(\"USERNAME\")\n\tif username == \"\" {\n\t\tpanic(\"$USERNAME variable is empty or not set\")\n\t}\n\n\tgUser = &user.User{\n\t\tHomeDir:  homeDir,\n\t\tUsername: username,\n\t}\n\n\tconfig := cmp.Or(\n\t\tos.Getenv(\"LF_CONFIG_HOME\"),\n\t\tos.Getenv(\"XDG_CONFIG_HOME\"),\n\t\tos.Getenv(\"APPDATA\"),\n\t)\n\n\tgConfigPaths = []string{\n\t\tfilepath.Join(os.Getenv(\"ProgramData\"), \"lf\", \"lfrc\"),\n\t\tfilepath.Join(config, \"lf\", \"lfrc\"),\n\t}\n\n\tgColorsPaths = []string{\n\t\tfilepath.Join(os.Getenv(\"ProgramData\"), \"lf\", \"colors\"),\n\t\tfilepath.Join(config, \"lf\", \"colors\"),\n\t}\n\n\tgIconsPaths = []string{\n\t\tfilepath.Join(os.Getenv(\"ProgramData\"), \"lf\", \"icons\"),\n\t\tfilepath.Join(config, \"lf\", \"icons\"),\n\t}\n\n\tdata := cmp.Or(\n\t\tos.Getenv(\"LF_DATA_HOME\"),\n\t\tos.Getenv(\"XDG_DATA_HOME\"),\n\t\tos.Getenv(\"LOCALAPPDATA\"),\n\t)\n\n\tgFilesPath = filepath.Join(data, \"lf\", \"files\")\n\tgMarksPath = filepath.Join(data, \"lf\", \"marks\")\n\tgTagsPath = filepath.Join(data, \"lf\", \"tags\")\n\tgHistoryPath = filepath.Join(data, \"lf\", \"history\")\n\n\tsocket, err := syscall.Socket(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)\n\tif err != nil {\n\t\tgDefaultSocketProt = \"tcp\"\n\t\tgDefaultSocketPath = \"127.0.0.1:12345\"\n\t} else {\n\t\truntime := os.TempDir()\n\t\tgDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf(\"lf.%s.sock\", gUser.Username))\n\t\tsyscall.Close(socket)\n\t}\n\n\ts := cmp.Or(os.Getenv(\"PATHEXT\"), \".COM;.EXE;.BAT;.CMD\")\n\tfor ext := range strings.SplitSeq(s, \";\") {\n\t\tif ext == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tenvPathExts = append(envPathExts, strings.ToLower(ext))\n\t}\n}\n\nfunc detachedCommand(name string, arg ...string) *exec.Cmd {\n\tcmd := exec.Command(name, arg...)\n\tcmd.SysProcAttr = &windows.SysProcAttr{CreationFlags: 8}\n\treturn cmd\n}\n\nfunc shellCommand(s string, args []string) *exec.Cmd {\n\t// Windows CMD requires special handling to deal with quoted arguments\n\tif strings.ToLower(gOpts.shell) == \"cmd\" {\n\t\tvar builder strings.Builder\n\t\tbuilder.WriteString(s)\n\t\tfor _, arg := range args {\n\t\t\tfmt.Fprintf(&builder, ` \"%s\"`, arg)\n\t\t}\n\t\tshellOpts := strings.Join(gOpts.shellopts, \" \")\n\t\tcmdline := fmt.Sprintf(`%s %s %s \"%s\"`, gOpts.shell, shellOpts, gOpts.shellflag, builder.String())\n\n\t\tcmd := exec.Command(gOpts.shell)\n\t\tcmd.SysProcAttr = &windows.SysProcAttr{CmdLine: cmdline}\n\t\treturn cmd\n\t}\n\n\targs = append([]string{gOpts.shellflag, s}, args...)\n\targs = append(gOpts.shellopts, args...)\n\treturn exec.Command(gOpts.shell, args...)\n}\n\nfunc shellSetPG(_ *exec.Cmd) {\n}\n\nfunc shellKill(cmd *exec.Cmd) error {\n\treturn cmd.Process.Kill()\n}\n\nfunc setDefaults() {\n\tgOpts.cmds[\"open\"] = &execExpr{\"&\", \"%OPENER% %f%\"}\n\tgOpts.nkeys[\"e\"] = &execExpr{\"$\", \"%EDITOR% %f%\"}\n\tgOpts.vkeys[\"e\"] = &execExpr{\"$\", \"%EDITOR% %f%\"}\n\tgOpts.nkeys[\"i\"] = &execExpr{\"!\", \"%PAGER% %f%\"}\n\tgOpts.vkeys[\"i\"] = &execExpr{\"!\", \"%PAGER% %f%\"}\n\tgOpts.nkeys[\"w\"] = &execExpr{\"$\", \"%SHELL%\"}\n\tgOpts.vkeys[\"w\"] = &execExpr{\"$\", \"%SHELL%\"}\n\n\tgOpts.cmds[\"help\"] = &execExpr{\"!\", \"%lf% -doc | %PAGER%\"}\n\tgOpts.nkeys[\"<f-1>\"] = &callExpr{\"help\", nil, 1}\n\tgOpts.vkeys[\"<f-1>\"] = &callExpr{\"help\", nil, 1}\n\n\tgOpts.cmds[\"maps\"] = &execExpr{\"!\", `%lf% -remote \"query %id% maps\" | %PAGER%`}\n\tgOpts.cmds[\"nmaps\"] = &execExpr{\"!\", `%lf% -remote \"query %id% nmaps\" | %PAGER%`}\n\tgOpts.cmds[\"vmaps\"] = &execExpr{\"!\", `%lf% -remote \"query %id% vmaps\" | %PAGER%`}\n\tgOpts.cmds[\"cmaps\"] = &execExpr{\"!\", `%lf% -remote \"query %id% cmaps\" | %PAGER%`}\n\tgOpts.cmds[\"cmds\"] = &execExpr{\"!\", `%lf% -remote \"query %id% cmds\" | %PAGER%`}\n}\n\nfunc setUserUmask() {}\n\nfunc isExecutable(f os.FileInfo) bool {\n\text := filepath.Ext(f.Name())\n\tif ext == \"\" {\n\t\treturn false\n\t}\n\text = strings.ToLower(ext)\n\tfor _, x := range envPathExts {\n\t\tif ext == x {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {\n\tptr, err := windows.UTF16PtrFromString(filepath.Join(path, f.Name()))\n\tif err != nil {\n\t\treturn false\n\t}\n\tattrs, err := windows.GetFileAttributes(ptr)\n\tif err != nil {\n\t\treturn false\n\t}\n\n\tif attrs&windows.FILE_ATTRIBUTE_HIDDEN != 0 {\n\t\treturn true\n\t}\n\n\thidden := false\n\tfor _, pattern := range hiddenfiles {\n\t\tif matchPattern(strings.TrimPrefix(pattern, \"!\"), f.Name(), path) {\n\t\t\thidden = !strings.HasPrefix(pattern, \"!\")\n\t\t}\n\t}\n\n\treturn hidden\n}\n\nfunc userName(_ os.FileInfo) string {\n\treturn \"\"\n}\n\nfunc groupName(_ os.FileInfo) string {\n\treturn \"\"\n}\n\nfunc linkCount(_ os.FileInfo) string {\n\treturn \"\"\n}\n\nfunc errCrossDevice(err error) bool {\n\treturn err.(*os.LinkError).Err.(windows.Errno) == windows.ERROR_NOT_SAME_DEVICE\n}\n\nfunc quoteString(s string) string {\n\t// Windows CMD requires special handling to deal with quoted arguments\n\tif strings.ToLower(gOpts.shell) == \"cmd\" {\n\t\treturn fmt.Sprintf(`\"%s\"`, s)\n\t}\n\treturn s\n}\n\nfunc shellEscape(s string) string {\n\tfor _, r := range s {\n\t\tif strings.ContainsRune(\" !%&'()+,;=[]^`{}~\", r) {\n\t\t\treturn fmt.Sprintf(`\"%s\"`, s)\n\t\t}\n\t}\n\treturn s\n}\n\nfunc shellUnescape(s string) string {\n\treturn strings.ReplaceAll(s, `\"`, \"\")\n}\n"
  },
  {
    "path": "parse.go",
    "content": "package main\n\n// Grammar of the language used in the evaluator\n//\n// Expr         = SetExpr\n//              | SetLocalExpr\n//              | MapExpr\n//              | NMapExpr\n//              | VMapExpr\n//              | CMapExpr\n//              | CmdExpr\n//              | CallExpr\n//              | ExecExpr\n//              | ListExpr\n//\n// SetExpr      = 'set' <opt> <val> ';'\n//\n// SetLocalExpr = 'setlocal' <dir> <opt> <val> ';'\n//\n// MapExpr      = 'map' <keys> Expr\n//\n// NMapExpr     = 'nmap' <keys> Expr\n//\n// VMapExpr     = 'vmap' <keys> Expr\n//\n// CMapExpr     = 'cmap' <key> Expr\n//\n// CmdExpr      = 'cmd' <name> Expr\n//\n// CallExpr     = <name> <args> ';'\n//\n// ExecExpr     = Prefix      <value>      '\\n'\n//              | Prefix '{{' <value> '}}' ';'\n//\n// Prefix       = '$' | '%' | '!' | '&'\n//\n// ListExpr     = ':'      Expr ListRest      '\\n'\n//              | ':' '{{' Expr ListRest '}}' ';'\n//\n// ListRest     = Nil\n//              | Expr ListExpr\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"io\"\n\t\"strings\"\n)\n\ntype expr interface {\n\tString() string\n\teval(app *app, args []string)\n}\n\ntype setExpr struct {\n\topt string\n\tval string\n}\n\nfunc (e *setExpr) String() string {\n\tif e.val == \"\" {\n\t\treturn fmt.Sprintf(\"set %s\", e.opt)\n\t}\n\treturn fmt.Sprintf(\"set %s %s\", e.opt, e.val)\n}\n\ntype setLocalExpr struct {\n\tpath string\n\topt  string\n\tval  string\n}\n\nfunc (e *setLocalExpr) String() string {\n\tif e.val == \"\" {\n\t\treturn fmt.Sprintf(\"setlocal %s %s\", e.path, e.opt)\n\t}\n\treturn fmt.Sprintf(\"setlocal %s %s %s\", e.path, e.opt, e.val)\n}\n\ntype mapExpr struct {\n\tkeys string\n\texpr expr\n}\n\nfunc (e *mapExpr) String() string {\n\tif e.expr == nil {\n\t\treturn fmt.Sprintf(\"map %s\", e.keys)\n\t}\n\treturn fmt.Sprintf(\"map %s %s\", e.keys, e.expr)\n}\n\ntype nmapExpr struct {\n\tkeys string\n\texpr expr\n}\n\nfunc (e *nmapExpr) String() string {\n\tif e.expr == nil {\n\t\treturn fmt.Sprintf(\"nmap %s\", e.keys)\n\t}\n\treturn fmt.Sprintf(\"nmap %s %s\", e.keys, e.expr)\n}\n\ntype vmapExpr struct {\n\tkeys string\n\texpr expr\n}\n\nfunc (e *vmapExpr) String() string {\n\tif e.expr == nil {\n\t\treturn fmt.Sprintf(\"vmap %s\", e.keys)\n\t}\n\treturn fmt.Sprintf(\"vmap %s %s\", e.keys, e.expr)\n}\n\ntype cmapExpr struct {\n\tkey  string\n\texpr expr\n}\n\nfunc (e *cmapExpr) String() string {\n\tif e.expr == nil {\n\t\treturn fmt.Sprintf(\"cmap %s\", e.key)\n\t}\n\treturn fmt.Sprintf(\"cmap %s %s\", e.key, e.expr)\n}\n\ntype cmdExpr struct {\n\tname string\n\texpr expr\n}\n\nfunc (e *cmdExpr) String() string {\n\tif e.expr == nil {\n\t\treturn fmt.Sprintf(\"cmd %s\", e.name)\n\t}\n\treturn fmt.Sprintf(\"cmd %s %s\", e.name, e.expr)\n}\n\ntype callExpr struct {\n\tname  string\n\targs  []string\n\tcount int\n}\n\nfunc (e *callExpr) String() string {\n\treturn strings.Join(append([]string{e.name}, e.args...), \" \")\n}\n\ntype execExpr struct {\n\tprefix string\n\tvalue  string\n}\n\nfunc (e *execExpr) String() string {\n\tvar buf bytes.Buffer\n\n\tbuf.WriteString(e.prefix)\n\tbuf.WriteString(\"{{ \")\n\n\tlines := strings.Split(e.value, \"\\n\")\n\n\tfor _, line := range lines {\n\t\ttrimmed := strings.TrimSpace(line)\n\t\tif trimmed == \"\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tbuf.WriteString(trimmed)\n\n\t\tif len(lines) > 1 {\n\t\t\tbuf.WriteString(\" ...\")\n\t\t}\n\n\t\tbreak\n\t}\n\n\tbuf.WriteString(\" }}\")\n\n\treturn buf.String()\n}\n\ntype listExpr struct {\n\texprs []expr\n\tcount int\n}\n\nfunc (e *listExpr) String() string {\n\tvar buf bytes.Buffer\n\n\tbuf.WriteString(\":{{ \")\n\n\tfor _, expr := range e.exprs {\n\t\tbuf.WriteString(expr.String())\n\t\tbuf.WriteString(\"; \")\n\t}\n\n\tbuf.WriteString(\"}}\")\n\n\treturn buf.String()\n}\n\ntype parser struct {\n\tscanner *scanner\n\texpr    expr\n\terr     error\n}\n\nfunc newParser(r io.Reader) *parser {\n\tscanner := newScanner(r)\n\n\tscanner.scan()\n\n\treturn &parser{\n\t\tscanner: scanner,\n\t}\n}\n\nfunc (p *parser) parseExpr() expr {\n\ts := p.scanner\n\n\tvar result expr\n\n\tswitch s.typ {\n\tcase tokenEOF:\n\t\treturn nil\n\tcase tokenIdent:\n\t\tswitch s.tok {\n\t\tcase \"set\":\n\t\t\tvar val string\n\n\t\t\ts.scan()\n\t\t\tif s.typ != tokenIdent {\n\t\t\t\tp.err = fmt.Errorf(\"expected identifier: %s\", s.tok)\n\t\t\t}\n\t\t\topt := s.tok\n\n\t\t\ts.scan()\n\t\t\tif s.typ != tokenSemicolon {\n\t\t\t\tval = s.tok\n\t\t\t\ts.scan()\n\t\t\t}\n\n\t\t\ts.scan()\n\n\t\t\tresult = &setExpr{opt, val}\n\t\tcase \"setlocal\":\n\t\t\tvar val string\n\n\t\t\ts.scan()\n\t\t\tif s.typ != tokenIdent {\n\t\t\t\tp.err = fmt.Errorf(\"expected directory: %s\", s.tok)\n\t\t\t}\n\t\t\tdir := s.tok\n\n\t\t\ts.scan()\n\t\t\tif s.typ != tokenIdent {\n\t\t\t\tp.err = fmt.Errorf(\"expected identifier: %s\", s.tok)\n\t\t\t}\n\t\t\topt := s.tok\n\n\t\t\ts.scan()\n\t\t\tif s.typ != tokenSemicolon {\n\t\t\t\tval = s.tok\n\t\t\t\ts.scan()\n\t\t\t}\n\n\t\t\ts.scan()\n\n\t\t\tresult = &setLocalExpr{dir, opt, val}\n\t\tcase \"map\":\n\t\t\tvar expr expr\n\n\t\t\ts.scan()\n\t\t\tkeys := s.tok\n\n\t\t\ts.scan()\n\t\t\tif s.typ != tokenSemicolon {\n\t\t\t\texpr = p.parseExpr()\n\t\t\t} else {\n\t\t\t\ts.scan()\n\t\t\t}\n\n\t\t\tresult = &mapExpr{keys, expr}\n\t\tcase \"nmap\":\n\t\t\tvar expr expr\n\n\t\t\ts.scan()\n\t\t\tkeys := s.tok\n\n\t\t\ts.scan()\n\t\t\tif s.typ != tokenSemicolon {\n\t\t\t\texpr = p.parseExpr()\n\t\t\t} else {\n\t\t\t\ts.scan()\n\t\t\t}\n\n\t\t\tresult = &nmapExpr{keys, expr}\n\t\tcase \"vmap\":\n\t\t\tvar expr expr\n\n\t\t\ts.scan()\n\t\t\tkeys := s.tok\n\n\t\t\ts.scan()\n\t\t\tif s.typ != tokenSemicolon {\n\t\t\t\texpr = p.parseExpr()\n\t\t\t} else {\n\t\t\t\ts.scan()\n\t\t\t}\n\n\t\t\tresult = &vmapExpr{keys, expr}\n\t\tcase \"cmap\":\n\t\t\tvar expr expr\n\n\t\t\ts.scan()\n\t\t\tkey := s.tok\n\n\t\t\ts.scan()\n\t\t\tif s.typ != tokenSemicolon {\n\t\t\t\texpr = p.parseExpr()\n\t\t\t} else {\n\t\t\t\ts.scan()\n\t\t\t}\n\n\t\t\tresult = &cmapExpr{key, expr}\n\t\tcase \"cmd\":\n\t\t\tvar expr expr\n\n\t\t\ts.scan()\n\t\t\tname := s.tok\n\n\t\t\ts.scan()\n\t\t\tif s.typ != tokenSemicolon {\n\t\t\t\texpr = p.parseExpr()\n\t\t\t} else {\n\t\t\t\ts.scan()\n\t\t\t}\n\n\t\t\tresult = &cmdExpr{name, expr}\n\t\tdefault:\n\t\t\tname := s.tok\n\n\t\t\tvar args []string\n\t\t\tfor s.scan() && s.typ != tokenSemicolon {\n\t\t\t\targs = append(args, s.tok)\n\t\t\t}\n\n\t\t\ts.scan()\n\n\t\t\tresult = &callExpr{name, args, 1}\n\t\t}\n\tcase tokenColon:\n\t\ts.scan()\n\n\t\tvar exprs []expr\n\t\tif s.typ == tokenLBraces {\n\t\t\ts.scan()\n\t\t\tfor {\n\t\t\t\te := p.parseExpr()\n\t\t\t\tif e == nil {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\texprs = append(exprs, e)\n\t\t\t\tif s.typ == tokenRBraces {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\ts.scan()\n\t\t} else {\n\t\t\tfor {\n\t\t\t\te := p.parseExpr()\n\t\t\t\tif e == nil {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\texprs = append(exprs, e)\n\t\t\t\tif s.tok == \"\\n\" {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\ts.scan()\n\n\t\tresult = &listExpr{exprs, 1}\n\tcase tokenPrefix:\n\t\tvar expr string\n\n\t\tprefix := s.tok\n\n\t\ts.scan()\n\t\tif s.typ == tokenLBraces {\n\t\t\ts.scan()\n\t\t\texpr = s.tok\n\t\t\ts.scan()\n\t\t} else {\n\t\t\texpr = s.tok\n\t\t}\n\n\t\ts.scan()\n\t\ts.scan()\n\n\t\tresult = &execExpr{prefix, expr}\n\tdefault:\n\t\tp.err = fmt.Errorf(\"unexpected token: %s\", s.tok)\n\t}\n\n\treturn result\n}\n\nfunc (p *parser) parse() bool {\n\tp.expr = p.parseExpr()\n\treturn p.expr != nil\n}\n"
  },
  {
    "path": "ruler.go",
    "content": "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.default\nvar gDefaultRuler string\n\ntype statData struct {\n\tPath        string\n\tName        string\n\tExtension   string\n\tSize        int64\n\tDirSize     int64\n\tDirCount    int\n\tPermissions string\n\tModTime     string\n\tAccessTime  string\n\tBirthTime   string\n\tChangeTime  string\n\tLinkCount   string\n\tUser        string\n\tGroup       string\n\tTarget      string\n\tCustomInfo  string\n}\n\ntype rulerData struct {\n\tSPACER           string\n\tMessage          string\n\tKeys             string\n\tProgress         []string\n\tCopy             []string\n\tCut              []string\n\tSelect           []string\n\tVisual           []string\n\tIndex            int\n\tTotal            int\n\tHidden           int\n\tAll              int\n\tLinePercentage   string\n\tScrollPercentage string\n\tFilter           []string\n\tMode             string\n\tOptions          map[string]string\n\tUserOptions      map[string]string\n\tStat             *statData\n}\n\nfunc parseRuler(path string) (*template.Template, error) {\n\tfuncs := template.FuncMap{\n\t\t\"df\":       func() string { return diskFree(\".\") },\n\t\t\"env\":      os.Getenv,\n\t\t\"humanize\": humanize,\n\t\t\"join\":     strings.Join,\n\t\t\"lower\":    strings.ToLower,\n\t\t\"substr\":   func(s string, start, length int) string { return string([]rune(s)[start : start+length]) },\n\t\t\"upper\":    strings.ToUpper,\n\t}\n\n\tif path == \"\" {\n\t\treturn template.New(\"ruler\").Funcs(funcs).Parse(gDefaultRuler)\n\t}\n\n\treturn template.New(filepath.Base(path)).Funcs(funcs).ParseFiles(path)\n}\n\nfunc renderRuler(ruler *template.Template, data rulerData, width int) (string, string, error) {\n\tvar b strings.Builder\n\tif err := ruler.Execute(&b, data); err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\n\ts := strings.ReplaceAll(b.String(), \"\\n\", \"\")\n\tsections := strings.Split(s, \"\\x1f\")\n\n\tif len(sections) == 1 {\n\t\treturn s, \"\", nil\n\t}\n\n\twtot := 0\n\tfor _, section := range sections {\n\t\twtot += printLength(section)\n\t}\n\n\tif wtot > width {\n\t\treturn sections[0], strings.Join(sections[1:], \"\"), nil\n\t}\n\n\twspacer := max(width-wtot, 0) / (len(sections) - 1)\n\twspacerLast := max(width-wtot-wspacer*(len(sections)-2), 0)\n\n\tb.Reset()\n\tfor i, section := range sections {\n\t\tswitch i {\n\t\tcase 0:\n\t\t\tb.WriteString(section)\n\t\tcase len(sections) - 1:\n\t\t\tfmt.Fprintf(&b, \"%*s%s\", wspacerLast, \"\", section)\n\t\tdefault:\n\t\t\tfmt.Fprintf(&b, \"%*s%s\", wspacer, \"\", section)\n\t\t}\n\t}\n\n\treturn b.String(), \"\", nil\n}\n"
  },
  {
    "path": "scan.go",
    "content": "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 explicit keyword type\n\ttokenIdent     // e.g. set, ratios, 1:2:3\n\ttokenColon     // :\n\ttokenPrefix    // $, %, !, &\n\ttokenLBraces   // {{\n\ttokenRBraces   // }}\n\ttokenCommand   // in between a prefix to \\n or between {{ and }}\n\ttokenSemicolon // ;\n\t// comments are stripped\n)\n\ntype scanner struct {\n\tbuf []byte    // input buffer\n\toff int       // current offset in buf\n\tchr byte      // current character in buf\n\tsem bool      // insert semicolon\n\tnln bool      // insert newline\n\teof bool      // buffer ended\n\tkey bool      // scanning keys\n\tblk bool      // scanning block\n\tcmd bool      // scanning command\n\ttyp tokenType // scanned token type\n\ttok string    // scanned token value\n\t// TODO: pos\n}\n\nfunc newScanner(r io.Reader) *scanner {\n\tbuf, err := io.ReadAll(r)\n\tif err != nil {\n\t\tlog.Printf(\"scanning: %s\", err)\n\t}\n\n\tvar eof bool\n\tvar chr byte\n\n\tif len(buf) == 0 {\n\t\teof = true\n\t} else {\n\t\teof = false\n\t\tchr = buf[0]\n\t}\n\n\treturn &scanner{\n\t\tbuf: buf,\n\t\teof: eof,\n\t\tchr: chr,\n\t}\n}\n\nfunc (s *scanner) next() {\n\tif s.off+1 < len(s.buf) {\n\t\ts.off++\n\t\ts.chr = s.buf[s.off]\n\t\treturn\n\t}\n\n\ts.off = len(s.buf)\n\ts.chr = 0\n\ts.eof = true\n}\n\nfunc (s *scanner) peek() byte {\n\tif s.off+1 < len(s.buf) {\n\t\treturn s.buf[s.off+1]\n\t}\n\n\treturn 0\n}\n\nfunc isSpace(b byte) bool {\n\tswitch b {\n\tcase '\\t', '\\n', '\\v', '\\f', '\\r', ' ':\n\t\treturn true\n\t}\n\treturn false\n}\n\nfunc isDigit(b byte) bool {\n\treturn '0' <= b && b <= '9'\n}\n\nfunc isPrefix(b byte) bool {\n\tswitch b {\n\tcase '$', '%', '!', '&':\n\t\treturn true\n\t}\n\treturn false\n}\n\nfunc (s *scanner) scan() bool {\nscan:\n\tswitch {\n\tcase s.eof:\n\t\ts.next()\n\t\tif s.sem {\n\t\t\ts.typ = tokenSemicolon\n\t\t\ts.tok = \"\\n\"\n\t\t\ts.sem = false\n\t\t\treturn true\n\t\t}\n\t\tif s.nln {\n\t\t\ts.typ = tokenSemicolon\n\t\t\ts.tok = \"\\n\"\n\t\t\ts.nln = false\n\t\t\treturn true\n\t\t}\n\t\ts.typ = tokenEOF\n\t\ts.tok = \"EOF\"\n\t\treturn false\n\tcase s.key:\n\t\tbeg := s.off\n\t\tfor !s.eof && !isSpace(s.chr) {\n\t\t\ts.next()\n\t\t}\n\t\ts.typ = tokenIdent\n\t\ts.tok = string(s.buf[beg:s.off])\n\t\ts.key = false\n\tcase s.blk:\n\t\t// return here by setting s.cmd to false\n\t\t// after scanning the command in the loop below\n\t\tif !s.cmd {\n\t\t\ts.next()\n\t\t\ts.next()\n\t\t\ts.typ = tokenRBraces\n\t\t\ts.tok = \"}}\"\n\t\t\ts.blk = false\n\t\t\ts.sem = true\n\t\t\treturn true\n\t\t}\n\n\t\tbeg := s.off\n\n\t\tfor !s.eof {\n\t\t\ts.next()\n\t\t\tif s.chr == '}' {\n\t\t\t\tif !s.eof && s.peek() == '}' {\n\t\t\t\t\ts.typ = tokenCommand\n\t\t\t\t\ts.tok = string(s.buf[beg:s.off])\n\t\t\t\t\ts.cmd = false\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\ts.typ = tokenEOF\n\t\ts.tok = \"EOF\"\n\t\treturn false\n\tcase s.cmd:\n\t\tfor !s.eof && isSpace(s.chr) {\n\t\t\ts.next()\n\t\t}\n\n\t\tif !s.eof && s.chr == '{' {\n\t\t\tif s.peek() == '{' {\n\t\t\t\ts.next()\n\t\t\t\ts.next()\n\t\t\t\ts.typ = tokenLBraces\n\t\t\t\ts.tok = \"{{\"\n\t\t\t\ts.blk = true\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\n\t\tbeg := s.off\n\n\t\tfor !s.eof && s.chr != '\\n' {\n\t\t\ts.next()\n\t\t}\n\n\t\ts.typ = tokenCommand\n\t\ts.tok = string(s.buf[beg:s.off])\n\t\ts.cmd = false\n\t\ts.sem = true\n\tcase s.chr == '\\n':\n\t\tif s.sem {\n\t\t\ts.typ = tokenSemicolon\n\t\t\ts.tok = \"\\n\"\n\t\t\ts.sem = false\n\t\t\treturn true\n\t\t}\n\t\ts.next()\n\t\tif s.nln {\n\t\t\ts.typ = tokenSemicolon\n\t\t\ts.tok = \"\\n\"\n\t\t\ts.nln = false\n\t\t\treturn true\n\t\t}\n\t\tgoto scan\n\tcase isSpace(s.chr):\n\t\tfor !s.eof && isSpace(s.chr) && s.chr != '\\n' {\n\t\t\ts.next()\n\t\t}\n\t\tgoto scan\n\tcase s.chr == ';':\n\t\ts.typ = tokenSemicolon\n\t\ts.tok = \";\"\n\t\ts.sem = false\n\t\ts.next()\n\tcase s.chr == '#':\n\t\tfor !s.eof && s.chr != '\\n' {\n\t\t\ts.next()\n\t\t}\n\t\tgoto scan\n\tcase s.chr == '\"':\n\t\ts.next()\n\t\tvar buf []byte\n\t\tfor !s.eof && s.chr != '\"' {\n\t\t\tif s.chr == '\\\\' {\n\t\t\t\ts.next()\n\t\t\t\tswitch {\n\t\t\t\tcase s.chr == '\"' || s.chr == '\\\\':\n\t\t\t\t\tbuf = append(buf, s.chr)\n\t\t\t\tcase s.chr == 'a':\n\t\t\t\t\tbuf = append(buf, '\\a')\n\t\t\t\tcase s.chr == 'b':\n\t\t\t\t\tbuf = append(buf, '\\b')\n\t\t\t\tcase s.chr == 'f':\n\t\t\t\t\tbuf = append(buf, '\\f')\n\t\t\t\tcase s.chr == 'n':\n\t\t\t\t\tbuf = append(buf, '\\n')\n\t\t\t\tcase s.chr == 'r':\n\t\t\t\t\tbuf = append(buf, '\\r')\n\t\t\t\tcase s.chr == 't':\n\t\t\t\t\tbuf = append(buf, '\\t')\n\t\t\t\tcase s.chr == 'v':\n\t\t\t\t\tbuf = append(buf, '\\v')\n\t\t\t\tcase isDigit(s.chr):\n\t\t\t\t\tvar oct []byte\n\t\t\t\t\tfor isDigit(s.chr) {\n\t\t\t\t\t\toct = append(oct, s.chr)\n\t\t\t\t\t\ts.next()\n\t\t\t\t\t}\n\t\t\t\t\tn, err := strconv.ParseInt(string(oct), 8, 0)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tlog.Printf(\"scanning: %s\", err)\n\t\t\t\t\t}\n\t\t\t\t\tbuf = append(buf, byte(n))\n\t\t\t\t\tcontinue\n\t\t\t\tdefault:\n\t\t\t\t\tbuf = append(buf, '\\\\', s.chr)\n\t\t\t\t}\n\t\t\t\ts.next()\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tbuf = append(buf, s.chr)\n\t\t\ts.next()\n\t\t}\n\t\ts.typ = tokenIdent\n\t\ts.tok = string(buf)\n\t\ts.next()\n\tcase s.chr == '\\'':\n\t\ts.next()\n\t\tbeg := s.off\n\t\tfor !s.eof && s.chr != '\\'' {\n\t\t\ts.next()\n\t\t}\n\t\ts.typ = tokenIdent\n\t\ts.tok = string(s.buf[beg:s.off])\n\t\ts.next()\n\tcase s.chr == ':':\n\t\ts.typ = tokenColon\n\t\ts.tok = \":\"\n\t\ts.nln = true\n\t\ts.next()\n\tcase s.chr == '{' && s.peek() == '{':\n\t\ts.next()\n\t\ts.next()\n\t\ts.typ = tokenLBraces\n\t\ts.tok = \"{{\"\n\t\ts.sem = false\n\t\ts.nln = false\n\tcase s.chr == '}' && s.peek() == '}':\n\t\ts.next()\n\t\ts.next()\n\t\ts.typ = tokenRBraces\n\t\ts.tok = \"}}\"\n\t\ts.sem = true\n\tcase isPrefix(s.chr):\n\t\ts.typ = tokenPrefix\n\t\ts.tok = string(s.chr)\n\t\ts.cmd = true\n\t\ts.next()\n\tdefault:\n\t\tvar buf []byte\n\t\tfor !s.eof && !isSpace(s.chr) && s.chr != ';' && s.chr != '#' {\n\t\t\tif s.chr == '\\\\' {\n\t\t\t\ts.next()\n\t\t\t\tbuf = append(buf, s.chr)\n\t\t\t\ts.next()\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tbuf = append(buf, s.chr)\n\t\t\ts.next()\n\t\t}\n\n\t\ts.typ = tokenIdent\n\t\ts.tok = string(buf)\n\t\ts.sem = true\n\n\t\tif s.tok == \"push\" {\n\t\t\ts.key = true\n\t\t\tfor !s.eof && isSpace(s.chr) && s.chr != '\\n' {\n\t\t\t\ts.next()\n\t\t\t}\n\t\t}\n\t}\n\n\treturn true\n}\n"
  },
  {
    "path": "server.go",
    "content": "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.Conn)\n\tgQuitChan = make(chan struct{}, 1)\n\tgListener net.Listener\n)\n\nfunc serve() {\n\tif gLogPath != \"\" {\n\t\tf, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600)\n\t\tif err != nil {\n\t\t\tlog.Fatalf(\"failed to open log file: %s\", err)\n\t\t}\n\t\tdefer f.Close()\n\t\tlog.SetOutput(f)\n\t}\n\n\tlog.Print(\"*************** starting server ***************\")\n\n\tif gSocketProt == \"unix\" {\n\t\tsetUserUmask()\n\t}\n\n\tl, err := net.Listen(gSocketProt, gSocketPath)\n\tif err != nil {\n\t\tlog.Printf(\"listening socket: %s\", err)\n\t\treturn\n\t}\n\tdefer l.Close()\n\n\tgListener = l\n\n\tlisten(l)\n}\n\nfunc listen(l net.Listener) {\n\tfor {\n\t\tc, err := l.Accept()\n\t\tif err != nil {\n\t\t\tselect {\n\t\t\tcase <-gQuitChan:\n\t\t\t\tlog.Print(\"*************** closing server ***************\")\n\t\t\t\treturn\n\t\t\tdefault:\n\t\t\t\tlog.Printf(\"accepting connection: %s\", err)\n\t\t\t}\n\t\t}\n\t\tgo handleConn(c)\n\t}\n}\n\nfunc echoerr(c net.Conn, msg string) {\n\tfmt.Fprintln(c, msg)\n\tlog.Print(msg)\n}\n\nfunc echoerrf(c net.Conn, format string, a ...any) {\n\techoerr(c, fmt.Sprintf(format, a...))\n}\n\nfunc handleConn(c net.Conn) {\n\ts := bufio.NewScanner(c)\n\nLoop:\n\tfor s.Scan() {\n\t\tlog.Printf(\"listen: %s\", s.Text())\n\t\tword, rest := splitWord(s.Text())\n\t\tswitch word {\n\t\tcase \"conn\":\n\t\t\tif rest != \"\" {\n\t\t\t\tword2, _ := splitWord(rest)\n\t\t\t\tid, err := strconv.Atoi(word2)\n\t\t\t\tif err != nil {\n\t\t\t\t\techoerr(c, \"listen: conn: client id should be a number\")\n\t\t\t\t} else {\n\t\t\t\t\t// lifetime of the connection is managed by the server and\n\t\t\t\t\t// will be cleaned up via the `drop` command\n\t\t\t\t\tgConnList[id] = c\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\techoerr(c, \"listen: conn: requires a client id\")\n\t\t\t}\n\t\tcase \"drop\":\n\t\t\tif rest != \"\" {\n\t\t\t\tword2, _ := splitWord(rest)\n\t\t\t\tid, err := strconv.Atoi(word2)\n\t\t\t\tif err != nil {\n\t\t\t\t\techoerr(c, \"listen: drop: client id should be a number\")\n\t\t\t\t} else {\n\t\t\t\t\tif c2, ok := gConnList[id]; ok {\n\t\t\t\t\t\tc2.Close()\n\t\t\t\t\t}\n\t\t\t\t\tdelete(gConnList, id)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\techoerr(c, \"listen: drop: requires a client id\")\n\t\t\t}\n\t\tcase \"list\":\n\t\t\tids := make([]int, 0, len(gConnList))\n\t\t\tfor id := range gConnList {\n\t\t\t\tids = append(ids, id)\n\t\t\t}\n\t\t\tsort.Ints(ids)\n\t\t\tfor _, id := range ids {\n\t\t\t\tfmt.Fprintln(c, id)\n\t\t\t}\n\t\tcase \"send\":\n\t\t\tif rest != \"\" {\n\t\t\t\tword2, rest2 := splitWord(rest)\n\t\t\t\tid, err := strconv.Atoi(word2)\n\t\t\t\tif err != nil {\n\t\t\t\t\tfor id, c2 := range gConnList {\n\t\t\t\t\t\tif _, err := fmt.Fprintln(c2, rest); err != nil {\n\t\t\t\t\t\t\techoerrf(c, \"failed to send command to client %v: %s\", id, err)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif c2, ok := gConnList[id]; ok {\n\t\t\t\t\t\tif _, err := fmt.Fprintln(c2, rest2); err != nil {\n\t\t\t\t\t\t\techoerrf(c, \"failed to send command to client %v: %s\", id, err)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\techoerr(c, \"listen: send: no such client id is connected\")\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tcase \"query\":\n\t\t\tif rest == \"\" {\n\t\t\t\techoerr(c, \"listen: query: requires a client id\")\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tword2, rest2 := splitWord(rest)\n\t\t\tid, err := strconv.Atoi(word2)\n\t\t\tif err != nil {\n\t\t\t\techoerr(c, \"listen: query: client id should be a number\")\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tc2, ok := gConnList[id]\n\t\t\tif !ok {\n\t\t\t\techoerr(c, \"listen: query: no such client id is connected\")\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tif _, err := fmt.Fprintln(c2, \"query \"+rest2); err != nil {\n\t\t\t\techoerrf(c, \"failed to send query to client %v: %s\", id, err)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\ts2 := bufio.NewScanner(c2)\n\t\t\tfor s2.Scan() && s2.Text() != \"\" {\n\t\t\t\tif _, err := fmt.Fprintln(c, s2.Text()); err != nil {\n\t\t\t\t\tlog.Printf(\"failed to forward query response from client %v: %s\", id, err)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif s2.Err() != nil {\n\t\t\t\techoerrf(c, \"failed to read query response from client %v: %s\", id, s2.Err())\n\t\t\t}\n\t\tcase \"quit\":\n\t\t\tif len(gConnList) == 0 {\n\t\t\t\tgQuitChan <- struct{}{}\n\t\t\t\tgListener.Close()\n\t\t\t\tbreak Loop\n\t\t\t}\n\t\tcase \"quit!\":\n\t\t\tgQuitChan <- struct{}{}\n\t\t\tfor _, c := range gConnList {\n\t\t\t\tfmt.Fprintln(c, \"echo server is quitting...\")\n\t\t\t\tc.Close()\n\t\t\t}\n\t\t\tgListener.Close()\n\t\t\tbreak Loop\n\t\tdefault:\n\t\t\techoerrf(c, \"listen: unexpected command: %s\", word)\n\t\t}\n\t}\n\n\tif s.Err() != nil {\n\t\techoerrf(c, \"listening: %s\", s.Err())\n\t}\n\n\tc.Close()\n}\n"
  },
  {
    "path": "sixel.go",
    "content": "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 sixelScreen struct {\n\tlastFile   string\n\tlastWin    win\n\tforceClear bool\n}\n\nfunc (sxs *sixelScreen) clearSixel(win *win, screen tcell.Screen, filePath string) {\n\tif sxs.lastFile != \"\" && (filePath != sxs.lastFile || *win != sxs.lastWin || sxs.forceClear) {\n\t\tscreen.LockRegion(sxs.lastWin.x, sxs.lastWin.y, sxs.lastWin.w, sxs.lastWin.h, false)\n\t}\n}\n\nfunc (sxs *sixelScreen) printSixel(win *win, screen tcell.Screen, reg *reg) {\n\tif reg.path == sxs.lastFile && *win == sxs.lastWin && !sxs.forceClear {\n\t\treturn\n\t}\n\n\tcw, ch, err := cellSize(screen)\n\tif err != nil {\n\t\tlog.Printf(\"sixel: %s\", err)\n\t\treturn\n\t}\n\n\ty := win.y\n\tvar b strings.Builder\n\n\tfor _, line := range reg.lines {\n\t\tif !strings.HasPrefix(line, \"\\033P\") {\n\t\t\tif y >= win.y+win.h {\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tscreen.LockRegion(win.x, y, printLength(line), 1, true)\n\t\t\tfmt.Fprintf(&b, \"\\033[%d;%dH\", y+1, win.x+1)\n\t\t\tb.WriteString(line)\n\t\t\ty++\n\t\t\tcontinue\n\t\t}\n\n\t\tmatches := reSixelSize.FindStringSubmatch(line)\n\t\tif matches == nil {\n\t\t\tlog.Print(\"sixel: failed to get image size\")\n\t\t\tcontinue\n\t\t}\n\n\t\tiw, _ := strconv.Atoi(matches[1])\n\t\tih, _ := strconv.Atoi(matches[2])\n\n\t\tif os.Getenv(\"TMUX\") != \"\" {\n\t\t\t// tmux rounds the image height up to a multiple of 6, so we\n\t\t\t// need to do the same to avoid overwriting the image, as tmux\n\t\t\t// would remove the image if we touched it.\n\t\t\tih = (ih + 5) / 6 * 6\n\t\t}\n\n\t\tsw := (iw + cw - 1) / cw\n\t\tsh := (ih + ch - 1) / ch\n\n\t\tif y+sh-1 >= win.y+win.h {\n\t\t\tbreak\n\t\t}\n\n\t\tscreen.LockRegion(win.x, y, sw, sh, true)\n\t\tfmt.Fprintf(&b, \"\\033[%d;%dH\", y+1, win.x+1)\n\t\tb.WriteString(line)\n\t\ty += sh\n\t}\n\n\tfmt.Fprint(os.Stderr, \"\\033[?2026h\") // Begin synchronized update\n\tfmt.Fprint(os.Stderr, \"\\0337\")       // Save cursor position\n\tfmt.Fprint(os.Stderr, b.String())    // Write data\n\tfmt.Fprint(os.Stderr, \"\\0338\")       // Restore cursor position\n\tfmt.Fprint(os.Stderr, \"\\033[?2026l\") // End synchronized update\n\n\tsxs.lastFile = reg.path\n\tsxs.lastWin = *win\n\tsxs.forceClear = false\n}\n\nfunc cellSize(screen tcell.Screen) (int, int, error) {\n\ttty, ok := screen.Tty()\n\tif !ok {\n\t\t// fallback for Windows Terminal\n\t\treturn 10, 20, nil\n\t}\n\n\tws, err := tty.WindowSize()\n\tif err != nil {\n\t\treturn -1, -1, fmt.Errorf(\"failed to get window size: %w\", err)\n\t}\n\n\tcw, ch := ws.CellDimensions()\n\tif cw <= 0 || ch <= 0 {\n\t\treturn -1, -1, errors.New(\"cell dimensions should be greater than 0\")\n\t}\n\n\treturn cw, ch, nil\n}\n"
  },
  {
    "path": "termseq.go",
    "content": "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 the byte that starts ANSI control sequences.\nconst gEscapeCode byte = '\\x1b'\n\n// stripTermSequence is used to remove style-related ANSI escape sequences from\n// a given string.\n//\n// Note: this function is based on [printLength] and only strips style-related\n// sequences, `erase in line`, and `OSC 8` sequences. Other codes (e.g. cursor\n// moves), as well as broken escape sequences, are not removed. This prevents\n// mismatches between the two functions and avoids misalignment when rendering\n// the UI.\nfunc stripTermSequence(s string) string {\n\tvar b strings.Builder\n\tslen := len(s)\n\tfor i := 0; i < slen; {\n\t\tseq := readTermSequence(s[i:])\n\t\tif seq != \"\" {\n\t\t\ti += len(seq) // skip known sequence\n\t\t\tcontinue\n\t\t}\n\n\t\tr, w := utf8.DecodeRuneInString(s[i:])\n\t\ti += w\n\t\tb.WriteRune(r)\n\t}\n\n\treturn b.String()\n}\n\n// readTermSequence is used to extract and return a terminal sequence from a\n// given string. If no supported sequence could be found, an empty string is\n// returned.\n//\n// CSI (Control Sequence Introducer):\n//   - SGR (Select Graphic Rendition) `m`, used for text styling\n//   - EL (Erase in Line) `K`, returned only so we can skip it\n//\n// OSC (Operating System Command):\n//   - OSC 8, hyperlinks\nfunc readTermSequence(s string) string {\n\tslen := len(s)\n\t// must start with ESC\n\tif slen < 2 || s[0] != gEscapeCode {\n\t\treturn \"\"\n\t}\n\n\tswitch s[1] {\n\tcase '[': // CSI\n\t\ti := strings.IndexAny(s[:min(slen, 64)], \"mK\")\n\t\tif i == -1 {\n\t\t\treturn \"\"\n\t\t}\n\t\treturn s[:i+1]\n\tcase ']': // OSC\n\t\tif slen < 4 || s[2] != '8' || s[3] != ';' {\n\t\t\treturn \"\"\n\t\t}\n\t\t// find string terminator\n\t\tfor i := 4; i < slen; i++ {\n\t\t\tb := s[i]\n\t\t\t// BEL (XTerm)\n\t\t\tif b == 0x07 {\n\t\t\t\treturn s[:i+1]\n\t\t\t}\n\t\t\t// ESC\\ (ECMA-48)\n\t\t\tif b == gEscapeCode && i+1 < slen && s[i+1] == '\\\\' {\n\t\t\t\treturn s[:i+2]\n\t\t\t}\n\t\t}\n\t\t// TODO: C1 forms?\n\t\treturn \"\"\n\tdefault:\n\t\treturn \"\"\n\t}\n}\n\n// optionToFmtstr takes an escape sequence option (e.g. `\\033[1m`) and outputs\n// a complete format string (e.g. `\\033[1m%s\\033[0m`).\nfunc optionToFmtstr(optstr string) string {\n\tif !strings.Contains(optstr, \"%s\") {\n\t\treturn optstr + \"%s\\033[0m\"\n\t} else {\n\t\treturn optstr\n\t}\n}\n\n// parseEscapeSequence takes an escape sequence option (e.g. `\\033[1m`) and\n// converts it to a [tcell.Style] object.\n// Legacy function that only accepts SGR. Kept for convenience.\nfunc parseEscapeSequence(s string) tcell.Style {\n\ts = strings.TrimPrefix(s, \"\\033[\")\n\tif i := strings.IndexByte(s, 'm'); i >= 0 {\n\t\ts = s[:i]\n\t}\n\treturn applySGR(s, tcell.StyleDefault)\n}\n\n// applyTermSequence takes an escape sequence (e.g. `\\033[1m`) and applies it\n// to the given [tcell.Style] object.\n// Accepts SGR and OSC sequences.\nfunc applyTermSequence(s string, st tcell.Style) tcell.Style {\n\tslen := len(s)\n\tif slen < 2 || s[0] != gEscapeCode {\n\t\treturn st\n\t}\n\tswitch s[1] {\n\tcase '[':\n\t\tif s[slen-1] == 'm' {\n\t\t\treturn applySGR(s[2:slen-1], st)\n\t\t}\n\t\treturn st\n\tcase ']':\n\t\t// trim terminator (BEL or ESC\\), then parse body\n\t\tif s[slen-1] == 0x07 {\n\t\t\treturn applyOSC(s[2:slen-1], st)\n\t\t} else if slen >= 2 && s[slen-2] == gEscapeCode && s[slen-1] == '\\\\' {\n\t\t\treturn applyOSC(s[2:slen-2], st)\n\t\t}\n\t\treturn st\n\tdefault:\n\t\treturn st\n\t}\n}\n\n// applySGR takes an SGR sequence and applies it to the given [tcell.Style]\n// object.\nfunc applySGR(s string, st tcell.Style) tcell.Style {\n\ttoks := strings.Split(s, \";\")\n\n\t// ECMA-48 details the standard\n\ttokslen := len(toks)\n\nloop:\n\tfor i := 0; i < tokslen; i++ {\n\t\tswitch strings.TrimLeft(toks[i], \"0\") {\n\t\tcase \"\":\n\t\t\tst = tcell.StyleDefault\n\t\tcase \"1\":\n\t\t\tst = st.Bold(true)\n\t\tcase \"2\":\n\t\t\tst = st.Dim(true)\n\t\tcase \"3\":\n\t\t\tst = st.Italic(true)\n\t\tcase \"4:0\":\n\t\t\tst = st.Underline(false)\n\t\tcase \"4\", \"4:1\":\n\t\t\tst = st.Underline(true)\n\t\tcase \"4:2\":\n\t\t\tst = st.Underline(tcell.UnderlineStyleDouble)\n\t\tcase \"4:3\":\n\t\t\tst = st.Underline(tcell.UnderlineStyleCurly)\n\t\tcase \"4:4\":\n\t\t\tst = st.Underline(tcell.UnderlineStyleDotted)\n\t\tcase \"4:5\":\n\t\t\tst = st.Underline(tcell.UnderlineStyleDashed)\n\t\tcase \"5\", \"6\":\n\t\t\tst = st.Blink(true)\n\t\tcase \"7\":\n\t\t\tst = st.Reverse(true)\n\t\tcase \"8\":\n\t\t\t// TODO: tcell PR for proper conceal\n\t\t\tst = st.Foreground(st.GetBackground())\n\t\tcase \"9\":\n\t\t\tst = st.StrikeThrough(true)\n\t\tcase \"22\":\n\t\t\tst = st.Bold(false).Dim(false)\n\t\tcase \"23\":\n\t\t\tst = st.Italic(false)\n\t\tcase \"24\":\n\t\t\tst = st.Underline(false)\n\t\tcase \"25\":\n\t\t\tst = st.Blink(false)\n\t\tcase \"27\":\n\t\t\tst = st.Reverse(false)\n\t\tcase \"29\":\n\t\t\tst = st.StrikeThrough(false)\n\t\tcase \"30\", \"31\", \"32\", \"33\", \"34\", \"35\", \"36\", \"37\":\n\t\t\tn, _ := strconv.Atoi(toks[i])\n\t\t\tst = st.Foreground(tcell.PaletteColor(n - 30))\n\t\tcase \"90\", \"91\", \"92\", \"93\", \"94\", \"95\", \"96\", \"97\":\n\t\t\tn, _ := strconv.Atoi(toks[i])\n\t\t\tst = st.Foreground(tcell.PaletteColor(n - 82))\n\t\tcase \"38\":\n\t\t\tcolor, offset, err := parseColor(toks[i+1:])\n\t\t\tif err != nil {\n\t\t\t\tlog.Printf(\"error processing ansi code 38: %s\", err)\n\t\t\t\tbreak loop\n\t\t\t}\n\t\t\tst = st.Foreground(color)\n\t\t\ti += offset\n\t\tcase \"40\", \"41\", \"42\", \"43\", \"44\", \"45\", \"46\", \"47\":\n\t\t\tn, _ := strconv.Atoi(toks[i])\n\t\t\tst = st.Background(tcell.PaletteColor(n - 40))\n\t\tcase \"100\", \"101\", \"102\", \"103\", \"104\", \"105\", \"106\", \"107\":\n\t\t\tn, _ := strconv.Atoi(toks[i])\n\t\t\tst = st.Background(tcell.PaletteColor(n - 92))\n\t\tcase \"48\":\n\t\t\tcolor, offset, err := parseColor(toks[i+1:])\n\t\t\tif err != nil {\n\t\t\t\tlog.Printf(\"error processing ansi code 48: %s\", err)\n\t\t\t\tbreak loop\n\t\t\t}\n\t\t\tst = st.Background(color)\n\t\t\ti += offset\n\t\tcase \"58\":\n\t\t\tcolor, offset, err := parseColor(toks[i+1:])\n\t\t\tif err != nil {\n\t\t\t\tlog.Printf(\"error processing ansi code 58: %s\", err)\n\t\t\t\tbreak loop\n\t\t\t}\n\t\t\tst = st.Underline(color)\n\t\t\ti += offset\n\t\tdefault:\n\t\t\tlog.Printf(\"unknown ansi code: %s\", toks[i])\n\t\t}\n\t}\n\n\treturn st\n}\n\n// applyOSC takes an OSC sequence and applies it to the given [tcell.Style]\n// object.\n// It currently supports OSC 8 hyperlinks only, implemented as specified by\n// https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda.\nfunc applyOSC(body string, st tcell.Style) tcell.Style {\n\textractID := func(params string) string {\n\t\tfor seg := range strings.SplitSeq(params, \":\") {\n\t\t\tif seg == \"\" {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif k, v, ok := strings.Cut(seg, \"=\"); ok && k == \"id\" {\n\t\t\t\treturn v\n\t\t\t}\n\t\t}\n\t\treturn \"\"\n\t}\n\n\ttoks := strings.SplitN(body, \";\", 3)\n\tif len(toks) < 2 {\n\t\treturn st\n\t}\n\tswitch toks[0] {\n\tcase \"8\":\n\t\tif len(toks) < 3 {\n\t\t\treturn st\n\t\t}\n\t\turl := toks[2]\n\t\tif url == \"\" {\n\t\t\treturn st\n\t\t}\n\n\t\tst = st.Url(url)\n\t\t// Optional property used to identify grouped hyperlinks.\n\t\tif id := extractID(toks[1]); id != \"\" {\n\t\t\tst = st.UrlId(id)\n\t\t}\n\t\treturn st\n\tdefault:\n\t\treturn st\n\t}\n}\n"
  },
  {
    "path": "termseq_test.go",
    "content": "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\nfunc TestStripTermSequence(t *testing.T) {\n\ttests := []struct {\n\t\ts   string\n\t\texp string\n\t}{\n\t\t{\"\", \"\"},                      // empty\n\t\t{\"foo bar\", \"foo bar\"},        // plain text\n\t\t{\"\\033[31mRed\\033[0m\", \"Red\"}, // octal syntax\n\t\t{\"\\x1b[31mRed\\x1b[0m\", \"Red\"}, // hexadecimal syntax\n\t\t{\"foo\\x1b[31mRed\", \"fooRed\"},  // no reset parameter\n\t\t{\n\t\t\t\"foo\\x1b[1;31;102mBoldRedGreen\\x1b[0mbar\",\n\t\t\t\"fooBoldRedGreenbar\",\n\t\t}, // multiple attributes\n\t\t{\n\t\t\t\"misc.go:func \\x1b[01;31m\\x1b[KstripTermSequence\\x1b[m\\x1b[K(s string) string {\",\n\t\t\t\"misc.go:func stripTermSequence(s string) string {\",\n\t\t}, // `grep` output containing `erase in line` sequence\n\n\t\t// OSC 8 hyperlinks\n\t\t{\n\t\t\t\"\\x1b]8;;https://example.com\\x1b\\\\example.com\\x1b]8;;\\x1b\\\\\",\n\t\t\t\"example.com\",\n\t\t}, // open/close with ST (ESC\\)\n\t\t{\n\t\t\t\"\\x1b]8;;https://example.com\\x07example.com\\x1b]8;;\\x07\",\n\t\t\t\"example.com\",\n\t\t}, // open/close with BEL\n\t\t{\n\t\t\t\"\\x1b]8;id=42;https://example.com\\x1b\\\\label\\x1b]8;;\\x1b\\\\\",\n\t\t\t\"label\",\n\t\t}, // params present\n\t\t{\n\t\t\t\"\\x1b]8;;https://example.com\\x1b\\\\example.com\",\n\t\t\t\"example.com\",\n\t\t}, // open without close\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := stripTermSequence(test.s); got != test.exp {\n\t\t\tt.Errorf(\"at input %q expected %q but got %q\", test.s, test.exp, got)\n\t\t}\n\t\t// we rely on both functions extracting the same runes\n\t\t// to avoid misalignment\n\t\tif printLength(test.s) != len(stripTermSequence(test.s)) {\n\t\t\tt.Errorf(\"at input %q expected '%d' but got '%d'\", test.s, printLength(test.s), len(stripTermSequence(test.s)))\n\t\t}\n\t}\n}\n\nfunc TestReadTermSequence(t *testing.T) {\n\ttests := []struct {\n\t\ts, exp string\n\t}{\n\t\t{\"\", \"\"},        // empty\n\t\t{\"foo bar\", \"\"}, // plain text\n\t\t{\"\\x1b\", \"\"},    // lone ESC\n\t\t{\"\\x1bX\", \"\"},   // unknown ESC sequence\n\n\t\t{\"\\x1b[31m\", \"\\x1b[31m\"},     // CSI SGR\n\t\t{\"\\x1b[K\", \"\\x1b[K\"},         // CSI EL\n\t\t{\"\\x1b[1;31m\", \"\\x1b[1;31m\"}, // CSI SGR (multiple params)\n\t\t{\"\\x1b[31\", \"\"},              // CSI incomplete (no terminator)\n\t\t{\"foo\\x1b[31m\", \"\"},          // doesn't start with ESC\n\n\t\t{\"\\x1b]8;;https://example.com\\x1b\\\\\", \"\\x1b]8;;https://example.com\\x1b\\\\\"}, // OSC 8 (ST terminator)\n\t\t{\"\\x1b]8;;https://example.com\\x07\", \"\\x1b]8;;https://example.com\\x07\"},     // OSC 8 (BEL terminator)\n\t\t{\"\\x1b]0;title\\x07\", \"\"}, // non-OSC8 OSC (ignored)\n\t}\n\n\tfor _, tc := range tests {\n\t\tif got := readTermSequence(tc.s); got != tc.exp {\n\t\t\tt.Errorf(\"input %q: got %q, want %q\", tc.s, got, tc.exp)\n\t\t}\n\t}\n}\n\nfunc TestOptionToFmtstr(t *testing.T) {\n\ttests := []struct {\n\t\ts   string\n\t\texp string\n\t}{\n\t\t{\"\\033[1m\", \"\\033[1m%s\\033[0m\"},\n\t\t{\"\\033[1;7;31;42m\", \"\\033[1;7;31;42m%s\\033[0m\"},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := optionToFmtstr(test.s); got != test.exp {\n\t\t\tt.Errorf(\"at input %q expected %q but got %q\", test.s, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestParseEscapeSequence(t *testing.T) {\n\ttests := []struct {\n\t\ts   string\n\t\texp tcell.Style\n\t}{\n\t\t{\"\\033[1m\", tcell.StyleDefault.Bold(true)},\n\t\t{\"\\033[1;7;31;42m\", tcell.StyleDefault.Bold(true).Reverse(true).Foreground(color.XTerm1).Background(color.XTerm2)},\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := parseEscapeSequence(test.s); got != test.exp {\n\t\t\tt.Errorf(\"at input %q expected '%v' but got '%v'\", test.s, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestApplyTermSequence(t *testing.T) {\n\ttests := []struct {\n\t\ts   string\n\t\texp tcell.Style\n\t}{\n\t\t{\"\", tcell.StyleDefault},\n\t\t{\"\\x1b[1m\", tcell.StyleDefault.Bold(true)},\n\t\t{\"\\x1b[1;7;31;42m\", tcell.StyleDefault.Bold(true).Reverse(true).Foreground(color.XTerm1).Background(color.XTerm2)},\n\t\t{\"\\x1b]8;;https://example.com\\x1b\\\\\", tcell.StyleDefault.Url(\"https://example.com\")},                  // OSC 8 terminated with ST (ESC\\), no `id` provided\n\t\t{\"\\x1b]8;;https://example.com\\x07\", tcell.StyleDefault.Url(\"https://example.com\")},                    // OSC 8 terminated with BEL, no `id` provided\n\t\t{\"\\x1b]8;id=42;https://example.com\\x1b\\\\\", tcell.StyleDefault.Url(\"https://example.com\").UrlId(\"42\")}, // OSC 8, `id` provided\n\t}\n\n\tfor _, test := range tests {\n\t\tif got := applyTermSequence(test.s, tcell.StyleDefault); !reflect.DeepEqual(got, test.exp) {\n\t\t\tt.Errorf(\"at input %q expected '%v' but got '%v'\", test.s, test.exp, got)\n\t\t}\n\t}\n}\n\nfunc TestApplySGR(t *testing.T) {\n\tnone := tcell.StyleDefault\n\n\ttests := []struct {\n\t\ts     string\n\t\tst    tcell.Style\n\t\tstExp tcell.Style\n\t}{\n\t\t{\"\", none, none},\n\t\t{\"\", none.Foreground(color.XTerm1).Background(color.XTerm1), none},\n\t\t{\"\", none.Bold(true), none},\n\t\t{\"\", none.Foreground(color.XTerm1).Bold(true), none},\n\n\t\t{\"0\", none, none},\n\t\t{\"0\", none.Foreground(color.XTerm1).Background(color.XTerm1), none},\n\t\t{\"0\", none.Bold(true), none},\n\t\t{\"0\", none.Foreground(color.XTerm1).Bold(true), none},\n\n\t\t{\"1\", none, none.Bold(true)},\n\t\t{\"4\", none, none.Underline(true)},\n\t\t{\"7\", none, none.Reverse(true)},\n\n\t\t{\"1\", none.Foreground(color.XTerm1), none.Foreground(color.XTerm1).Bold(true)},\n\t\t{\"4\", none.Foreground(color.XTerm1), none.Foreground(color.XTerm1).Underline(true)},\n\t\t{\"7\", none.Foreground(color.XTerm1), none.Foreground(color.XTerm1).Reverse(true)},\n\n\t\t{\"4\", none.Bold(true), none.Bold(true).Underline(true)},\n\t\t{\"4\", none.Foreground(color.XTerm1).Bold(true), none.Foreground(color.XTerm1).Bold(true).Underline(true)},\n\n\t\t{\"4:0\", none, none},\n\t\t{\"4:0\", none.Underline(true), none},\n\t\t{\"4:1\", none, none.Underline(true)},\n\t\t{\"4:2\", none, none.Underline(tcell.UnderlineStyleDouble)},\n\t\t{\"4:3\", none, none.Underline(tcell.UnderlineStyleCurly)},\n\t\t{\"4:4\", none, none.Underline(tcell.UnderlineStyleDotted)},\n\t\t{\"4:5\", none, none.Underline(tcell.UnderlineStyleDashed)},\n\n\t\t{\"22\", none.Italic(true).Bold(true).Dim(true), none.Italic(true)},\n\t\t{\"23\", none.Bold(true).Italic(true), none.Bold(true)},\n\t\t{\"24\", none.Bold(true).Underline(true), none.Bold(true)},\n\t\t{\"25\", none.Bold(true).Blink(true), none.Bold(true)},\n\t\t{\"27\", none.Bold(true).Reverse(true), none.Bold(true)},\n\t\t{\"29\", none.Bold(true).StrikeThrough(true), none.Bold(true)},\n\n\t\t{\"31\", none, none.Foreground(color.XTerm1)},\n\t\t{\"31\", none.Foreground(color.XTerm2), none.Foreground(color.XTerm1)},\n\t\t{\"31\", none.Foreground(color.XTerm2).Bold(true), none.Foreground(color.XTerm1).Bold(true)},\n\n\t\t{\"41\", none, none.Background(color.XTerm1)},\n\t\t{\"41\", none.Background(color.XTerm2), none.Background(color.XTerm1)},\n\n\t\t{\"1;31\", none, none.Foreground(color.XTerm1).Bold(true)},\n\t\t{\"1;31\", none.Foreground(color.XTerm2), none.Foreground(color.XTerm1).Bold(true)},\n\n\t\t{\"01;31\", none, none.Foreground(color.XTerm1).Bold(true)},\n\t\t{\"01;31\", none.Foreground(color.XTerm2), none.Foreground(color.XTerm1).Bold(true)},\n\n\t\t{\"38;5;0\", none, none.Foreground(color.XTerm0)},\n\t\t{\"38;5;1\", none, none.Foreground(color.XTerm1)},\n\t\t{\"38;5;8\", none, none.Foreground(color.XTerm8)},\n\t\t{\"38;5;16\", none, none.Foreground(color.XTerm16)},\n\t\t{\"38;5;232\", none, none.Foreground(color.XTerm232)},\n\n\t\t{\"38;5;1\", none.Foreground(color.XTerm2), none.Foreground(color.XTerm1)},\n\t\t{\"38;5;1\", none.Foreground(color.XTerm2).Bold(true), none.Foreground(color.XTerm1).Bold(true)},\n\n\t\t{\"48;5;0\", none, none.Background(color.XTerm0)},\n\t\t{\"48;5;1\", none, none.Background(color.XTerm1)},\n\t\t{\"48;5;8\", none, none.Background(color.XTerm8)},\n\t\t{\"48;5;16\", none, none.Background(color.XTerm16)},\n\t\t{\"48;5;232\", none, none.Background(color.XTerm232)},\n\n\t\t{\"48;5;1\", none.Background(color.XTerm2), none.Background(color.XTerm1)},\n\n\t\t{\"1;38;5;1\", none, none.Foreground(color.XTerm1).Bold(true)},\n\t\t{\"1;38;5;1\", none.Foreground(color.XTerm2), none.Foreground(color.XTerm1).Bold(true)},\n\n\t\t{\"38;2;5;102;8\", none, none.Foreground(tcell.NewRGBColor(5, 102, 8))},\n\t\t{\"48;2;0;48;143\", none, none.Background(tcell.NewRGBColor(0, 48, 143))},\n\n\t\t// Fixes color construction issue: https://github.com/gokcehan/lf/pull/439#issuecomment-674409446\n\t\t{\"38;5;34;1\", none, none.Foreground(color.XTerm34).Bold(true)},\n\t}\n\n\tfor _, test := range tests {\n\t\tif stGot := applySGR(test.s, test.st); stGot != test.stExp {\n\t\t\tt.Errorf(\"at input '%s' with '%v' expected '%v' but got '%v'\",\n\t\t\t\ttest.s, test.st, test.stExp, stGot)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "ui.go",
    "content": "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\t\"text/tabwriter\"\n\t\"text/template\"\n\t\"time\"\n\t\"unicode/utf8\"\n\n\t\"github.com/gdamore/tcell/v3\"\n\t\"github.com/rivo/uniseg\"\n\t\"golang.org/x/term\"\n)\n\nconst previewLoadingDelay = 100 * time.Millisecond\n\ntype win struct {\n\tw, h, x, y int\n}\n\nfunc newWin(w, h, x, y int) *win {\n\treturn &win{w, h, x, y}\n}\n\nfunc (win *win) renew(w, h, x, y int) {\n\twin.w, win.h, win.x, win.y = w, h, x, y\n}\n\n// printLength returns the display width of s in terminal cells.\n//\n// It ignores supported terminal control sequences (see [readTermSequence])\n// and accounts for tab expansions using the `tabstop` option.\nfunc printLength(s string) int {\n\tlength := 0\n\n\tslen := len(s)\n\tfor i := 0; i < slen; {\n\t\tseq := readTermSequence(s[i:])\n\t\tif seq != \"\" {\n\t\t\ti += len(seq)\n\t\t\tcontinue\n\t\t}\n\n\t\tgc, _, w, _ := uniseg.FirstGraphemeClusterInString(s[i:], -1)\n\t\ti += len(gc)\n\n\t\tif gc == \"\\t\" {\n\t\t\tlength += gOpts.tabstop - length%gOpts.tabstop\n\t\t} else {\n\t\t\tlength += w\n\t\t}\n\t}\n\n\treturn length\n}\n\nfunc (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s string) tcell.Style {\n\tvar b strings.Builder\n\toff := 0\n\tput := func() {\n\t\tif b.Len() > 0 {\n\t\t\ts := b.String()\n\t\t\tscreen.PutStrStyled(win.x+x+off, win.y+y, s, st)\n\t\t\toff += printLength(s)\n\t\t\tb.Reset()\n\t\t}\n\t}\n\n\tslen := len(s)\n\tfor i := 0; i < slen; {\n\t\tseq := readTermSequence(s[i:])\n\t\tif seq != \"\" {\n\t\t\tput()\n\t\t\tst = applyTermSequence(seq, st)\n\t\t\ti += len(seq)\n\t\t\tcontinue\n\t\t}\n\n\t\tgc, _, _, _ := uniseg.FirstGraphemeClusterInString(s[i:], -1)\n\t\tif gc == \"\\t\" {\n\t\t\tw := gOpts.tabstop - (x+off+printLength(b.String()))%gOpts.tabstop\n\t\t\tb.WriteString(strings.Repeat(\" \", w))\n\t\t} else if gc != \"\\r\" && gc != \"\\n\" {\n\t\t\tb.WriteString(gc)\n\t\t}\n\n\t\ti += len(gc)\n\t}\n\n\tput()\n\treturn st\n}\n\nfunc (win *win) printf(screen tcell.Screen, x, y int, st tcell.Style, format string, a ...any) {\n\twin.print(screen, x, y, st, fmt.Sprintf(format, a...))\n}\n\nfunc (win *win) printLine(screen tcell.Screen, x, y int, st tcell.Style, s string) {\n\twin.printf(screen, x, y, st, \"%s%*s\", s, win.w-printLength(s), \"\")\n}\n\nfunc (win *win) printRight(screen tcell.Screen, y int, st tcell.Style, s string) {\n\twin.print(screen, win.w-printLength(s), y, st, s)\n}\n\nfunc (win *win) printMsg(screen tcell.Screen, s string) {\n\tpad := 1\n\tif gOpts.mergeindicators {\n\t\tpad--\n\t}\n\tst := tcell.StyleDefault.Reverse(true)\n\twin.print(screen, pad, 0, st, s)\n}\n\nfunc (win *win) printReg(screen tcell.Screen, reg *reg, sxs *sixelScreen, previewTimer *time.Timer) {\n\tswitch {\n\tcase reg.loading:\n\t\tif time.Since(reg.loadTime) > previewLoadingDelay {\n\t\t\twin.printMsg(screen, \"loading...\")\n\t\t} else {\n\t\t\tpreviewTimer.Reset(previewLoadingDelay)\n\t\t}\n\tcase reg.sixel:\n\t\tsxs.printSixel(win, screen, reg)\n\tdefault:\n\t\tst := tcell.StyleDefault\n\t\tfor i, l := range reg.lines {\n\t\t\tif i > win.h-1 {\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tst = win.print(screen, 0, i, st, l)\n\t\t}\n\t}\n\n\tif !reg.sixel {\n\t\tsxs.lastFile = \"\"\n\t}\n}\n\nvar gThisYear = time.Now().Year()\n\nfunc infotimefmt(t time.Time) string {\n\tif t.Year() == gThisYear {\n\t\treturn t.Format(gOpts.infotimefmtnew)\n\t}\n\treturn t.Format(gOpts.infotimefmtold)\n}\n\nfunc fileInfo(f *file, d *dir, userWidth, groupWidth, customWidth int) (string, string, int) {\n\tvar info strings.Builder\n\tvar custom string\n\tvar off int\n\n\tfor _, s := range getInfo(d.path) {\n\t\tswitch s {\n\t\tcase \"size\":\n\t\t\tif f.IsDir() && getDirCounts(d.path) {\n\t\t\t\tswitch {\n\t\t\t\tcase f.dirCount < 0:\n\t\t\t\t\tinfo.WriteString(\"     !\")\n\t\t\t\tcase f.dirCount < 10000:\n\t\t\t\t\tfmt.Fprintf(&info, \" %5d\", f.dirCount)\n\t\t\t\tdefault:\n\t\t\t\t\tinfo.WriteString(\" 9999+\")\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tswitch {\n\t\t\t\tcase f.dirSize >= 0:\n\t\t\t\t\tfmt.Fprintf(&info, \" %5s\", humanize(f.dirSize))\n\t\t\t\tcase f.IsDir():\n\t\t\t\t\tinfo.WriteString(\"     -\")\n\t\t\t\tdefault:\n\t\t\t\t\tfmt.Fprintf(&info, \" %5s\", humanize(f.Size()))\n\t\t\t\t}\n\t\t\t}\n\t\tcase \"time\":\n\t\t\tfmt.Fprintf(&info, \" %*s\", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.ModTime()))\n\t\tcase \"atime\":\n\t\t\tfmt.Fprintf(&info, \" %*s\", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.accessTime))\n\t\tcase \"btime\":\n\t\t\tfmt.Fprintf(&info, \" %*s\", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.birthTime))\n\t\tcase \"ctime\":\n\t\t\tfmt.Fprintf(&info, \" %*s\", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.changeTime))\n\t\tcase \"perm\":\n\t\t\tinfo.WriteString(\" \" + permString(f.Mode()))\n\t\tcase \"user\":\n\t\t\tfmt.Fprintf(&info, \" %-*s\", userWidth, userName(f.FileInfo))\n\t\tcase \"group\":\n\t\t\tfmt.Fprintf(&info, \" %-*s\", groupWidth, groupName(f.FileInfo))\n\t\tcase \"custom\":\n\t\t\t// Prevent useless spacers, as `custom` allows empty values\n\t\t\tif customWidth < 1 {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\t// To allow for the usage of escape sequences, store `custom`\n\t\t\t// separately and print it later using the offset.\n\t\t\toff = info.Len()\n\t\t\tfmt.Fprintf(&info, \" %*s\", customWidth, \"\")\n\t\t\tcustom = fmt.Sprintf(\" %s%*s\", f.customInfo, customWidth-printLength(f.customInfo), \"\")\n\t\tdefault:\n\t\t\tlog.Printf(\"unknown info type: %s\", s)\n\t\t}\n\t}\n\n\treturn info.String(), custom, off\n}\n\ntype dirContext struct {\n\tselections map[string]int\n\tclipboard  clipboard\n\ttags       map[string]string\n}\n\n// dirRole describes what kind of directory pane is being drawn.\ntype dirRole byte\n\nconst (\n\tActive  dirRole = iota // Current directory pane.\n\tParent                 // Parent or ancestor directory pane.\n\tPreview                // Preview pane when it shows a directory listing.\n)\n\ntype dirStyle struct {\n\tcolors styleMap\n\ticons  iconMap\n\trole   dirRole\n}\n\nfunc (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirStyle, previewTimer *time.Timer) {\n\tif win.w < 5 || dir == nil {\n\t\treturn\n\t}\n\n\tfileslen := len(dir.files)\n\n\tswitch {\n\tcase dir.loading && fileslen == 0:\n\t\tif time.Since(dir.loadTime) > previewLoadingDelay {\n\t\t\twin.printMsg(ui.screen, \"loading...\")\n\t\t} else {\n\t\t\tpreviewTimer.Reset(previewLoadingDelay)\n\t\t}\n\t\treturn\n\tcase dir.noPerm:\n\t\twin.printMsg(ui.screen, \"permission denied\")\n\t\treturn\n\tcase fileslen == 0:\n\t\twin.printMsg(ui.screen, \"empty\")\n\t\treturn\n\t}\n\n\tbeg := max(dir.ind-dir.pos, 0)\n\tend := min(beg+win.h, fileslen)\n\n\tif beg > end {\n\t\treturn\n\t}\n\n\tvar lnwidth int\n\n\tif dirStyle.role == Active && (gOpts.number || gOpts.relativenumber) {\n\t\tlnwidth = 1\n\t\tfor j := 10; j <= fileslen; j *= 10 {\n\t\t\tlnwidth++\n\t\t}\n\t\tif gOpts.number && gOpts.relativenumber {\n\t\t\tlnwidth = max(lnwidth, 2)\n\t\t}\n\t}\n\n\tvar userWidth, groupWidth, customWidth int\n\tvar fetchedCustom bool\n\n\t// Only fetch user/group/custom widths if configured to display them\n\tfor _, s := range getInfo(dir.path) {\n\t\tswitch s {\n\t\tcase \"user\":\n\t\t\tuserWidth = getUserWidth(dir, beg, end)\n\t\tcase \"group\":\n\t\t\tgroupWidth = getGroupWidth(dir, beg, end)\n\t\tcase \"custom\":\n\t\t\tcustomWidth = getCustomWidth(dir, beg, end)\n\t\t\tfetchedCustom = true // Can have a length of 0\n\t\t}\n\n\t\tif userWidth > 0 && groupWidth > 0 && fetchedCustom {\n\t\t\tbreak\n\t\t}\n\t}\n\n\tindOff, tagOff, nameOff := lnwidth, lnwidth, lnwidth+1\n\tif !gOpts.mergeindicators {\n\t\ttagOff++\n\t\tnameOff++\n\t}\n\n\tvisualSelections := dir.visualSelections()\n\tfor i, f := range dir.files[beg:end] {\n\t\tst := dirStyle.colors.get(f)\n\n\t\tif lnwidth > 0 {\n\t\t\tvar ln string\n\n\t\t\tif gOpts.number && !gOpts.relativenumber {\n\t\t\t\tln = fmt.Sprintf(\"%*d\", lnwidth, i+1+beg)\n\t\t\t} else if gOpts.relativenumber {\n\t\t\t\tswitch {\n\t\t\t\tcase i < dir.pos:\n\t\t\t\t\tln = fmt.Sprintf(\"%*d\", lnwidth, dir.pos-i)\n\t\t\t\tcase i > dir.pos:\n\t\t\t\t\tln = fmt.Sprintf(\"%*d\", lnwidth, i-dir.pos)\n\t\t\t\tcase gOpts.number:\n\t\t\t\t\tln = fmt.Sprintf(\"%-*d\", lnwidth, i+1+beg)\n\t\t\t\tdefault:\n\t\t\t\t\tln = fmt.Sprintf(\"%*d\", lnwidth, 0)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfmtStr := optionToFmtstr(gOpts.numberfmt)\n\t\t\tif i == dir.pos && gOpts.numbercursorfmt != \"\" {\n\t\t\t\tfmtStr = optionToFmtstr(gOpts.numbercursorfmt)\n\t\t\t}\n\t\t\twin.print(ui.screen, 0, i, tcell.StyleDefault, fmt.Sprintf(fmtStr, ln))\n\t\t}\n\n\t\tpath := filepath.Join(dir.path, f.Name())\n\n\t\tvar fmtStr string\n\t\tif slices.Contains(visualSelections, path) {\n\t\t\tfmtStr = gOpts.visualfmt\n\t\t} else if _, ok := context.selections[path]; ok {\n\t\t\tfmtStr = gOpts.selectfmt\n\t\t} else if slices.Contains(context.clipboard.paths, path) {\n\t\t\tif context.clipboard.mode == clipboardCopy {\n\t\t\t\tfmtStr = gOpts.copyfmt\n\t\t\t} else {\n\t\t\t\tfmtStr = gOpts.cutfmt\n\t\t\t}\n\t\t}\n\n\t\ttag := \" \"\n\t\tif val, ok := context.tags[path]; ok && len(val) > 0 {\n\t\t\ttag = val\n\t\t}\n\n\t\tif fmtStr != \"\" {\n\t\t\tind := \" \"\n\t\t\tif gOpts.mergeindicators {\n\t\t\t\tind = tag\n\t\t\t}\n\t\t\twin.print(ui.screen, indOff, i, parseEscapeSequence(fmtStr), ind)\n\t\t}\n\n\t\t// make space for select marker, and leave another space at the end\n\t\tmaxWidth := win.w - lnwidth - 2\n\n\t\tvar icon string\n\t\tvar iconDef iconDef\n\t\tif gOpts.icons {\n\t\t\ticonDef = dirStyle.icons.get(f)\n\t\t\ticon = iconDef.icon + \" \"\n\t\t}\n\n\t\t// subtract space for icon\n\t\tmaxFilenameWidth := maxWidth - uniseg.StringWidth(icon)\n\t\t// subtract space for tag if not merged with selection marker\n\t\tif !gOpts.mergeindicators {\n\t\t\tmaxFilenameWidth--\n\t\t}\n\n\t\tinfo, custom, customOff := fileInfo(f, dir, userWidth, groupWidth, customWidth)\n\t\tinfolen := len(info)\n\t\tshowInfo := infolen > 0 && 2*infolen < maxWidth\n\t\tif showInfo {\n\t\t\tmaxFilenameWidth -= infolen\n\t\t}\n\n\t\tfilename := truncateFilename(f, maxFilenameWidth, gOpts.truncatepct, gOpts.truncatechar)\n\t\tspacing := maxFilenameWidth - uniseg.StringWidth(filename)\n\t\tif spacing > 0 {\n\t\t\tfilename += strings.Repeat(\" \", spacing)\n\t\t}\n\n\t\tif showInfo {\n\t\t\tfilename += info\n\t\t\tcustomOff += nameOff + uniseg.StringWidth(icon) + maxFilenameWidth\n\t\t}\n\n\t\tif i == dir.pos {\n\t\t\tvar cursorFmt string\n\t\t\tswitch dirStyle.role {\n\t\t\tcase Active:\n\t\t\t\tcursorFmt = optionToFmtstr(gOpts.cursoractivefmt)\n\t\t\tcase Parent:\n\t\t\t\tcursorFmt = optionToFmtstr(gOpts.cursorparentfmt)\n\t\t\tcase Preview:\n\t\t\t\tcursorFmt = optionToFmtstr(gOpts.cursorpreviewfmt)\n\t\t\t}\n\n\t\t\t// print tag separately as it can contain color escape sequences\n\t\t\tif !gOpts.mergeindicators || fmtStr == \"\" {\n\t\t\t\twin.print(ui.screen, tagOff, i, st, fmt.Sprintf(cursorFmt, tag))\n\t\t\t}\n\n\t\t\twin.print(ui.screen, nameOff, i, st, fmt.Sprintf(cursorFmt, icon+filename+\" \"))\n\n\t\t\t// print over the empty space we reserved for the custom info\n\t\t\tif showInfo && custom != \"\" {\n\t\t\t\twin.print(ui.screen, customOff, i, st, fmt.Sprintf(cursorFmt, stripTermSequence(custom)))\n\t\t\t}\n\t\t} else {\n\t\t\tif !gOpts.mergeindicators || fmtStr == \"\" {\n\t\t\t\tif tag == \" \" {\n\t\t\t\t\twin.print(ui.screen, tagOff, i, st, \" \")\n\t\t\t\t} else {\n\t\t\t\t\ttagStr := fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), tag)\n\t\t\t\t\twin.print(ui.screen, tagOff, i, tcell.StyleDefault, tagStr)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif len(icon) > 0 {\n\t\t\t\ticonStyle := st\n\t\t\t\tif iconDef.hasStyle {\n\t\t\t\t\ticonStyle = iconDef.style\n\t\t\t\t}\n\t\t\t\twin.print(ui.screen, nameOff, i, iconStyle, icon)\n\t\t\t}\n\n\t\t\twin.print(ui.screen, nameOff+uniseg.StringWidth(icon), i, st, filename+\" \")\n\n\t\t\t// print over the empty space we reserved for the custom info\n\t\t\tif showInfo && custom != \"\" {\n\t\t\t\twin.print(ui.screen, customOff, i, st, custom)\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc getUserWidth(dir *dir, beg, end int) int {\n\tmaxw := 0\n\n\tfor _, f := range dir.files[beg:end] {\n\t\tmaxw = max(len(userName(f.FileInfo)), maxw)\n\t}\n\n\treturn maxw\n}\n\nfunc getGroupWidth(dir *dir, beg, end int) int {\n\tmaxw := 0\n\n\tfor _, f := range dir.files[beg:end] {\n\t\tmaxw = max(len(groupName(f.FileInfo)), maxw)\n\t}\n\n\treturn maxw\n}\n\nfunc getCustomWidth(dir *dir, beg, end int) int {\n\tmaxw := 0\n\n\tfor _, f := range dir.files[beg:end] {\n\t\tmaxw = max(printLength(f.customInfo), maxw)\n\t}\n\n\treturn maxw\n}\n\nfunc getWins(screen tcell.Screen) []*win {\n\twtot, htot := screen.Size()\n\n\th := max(htot-2, 0)\n\tx, y := 0, 1\n\tif gOpts.drawbox && gOpts.borderstyle&borderOutline != 0 {\n\t\th = max(htot-4, 0)\n\t\tx, y = 1, 2\n\t}\n\n\twidths := getWidths(wtot, gOpts.ratios, gOpts.drawbox, gOpts.borderstyle)\n\twins := make([]*win, 0, len(widths))\n\tfor _, w := range widths {\n\t\twins = append(wins, newWin(w, h, x, y))\n\t\tx += w + 1\n\t}\n\n\treturn wins\n}\n\ntype menuSelect struct {\n\tx, y int    // selection position in menuWin (cells)\n\ts    string // selected entry text to draw with `menuselectfmt`\n}\n\ntype ui struct {\n\tscreen      tcell.Screen       // primary screen used for drawing and event polling\n\tsxScreen    sixelScreen        // sixel preview state\n\twins        []*win             // pane windows from `ratios` (last is `preview` when enabled)\n\tpromptWin   *win               // prompt line window\n\tmsgWin      *win               // status line window\n\tmenuWin     *win               // menu window\n\tmsg         string             // message/output shown in msgWin\n\texprChan    chan expr          // expr queue\n\tevChan      chan tcell.Event   // merged event queue (keyChan + tevChan)\n\tmenu        string             // rendered (multiline) menu text (i.e. completions, binds, marks)\n\tmenuSelect  *menuSelect        // selected menu entry (completion menu only)\n\tcmdPrefix   string             // command prefix/prompt (empty: Normal mode)\n\tcmdAccLeft  string             // command buffer left of cursor\n\tcmdAccRight string             // command buffer right of cursor\n\tcmdYankBuf  string             // yank buffer for command line editing\n\tkeyAcc      string             // keys typed so far for mapping lookup\n\tkeyCount    string             // count prefix for next command\n\tstyles      styleMap           // parsed styles\n\ticons       iconMap            // parsed icons\n\truler       *template.Template // compiled `rulerfile`\n\trulerErr    error              // `rulerfile` parse error (if any)\n\tcurrentFile string             // last path passed to `on-select`\n\tpasteEvent  bool               // whether paste event is active (to ignore pasted input in Normal mode)\n}\n\nfunc newUI(screen tcell.Screen) *ui {\n\twtot, htot := screen.Size()\n\n\tui := &ui{\n\t\tscreen:      screen,\n\t\twins:        getWins(screen),\n\t\tpromptWin:   newWin(wtot, 1, 0, 0),\n\t\tmsgWin:      newWin(wtot, 1, 0, htot-1),\n\t\tmenuWin:     newWin(wtot, 1, 0, htot-2),\n\t\texprChan:    make(chan expr, 1000),\n\t\tevChan:      make(chan tcell.Event, 1000),\n\t\tstyles:      parseStyles(),\n\t\ticons:       parseIcons(),\n\t\tcurrentFile: \"\",\n\t\tsxScreen:    sixelScreen{},\n\t}\n\tui.ruler, ui.rulerErr = parseRuler(gOpts.rulerfile)\n\n\treturn ui\n}\n\nfunc (ui *ui) winAt(x, y int) (int, *win) {\n\tfor i := len(ui.wins) - 1; i >= 0; i-- {\n\t\tw := ui.wins[i]\n\t\tif x >= w.x && y >= w.y && y < w.y+w.h {\n\t\t\treturn i, w\n\t\t}\n\t}\n\treturn -1, nil\n}\n\nfunc (ui *ui) renew() {\n\tui.wins = getWins(ui.screen)\n\n\twtot, htot := ui.screen.Size()\n\tui.promptWin.renew(wtot, 1, 0, 0)\n\tui.msgWin.renew(wtot, 1, 0, htot-1)\n\tui.menuWin.renew(wtot, 1, 0, htot-2)\n}\n\nfunc (ui *ui) echo(msg string) {\n\tui.msg = msg\n}\n\nfunc (ui *ui) echomsg(msg string) {\n\tui.echo(msg)\n\tlog.Print(msg)\n}\n\nfunc (ui *ui) echoerr(msg string) {\n\tui.echo(fmt.Sprintf(optionToFmtstr(gOpts.errorfmt), msg))\n\tlog.Printf(\"error: %s\", msg)\n}\n\nfunc (ui *ui) echoerrf(format string, a ...any) {\n\tui.echoerr(fmt.Sprintf(format, a...))\n}\n\n// reg represents the preview for a file.\n// This can also be used to represent the preview of a directory if\n// `dirpreviews` is enabled.\n//\n// Note: the name `reg` is historical. It originally meant \"regular\"\n// file preview, but `previewer` now also supports non-regular files.\ntype reg struct {\n\tloading  bool\n\tvolatile bool\n\tloadTime time.Time\n\tpath     string\n\tlines    []string\n\tsixel    bool\n}\n\nfunc (ui *ui) loadFile(app *app, volatile bool) {\n\tif volatile {\n\t\tapp.nav.previewChan <- \"\"\n\t}\n\n\tcurr := app.nav.currFile()\n\tif curr == nil {\n\t\treturn\n\t}\n\n\tif curr.path != ui.currentFile {\n\t\tui.currentFile = curr.path\n\t\tonSelect(app)\n\t}\n\n\tif !gOpts.preview {\n\t\treturn\n\t}\n\n\tif curr.isPreviewable() {\n\t\tapp.nav.loadReg(curr.path, volatile)\n\t} else if curr.IsDir() {\n\t\tdir := app.nav.getDir(curr.path)\n\t\tapp.nav.checkDir(dir)\n\t}\n}\n\nfunc (ui *ui) drawPromptLine(nav *nav) {\n\tst := tcell.StyleDefault\n\n\tdir := nav.currDir()\n\tpwd := dir.path\n\n\tif after, ok := strings.CutPrefix(pwd, gUser.HomeDir); ok {\n\t\tpwd = filepath.Join(\"~\", after)\n\t}\n\n\tsep := string(filepath.Separator)\n\n\tvar fname string\n\tif curr := nav.currFile(); curr != nil {\n\t\tfname = filepath.Base(curr.path)\n\t}\n\n\tvar prompt string\n\n\tprompt = strings.ReplaceAll(gOpts.promptfmt, \"%u\", gUser.Username)\n\tprompt = strings.ReplaceAll(prompt, \"%h\", gHostname)\n\tprompt = strings.ReplaceAll(prompt, \"%f\", fname)\n\n\tif printLength(strings.ReplaceAll(strings.ReplaceAll(prompt, \"%w\", pwd), \"%d\", pwd)) > ui.promptWin.w {\n\t\tnames := strings.Split(pwd, sep)\n\t\tfor i := range names {\n\t\t\tif names[i] == \"\" {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tr, _ := utf8.DecodeRuneInString(names[i])\n\t\t\tnames[i] = string(r)\n\t\t\tif printLength(strings.ReplaceAll(strings.ReplaceAll(prompt, \"%w\", strings.Join(names, sep)), \"%d\", strings.Join(names, sep))) <= ui.promptWin.w {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tpwd = strings.Join(names, sep)\n\t}\n\n\tprompt = strings.ReplaceAll(prompt, \"%w\", pwd)\n\tif !strings.HasSuffix(pwd, sep) {\n\t\tpwd += sep\n\t}\n\tprompt = strings.ReplaceAll(prompt, \"%d\", pwd)\n\n\tif len(dir.filter) != 0 {\n\t\tprompt = strings.ReplaceAll(prompt, \"%F\", fmt.Sprint(dir.filter))\n\t} else {\n\t\tprompt = strings.ReplaceAll(prompt, \"%F\", \"\")\n\t}\n\n\t// spacer\n\tavail := ui.promptWin.w - printLength(prompt) + 2\n\tif avail > 0 {\n\t\tprompt = strings.Replace(prompt, \"%S\", strings.Repeat(\" \", avail), 1)\n\t}\n\tprompt = strings.ReplaceAll(prompt, \"%S\", \"\")\n\n\tui.promptWin.print(ui.screen, 0, 0, st, prompt)\n}\n\nfunc formatRulerOpt(name, val string) string {\n\t// handle escape character so it doesn't mess up the ruler\n\tval = strings.ReplaceAll(val, \"\\033\", \"\\033[7m\\\\033\\033[0m\")\n\n\t// display name of builtin options for clarity\n\tif !strings.HasPrefix(name, \"lf_user_\") {\n\t\treturn fmt.Sprintf(\"%s=%s\", strings.TrimPrefix(name, \"lf_\"), val)\n\t}\n\n\treturn val\n}\n\nfunc (ui *ui) drawStat(nav *nav) {\n\tif ui.msg != \"\" {\n\t\tui.msgWin.print(ui.screen, 0, 0, tcell.StyleDefault, ui.msg)\n\t\treturn\n\t}\n\n\tcurr := nav.currFile()\n\tif curr == nil {\n\t\treturn\n\t}\n\n\tif curr.err != nil {\n\t\tui.echoerrf(\"stat: %s\", curr.err)\n\t\tui.msgWin.print(ui.screen, 0, 0, tcell.StyleDefault, ui.msg)\n\t\treturn\n\t}\n\n\tstatfmt := strings.ReplaceAll(gOpts.statfmt, \"|\", \"\\x1f\")\n\treplace := func(s, val string) {\n\t\tif val == \"\" {\n\t\t\tval = \"\\x00\"\n\t\t}\n\t\tstatfmt = strings.ReplaceAll(statfmt, s, val)\n\t}\n\tif nav.isVisualMode() {\n\t\treplace(\"%m\", \"VISUAL\")\n\t\treplace(\"%M\", \"VISUAL\")\n\t} else {\n\t\treplace(\"%m\", \"\")\n\t\treplace(\"%M\", \"NORMAL\")\n\t}\n\treplace(\"%p\", permString(curr.Mode()))\n\treplace(\"%c\", linkCount(curr))\n\treplace(\"%u\", userName(curr))\n\treplace(\"%g\", groupName(curr))\n\treplace(\"%s\", humanize(curr.Size()))\n\treplace(\"%S\", fmt.Sprintf(\"%5s\", humanize(curr.Size())))\n\treplace(\"%t\", curr.ModTime().Format(gOpts.timefmt))\n\treplace(\"%l\", curr.linkTarget)\n\n\tvar fileInfo strings.Builder\n\tfor section := range strings.SplitSeq(statfmt, \"\\x1f\") {\n\t\tif !strings.Contains(section, \"\\x00\") {\n\t\t\tfileInfo.WriteString(section)\n\t\t}\n\t}\n\n\tui.msgWin.print(ui.screen, 0, 0, tcell.StyleDefault, fileInfo.String())\n}\n\nfunc (ui *ui) drawRuler(nav *nav) {\n\tst := tcell.StyleDefault\n\n\tdir := nav.currDir()\n\n\ttot := len(dir.files)\n\tind := min(dir.ind+1, tot)\n\thid := len(dir.allFiles) - tot\n\tacc := ui.keyCount + ui.keyAcc\n\n\tvar percentage string\n\tbeg := max(dir.ind-dir.pos, 0)\n\tswitch {\n\tcase tot <= nav.height:\n\t\tpercentage = \"All\"\n\tcase beg == 0:\n\t\tpercentage = \"Top\"\n\tcase beg == tot-nav.height:\n\t\tpercentage = \"Bot\"\n\tdefault:\n\t\tpercentage = fmt.Sprintf(\"%2d%%\", beg*100/(tot-nav.height))\n\t}\n\n\tnumClipCopy := 0\n\tnumClipMove := 0\n\tif nav.clipboard.mode == clipboardCopy {\n\t\tnumClipCopy = len(nav.clipboard.paths)\n\t} else {\n\t\tnumClipMove = len(nav.clipboard.paths)\n\t}\n\n\tcurrSelections := nav.currSelections()\n\tcurrVSelections := nav.currDir().visualSelections()\n\n\tprogress := []string{}\n\n\tif nav.copyJobs > 0 {\n\t\tif nav.copyTotal == 0 {\n\t\t\tprogress = append(progress, fmt.Sprintf(\"[0%%]\"))\n\t\t} else {\n\t\t\tprogress = append(progress, fmt.Sprintf(\"[%d%%]\", nav.copyBytes*100/nav.copyTotal))\n\t\t}\n\t}\n\n\tif nav.moveTotal > 0 {\n\t\tprogress = append(progress, fmt.Sprintf(\"[%d/%d]\", nav.moveCount, nav.moveTotal))\n\t}\n\n\tif nav.deleteTotal > 0 {\n\t\tprogress = append(progress, fmt.Sprintf(\"[%d/%d]\", nav.deleteCount, nav.deleteTotal))\n\t}\n\n\topts := getOptsMap()\n\n\trulerfmt := strings.ReplaceAll(gOpts.rulerfmt, \"|\", \"\\x1f\")\n\trulerfmt = reRulerSub.ReplaceAllStringFunc(rulerfmt, func(s string) string {\n\t\tvar result string\n\t\tswitch s {\n\t\tcase \"%a\":\n\t\t\tresult = acc\n\t\tcase \"%p\":\n\t\t\tresult = strings.Join(progress, \" \")\n\t\tcase \"%m\":\n\t\t\tresult = fmt.Sprintf(\"%.d\", numClipMove)\n\t\tcase \"%c\":\n\t\t\tresult = fmt.Sprintf(\"%.d\", numClipCopy)\n\t\tcase \"%s\":\n\t\t\tresult = fmt.Sprintf(\"%.d\", len(currSelections))\n\t\tcase \"%v\":\n\t\t\tresult = fmt.Sprintf(\"%.d\", len(currVSelections))\n\t\tcase \"%f\":\n\t\t\tresult = strings.Join(dir.filter, \" \")\n\t\tcase \"%i\":\n\t\t\tresult = strconv.Itoa(ind)\n\t\tcase \"%t\":\n\t\t\tresult = strconv.Itoa(tot)\n\t\tcase \"%h\":\n\t\t\tresult = strconv.Itoa(hid)\n\t\tcase \"%P\":\n\t\t\tresult = percentage\n\t\tcase \"%d\":\n\t\t\tresult = diskFree(dir.path)\n\t\tdefault:\n\t\t\ts = strings.TrimSuffix(strings.TrimPrefix(s, \"%{\"), \"}\")\n\t\t\tif val, ok := opts[s]; ok {\n\t\t\t\tresult = formatRulerOpt(s, val)\n\t\t\t}\n\t\t}\n\t\tif result == \"\" {\n\t\t\treturn \"\\x00\"\n\t\t}\n\t\treturn result\n\t})\n\tvar ruler strings.Builder\n\tfor section := range strings.SplitSeq(rulerfmt, \"\\x1f\") {\n\t\tif !strings.Contains(section, \"\\x00\") {\n\t\t\truler.WriteString(section)\n\t\t}\n\t}\n\tui.msgWin.printRight(ui.screen, 0, st, ruler.String())\n}\n\nfunc (ui *ui) drawRulerFile(nav *nav) {\n\tif ui.rulerErr != nil {\n\t\terr := fmt.Sprintf(optionToFmtstr(gOpts.errorfmt), fmt.Errorf(\"parsing ruler: %w\", ui.rulerErr))\n\t\tui.msgWin.print(ui.screen, 0, 0, tcell.StyleDefault, err)\n\t\treturn\n\t}\n\n\tvar stat *statData\n\tcurr := nav.currFile()\n\tif curr != nil {\n\t\tif curr.err == nil {\n\t\t\tstat = &statData{\n\t\t\t\tPath:        curr.path,\n\t\t\t\tName:        curr.Name(),\n\t\t\t\tExtension:   curr.ext,\n\t\t\t\tSize:        curr.Size(),\n\t\t\t\tDirSize:     curr.dirSize,\n\t\t\t\tDirCount:    curr.dirCount,\n\t\t\t\tPermissions: permString(curr.Mode()),\n\t\t\t\tModTime:     curr.ModTime().Format(gOpts.timefmt),\n\t\t\t\tAccessTime:  curr.accessTime.Format(gOpts.timefmt),\n\t\t\t\tBirthTime:   curr.birthTime.Format(gOpts.timefmt),\n\t\t\t\tChangeTime:  curr.changeTime.Format(gOpts.timefmt),\n\t\t\t\tLinkCount:   linkCount(curr),\n\t\t\t\tUser:        userName(curr),\n\t\t\t\tGroup:       groupName(curr),\n\t\t\t\tTarget:      curr.linkTarget,\n\t\t\t\tCustomInfo:  curr.customInfo,\n\t\t\t}\n\t\t} else {\n\t\t\tui.echoerrf(\"stat: %s\", curr.err)\n\t\t}\n\t}\n\n\tdir := nav.currDir()\n\ttot := len(dir.files)\n\tind := min(dir.ind+1, tot)\n\tall := len(dir.allFiles)\n\thid := all - tot\n\n\tvar linePercentage string\n\tif tot == 0 {\n\t\tlinePercentage = \"100%\"\n\t} else {\n\t\tlinePercentage = fmt.Sprintf(\"%d%%\", ind*100/tot)\n\t}\n\n\tvar scrollPercentage string\n\tbeg := max(dir.ind-dir.pos, 0)\n\tswitch {\n\tcase tot <= nav.height:\n\t\tscrollPercentage = \"All\"\n\tcase beg == 0:\n\t\tscrollPercentage = \"Top\"\n\tcase beg == tot-nav.height:\n\t\tscrollPercentage = \"Bot\"\n\tdefault:\n\t\tscrollPercentage = fmt.Sprintf(\"%2d%%\", beg*100/(tot-nav.height))\n\t}\n\n\tvar copiedPaths []string\n\tvar cutPaths []string\n\tif nav.clipboard.mode == clipboardCopy {\n\t\tcopiedPaths = nav.clipboard.paths\n\t} else {\n\t\tcutPaths = nav.clipboard.paths\n\t}\n\n\tcurrSelections := nav.currSelections()\n\tcurrVSelections := nav.currDir().visualSelections()\n\n\tprogress := []string{}\n\n\tif nav.copyJobs > 0 {\n\t\tif nav.copyTotal == 0 {\n\t\t\tprogress = append(progress, fmt.Sprintf(\"[0%%]\"))\n\t\t} else {\n\t\t\tprogress = append(progress, fmt.Sprintf(\"[%d%%]\", nav.copyBytes*100/nav.copyTotal))\n\t\t}\n\t}\n\n\tif nav.moveTotal > 0 {\n\t\tprogress = append(progress, fmt.Sprintf(\"[%d/%d]\", nav.moveCount, nav.moveTotal))\n\t}\n\n\tif nav.deleteTotal > 0 {\n\t\tprogress = append(progress, fmt.Sprintf(\"[%d/%d]\", nav.deleteCount, nav.deleteTotal))\n\t}\n\n\tmode := \"NORMAL\"\n\tif nav.isVisualMode() {\n\t\tmode = \"VISUAL\"\n\t}\n\n\toptions := make(map[string]string)\n\tv := reflect.ValueOf(gOpts)\n\tt := v.Type()\n\tfor i := range v.NumField() {\n\t\tname := t.Field(i).Name\n\t\tswitch name {\n\t\tcase \"nkeys\", \"vkeys\", \"cmdkeys\", \"cmds\", \"user\":\n\t\t\tcontinue\n\t\tdefault:\n\t\t\toptions[name] = fieldToString(v.Field(i))\n\t\t}\n\t}\n\n\tdata := rulerData{\n\t\tSPACER:           \"\\x1f\",\n\t\tMessage:          ui.msg,\n\t\tKeys:             ui.keyCount + ui.keyAcc,\n\t\tProgress:         progress,\n\t\tCopy:             copiedPaths,\n\t\tCut:              cutPaths,\n\t\tSelect:           currSelections,\n\t\tVisual:           currVSelections,\n\t\tIndex:            ind,\n\t\tTotal:            tot,\n\t\tHidden:           hid,\n\t\tAll:              all,\n\t\tLinePercentage:   linePercentage,\n\t\tScrollPercentage: scrollPercentage,\n\t\tFilter:           dir.filter,\n\t\tMode:             mode,\n\t\tOptions:          options,\n\t\tUserOptions:      gOpts.user,\n\t\tStat:             stat,\n\t}\n\n\tleft, right, err := renderRuler(ui.ruler, data, ui.msgWin.w)\n\tif err != nil {\n\t\terr := fmt.Sprintf(optionToFmtstr(gOpts.errorfmt), fmt.Errorf(\"rendering ruler: %w\", err))\n\t\tui.msgWin.print(ui.screen, 0, 0, tcell.StyleDefault, err)\n\t\treturn\n\t}\n\n\tui.msgWin.print(ui.screen, 0, 0, tcell.StyleDefault, left)\n\tui.msgWin.printRight(ui.screen, 0, tcell.StyleDefault, right)\n}\n\nfunc (ui *ui) drawPreview(nav *nav, context *dirContext) {\n\tcurr := nav.currFile()\n\tif curr == nil {\n\t\treturn\n\t}\n\n\twin := ui.wins[len(ui.wins)-1]\n\tui.sxScreen.clearSixel(win, ui.screen, curr.path)\n\n\tif gOpts.preview {\n\t\tif curr.isPreviewable() {\n\t\t\tif reg, ok := nav.regCache[curr.path]; ok {\n\t\t\t\twin.printReg(ui.screen, reg, &ui.sxScreen, nav.previewTimer)\n\t\t\t}\n\t\t} else if curr.IsDir() {\n\t\t\tui.sxScreen.lastFile = \"\"\n\t\t\tdir := nav.getDir(curr.path)\n\t\t\tdirStyle := &dirStyle{colors: ui.styles, icons: ui.icons, role: Preview}\n\t\t\twin.printDir(ui, dir, context, dirStyle, nav.previewTimer)\n\t\t}\n\t}\n}\n\nfunc (ui *ui) drawBox() {\n\tst := parseEscapeSequence(gOpts.borderfmt)\n\n\tw, h := ui.screen.Size()\n\tstyle := gOpts.borderstyle\n\n\tif style&borderOutline != 0 {\n\t\tfor i := 1; i < w-1; i++ {\n\t\t\tui.screen.PutStrStyled(i, 1, string(tcell.RuneHLine), st)\n\t\t\tui.screen.PutStrStyled(i, h-2, string(tcell.RuneHLine), st)\n\t\t}\n\n\t\tfor i := 2; i < h-2; i++ {\n\t\t\tui.screen.PutStrStyled(0, i, string(tcell.RuneVLine), st)\n\t\t\tui.screen.PutStrStyled(w-1, i, string(tcell.RuneVLine), st)\n\t\t}\n\n\t\tif style&borderRound != 0 {\n\t\t\tui.screen.PutStrStyled(0, 1, \"╭\", st)\n\t\t\tui.screen.PutStrStyled(w-1, 1, \"╮\", st)\n\t\t\tui.screen.PutStrStyled(0, h-2, \"╰\", st)\n\t\t\tui.screen.PutStrStyled(w-1, h-2, \"╯\", st)\n\t\t} else {\n\t\t\tui.screen.PutStrStyled(0, 1, string(tcell.RuneULCorner), st)\n\t\t\tui.screen.PutStrStyled(w-1, 1, string(tcell.RuneURCorner), st)\n\t\t\tui.screen.PutStrStyled(0, h-2, string(tcell.RuneLLCorner), st)\n\t\t\tui.screen.PutStrStyled(w-1, h-2, string(tcell.RuneLRCorner), st)\n\t\t}\n\t}\n\n\tif style&borderSeparators == 0 {\n\t\treturn\n\t}\n\n\ttop, bot := 1, h-1\n\tif style&borderOutline != 0 {\n\t\ttop, bot = 2, h-2\n\t}\n\n\tfor wind := range len(ui.wins) - 1 {\n\t\tx := ui.wins[wind].x + ui.wins[wind].w\n\t\tif style&borderOutline != 0 {\n\t\t\tui.screen.PutStrStyled(x, 1, string(tcell.RuneTTee), st)\n\t\t}\n\t\tfor y := top; y < bot; y++ {\n\t\t\tui.screen.PutStrStyled(x, y, string(tcell.RuneVLine), st)\n\t\t}\n\t\tif style&borderOutline != 0 {\n\t\t\tui.screen.PutStrStyled(x, h-2, string(tcell.RuneBTee), st)\n\t\t}\n\t}\n}\n\nfunc (ui *ui) drawMenu() {\n\tif ui.menu == \"\" {\n\t\treturn\n\t}\n\n\tlines := strings.Split(ui.menu, \"\\n\")\n\tlines = lines[:len(lines)-1]\n\n\tui.menuWin.h = len(lines)\n\tui.menuWin.y = ui.msgWin.y - ui.menuWin.h\n\n\t// clear sixel image if it overlaps with the menu\n\tui.screen.LockRegion(ui.menuWin.x, ui.menuWin.y, ui.menuWin.w, ui.menuWin.h, false)\n\tui.sxScreen.forceClear = true\n\n\tfor i, line := range lines {\n\t\tvar st tcell.Style\n\t\tif i == 0 {\n\t\t\tst = parseEscapeSequence(gOpts.menuheaderfmt)\n\t\t} else {\n\t\t\tst = parseEscapeSequence(gOpts.menufmt)\n\t\t}\n\n\t\tui.menuWin.printLine(ui.screen, 0, i, st, line)\n\t}\n\n\tif ui.menuSelect != nil {\n\t\tst := parseEscapeSequence(gOpts.menuselectfmt)\n\t\tui.menuWin.print(ui.screen, ui.menuSelect.x, ui.menuSelect.y, st, ui.menuSelect.s)\n\t}\n}\n\nfunc (ui *ui) dirOfWin(nav *nav, wind int) *dir {\n\twins := len(ui.wins)\n\tif gOpts.preview {\n\t\twins--\n\t}\n\tind := len(nav.dirPaths) - wins + wind\n\tif ind < 0 {\n\t\treturn nil\n\t}\n\treturn nav.getDir(nav.dirPaths[ind])\n}\n\nfunc (ui *ui) draw(nav *nav) {\n\tst := tcell.StyleDefault\n\tcontext := dirContext{selections: nav.selections, clipboard: nav.clipboard, tags: nav.tags}\n\n\tui.screen.Clear()\n\n\tui.drawPromptLine(nav)\n\n\twins := len(ui.wins)\n\tif gOpts.preview {\n\t\twins--\n\t}\n\tfor i := range wins {\n\t\trole := Parent\n\t\tif i == wins-1 {\n\t\t\trole = Active\n\t\t}\n\t\tif dir := ui.dirOfWin(nav, i); dir != nil {\n\t\t\tdirStyle := &dirStyle{colors: ui.styles, icons: ui.icons, role: role}\n\t\t\tui.wins[i].printDir(ui, dir, &context, dirStyle, nav.previewTimer)\n\t\t}\n\t}\n\n\tswitch ui.cmdPrefix {\n\tcase \"\":\n\t\tif gOpts.rulerfmt == \"\" {\n\t\t\tui.drawRulerFile(nav)\n\t\t} else {\n\t\t\tui.drawStat(nav)\n\t\t\tui.drawRuler(nav)\n\t\t}\n\t\tui.screen.HideCursor()\n\tcase \">\":\n\t\tmaxWidth := ui.msgWin.w - 1 // leave space for cursor at the end\n\t\tprefix := truncateRight(ui.cmdPrefix, maxWidth)\n\t\tleft := truncateLeft(ui.cmdAccLeft, maxWidth-uniseg.StringWidth(prefix)-printLength(ui.msg))\n\t\tui.msgWin.printLine(ui.screen, 0, 0, st, prefix+ui.msg)\n\t\tui.msgWin.print(ui.screen, uniseg.StringWidth(prefix)+printLength(ui.msg), 0, st, left+ui.cmdAccRight)\n\t\tui.screen.ShowCursor(ui.msgWin.x+uniseg.StringWidth(prefix)+printLength(ui.msg)+uniseg.StringWidth(left), ui.msgWin.y)\n\tdefault:\n\t\tmaxWidth := ui.msgWin.w - 1 // leave space for cursor at the end\n\t\tprefix := truncateRight(ui.cmdPrefix, maxWidth)\n\t\tleft := truncateLeft(ui.cmdAccLeft, maxWidth-uniseg.StringWidth(prefix))\n\t\tui.msgWin.printLine(ui.screen, 0, 0, st, prefix+left+ui.cmdAccRight)\n\t\tui.screen.ShowCursor(ui.msgWin.x+uniseg.StringWidth(prefix)+uniseg.StringWidth(left), ui.msgWin.y)\n\t}\n\n\tui.drawPreview(nav, &context)\n\n\tif gOpts.drawbox {\n\t\tui.drawBox()\n\t}\n\n\tui.drawMenu()\n\n\tui.screen.Show()\n}\n\nfunc findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) {\n\tbinds = make(map[string]expr)\n\tfor key, expr := range keys {\n\t\tif !strings.HasPrefix(key, prefix) {\n\t\t\tcontinue\n\t\t}\n\t\tbinds[key] = expr\n\t\tif key == prefix {\n\t\t\tok = true\n\t\t}\n\t}\n\treturn\n}\n\nfunc listBinds(binds map[string]map[string]expr) string {\n\tt := new(tabwriter.Writer)\n\tb := new(bytes.Buffer)\n\n\t// merge keys by command across modes\n\tm := make(map[string]map[string]string)\n\tfor mode, keys := range binds {\n\t\tfor key, expr := range keys {\n\t\t\tif _, ok := m[key]; !ok {\n\t\t\t\tm[key] = make(map[string]string)\n\t\t\t}\n\t\t\tm[key][expr.String()] += mode\n\t\t}\n\t}\n\n\ttype entry struct {\n\t\tmode, key, cmd string\n\t}\n\n\t// collect normalized entries\n\tvar entries []entry\n\tfor key, cmds := range m {\n\t\tfor cmd, modes := range cmds {\n\t\t\ttmp := []rune(modes)\n\t\t\tslices.Sort(tmp)\n\t\t\tentries = append(entries, entry{string(tmp), key, cmd})\n\t\t}\n\t}\n\n\tsort.Slice(entries, func(i, j int) bool {\n\t\tif entries[i].key != entries[j].key {\n\t\t\treturn entries[i].key < entries[j].key\n\t\t}\n\t\treturn entries[i].mode < entries[j].mode\n\t})\n\n\tt.Init(b, 0, gOpts.tabstop, 2, '\\t', 0)\n\tfmt.Fprintln(t, \"mode\\tkey\\tcommand\")\n\tfor _, e := range entries {\n\t\tfmt.Fprintf(t, \"%s\\t%s\\t%s\\n\", e.mode, e.key, e.cmd)\n\t}\n\tt.Flush()\n\n\treturn b.String()\n}\n\nfunc listMatchingBinds(binds map[string]expr, prefix string) string {\n\tt := new(tabwriter.Writer)\n\tb := new(bytes.Buffer)\n\n\tkeys := make([]string, 0, len(binds))\n\tfor k := range binds {\n\t\tkeys = append(keys, k)\n\t}\n\tsort.Strings(keys)\n\n\tt.Init(b, 0, gOpts.tabstop, 2, '\\t', 0)\n\tfmt.Fprintln(t, \"key\\tcommand\")\n\tfor _, k := range keys {\n\t\tremain, _ := strings.CutPrefix(k, prefix)\n\t\tfmt.Fprintf(t, \"%s\\t%v\\n\", remain, binds[k])\n\t}\n\tt.Flush()\n\n\treturn b.String()\n}\n\nfunc listCmds(cmds map[string]expr) string {\n\tt := new(tabwriter.Writer)\n\tb := new(bytes.Buffer)\n\n\tkeys := make([]string, 0, len(cmds))\n\tfor k := range cmds {\n\t\tkeys = append(keys, k)\n\t}\n\tsort.Strings(keys)\n\n\tt.Init(b, 0, gOpts.tabstop, 2, '\\t', 0)\n\tfmt.Fprintln(t, \"name\\tcommand\")\n\tfor _, k := range keys {\n\t\tfmt.Fprintf(t, \"%s\\t%v\\n\", k, cmds[k])\n\t}\n\tt.Flush()\n\n\treturn b.String()\n}\n\nfunc listJumps(jumps []string, ind int) string {\n\tt := new(tabwriter.Writer)\n\tb := new(bytes.Buffer)\n\n\tmaxlength := len(strconv.Itoa(max(ind, len(jumps)-1-ind)))\n\n\tt.Init(b, 0, gOpts.tabstop, 2, '\\t', 0)\n\tfmt.Fprintln(t, \"  jump\\tpath\")\n\t// print jumps in order of most recent, Vim uses the opposite order\n\tfor i := len(jumps) - 1; i >= 0; i-- {\n\t\tswitch {\n\t\tcase i < ind:\n\t\t\tfmt.Fprintf(t, \"  %*d\\t%s\\n\", maxlength, ind-i, jumps[i])\n\t\tcase i > ind:\n\t\t\tfmt.Fprintf(t, \"  %*d\\t%s\\n\", maxlength, i-ind, jumps[i])\n\t\tdefault:\n\t\t\tfmt.Fprintf(t, \"> %*d\\t%s\\n\", maxlength, 0, jumps[i])\n\t\t}\n\t}\n\tt.Flush()\n\n\treturn b.String()\n}\n\nfunc listHistory(history []string) string {\n\tt := new(tabwriter.Writer)\n\tb := new(bytes.Buffer)\n\n\tmaxlength := len(strconv.Itoa(len(history)))\n\n\tt.Init(b, 0, gOpts.tabstop, 2, '\\t', 0)\n\tfmt.Fprintln(t, \"number\\tcommand\")\n\tfor i, cmd := range history {\n\t\tfmt.Fprintf(t, \"%*d\\t%s\\n\", maxlength, i+1, cmd)\n\t}\n\tt.Flush()\n\n\treturn b.String()\n}\n\nfunc listMarks(marks map[string]string) string {\n\tt := new(tabwriter.Writer)\n\tb := new(bytes.Buffer)\n\n\tkeys := make([]string, 0, len(marks))\n\tfor k := range marks {\n\t\tkeys = append(keys, k)\n\t}\n\tsort.Strings(keys)\n\n\tt.Init(b, 0, gOpts.tabstop, 2, '\\t', 0)\n\tfmt.Fprintln(t, \"mark\\tpath\")\n\tfor _, k := range keys {\n\t\tfmt.Fprintf(t, \"%s\\t%s\\n\", k, marks[k])\n\t}\n\tt.Flush()\n\n\treturn b.String()\n}\n\nfunc listFilesInCurrDir(nav *nav) string {\n\tdir := nav.currDir()\n\tif dir.loading {\n\t\tlog.Printf(\"listFilesInCurrDir(): %s is still loading, `files` isn't ready for remote query\", dir.path)\n\t\treturn \"\"\n\t}\n\n\tb := new(strings.Builder)\n\tfor _, file := range dir.files {\n\t\tfmt.Fprintln(b, file.path)\n\t}\n\n\treturn b.String()\n}\n\n// readNormalEvent is used to read a normal event on the client side. For keys,\n// digits are interpreted as command counts but this is only done for digits\n// preceding any non-digit characters (e.g. \"42y2k\" as 42 times \"y2k\").\nfunc (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {\n\tdraw := &callExpr{\"draw\", nil, 1}\n\tcount := 0\n\n\tkeys := gOpts.nkeys\n\tif nav.isVisualMode() {\n\t\tkeys = gOpts.vkeys\n\t}\n\n\tswitch tev := ev.(type) {\n\tcase *tcell.EventKey:\n\t\tif ui.pasteEvent {\n\t\t\treturn nil\n\t\t}\n\n\t\tisDigitKey := func(*tcell.EventKey) bool {\n\t\t\tif tev.Key() != tcell.KeyRune || tev.Modifiers() != tcell.ModNone {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\ts := tev.Str()\n\t\t\treturn len(s) == 1 && s[0] >= '0' && s[0] <= '9'\n\t\t}\n\n\t\tswitch {\n\t\tcase tev.Key() == tcell.KeyEsc && ui.keyAcc != \"\":\n\t\t\tui.keyAcc = \"\"\n\t\t\tui.keyCount = \"\"\n\t\t\tui.menu = \"\"\n\t\t\treturn draw\n\t\tcase isDigitKey(tev) && ui.keyAcc == \"\":\n\t\t\tui.keyCount += tev.Str()\n\t\t\treturn draw\n\t\tdefault:\n\t\t\tui.keyAcc += readKey(tev)\n\t\t}\n\n\t\tbinds, ok := findBinds(keys, ui.keyAcc)\n\n\t\tswitch len(binds) {\n\t\tcase 0:\n\t\t\tui.echoerrf(\"unknown mapping: %s\", ui.keyAcc)\n\t\t\tui.keyAcc = \"\"\n\t\t\tui.keyCount = \"\"\n\t\t\tui.menu = \"\"\n\t\t\treturn draw\n\t\tdefault:\n\t\t\tif ok {\n\t\t\t\tif ui.keyCount != \"\" {\n\t\t\t\t\tc, err := strconv.Atoi(ui.keyCount)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tlog.Printf(\"converting command count: %s\", err)\n\t\t\t\t\t}\n\t\t\t\t\tcount = c\n\t\t\t\t}\n\t\t\t\texpr := keys[ui.keyAcc]\n\n\t\t\t\tif count != 0 {\n\t\t\t\t\tswitch e := expr.(type) {\n\t\t\t\t\tcase *callExpr:\n\t\t\t\t\t\texpr = &callExpr{name: e.name, args: e.args, count: count}\n\t\t\t\t\tcase *listExpr:\n\t\t\t\t\t\texpr = &listExpr{exprs: e.exprs, count: count}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tui.keyAcc = \"\"\n\t\t\t\tui.keyCount = \"\"\n\t\t\t\tui.menu = \"\"\n\t\t\t\treturn expr\n\t\t\t}\n\t\t\tif gOpts.showbinds {\n\t\t\t\t// mode and already typed keys are obvious here; no need to clutter the menu\n\t\t\t\tui.menu = listMatchingBinds(binds, ui.keyAcc)\n\t\t\t}\n\t\t\treturn draw\n\t\t}\n\tcase *tcell.EventMouse:\n\t\tif ui.cmdPrefix != \"\" {\n\t\t\treturn nil\n\t\t}\n\n\t\tvar button string\n\n\t\tswitch tev.Buttons() {\n\t\tcase tcell.Button1:\n\t\t\tbutton = \"<m-1>\"\n\t\tcase tcell.Button2:\n\t\t\tbutton = \"<m-2>\"\n\t\tcase tcell.Button3:\n\t\t\tbutton = \"<m-3>\"\n\t\tcase tcell.Button4:\n\t\t\tbutton = \"<m-4>\"\n\t\tcase tcell.Button5:\n\t\t\tbutton = \"<m-5>\"\n\t\tcase tcell.Button6:\n\t\t\tbutton = \"<m-6>\"\n\t\tcase tcell.Button7:\n\t\t\tbutton = \"<m-7>\"\n\t\tcase tcell.Button8:\n\t\t\tbutton = \"<m-8>\"\n\t\tcase tcell.WheelUp:\n\t\t\tbutton = \"<m-up>\"\n\t\tcase tcell.WheelDown:\n\t\t\tbutton = \"<m-down>\"\n\t\tcase tcell.WheelLeft:\n\t\t\tbutton = \"<m-left>\"\n\t\tcase tcell.WheelRight:\n\t\t\tbutton = \"<m-right>\"\n\t\tcase tcell.ButtonNone:\n\t\t\treturn nil\n\t\t}\n\t\tif tev.Modifiers() == tcell.ModCtrl {\n\t\t\tbutton = \"<c-\" + button[1:]\n\t\t}\n\t\tif expr, ok := keys[button]; ok {\n\t\t\treturn expr\n\t\t}\n\t\tif button != \"<m-1>\" && button != \"<m-2>\" {\n\t\t\tui.echoerrf(\"unknown mapping: %s\", button)\n\t\t\tui.keyAcc = \"\"\n\t\t\tui.keyCount = \"\"\n\t\t\tui.menu = \"\"\n\t\t\treturn draw\n\t\t}\n\n\t\tx, y := tev.Position()\n\t\twind, w := ui.winAt(x, y)\n\t\tif wind == -1 {\n\t\t\treturn nil\n\t\t}\n\n\t\tvar dir *dir\n\t\tif gOpts.preview && wind == len(ui.wins)-1 {\n\t\t\tcurr := nav.currFile()\n\t\t\tif curr == nil {\n\t\t\t\treturn nil\n\t\t\t} else if !curr.IsDir() || gOpts.dirpreviews {\n\t\t\t\tif tev.Buttons() != tcell.Button2 {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\treturn &callExpr{\"open\", nil, 1}\n\t\t\t}\n\n\t\t\tdir = nav.getDir(curr.path)\n\t\t} else {\n\t\t\tdir = ui.dirOfWin(nav, wind)\n\t\t\tif dir == nil {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}\n\n\t\tvar file *file\n\t\tind := dir.ind - dir.pos + y - w.y\n\t\tif ind < len(dir.files) {\n\t\t\tfile = dir.files[ind]\n\t\t}\n\n\t\tif file != nil {\n\t\t\tsel := &callExpr{\"select\", []string{file.path}, 1}\n\n\t\t\tif tev.Buttons() == tcell.Button1 {\n\t\t\t\treturn sel\n\t\t\t}\n\t\t\tif file.IsDir() {\n\t\t\t\treturn &callExpr{\"cd\", []string{file.path}, 1}\n\t\t\t}\n\t\t\treturn &listExpr{[]expr{sel, &callExpr{\"open\", nil, 1}}, 1}\n\t\t}\n\t\tif tev.Buttons() == tcell.Button1 {\n\t\t\treturn &callExpr{\"cd\", []string{dir.path}, 1}\n\t\t}\n\tcase *tcell.EventResize:\n\t\treturn &callExpr{\"redraw\", nil, 1}\n\tcase *tcell.EventError:\n\t\tlog.Printf(\"Got EventError: '%s' at %s\", tev.Error(), tev.When())\n\tcase *tcell.EventInterrupt:\n\t\tlog.Printf(\"Got EventInterrupt: at %s\", tev.When())\n\tcase *tcell.EventFocus:\n\t\tif tev.Focused {\n\t\t\treturn &callExpr{\"on-focus-gained\", nil, 1}\n\t\t} else {\n\t\t\treturn &callExpr{\"on-focus-lost\", nil, 1}\n\t\t}\n\tcase *tcell.EventPaste:\n\t\tif tev.Start() {\n\t\t\tui.pasteEvent = true\n\t\t} else if tev.End() {\n\t\t\tui.pasteEvent = false\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc readCmdEvent(ev tcell.Event) expr {\n\tif tev, ok := ev.(*tcell.EventKey); ok {\n\t\tif tev.Key() == tcell.KeyRune && tev.Modifiers()&tcell.ModAlt == 0 {\n\t\t\treturn &callExpr{\"cmd-insert\", []string{tev.Str()}, 1}\n\t\t}\n\n\t\tif expr, ok := gOpts.cmdkeys[readKey(tev)]; ok {\n\t\t\treturn expr\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (ui *ui) readEvent(ev tcell.Event, nav *nav) expr {\n\tif ev == nil {\n\t\treturn nil\n\t}\n\n\tif _, ok := ev.(*tcell.EventKey); ok && ui.cmdPrefix != \"\" {\n\t\treturn readCmdEvent(ev)\n\t}\n\n\treturn ui.readNormalEvent(ev, nav)\n}\n\nfunc (ui *ui) readEvents() {\n\tfor ev := range ui.screen.EventQ() {\n\t\tui.evChan <- ev\n\t}\n}\n\nfunc (ui *ui) suspend() error {\n\tui.sxScreen.forceClear = true\n\treturn ui.screen.Suspend()\n}\n\nfunc (ui *ui) resume() error {\n\treturn ui.screen.Resume()\n}\n\nfunc (ui *ui) exportSizes() {\n\tw, h := ui.screen.Size()\n\tos.Setenv(\"lf_width\", strconv.Itoa(w))\n\tos.Setenv(\"lf_height\", strconv.Itoa(h))\n}\n\nfunc anyKey() {\n\tfmt.Fprint(os.Stderr, gOpts.waitmsg)\n\tdefer fmt.Fprintln(os.Stderr)\n\toldState, err := term.MakeRaw(int(os.Stdin.Fd()))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer func() {\n\t\tif err := term.Restore(int(os.Stdin.Fd()), oldState); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}()\n\n\tb := make([]byte, 8)\n\tif _, err := os.Stdin.Read(b); err != nil {\n\t\tlog.Printf(\"Failed to read key press: %s\", err)\n\t}\n}\n\nfunc listMatches(screen tcell.Screen, matches []compMatch, selectedInd int) (string, *menuSelect) {\n\tif len(matches) < 2 {\n\t\treturn \"\", nil\n\t}\n\n\twtot, _ := screen.Size()\n\twcol := 0\n\tfor _, m := range matches {\n\t\twcol = max(wcol, uniseg.StringWidth(m.name))\n\t}\n\twcol += gOpts.tabstop - wcol%gOpts.tabstop\n\tncol := max(wtot/wcol, 1)\n\n\tvar b strings.Builder\n\tb.WriteString(\"possible matches\")\n\n\tfor i, match := range matches {\n\t\tif i%ncol == 0 {\n\t\t\tb.WriteByte('\\n')\n\t\t}\n\t\tw := uniseg.StringWidth(match.name)\n\t\tfmt.Fprintf(&b, \"%s%*s\", match.name, wcol-w, \"\")\n\t}\n\n\tb.WriteByte('\\n')\n\n\tvar selection *menuSelect\n\tif selectedInd != -1 {\n\t\tselection = &menuSelect{selectedInd % ncol * wcol, selectedInd/ncol + 1, matches[selectedInd].name}\n\t}\n\n\treturn b.String(), selection\n}\n"
  },
  {
    "path": "watch.go",
    "content": "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\twatcher  *fsnotify.Watcher\n\tevents   <-chan fsnotify.Event\n\tquit     chan struct{}\n\tpending  map[watchUpdate]bool\n\ttimeout  chan watchUpdate\n\tdirChan  chan<- *dir\n\tfileChan chan<- *file\n\tdelChan  chan<- string\n}\n\nfunc newWatch(dirChan chan<- *dir, fileChan chan<- *file, delChan chan<- string) *watch {\n\twatch := &watch{\n\t\tquit:     make(chan struct{}),\n\t\tpending:  make(map[watchUpdate]bool),\n\t\ttimeout:  make(chan watchUpdate, 1024),\n\t\tdirChan:  dirChan,\n\t\tfileChan: fileChan,\n\t\tdelChan:  delChan,\n\t}\n\n\treturn watch\n}\n\nfunc (watch *watch) start() {\n\tif watch.watcher != nil {\n\t\treturn\n\t}\n\n\twatcher, err := fsnotify.NewWatcher()\n\tif err != nil {\n\t\tlog.Printf(\"start watcher: %s\", err)\n\t\treturn\n\t}\n\n\twatch.watcher = watcher\n\twatch.events = watcher.Events\n\n\tgo watch.loop()\n}\n\nfunc (watch *watch) stop() {\n\tif watch.watcher == nil {\n\t\treturn\n\t}\n\n\twatch.quit <- struct{}{}\n\twatch.watcher.Close()\n\n\twatch.watcher = nil\n\twatch.events = nil\n}\n\nfunc (watch *watch) add(path string) {\n\tif watch.watcher == nil {\n\t\treturn\n\t}\n\n\t// ignore /dev since write updates to /dev/tty causes high cpu usage\n\tif path != \"/dev\" {\n\t\tif err := watch.watcher.Add(path); err != nil {\n\t\t\tlog.Printf(\"watch path %s: %s\", path, err)\n\t\t}\n\t}\n}\n\nfunc (watch *watch) loop() {\n\tfor {\n\t\tselect {\n\t\tcase ev := <-watch.events:\n\t\t\tif ev.Has(fsnotify.Create) {\n\t\t\t\tfor _, path := range watch.getSameDirs(filepath.Dir(ev.Name)) {\n\t\t\t\t\twatch.addUpdate(watchUpdate{\"dir\", path})\n\t\t\t\t\twatch.addUpdate(watchUpdate{\"file\", path})\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ev.Has(fsnotify.Remove) || ev.Has(fsnotify.Rename) {\n\t\t\t\tdir, file := filepath.Split(ev.Name)\n\t\t\t\tfor _, path := range watch.getSameDirs(dir) {\n\t\t\t\t\twatch.delChan <- filepath.Join(path, file)\n\t\t\t\t\twatch.addUpdate(watchUpdate{\"dir\", path})\n\t\t\t\t\twatch.addUpdate(watchUpdate{\"file\", path})\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ev.Has(fsnotify.Write) || ev.Has(fsnotify.Chmod) {\n\t\t\t\t// skip write updates for the log file, otherwise it is possible\n\t\t\t\t// to have an infinite loop where writing to the log file causes\n\t\t\t\t// it to be reloaded, which in turn triggers more events that\n\t\t\t\t// are then logged\n\t\t\t\tif ev.Name == gLogPath && ev.Has(fsnotify.Write) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tdir, file := filepath.Split(ev.Name)\n\t\t\t\tfor _, path := range watch.getSameDirs(dir) {\n\t\t\t\t\twatch.addUpdate(watchUpdate{\"file\", filepath.Join(path, file)})\n\t\t\t\t}\n\t\t\t}\n\t\tcase update := <-watch.timeout:\n\t\t\tif watch.pending[update] {\n\t\t\t\twatch.processUpdate(update)\n\t\t\t\ttime.AfterFunc(100*time.Millisecond, func() { watch.timeout <- update })\n\t\t\t\twatch.pending[update] = false\n\t\t\t} else {\n\t\t\t\tdelete(watch.pending, update)\n\t\t\t}\n\t\tcase <-watch.quit:\n\t\t\treturn\n\t\t}\n\t}\n}\n\ntype watchUpdate struct {\n\tkind string\n\tpath string\n}\n\nfunc (watch *watch) addUpdate(update watchUpdate) {\n\t// process an update immediately if is the first time, otherwise store it\n\t// and process only after a timeout to reduce the number of actual loads\n\tif _, ok := watch.pending[update]; !ok {\n\t\twatch.processUpdate(update)\n\t\ttime.AfterFunc(100*time.Millisecond, func() { watch.timeout <- update })\n\t\twatch.pending[update] = false\n\t} else {\n\t\twatch.pending[update] = true\n\t}\n}\n\nfunc (watch *watch) processUpdate(update watchUpdate) {\n\tswitch update.kind {\n\tcase \"dir\":\n\t\tif _, err := os.Lstat(update.path); err == nil {\n\t\t\tdir := newDir(update.path)\n\t\t\tdir.sort()\n\t\t\twatch.dirChan <- dir\n\t\t}\n\tcase \"file\":\n\t\tif _, err := os.Lstat(update.path); err == nil {\n\t\t\twatch.fileChan <- newFile(update.path)\n\t\t}\n\t}\n}\n\n// Hacky workaround since fsnotify reports changes for only one path if a\n// directory is located at more than one path (e.g. bind mounts).\nfunc (watch *watch) getSameDirs(dir string) []string {\n\tvar paths []string\n\n\tdirStat, err := os.Stat(dir)\n\tif err != nil {\n\t\treturn nil\n\t}\n\n\tfor _, path := range watch.watcher.WatchList() {\n\t\tif path == dir {\n\t\t\tpaths = append(paths, path)\n\t\t\tcontinue\n\t\t}\n\n\t\tstat, err := os.Stat(path)\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tif os.SameFile(stat, dirStat) {\n\t\t\tpaths = append(paths, path)\n\t\t}\n\t}\n\n\treturn paths\n}\n"
  }
]