Repository: ogham/exa Branch: master Commit: 3d1edbb47052 Files: 250 Total size: 720.4 KB Directory structure: gitextract_pkcv6wm8/ ├── .github/ │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE/ │ │ └── bug_report.md │ └── workflows/ │ └── unit-tests.yml ├── .gitignore ├── .rustfmt.toml ├── Cargo.toml ├── Justfile ├── LICENCE ├── README.md ├── Vagrantfile ├── build.rs ├── completions/ │ ├── bash/ │ │ └── exa │ ├── fish/ │ │ └── exa.fish │ └── zsh/ │ └── _exa ├── devtools/ │ ├── README.md │ ├── dev-bash.sh │ ├── dev-create-test-filesystem.sh │ ├── dev-fixtures.sh │ ├── dev-help.sh │ ├── dev-package-for-linux.sh │ ├── dev-run-debug.sh │ ├── dev-run-release.sh │ ├── dev-set-up-environment.sh │ ├── dev-versions.sh │ └── local-package-for-macos.sh ├── man/ │ ├── exa.1.md │ └── exa_colors.5.md ├── rust-toolchain.toml ├── snap/ │ ├── .gitignore │ └── snapcraft.yaml ├── src/ │ ├── fs/ │ │ ├── dir.rs │ │ ├── dir_action.rs │ │ ├── feature/ │ │ │ ├── git.rs │ │ │ ├── mod.rs │ │ │ └── xattr.rs │ │ ├── fields.rs │ │ ├── file.rs │ │ ├── filter.rs │ │ └── mod.rs │ ├── info/ │ │ ├── filetype.rs │ │ ├── mod.rs │ │ └── sources.rs │ ├── logger.rs │ ├── main.rs │ ├── options/ │ │ ├── dir_action.rs │ │ ├── error.rs │ │ ├── file_name.rs │ │ ├── filter.rs │ │ ├── flags.rs │ │ ├── help.rs │ │ ├── mod.rs │ │ ├── parser.rs │ │ ├── theme.rs │ │ ├── vars.rs │ │ ├── version.rs │ │ └── view.rs │ ├── output/ │ │ ├── cell.rs │ │ ├── details.rs │ │ ├── escape.rs │ │ ├── file_name.rs │ │ ├── grid.rs │ │ ├── grid_details.rs │ │ ├── icons.rs │ │ ├── lines.rs │ │ ├── mod.rs │ │ ├── render/ │ │ │ ├── blocks.rs │ │ │ ├── filetype.rs │ │ │ ├── git.rs │ │ │ ├── groups.rs │ │ │ ├── inode.rs │ │ │ ├── links.rs │ │ │ ├── mod.rs │ │ │ ├── octal.rs │ │ │ ├── permissions.rs │ │ │ ├── size.rs │ │ │ ├── times.rs │ │ │ └── users.rs │ │ ├── table.rs │ │ ├── time.rs │ │ └── tree.rs │ └── theme/ │ ├── default_theme.rs │ ├── lsc.rs │ ├── mod.rs │ └── ui_styles.rs └── xtests/ ├── README.md ├── attributes.toml ├── colour-term.toml ├── debug-logging.toml ├── details-view-dates.toml ├── details-view-filesizes.toml ├── details-view-passwd.toml ├── details-view-permissions.toml ├── details-view.toml ├── dotfiles.toml ├── errors.toml ├── features/ │ ├── none.toml │ └── outputs/ │ └── disabled_git.txt ├── git-ignore.toml ├── git.toml ├── grid-details-view.toml ├── grid-view.toml ├── help.toml ├── icons.toml ├── ignore-glob.toml ├── input-options.toml ├── lines-view.toml ├── outputs/ │ ├── attributes_files_xattrs_tree.ansitxt │ ├── attributes_xattrs_long_tree.ansitxt │ ├── attributes_xattrs_tree.ansitxt │ ├── dates_long_currentyear_localefr.ansitxt │ ├── dates_long_localefr.ansitxt │ ├── dates_long_localejp.ansitxt │ ├── dates_long_time_accessed.ansitxt │ ├── dates_long_time_created.ansitxt │ ├── dates_long_time_modified.ansitxt │ ├── dates_long_timestyle_fulliso.ansitxt │ ├── dates_long_timestyle_iso.ansitxt │ ├── dates_long_timestyle_longiso.ansitxt │ ├── dev_long.ansitxt │ ├── dirs_grid.ansitxt │ ├── dirs_oneline.ansitxt │ ├── error_columns_invalid.ansitxt │ ├── error_columns_nines.ansitxt │ ├── error_grid_rows_invalid.ansitxt │ ├── error_grid_rows_nines.ansitxt │ ├── error_icon_spacing_invalid.ansitxt │ ├── error_icon_spacing_nines.ansitxt │ ├── error_invalid_option.ansitxt │ ├── error_level_invalid.ansitxt │ ├── error_level_nines.ansitxt │ ├── error_tree_all_all.ansitxt │ ├── exts_compressed_paths_themed.ansitxt │ ├── exts_compressed_paths_themed_reset.ansitxt │ ├── exts_grid_monochrome.ansitxt │ ├── exts_grid_sort_name_reverse.ansitxt │ ├── exts_oneline_icons.ansitxt │ ├── exts_oneline_sort_ext.ansitxt │ ├── exts_oneline_sort_extcase.ansitxt │ ├── exts_oneline_sort_name.ansitxt │ ├── exts_oneline_sort_name_reverse.ansitxt │ ├── exts_oneline_sort_namecase.ansitxt │ ├── exts_themed_reset.ansitxt │ ├── far_dates_long.ansitxt │ ├── files_grid_13col.ansitxt │ ├── files_grid_20col.ansitxt │ ├── files_grid_4col.ansitxt │ ├── files_grid_8col.ansitxt │ ├── files_grid_icons.ansitxt │ ├── files_grid_monochrome.ansitxt │ ├── files_long.ansitxt │ ├── files_long_binary.ansitxt │ ├── files_long_bytes.ansitxt │ ├── files_long_colourscale.ansitxt │ ├── files_long_colourscale_binary.ansitxt │ ├── files_long_colourscale_bytes.ansitxt │ ├── files_long_grid_1col.ansitxt │ ├── files_long_grid_2col.ansitxt │ ├── files_long_grid_3col.ansitxt │ ├── files_long_grid_4col.ansitxt │ ├── files_long_grid_exa_grid_rows_2_3files.ansitxt │ ├── files_long_grid_exa_grid_rows_5_15files.ansitxt │ ├── files_long_grid_exa_grid_rows_6_15files.ansitxt │ ├── files_long_grid_header_1file.ansitxt │ ├── files_long_grid_header_2files.ansitxt │ ├── files_long_grid_icons.ansitxt │ ├── files_long_header.ansitxt │ ├── files_long_header_binary.ansitxt │ ├── files_long_header_bytes.ansitxt │ ├── files_long_icons.ansitxt │ ├── files_long_monochrome.ansitxt │ ├── files_long_tree_icons.ansitxt │ ├── files_oneline_icons.ansitxt │ ├── files_paths_grid_3col.ansitxt │ ├── files_paths_grid_5col.ansitxt │ ├── files_paths_grid_7col.ansitxt │ ├── files_paths_long_grid_1col.ansitxt │ ├── files_paths_long_grid_2col.ansitxt │ ├── files_paths_long_grid_3col.ansitxt │ ├── files_tree_icons.ansitxt │ ├── git1+2_long.ansitxt │ ├── git1+2_long_directories.ansitxt │ ├── git1+2_long_nested.ansitxt │ ├── git1_long.ansitxt │ ├── git1_long_additions.ansitxt │ ├── git1_long_edits.ansitxt │ ├── git1_long_moves.ansitxt │ ├── git1_long_multiple.ansitxt │ ├── git1_long_recurse.ansitxt │ ├── git1_long_tree.ansitxt │ ├── git1_paths_long_grid.ansitxt │ ├── git2_ignoreds_grid_gitignore.ansitxt │ ├── git2_ignoreds_lines_gitignore.ansitxt │ ├── git2_ignoreds_long_gitignore.ansitxt │ ├── git2_ignoreds_long_grid_gitignore.ansitxt │ ├── git2_ignoreds_long_recurse_gitignore.ansitxt │ ├── git2_ignoreds_long_tree_gitignore.ansitxt │ ├── git2_ignoreds_tree_gitignore.ansitxt │ ├── git2_long.ansitxt │ ├── git2_long_ignoredcontent.ansitxt │ ├── git2_long_ignoreddir.ansitxt │ ├── git2_long_ignorednested.ansitxt │ ├── git2_long_multiple.ansitxt │ ├── git2_long_nested.ansitxt │ ├── git2_long_recurse.ansitxt │ ├── git2_long_recurse_gitignore.ansitxt │ ├── git2_long_tree.ansitxt │ ├── git2_long_tree_gitignore.ansitxt │ ├── git2_tree_gitignore.ansitxt │ ├── git3_long.ansitxt │ ├── git4_long.ansitxt │ ├── help.ansitxt │ ├── hiddens_grid.ansitxt │ ├── hiddens_grid_all.ansitxt │ ├── hiddens_grid_all_all.ansitxt │ ├── hiddens_long.ansitxt │ ├── hiddens_long_all.ansitxt │ ├── hiddens_long_all_all.ansitxt │ ├── links_grid.ansitxt │ ├── links_grid_monochrome.ansitxt │ ├── links_lines.ansitxt │ ├── links_long_classify.ansitxt │ ├── links_oneline_icons.ansitxt │ ├── links_oneline_icons_width0.ansitxt │ ├── links_oneline_icons_width2.ansitxt │ ├── links_oneline_icons_width3.ansitxt │ ├── links_oneline_sort_type.ansitxt │ ├── links_oneline_themed.ansitxt │ ├── links_paths_lines.ansitxt │ ├── links_tree.ansitxt │ ├── links_xattrs_tree.ansitxt │ ├── names_grid.ansitxt │ ├── names_grid_across.ansitxt │ ├── names_grid_recurse.ansitxt │ ├── names_lines.ansitxt │ ├── names_tree.ansitxt │ ├── passwd_long_group_header.ansitxt │ ├── permissions_long_group_header.ansitxt │ ├── permissions_long_group_header_sudo.ansitxt │ ├── permissions_long_themed.ansitxt │ ├── permissions_oneline_icons.ansitxt │ ├── proc_1_root.ansitxt │ ├── proc_1_root_xattrs.ansitxt │ ├── specials_long.ansitxt │ ├── specials_long_classify.ansitxt │ ├── specials_oneline_sort_type.ansitxt │ └── specials_oneline_themed.ansitxt ├── run.sh ├── sorting.toml ├── themes.toml └── tree-view.toml ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/FUNDING.yml ================================================ github: ogham ================================================ FILE: .github/ISSUE_TEMPLATE/bug_report.md ================================================ --- name: exa is unmaintained about: Please use the active fork eza instead. --- exa is unmaintained, please use the active fork eza instead. --- ================================================ FILE: .github/workflows/unit-tests.yml ================================================ name: Unit tests on: push: branches: [ master ] paths: - '.github/workflows/*' - 'src/**' - 'Cargo.*' - build.rs pull_request: branches: [ master ] paths: - '.github/workflows/*' - 'src/**' - 'Cargo.*' - build.rs env: CARGO_TERM_COLOR: always jobs: unit-tests: runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.rust == 'nightly' }} strategy: matrix: os: [ubuntu-latest, macos-latest] rust: [1.66.1, stable, beta, nightly] steps: - name: Checkout repository uses: actions/checkout@v3 - name: Install Rust toolchain uses: dtolnay/rust-toolchain@v1 with: toolchain: ${{ matrix.rust }} - name: Install cargo-hack run: cargo install cargo-hack@0.5.27 - name: Run unit tests run: cargo hack test --feature-powerset ================================================ FILE: .gitignore ================================================ # Rust stuff target # Vagrant stuff .vagrant *.log # Compiled artifacts # (see devtools/*-package-for-*.sh) /exa-linux-x86_64 /exa-linux-x86_64-*.zip /exa-macos-x86_64 /exa-macos-x86_64-*.zip /MD5SUMS /SHA1SUMS # Snap stuff parts prime stage *.snap ================================================ FILE: .rustfmt.toml ================================================ disable_all_formatting = true ================================================ FILE: Cargo.toml ================================================ [package] name = "exa" description = "A modern replacement for ls" authors = ["Benjamin Sago "] categories = ["command-line-utilities"] edition = "2021" rust-version = "1.66.1" exclude = ["/devtools/*", "/Justfile", "/Vagrantfile", "/screenshots.png"] readme = "README.md" homepage = "https://the.exa.website/" license = "MIT" repository = "https://github.com/ogham/exa" version = "0.10.1" [[bin]] name = "exa" [dependencies] ansi_term = "0.12" glob = "0.3" lazy_static = "1.3" libc = "0.2" locale = "0.2" log = "0.4" natord = "1.0" num_cpus = "1.10" number_prefix = "0.4" scoped_threadpool = "0.1" term_grid = "0.2.0" terminal_size = "0.1.16" unicode-width = "0.1" zoneinfo_compiled = "0.5.1" [target.'cfg(unix)'.dependencies] users = "0.11" [dependencies.datetime] version = "0.5.2" default-features = false features = ["format"] [dependencies.git2] version = "0.13" optional = true default-features = false [build-dependencies.datetime] version = "0.5.2" default-features = false [features] default = [ "git" ] git = [ "git2" ] vendored-openssl = ["git2/vendored-openssl"] # make dev builds faster by excluding debug symbols [profile.dev] debug = false # use LTO for smaller binaries (that take longer to build) [profile.release] lto = true [package.metadata.deb] license-file = [ "LICENCE", "4" ] depends = "$auto" extended-description = """ exa is a replacement for ls written in Rust. """ section = "utils" priority = "optional" assets = [ [ "target/release/exa", "/usr/bin/exa", "0755" ], [ "target/release/../man/exa.1", "/usr/share/man/man1/exa.1", "0644" ], [ "target/release/../man/exa_colors.5", "/usr/share/man/man5/exa_colors.5", "0644" ], [ "completions/bash/exa", "/usr/share/bash-completion/completions/exa", "0644" ], [ "completions/zsh/_exa", "/usr/share/zsh/site-functions/_exa", "0644" ], [ "completions/fish/exa.fish", "/usr/share/fish/vendor_completions.d/exa.fish", "0644" ], ] ================================================ FILE: Justfile ================================================ all: build test all-release: build-release test-release #----------# # building # #----------# # compile the exa binary @build: cargo build # compile the exa binary (in release mode) @build-release: cargo build --release --verbose # produce an HTML chart of compilation timings @build-time: cargo +nightly clean cargo +nightly build -Z timings # check that the exa binary can compile @check: cargo check #---------------# # running tests # #---------------# # run unit tests @test: cargo test --workspace -- --quiet # run unit tests (in release mode) @test-release: cargo test --workspace --release --verbose #------------------------# # running extended tests # #------------------------# # run extended tests @xtests: xtests/run.sh # run extended tests (using the release mode exa) @xtests-release: xtests/run.sh --release # display the number of extended tests that get run @count-xtests: grep -F '[[cmd]]' -R xtests | wc -l #-----------------------# # code quality and misc # #-----------------------# # lint the code @clippy: touch src/main.rs cargo clippy # update dependency versions, and checks for outdated ones @update-deps: cargo update command -v cargo-outdated >/dev/null || (echo "cargo-outdated not installed" && exit 1) cargo outdated # list unused dependencies @unused-deps: command -v cargo-udeps >/dev/null || (echo "cargo-udeps not installed" && exit 1) cargo +nightly udeps # check that every combination of feature flags is successful @check-features: command -v cargo-hack >/dev/null || (echo "cargo-hack not installed" && exit 1) cargo hack check --feature-powerset # build exa and run extended tests with features disabled @feature-checks *args: cargo build --no-default-features specsheet xtests/features/none.toml -shide {{args}} \ -O cmd.target.exa="${CARGO_TARGET_DIR:-../../target}/debug/exa" # print versions of the necessary build tools @versions: rustc --version cargo --version #---------------# # documentation # #---------------# # build the man pages @man: mkdir -p "${CARGO_TARGET_DIR:-target}/man" pandoc --standalone -f markdown -t man man/exa.1.md > "${CARGO_TARGET_DIR:-target}/man/exa.1" pandoc --standalone -f markdown -t man man/exa_colors.5.md > "${CARGO_TARGET_DIR:-target}/man/exa_colors.5" # build and preview the main man page (exa.1) @man-1-preview: man man "${CARGO_TARGET_DIR:-target}/man/exa.1" # build and preview the colour configuration man page (exa_colors.5) @man-5-preview: man man "${CARGO_TARGET_DIR:-target}/man/exa_colors.5" ================================================ FILE: LICENCE ================================================ The MIT License (MIT) Copyright (c) 2014 Benjamin Sago Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # exa is unmaintained, use the [fork eza](https://github.com/eza-community/eza) instead. (This repository isn’t archived because the only person with the rights to do so is unreachable). ---
# exa [exa](https://the.exa.website/) is a modern replacement for _ls_. **README Sections:** [Options](#options) — [Installation](#installation) — [Development](#development) [![Unit tests](https://github.com/ogham/exa/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/ogham/exa/actions/workflows/unit-tests.yml)
![Screenshots of exa](screenshots.png) --- **exa** is a modern replacement for the venerable file-listing command-line program `ls` that ships with Unix and Linux operating systems, giving it more features and better defaults. It uses colours to distinguish file types and metadata. It knows about symlinks, extended attributes, and Git. And it’s **small**, **fast**, and just **one single binary**. By deliberately making some decisions differently, exa attempts to be a more featureful, more user-friendly version of `ls`. For more information, see [exa’s website](https://the.exa.website/). ---

Command-line options

exa’s options are almost, but not quite, entirely unlike `ls`’s. ### Display options - **-1**, **--oneline**: display one entry per line - **-G**, **--grid**: display entries as a grid (default) - **-l**, **--long**: display extended details and attributes - **-R**, **--recurse**: recurse into directories - **-T**, **--tree**: recurse into directories as a tree - **-x**, **--across**: sort the grid across, rather than downwards - **-F**, **--classify**: display type indicator by file names - **--colo[u]r**: when to use terminal colours - **--colo[u]r-scale**: highlight levels of file sizes distinctly - **--icons**: display icons - **--no-icons**: don't display icons (always overrides --icons) ### Filtering options - **-a**, **--all**: show hidden and 'dot' files - **-d**, **--list-dirs**: list directories like regular files - **-L**, **--level=(depth)**: limit the depth of recursion - **-r**, **--reverse**: reverse the sort order - **-s**, **--sort=(field)**: which field to sort by - **--group-directories-first**: list directories before other files - **-D**, **--only-dirs**: list only directories - **--git-ignore**: ignore files mentioned in `.gitignore` - **-I**, **--ignore-glob=(globs)**: glob patterns (pipe-separated) of files to ignore Pass the `--all` option twice to also show the `.` and `..` directories. ### Long view options These options are available when running with `--long` (`-l`): - **-b**, **--binary**: list file sizes with binary prefixes - **-B**, **--bytes**: list file sizes in bytes, without any prefixes - **-g**, **--group**: list each file’s group - **-h**, **--header**: add a header row to each column - **-H**, **--links**: list each file’s number of hard links - **-i**, **--inode**: list each file’s inode number - **-m**, **--modified**: use the modified timestamp field - **-S**, **--blocks**: list each file’s number of file system blocks - **-t**, **--time=(field)**: which timestamp field to use - **-u**, **--accessed**: use the accessed timestamp field - **-U**, **--created**: use the created timestamp field - **-@**, **--extended**: list each file’s extended attributes and sizes - **--changed**: use the changed timestamp field - **--git**: list each file’s Git status, if tracked or ignored - **--time-style**: how to format timestamps - **--no-permissions**: suppress the permissions field - **--octal-permissions**: list each file's permission in octal format - **--no-filesize**: suppress the filesize field - **--no-user**: suppress the user field - **--no-time**: suppress the time field Some of the options accept parameters: - Valid **--color** options are **always**, **automatic**, and **never**. - Valid sort fields are **accessed**, **changed**, **created**, **extension**, **Extension**, **inode**, **modified**, **name**, **Name**, **size**, **type**, and **none**. Fields starting with a capital letter sort uppercase before lowercase. The modified field has the aliases **date**, **time**, and **newest**, while its reverse has the aliases **age** and **oldest**. - Valid time fields are **modified**, **changed**, **accessed**, and **created**. - Valid time styles are **default**, **iso**, **long-iso**, and **full-iso**. ---

Installation

exa is available for macOS and Linux. More information on how to install exa is available on [the Installation page](https://the.exa.website/install). ### Alpine Linux On Alpine Linux, [enable community repository](https://wiki.alpinelinux.org/wiki/Enable_Community_Repository) and install the [`exa`](https://pkgs.alpinelinux.org/package/edge/community/x86_64/exa) package. apk add exa ### Arch Linux On Arch, install the [`exa`](https://www.archlinux.org/packages/community/x86_64/exa/) package. pacman -S exa ### Android / Termux On Android / Termux, install the [`exa`](https://github.com/termux/termux-packages/tree/master/packages/exa) package. pkg install exa ### Debian On Debian, install the [`exa`](https://packages.debian.org/stable/exa) package. apt install exa ### Fedora On Fedora, install the [`exa`](https://src.fedoraproject.org/modules/exa) package. dnf install exa ### Gentoo On Gentoo, install the [`sys-apps/exa`](https://packages.gentoo.org/packages/sys-apps/exa) package. emerge sys-apps/exa ### Homebrew If you’re using [Homebrew](https://brew.sh/) on macOS, install the [`exa`](http://formulae.brew.sh/formula/exa) formula. brew install exa ### MacPorts If you're using [MacPorts](https://www.macports.org/) on macOS, install the [`exa`](https://ports.macports.org/port/exa/summary) port. port install exa ### Nix On nixOS, install the [`exa`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/exa/default.nix) package. nix-env -i exa ### openSUSE On openSUSE, install the [`exa`](https://software.opensuse.org/package/exa) package. zypper install exa ### Ubuntu On Ubuntu 20.10 (Groovy Gorilla) and later, install the [`exa`](https://packages.ubuntu.com/jammy/exa) package. sudo apt install exa ### Void Linux On Void Linux, install the [`exa`](https://github.com/void-linux/void-packages/blob/master/srcpkgs/exa/template) package. xbps-install -S exa ### Manual installation from GitHub Compiled binary versions of exa are uploaded to GitHub when a release is made. You can install exa manually by [downloading a release](https://github.com/ogham/exa/releases), extracting it, and copying the binary to a directory in your `$PATH`, such as `/usr/local/bin`. For more information, see the [Manual Installation page](https://the.exa.website/install/linux#manual). ### Cargo If you already have a Rust environment set up, you can use the `cargo install` command: cargo install exa Cargo will build the `exa` binary and place it in `$HOME/.cargo`. To build without Git support, run `cargo install --no-default-features exa` is also available, if the requisite dependencies are not installed. ---

Development Rust 1.66.1+ MIT Licence

exa is written in [Rust](https://www.rust-lang.org/). You will need rustc version 1.66.1 or higher. The recommended way to install Rust for development is from the [official download page](https://www.rust-lang.org/tools/install), using rustup. Once Rust is installed, you can compile exa with Cargo: cargo build cargo test - The [just](https://github.com/casey/just) command runner can be used to run some helpful development commands, in a manner similar to `make`. Run `just --list` to get an overview of what’s available. - If you are compiling a copy for yourself, be sure to run `cargo build --release` or `just build-release` to benefit from release-mode optimisations. Copy the resulting binary, which will be in the `target/release` directory, into a folder in your `$PATH`. `/usr/local/bin` is usually a good choice. - To compile and install the manual pages, you will need [pandoc](https://pandoc.org/). The `just man` command will compile the Markdown into manual pages, which it will place in the `target/man` directory. To use them, copy them into a directory that `man` will read. `/usr/local/share/man` is usually a good choice. - exa depends on [libgit2](https://github.com/rust-lang/git2-rs) for certain features. If you’re unable to compile libgit2, you can opt out of Git support by running `cargo build --no-default-features`. - If you intend to compile for musl, you will need to use the flag `vendored-openssl` if you want to get the Git feature working. The full command is `cargo build --release --target=x86_64-unknown-linux-musl --features vendored-openssl,git`. For more information, see the [Building from Source page](https://the.exa.website/install/source). ### Testing with Vagrant exa uses [Vagrant][] to configure virtual machines for testing. Programs such as exa that are basically interfaces to the system are [notoriously difficult to test][testing]. Although the internal components have unit tests, it’s impossible to do a complete end-to-end test without mandating the current user’s name, the time zone, the locale, and directory structure to test. (And yes, these tests are worth doing. I have missed an edge case on many an occasion.) The initial attempt to solve the problem was just to create a directory of “awkward” test cases, run exa on it, and make sure it produced the correct output. But even this output would change if, say, the user’s locale formats dates in a different way. These can be mocked inside the code, but at the cost of making that code more complicated to read and understand. An alternative solution is to fake *everything*: create a virtual machine with a known state and run the tests on *that*. This is what Vagrant does. Although it takes a while to download and set up, it gives everyone the same development environment to test for any obvious regressions. [Vagrant]: https://www.vagrantup.com/ [testing]: https://eev.ee/blog/2016/08/22/testing-for-people-who-hate-testing/#troublesome-cases First, initialise the VM: host$ vagrant up The first command downloads the virtual machine image, and then runs our provisioning script, which installs Rust and exa’s build-time dependencies, configures the environment, and generates some awkward files and folders to use as test cases. Once this is done, you can SSH in, and build and test: host$ vagrant ssh vm$ cd /vagrant vm$ cargo build vm$ ./xtests/run All the tests passed! Of course, the drawback of having a standard development environment is that you stop noticing bugs that occur outside of it. For this reason, Vagrant isn’t a *necessary* development step — it’s there if you’d like to use it, but exa still gets used and tested on other platforms. It can still be built and compiled on any target triple that it supports, VM or no VM, with `cargo build` and `cargo test`. ================================================ FILE: Vagrantfile ================================================ Vagrant.configure(2) do |config| # We use Ubuntu instead of Debian because the image comes with two-way # shared folder support by default. UBUNTU = 'hashicorp/bionic64' config.vm.define(:exa) do |config| config.vm.provider :virtualbox do |v| v.name = 'exa' v.memory = 2048 v.cpus = `nproc`.chomp.to_i end config.vm.provider :vmware_desktop do |v| v.vmx['memsize'] = '2048' v.vmx['numvcpus'] = `nproc`.chomp end config.vm.box = UBUNTU config.vm.hostname = 'exa' # Make sure we know the VM image’s default user name. The ‘cassowary’ user # (specified later) is used for most of the test *output*, but we still # need to know where the ‘target’ and ‘.cargo’ directories go. developer = 'vagrant' # Install the dependencies needed for exa to build, as quietly as # apt can do. config.vm.provision :shell, privileged: true, inline: <<-EOF if hash fish &>/dev/null; then echo "Tools are already installed" else trap 'exit' ERR echo "Installing tools" apt-get update -qq apt-get install -qq -o=Dpkg::Use-Pty=0 \ git gcc curl attr libgit2-dev zip \ fish zsh bash bash-completion fi EOF # Install Rust. # This is done as vagrant, not root, because it’s vagrant # who actually uses it. Sent to /dev/null because the progress # bar produces a ton of output. config.vm.provision :shell, privileged: false, inline: <<-EOF if hash rustc &>/dev/null; then echo "Rust is already installed" else trap 'exit' ERR echo "Installing Rust" curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --profile minimal --component rustc,rust-std,cargo,clippy -y > /dev/null source $HOME/.cargo/env echo "Installing cargo-hack" cargo install -q cargo-hack echo "Installing specsheet" cargo install -q --git https://github.com/ogham/specsheet fi EOF # Privileged installation and setup scripts. config.vm.provision :shell, privileged: true, inline: <<-EOF # Install Just, the command runner. if hash just &>/dev/null; then echo "just is already installed" else trap 'exit' ERR echo "Installing just" wget -q "https://github.com/casey/just/releases/download/v0.8.3/just-v0.8.3-x86_64-unknown-linux-musl.tar.gz" tar -xf "just-v0.8.3-x86_64-unknown-linux-musl.tar.gz" cp just /usr/local/bin fi # Guarantee that the timezone is UTC — some of the tests # depend on this (for now). timedatectl set-timezone UTC # Use a different ‘target’ directory on the VM than on the host. # By default it just uses the one in /vagrant/target, which can # cause problems if it has different permissions than the other # directories, or contains object files compiled for the host. echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/#{developer}/.cargo/bin"' > /etc/environment echo 'CARGO_TARGET_DIR="/home/#{developer}/target"' >> /etc/environment # Create a variety of misc scripts. ln -sf /vagrant/devtools/dev-run-debug.sh /usr/bin/exa ln -sf /vagrant/devtools/dev-run-release.sh /usr/bin/rexa echo -e "#!/bin/sh\ncargo build --manifest-path /vagrant/Cargo.toml \\$@" > /usr/bin/build-exa ln -sf /usr/bin/build-exa /usr/bin/b echo -e "#!/bin/sh\ncargo test --manifest-path /vagrant/Cargo.toml \\$@ -- --quiet" > /usr/bin/test-exa ln -sf /usr/bin/test-exa /usr/bin/t echo -e "#!/bin/sh\n/vagrant/xtests/run.sh" > /usr/bin/run-xtests ln -sf /usr/bin/run-xtests /usr/bin/x echo -e "#!/bin/sh\nbuild-exa && test-exa && run-xtests" > /usr/bin/compile-exa ln -sf /usr/bin/compile-exa /usr/bin/c echo -e "#!/bin/sh\nbash /vagrant/devtools/dev-package-for-linux.sh \\$@" > /usr/bin/package-exa echo -e "#!/bin/sh\ncat /etc/motd" > /usr/bin/halp chmod +x /usr/bin/{exa,rexa,b,t,x,c,build-exa,test-exa,run-xtests,compile-exa,package-exa,halp} # Configure the welcoming text that gets shown: # Capture the help text so it gets displayed first rm -f /etc/update-motd.d/* bash /vagrant/devtools/dev-help.sh > /etc/motd # Tell bash to execute a bunch of stuff when a session starts echo "source /vagrant/devtools/dev-bash.sh" > /home/#{developer}/.bash_profile chown #{developer} /home/#{developer}/.bash_profile # Disable last login date in sshd sed -i '/PrintLastLog yes/c\PrintLastLog no' /etc/ssh/sshd_config systemctl restart sshd # Link the completion files so they’re “installed”: # bash test -h /etc/bash_completion.d/exa \ || ln -s /vagrant/contrib/completions.bash /etc/bash_completion.d/exa # zsh test -h /usr/share/zsh/vendor-completions/_exa \ || ln -s /vagrant/contrib/completions.zsh /usr/share/zsh/vendor-completions/_exa # fish test -h /usr/share/fish/completions/exa.fish \ || ln -s /vagrant/contrib/completions.fish /usr/share/fish/completions/exa.fish EOF # Install kcov for test coverage # This doesn’t run coverage over the xtests so it’s less useful for now if ENV.key?('INSTALL_KCOV') config.vm.provision :shell, privileged: false, inline: <<-EOF trap 'exit' ERR test -e ~/.cargo/bin/cargo-kcov \ || cargo install cargo-kcov sudo apt-get install -qq -o=Dpkg::Use-Pty=0 -y \ cmake g++ pkg-config \ libcurl4-openssl-dev libdw-dev binutils-dev libiberty-dev cargo kcov --print-install-kcov-sh | sudo sh EOF end config.vm.provision :shell, privileged: true, path: 'devtools/dev-set-up-environment.sh' config.vm.provision :shell, privileged: false, path: 'devtools/dev-create-test-filesystem.sh' end end ================================================ FILE: build.rs ================================================ /// The version string isn’t the simplest: we want to show the version, /// current Git hash, and compilation date when building *debug* versions, but /// just the version for *release* versions so the builds are reproducible. /// /// This script generates the string from the environment variables that Cargo /// adds (http://doc.crates.io/environment-variables.html) and runs `git` to /// get the SHA1 hash. It then writes the string into a file, which exa then /// includes at build-time. /// /// - https://stackoverflow.com/q/43753491/3484614 /// - https://crates.io/crates/vergen use std::env; use std::fs::File; use std::io::{self, Write}; use std::path::PathBuf; use datetime::{LocalDateTime, ISO}; /// The build script entry point. fn main() -> io::Result<()> { #![allow(clippy::write_with_newline)] let tagline = "exa - list files on the command-line"; let url = "https://the.exa.website/"; let ver = if is_debug_build() { format!("{}\nv{} \\1;31m(pre-release debug build!)\\0m\n\\1;4;34m{}\\0m", tagline, version_string(), url) } else if is_development_version() { format!("{}\nv{} [{}] built on {} \\1;31m(pre-release!)\\0m\n\\1;4;34m{}\\0m", tagline, version_string(), git_hash(), build_date(), url) } else { format!("{}\nv{}\n\\1;4;34m{}\\0m", tagline, version_string(), url) }; // We need to create these files in the Cargo output directory. let out = PathBuf::from(env::var("OUT_DIR").unwrap()); let path = &out.join("version_string.txt"); // Bland version text let mut f = File::create(path).unwrap_or_else(|_| { panic!("{}", path.to_string_lossy().to_string()) }); writeln!(f, "{}", strip_codes(&ver))?; Ok(()) } /// Removes escape codes from a string. fn strip_codes(input: &str) -> String { input.replace("\\0m", "") .replace("\\1;31m", "") .replace("\\1;4;34m", "") } /// Retrieve the project’s current Git hash, as a string. fn git_hash() -> String { use std::process::Command; String::from_utf8_lossy( &Command::new("git") .args(&["rev-parse", "--short", "HEAD"]) .output().unwrap() .stdout).trim().to_string() } /// Whether we should show pre-release info in the version string. /// /// Both weekly releases and actual releases are --release releases, /// but actual releases will have a proper version number. fn is_development_version() -> bool { cargo_version().ends_with("-pre") || env::var("PROFILE").unwrap() == "debug" } /// Whether we are building in debug mode. fn is_debug_build() -> bool { env::var("PROFILE").unwrap() == "debug" } /// Retrieves the [package] version in Cargo.toml as a string. fn cargo_version() -> String { env::var("CARGO_PKG_VERSION").unwrap() } /// Returns the version and build parameters string. fn version_string() -> String { let mut ver = cargo_version(); let feats = nonstandard_features_string(); if ! feats.is_empty() { ver.push_str(&format!(" [{}]", &feats)); } ver } /// Finds whether a feature is enabled by examining the Cargo variable. fn feature_enabled(name: &str) -> bool { env::var(&format!("CARGO_FEATURE_{}", name)) .map(|e| ! e.is_empty()) .unwrap_or(false) } /// A comma-separated list of non-standard feature choices. fn nonstandard_features_string() -> String { let mut s = Vec::new(); if feature_enabled("GIT") { s.push("+git"); } else { s.push("-git"); } s.join(", ") } /// Formats the current date as an ISO 8601 string. fn build_date() -> String { let now = LocalDateTime::now(); format!("{}", now.date().iso()) } ================================================ FILE: completions/bash/exa ================================================ _exa() { cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} case "$prev" in -'?'|--help|-v|--version) return ;; --colour) COMPREPLY=( $( compgen -W 'always auto never' -- "$cur" ) ) return ;; -L|--level) COMPREPLY=( $( compgen -W '{0..9}' -- "$cur" ) ) return ;; -s|--sort) COMPREPLY=( $( compgen -W 'name filename Name Filename size filesize extension Extension date time modified changed accessed created type inode oldest newest age none --' -- "$cur" ) ) return ;; -t|--time) COMPREPLY=( $( compgen -W 'modified changed accessed created --' -- "$cur" ) ) return ;; --time-style) COMPREPLY=( $( compgen -W 'default iso long-iso full-iso --' -- "$cur" ) ) return ;; esac case "$cur" in # _parse_help doesn’t pick up short options when they are on the same line than long options --*) # colo[u]r isn’t parsed correctly so we filter these options out and add them by hand parse_help=$( exa --help | grep -oE ' (\-\-[[:alnum:]@-]+)' | tr -d ' ' | grep -v '\-\-colo' ) completions=$( echo '--color --colour --color-scale --colour-scale' $parse_help ) COMPREPLY=( $( compgen -W "$completions" -- "$cur" ) ) ;; -*) completions=$( exa --help | grep -oE ' (\-[[:alnum:]@])' | tr -d ' ' ) COMPREPLY=( $( compgen -W "$completions" -- "$cur" ) ) ;; *) _filedir ;; esac } && complete -o filenames -o bashdefault -F _exa exa ================================================ FILE: completions/fish/exa.fish ================================================ # Meta-stuff complete -c exa -s 'v' -l 'version' -d "Show version of exa" complete -c exa -s '?' -l 'help' -d "Show list of command-line options" # Display options complete -c exa -s '1' -l 'oneline' -d "Display one entry per line" complete -c exa -s 'l' -l 'long' -d "Display extended file metadata as a table" complete -c exa -s 'G' -l 'grid' -d "Display entries in a grid" complete -c exa -s 'x' -l 'across' -d "Sort the grid across, rather than downwards" complete -c exa -s 'R' -l 'recurse' -d "Recurse into directories" complete -c exa -s 'T' -l 'tree' -d "Recurse into directories as a tree" complete -c exa -s 'F' -l 'classify' -d "Display type indicator by file names" complete -c exa -l 'color' \ -l 'colour' -d "When to use terminal colours" -x -a " always\t'Always use colour' auto\t'Use colour if standard output is a terminal' never\t'Never use colour' " complete -c exa -l 'color-scale' \ -l 'colour-scale' -d "Highlight levels of file sizes distinctly" complete -c exa -l 'icons' -d "Display icons" complete -c exa -l 'no-icons' -d "Don't display icons" # Filtering and sorting options complete -c exa -l 'group-directories-first' -d "Sort directories before other files" complete -c exa -l 'git-ignore' -d "Ignore files mentioned in '.gitignore'" complete -c exa -s 'a' -l 'all' -d "Show hidden and 'dot' files" complete -c exa -s 'd' -l 'list-dirs' -d "List directories like regular files" complete -c exa -s 'L' -l 'level' -d "Limit the depth of recursion" -x -a "1 2 3 4 5 6 7 8 9" complete -c exa -s 'r' -l 'reverse' -d "Reverse the sort order" complete -c exa -s 's' -l 'sort' -d "Which field to sort by" -x -a " accessed\t'Sort by file accessed time' age\t'Sort by file modified time (newest first)' changed\t'Sort by changed time' created\t'Sort by file modified time' date\t'Sort by file modified time' ext\t'Sort by file extension' Ext\t'Sort by file extension (uppercase first)' extension\t'Sort by file extension' Extension\t'Sort by file extension (uppercase first)' filename\t'Sort by filename' Filename\t'Sort by filename (uppercase first)' inode\t'Sort by file inode' modified\t'Sort by file modified time' name\t'Sort by filename' Name\t'Sort by filename (uppercase first)' newest\t'Sort by file modified time (newest first)' none\t'Do not sort files at all' oldest\t'Sort by file modified time' size\t'Sort by file size' time\t'Sort by file modified time' type\t'Sort by file type' " complete -c exa -s 'I' -l 'ignore-glob' -d "Ignore files that match these glob patterns" -r complete -c exa -s 'D' -l 'only-dirs' -d "List only directories" # Long view options complete -c exa -s 'b' -l 'binary' -d "List file sizes with binary prefixes" complete -c exa -s 'B' -l 'bytes' -d "List file sizes in bytes, without any prefixes" complete -c exa -s 'g' -l 'group' -d "List each file's group" complete -c exa -s 'h' -l 'header' -d "Add a header row to each column" complete -c exa -s 'H' -l 'links' -d "List each file's number of hard links" complete -c exa -s 'i' -l 'inode' -d "List each file's inode number" complete -c exa -s 'S' -l 'blocks' -d "List each file's number of filesystem blocks" complete -c exa -s 't' -l 'time' -d "Which timestamp field to list" -x -a " modified\t'Display modified time' changed\t'Display changed time' accessed\t'Display accessed time' created\t'Display created time' " complete -c exa -s 'm' -l 'modified' -d "Use the modified timestamp field" complete -c exa -s 'n' -l 'numeric' -d "List numeric user and group IDs." complete -c exa -l 'changed' -d "Use the changed timestamp field" complete -c exa -s 'u' -l 'accessed' -d "Use the accessed timestamp field" complete -c exa -s 'U' -l 'created' -d "Use the created timestamp field" complete -c exa -l 'time-style' -d "How to format timestamps" -x -a " default\t'Use the default time style' iso\t'Display brief ISO timestamps' long-iso\t'Display longer ISO timestaps, up to the minute' full-iso\t'Display full ISO timestamps, up to the nanosecond' " complete -c exa -l 'no-permissions' -d "Suppress the permissions field" complete -c exa -l 'octal-permissions' -d "List each file's permission in octal format" complete -c exa -l 'no-filesize' -d "Suppress the filesize field" complete -c exa -l 'no-user' -d "Suppress the user field" complete -c exa -l 'no-time' -d "Suppress the time field" # Optional extras complete -c exa -l 'git' -d "List each file's Git status, if tracked" complete -c exa -s '@' -l 'extended' -d "List each file's extended attributes and sizes" ================================================ FILE: completions/zsh/_exa ================================================ #compdef exa # Save this file as _exa in /usr/local/share/zsh/site-functions or in any # other folder in $fpath. E.g. save it in a folder called ~/.zfunc and add a # line containing `fpath=(~/.zfunc $fpath)` somewhere before `compinit` in your # ~/.zshrc. __exa() { # Give completions using the `_arguments` utility function with # `-s` for option stacking like `exa -ab` for `exa -a -b` and # `-S` for delimiting options with `--` like in `exa -- -a`. _arguments -s -S \ "(- *)"{-v,--version}"[Show version of exa]" \ "(- *)"{-'\?',--help}"[Show list of command-line options]" \ {-1,--oneline}"[Display one entry per line]" \ {-l,--long}"[Display extended file metadata as a table]" \ {-G,--grid}"[Display entries as a grid]" \ {-x,--across}"[Sort the grid across, rather than downwards]" \ {-R,--recurse}"[Recurse into directories]" \ {-T,--tree}"[Recurse into directories as a tree]" \ {-F,--classify}"[Display type indicator by file names]" \ --colo{,u}r="[When to use terminal colours]:(when):(always auto never)" \ --colo{,u}r-scale"[Highlight levels of file sizes distinctly]" \ --icons"[Display icons]" \ --no-icons"[Hide icons]" \ --group-directories-first"[Sort directories before other files]" \ --git-ignore"[Ignore files mentioned in '.gitignore']" \ {-a,--all}"[Show hidden and 'dot' files]" \ {-d,--list-dirs}"[List directories like regular files]" \ {-D,--only-dirs}"[List only directories]" \ {-L,--level}"+[Limit the depth of recursion]" \ {-r,--reverse}"[Reverse the sort order]" \ {-s,--sort}="[Which field to sort by]:(sort field):(accessed age changed created date extension Extension filename Filename inode modified oldest name Name newest none size time type)" \ {-I,--ignore-glob}"[Ignore files that match these glob patterns]" \ {-b,--binary}"[List file sizes with binary prefixes]" \ {-B,--bytes}"[List file sizes in bytes, without any prefixes]" \ --changed"[Use the changed timestamp field]" \ {-g,--group}"[List each file's group]" \ {-h,--header}"[Add a header row to each column]" \ {-H,--links}"[List each file's number of hard links]" \ {-i,--inode}"[List each file's inode number]" \ {-m,--modified}"[Use the modified timestamp field]" \ {-n,--numeric}"[List numeric user and group IDs.]" \ {-S,--blocks}"[List each file's number of filesystem blocks]" \ {-t,--time}="[Which time field to show]:(time field):(accessed changed created modified)" \ --time-style="[How to format timestamps]:(time style):(default iso long-iso full-iso)" \ --no-permissions"[Suppress the permissions field]" \ --octal-permissions"[List each file's permission in octal format]" \ --no-filesize"[Suppress the filesize field]" \ --no-user"[Suppress the user field]" \ --no-time"[Suppress the time field]" \ {-u,--accessed}"[Use the accessed timestamp field]" \ {-U,--created}"[Use the created timestamp field]" \ --git"[List each file's Git status, if tracked]" \ {-@,--extended}"[List each file's extended attributes and sizes]" \ '*:filename:_files' } __exa ================================================ FILE: devtools/README.md ================================================ ## exa › development tools These scripts deal with things like packaging release-worthy versions of exa. They are **not general-purpose scripts** that you’re able to run from your main computer! They’re intended to be run from the Vagrant machine. ================================================ FILE: devtools/dev-bash.sh ================================================ # This file gets executed when a user starts a `bash` shell, usually because # they’ve just started a new Vagrant session with `vagrant ssh`. It configures # some (but not all) of the commands that you can use. # Display the installed versions of tools. # help banner bash /vagrant/devtools/dev-versions.sh # Configure the Cool Prompt™ (not actually trademarked). # The Cool Prompt tells you whether you’re in debug or strict mode, whether # you have colours configured, and whether your last command failed. nonzero_return() { RETVAL=$?; [ "$RETVAL" -ne 0 ] && echo "$RETVAL "; } debug_mode() { [ "$EXA_DEBUG" == "trace" ] && echo -n "trace-"; [ -n "$EXA_DEBUG" ] && echo "debug "; } strict_mode() { [ -n "$EXA_STRICT" ] && echo "strict "; } lsc_mode() { [ -n "$LS_COLORS" ] && echo "lsc "; } exac_mode() { [ -n "$EXA_COLORS" ] && echo "exac "; } export PS1="\[\e[1;36m\]\h \[\e[32m\]\w \[\e[31m\]\`nonzero_return\`\[\e[35m\]\`debug_mode\`\[\e[32m\]\`lsc_mode\`\[\e[1;32m\]\`exac_mode\`\[\e[33m\]\`strict_mode\`\[\e[36m\]\\$\[\e[0m\] " # The ‘debug’ function lets you switch debug mode on and off. # Turn it on if you need to see exa’s debugging logs. debug() { case "$1" in ""|"on") export EXA_DEBUG=1 ;; "off") export EXA_DEBUG= ;; "trace") export EXA_DEBUG=trace ;; "status") [ -n "$EXA_DEBUG" ] && echo "debug on" || echo "debug off" ;; *) echo "Usage: debug on|off|trace|status"; return 1 ;; esac; } # The ‘strict’ function lets you switch strict mode on and off. # Turn it on if you’d like exa’s command-line arguments checked. strict() { case "$1" in "on") export EXA_STRICT=1 ;; "off") export EXA_STRICT= ;; "") [ -n "$EXA_STRICT" ] && echo "strict on" || echo "strict off" ;; *) echo "Usage: strict on|off"; return 1 ;; esac; } # The ‘colors’ function sets or unsets the ‘LS_COLORS’ and ‘EXA_COLORS’ # environment variables. There’s also a ‘hacker’ theme which turns everything # green, which is usually used for checking that all colour codes work, and # for looking cool while you phreak some mainframes or whatever. colors() { case "$1" in "ls") export LS_COLORS="di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43" export EXA_COLORS="" ;; "hacker") export LS_COLORS="di=32:ex=32:fi=32:pi=32:so=32:bd=32:cd=32:ln=32:or=32:mi=32" export EXA_COLORS="ur=32:uw=32:ux=32:ue=32:gr=32:gw=32:gx=32:tr=32:tw=32:tx=32:su=32:sf=32:xa=32:sn=32:sb=32:df=32:ds=32:uu=32:un=32:gu=32:gn=32:lc=32:lm=32:ga=32:gm=32:gd=32:gv=32:gt=32:xx=32:da=32:in=32:bl=32:hd=32:lp=32:cc=32:" ;; "off") export LS_COLORS= export EXA_COLORS= ;; "") [ -n "$LS_COLORS" ] && echo "LS_COLORS=$LS_COLORS" || echo "ls-colors off" [ -n "$EXA_COLORS" ] && echo "EXA_COLORS=$EXA_COLORS" || echo "exa-colors off" ;; *) echo "Usage: ls-colors ls|hacker|off"; return 1 ;; esac; } ================================================ FILE: devtools/dev-create-test-filesystem.sh ================================================ #!/bin/bash # This script creates a bunch of awkward test case files. It gets # automatically run as part of Vagrant provisioning. trap 'exit' ERR if [[ ! -d "/vagrant" ]]; then echo "This script should be run in the Vagrant environment" exit 1 fi source "/vagrant/devtools/dev-fixtures.sh" # Delete old testcases if they exist already, then create a # directory to house new ones. if [[ -d "$TEST_ROOT" ]]; then echo -e "\033[1m[ 0/13]\033[0m Deleting existing test cases directory" sudo rm -rf "$TEST_ROOT" fi sudo mkdir "$TEST_ROOT" sudo chmod 777 "$TEST_ROOT" sudo mkdir "$TEST_ROOT/empty" # Awkward file size testcases. # This needs sudo to set the files’ users at the very end. mkdir "$TEST_ROOT/files" echo -e "\033[1m[ 1/13]\033[0m Creating file size testcases" for i in {1..13}; do fallocate -l "$i" "$TEST_ROOT/files/$i"_bytes fallocate -l "$i"KiB "$TEST_ROOT/files/$i"_KiB fallocate -l "$i"MiB "$TEST_ROOT/files/$i"_MiB done touch -t $FIXED_DATE "$TEST_ROOT/files/"* touch -t $FIXED_DATE "$TEST_ROOT/files/" chmod 644 "$TEST_ROOT/files/"* sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT/files/"* # File name extension testcases. # These aren’t tested in details view, but we set timestamps on them to # test that various sort options work. mkdir "$TEST_ROOT/file-names-exts" echo -e "\033[1m[ 2/13]\033[0m Creating file name extension testcases" touch "$TEST_ROOT/file-names-exts/Makefile" touch "$TEST_ROOT/file-names-exts/IMAGE.PNG" touch "$TEST_ROOT/file-names-exts/image.svg" touch "$TEST_ROOT/file-names-exts/VIDEO.AVI" touch "$TEST_ROOT/file-names-exts/video.wmv" touch "$TEST_ROOT/file-names-exts/music.mp3" touch "$TEST_ROOT/file-names-exts/MUSIC.OGG" touch "$TEST_ROOT/file-names-exts/lossless.flac" touch "$TEST_ROOT/file-names-exts/lossless.wav" touch "$TEST_ROOT/file-names-exts/crypto.asc" touch "$TEST_ROOT/file-names-exts/crypto.signature" touch "$TEST_ROOT/file-names-exts/document.pdf" touch "$TEST_ROOT/file-names-exts/DOCUMENT.XLSX" touch "$TEST_ROOT/file-names-exts/COMPRESSED.ZIP" touch "$TEST_ROOT/file-names-exts/compressed.tar.gz" touch "$TEST_ROOT/file-names-exts/compressed.tgz" touch "$TEST_ROOT/file-names-exts/compressed.tar.xz" touch "$TEST_ROOT/file-names-exts/compressed.txz" touch "$TEST_ROOT/file-names-exts/compressed.deb" touch "$TEST_ROOT/file-names-exts/backup~" touch "$TEST_ROOT/file-names-exts/#SAVEFILE#" touch "$TEST_ROOT/file-names-exts/file.tmp" touch "$TEST_ROOT/file-names-exts/compiled.class" touch "$TEST_ROOT/file-names-exts/compiled.o" touch "$TEST_ROOT/file-names-exts/compiled.js" touch "$TEST_ROOT/file-names-exts/compiled.coffee" # File name testcases. # bash really doesn’t want you to create a file with escaped characters # in its name, so we have to resort to the echo builtin and touch! mkdir "$TEST_ROOT/file-names" echo -e "\033[1m[ 3/13]\033[0m Creating file names testcases" echo -ne "$TEST_ROOT/file-names/ascii: hello" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/emoji: [🆒]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/utf-8: pâté" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/bell: [\a]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/backspace: [\b]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/form-feed: [\f]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/new-line: [\n]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/return: [\r]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/tab: [\t]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/vertical-tab: [\v]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/escape: [\033]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/ansi: [\033[34mblue\033[0m]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/invalid-utf8-1: [\xFF]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/invalid-utf8-2: [\xc3\x28]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/invalid-utf8-3: [\xe2\x82\x28]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/invalid-utf8-4: [\xf0\x28\x8c\x28]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/new-line-dir: [\n]" | xargs -0 mkdir echo -ne "$TEST_ROOT/file-names/new-line-dir: [\n]/subfile" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/new-line-dir: [\n]/another: [\n]" | xargs -0 touch echo -ne "$TEST_ROOT/file-names/new-line-dir: [\n]/broken" | xargs -0 touch mkdir "$TEST_ROOT/file-names/links" ln -s "$TEST_ROOT/file-names/new-line-dir"*/* "$TEST_ROOT/file-names/links" echo -ne "$TEST_ROOT/file-names/new-line-dir: [\n]/broken" | xargs -0 rm # Special file testcases. mkdir "$TEST_ROOT/specials" echo -e "\033[1m[ 4/13]\033[0m Creating special file kind testcases" sudo mknod "$TEST_ROOT/specials/block-device" b 3 60 sudo mknod "$TEST_ROOT/specials/char-device" c 14 40 sudo mknod "$TEST_ROOT/specials/named-pipe" p sudo touch -t $FIXED_DATE "$TEST_ROOT/specials/"* # Awkward symlink testcases. mkdir "$TEST_ROOT/links" echo -e "\033[1m[ 5/13]\033[0m Creating symlink testcases" ln -s / "$TEST_ROOT/links/root" ln -s /usr "$TEST_ROOT/links/usr" ln -s nowhere "$TEST_ROOT/links/broken" ln -s /proc/1/root "$TEST_ROOT/links/forbidden" touch "$TEST_ROOT/links/some_file" ln -s "$TEST_ROOT/links/some_file" "$TEST_ROOT/links/some_file_absolute" (cd "$TEST_ROOT/links"; ln -s "some_file" "some_file_relative") (cd "$TEST_ROOT/links"; ln -s "." "current_dir") (cd "$TEST_ROOT/links"; ln -s ".." "parent_dir") (cd "$TEST_ROOT/links"; ln -s "itself" "itself") # Awkward passwd testcases. # sudo is needed for these because we technically aren’t a member # of the groups (because they don’t exist), and chown and chgrp # are smart enough to disallow it! mkdir "$TEST_ROOT/passwd" echo -e "\033[1m[ 6/13]\033[0m Creating user and group testcases" touch -t $FIXED_DATE "$TEST_ROOT/passwd/unknown-uid" chmod 644 "$TEST_ROOT/passwd/unknown-uid" sudo chown $FIXED_BAD_UID:$FIXED_USER "$TEST_ROOT/passwd/unknown-uid" touch -t $FIXED_DATE "$TEST_ROOT/passwd/unknown-gid" chmod 644 "$TEST_ROOT/passwd/unknown-gid" sudo chown $FIXED_USER:$FIXED_BAD_GID "$TEST_ROOT/passwd/unknown-gid" # Awkward permission testcases. # Differences in the way ‘chmod’ handles setting ‘setuid’ and ‘setgid’ # when you don’t already own the file mean that we need to use ‘sudo’ # to change permissions to those. mkdir "$TEST_ROOT/permissions" echo -e "\033[1m[ 7/13]\033[0m Creating file permission testcases" mkdir "$TEST_ROOT/permissions/forbidden-directory" chmod 000 "$TEST_ROOT/permissions/forbidden-directory" touch -t $FIXED_DATE "$TEST_ROOT/permissions/forbidden-directory" sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT/permissions/forbidden-directory" for perms in 000 001 002 004 010 020 040 100 200 400 644 755 777 1000 1001 2000 2010 4000 4100 7666 7777; do touch "$TEST_ROOT/permissions/$perms" sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT/permissions/$perms" sudo chmod $perms "$TEST_ROOT/permissions/$perms" sudo touch -t $FIXED_DATE "$TEST_ROOT/permissions/$perms" done # Awkward date and time testcases. mkdir "$TEST_ROOT/dates" echo -e "\033[1m[ 8/13]\033[0m Creating date and time testcases" # created dates # there’s no way to touch the created date of a file... # so we have to do this the old-fashioned way! # (and make sure these don't actually get listed) touch -t $FIXED_OLD_DATE "$TEST_ROOT/dates/peach"; sleep 1 touch -t $FIXED_MED_DATE "$TEST_ROOT/dates/plum"; sleep 1 touch -t $FIXED_NEW_DATE "$TEST_ROOT/dates/pear" # modified dates touch -t $FIXED_OLD_DATE -m "$TEST_ROOT/dates/pear" touch -t $FIXED_MED_DATE -m "$TEST_ROOT/dates/peach" touch -t $FIXED_NEW_DATE -m "$TEST_ROOT/dates/plum" # accessed dates touch -t $FIXED_OLD_DATE -a "$TEST_ROOT/dates/plum" touch -t $FIXED_MED_DATE -a "$TEST_ROOT/dates/pear" touch -t $FIXED_NEW_DATE -a "$TEST_ROOT/dates/peach" sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/dates" mkdir "$TEST_ROOT/far-dates" touch -t $FIXED_PAST_DATE "$TEST_ROOT/far-dates/the-distant-past" touch -t $FIXED_FUTURE_DATE "$TEST_ROOT/far-dates/beyond-the-future" # Awkward extended attribute testcases. # We need to test combinations of various numbers of files *and* # extended attributes in directories. Turns out, the easiest way to # do this is to generate all combinations of files with “one-xattr” # or “two-xattrs” in their name and directories with “empty” or # “one-file” in their name, then just give the right number of # xattrs and children to those. mkdir "$TEST_ROOT/attributes" echo -e "\033[1m[ 9/13]\033[0m Creating extended attribute testcases" mkdir "$TEST_ROOT/attributes/files" touch "$TEST_ROOT/attributes/files/"{no-xattrs,one-xattr,two-xattrs}{,_forbidden} mkdir "$TEST_ROOT/attributes/dirs" mkdir "$TEST_ROOT/attributes/dirs/"{no-xattrs,one-xattr,two-xattrs}_{empty,one-file,two-files}{,_forbidden} setfattr -n user.greeting -v hello "$TEST_ROOT/attributes"/**/*{one-xattr,two-xattrs}* setfattr -n user.another_greeting -v hi "$TEST_ROOT/attributes"/**/*two-xattrs* for dir in "$TEST_ROOT/attributes/dirs/"*one-file*; do touch $dir/file-in-question done for dir in "$TEST_ROOT/attributes/dirs/"*two-files*; do touch $dir/this-file touch $dir/that-file done find "$TEST_ROOT/attributes" -exec touch {} -t $FIXED_DATE \; # I want to use the following to test, # but it only works on macos: #chmod +a "$FIXED_USER deny readextattr" "$TEST_ROOT/attributes"/**/*_forbidden sudo chmod 000 "$TEST_ROOT/attributes"/**/*_forbidden sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/attributes" # A sample Git repository # This uses cd because it's easier than telling Git where to go each time echo -e "\033[1m[10/13]\033[0m Creating Git testcases (1/4)" mkdir "$TEST_ROOT/git" cd "$TEST_ROOT/git" git init >/dev/null mkdir edits additions moves echo "original content" | tee edits/{staged,unstaged,both} >/dev/null echo "this file gets moved" > moves/hither git add edits moves git config --global user.email "exa@exa.exa" git config --global user.name "Exa Exa" git commit -m "Automated test commit" >/dev/null echo "modifications!" | tee edits/{staged,both} >/dev/null touch additions/{staged,edited} mv moves/{hither,thither} git add edits moves additions echo "more modifications!" | tee edits/unstaged edits/both additions/edited >/dev/null touch additions/unstaged find "$TEST_ROOT/git" -exec touch {} -t $FIXED_DATE \; sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git" # A second Git repository # for testing two at once echo -e "\033[1m[11/13]\033[0m Creating Git testcases (2/4)" mkdir -p "$TEST_ROOT/git2/deeply/nested/directory" cd "$TEST_ROOT/git2" git init >/dev/null touch "deeply/nested/directory/upd8d" git add "deeply/nested/directory/upd8d" git commit -m "Automated test commit" >/dev/null echo "Now with contents" > "deeply/nested/directory/upd8d" touch "deeply/nested/directory/l8st" echo -e "target\n*.mp3" > ".gitignore" mkdir "ignoreds" touch "ignoreds/music.mp3" touch "ignoreds/music.m4a" mkdir "ignoreds/nested" touch "ignoreds/nested/70s grove.mp3" touch "ignoreds/nested/funky chicken.m4a" mkdir "ignoreds/nested2" touch "ignoreds/nested2/ievan polkka.mp3" mkdir "target" touch "target/another ignored file" mkdir "deeply/nested/repository" cd "deeply/nested/repository" git init >/dev/null touch subfile # This file, ‘subfile’, should _not_ be marked as a new file by exa, because # it’s in the sub-repository but hasn’t been added to it. Were the sub-repo not # present, it would be marked as a new file, as the top-level repo knows about # the ‘deeply’ directory. find "$TEST_ROOT/git2" -exec touch {} -t $FIXED_DATE \; sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git2" # A third Git repository # Regression test for https://github.com/ogham/exa/issues/526 echo -e "\033[1m[12/13]\033[0m Creating Git testcases (3/4)" mkdir -p "$TEST_ROOT/git3" cd "$TEST_ROOT/git3" git init >/dev/null # Create a symbolic link pointing to a non-existing file ln -s aaa/aaa/a b # This normally fails with: find "$TEST_ROOT/git3" -exec touch {} -h -t $FIXED_DATE \; sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git3" # A fourth Git repository # Regression test for https://github.com/ogham/exa/issues/698 echo -e "\033[1m[12/13]\033[0m Creating Git testcases (4/4)" mkdir -p "$TEST_ROOT/git4" cd "$TEST_ROOT/git4" git init >/dev/null # Create a non UTF-8 file touch 'P'$'\b\211''UUU' find "$TEST_ROOT/git4" -exec touch {} -h -t $FIXED_DATE \; sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git4" # Hidden and dot file testcases. # We need to set the permissions of `.` and `..` because they actually # get displayed in the output here, so this has to come last. echo -e "\033[1m[13/13]\033[0m Creating hidden and dot file testcases" shopt -u dotglob GLOBIGNORE=".:.." mkdir "$TEST_ROOT/hiddens" cd "$TEST_ROOT/hiddens" touch "$TEST_ROOT/hiddens/visible" touch "$TEST_ROOT/hiddens/.hidden" touch "$TEST_ROOT/hiddens/..extra-hidden" # ./hiddens/ touch -t $FIXED_DATE "$TEST_ROOT/hiddens/"* chmod 644 "$TEST_ROOT/hiddens/"* sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT/hiddens/"* # . touch -t $FIXED_DATE "$TEST_ROOT/hiddens" chmod 755 "$TEST_ROOT/hiddens" sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT/hiddens" # .. sudo touch -t $FIXED_DATE "$TEST_ROOT" sudo chmod 755 "$TEST_ROOT" sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT" ================================================ FILE: devtools/dev-fixtures.sh ================================================ #!/bin/bash # This file contains the text fixtures — the known, constant data — that are # used when setting up the environment that exa’s tests get run in. # The directory that all the test files are created under. export TEST_ROOT=/testcases # Because the timestamps are formatted differently depending on whether # they’re in the current year or not (see `details.rs`), we have to make # sure that the files are created in the current year, so they get shown # in the format we expect. export CURRENT_YEAR=$(date "+%Y") export FIXED_DATE="${CURRENT_YEAR}01011234.56" # 1st January, 12:34:56 # We also need an UID and a GID that are guaranteed to not exist, to # test what happen when they don’t. export FIXED_BAD_UID=666 export FIXED_BAD_GID=616 # We create two users that own the test files. # # The first one just owns the ordinary ones, because we don’t want the # test outputs to depend on “vagrant” or “ubuntu” existing. # # The second one has a long name, to test that the file owner column # widens correctly. The benefit of Vagrant is that we don’t need to # set this up on the *actual* system! export FIXED_USER="cassowary" export FIXED_LONG_USER="antidisestablishmentarienism" # A couple of dates, for date-time testing. export FIXED_OLD_DATE='200303030000.00' export FIXED_MED_DATE='200606152314.29' # the june gets used for fr_FR locale tests export FIXED_NEW_DATE='200912221038.53' # and the december for ja_JP local tests # Dates that extend beyond 32-bit timespace. export FIXED_PAST_DATE='170001010000.00' export FIXED_FUTURE_DATE='230001010000.00' ================================================ FILE: devtools/dev-help.sh ================================================ # This file prints out some help text that says which commands are available # in the VM. It gets executed during Vagrant provisioning and its output gets # dumped into /etc/motd, to print it when a user starts a new Vagrant session. echo -e " \033[1;33mThe exa development environment!\033[0m exa's source is available at \033[33m/vagrant\033[0m. Binaries get built into \033[33m/home/vagrant/target\033[0m. \033[4mCommands\033[0m \033[32;1mexa\033[0m to run the built version of exa \033[32;1mbuild-exa\033[0m (or \033[32;1mb\033[0m) to run \033[1mcargo build\033[0m \033[32;1mtest-exa\033[0m (or \033[32;1mt\033[0m) to run \033[1mcargo test\033[0m \033[32;1mrun-xtests\033[0m (or \033[32;1mx\033[0m) to run the extended tests \033[32;1mcompile-exa\033[0m (or \033[32;1mc\033[0m) to run the above three \033[32;1mdebug\033[0m to toggle printing logs \033[32;1mstrict\033[0m to toggle strict mode \033[32;1mcolors\033[0m to toggle custom colours \033[32;1mhalp\033[0m to show all this again " ================================================ FILE: devtools/dev-package-for-linux.sh ================================================ set -e # This script builds a publishable release-worthy version of exa. # It gets the version number, builds exa using cargo, tests it, strips the # binary, compresses it into a zip, then puts it in /vagrant so it’s # accessible from the host machine. # # If you’re in the VM, you can run it using the ‘package-exa’ command. # Linux check! uname=$(uname -s) if [[ "$uname" != "Linux" ]]; then echo "Gotta be on Linux to run this (detected '$uname')!" exit 1 fi # First, we need to get the version number to figure out what to call the zip. # We do this by getting the first line from the Cargo.toml that matches # /version/, removing its whitespace, and building a command out of it, so the # shell executes something like `exa_version="0.8.0"`, which it understands as # a variable definition. Hey, it’s not a hack if it works. toml_file="/vagrant/Cargo.toml" eval exa_$(grep version $toml_file | head -n 1 | sed "s/ //g") if [ -z "$exa_version" ]; then echo "Failed to parse version number! Can't build exa!" exit 1 fi # Weekly builds have a bit more information in their version number (see build.rs). if [[ "$1" == "--weekly" ]]; then git_hash=$(GIT_DIR=/vagrant/.git git rev-parse --short --verify HEAD) date=$(date +"%Y-%m-%d") echo "Building exa weekly v$exa_version, date $date, Git hash $git_hash" else echo "Building exa v$exa_version" fi # Compilation is done in --release mode, which takes longer but produces a # faster binary. This binary gets built to a different place, so the extended # tests script needs to be told which one to use. echo -e "\n\033[4mCompiling release version of exa...\033[0m" exa_linux_binary="/vagrant/exa-linux-x86_64" rm -vf "$exa_linux_binary" cargo build --release --manifest-path "$toml_file" cargo test --release --manifest-path "$toml_file" --lib -- --quiet /vagrant/xtests/run.sh --release cp /home/vagrant/target/release/exa "$exa_linux_binary" # Stripping the binary before distributing it removes a bunch of debugging # symbols, saving some space. echo -e "\n\033[4mStripping binary...\033[0m" strip -v "$exa_linux_binary" # Compress the binary for upload. The ‘-j’ flag is necessary to avoid the # /vagrant path being in the zip too. Only the zip gets the version number, so # the binaries can have consistent names, and it’s still possible to tell # different *downloads* apart. echo -e "\n\033[4mZipping binary...\033[0m" if [[ "$1" == "--weekly" ]]; then exa_linux_zip="/vagrant/exa-linux-x86_64-${exa_version}-${date}-${git_hash}.zip" else exa_linux_zip="/vagrant/exa-linux-x86_64.zip" fi rm -vf "$exa_linux_zip" zip -j "$exa_linux_zip" "$exa_linux_binary" # There was a problem a while back where a library was getting unknowingly # *dynamically* linked, which broke the whole ‘self-contained binary’ concept. # So dump the linker table, in case anything unscrupulous shows up. echo -e "\n\033[4mLibraries linked:\033[0m" ldd "$exa_linux_binary" | sed "s/\t//" # Might as well use it to test itself, right? echo -e "\n\033[4mAll done! Files produced:\033[0m" "$exa_linux_binary" "$exa_linux_binary" "$exa_linux_zip" -lB ================================================ FILE: devtools/dev-run-debug.sh ================================================ #!/bin/bash if [[ -f ~/target/debug/exa ]]; then ~/target/debug/exa "$@" else echo -e "Debug exa binary does not exist!" echo -e "Run \033[32;1mb\033[0m or \033[32;1mbuild-exa\033[0m to create it" fi ================================================ FILE: devtools/dev-run-release.sh ================================================ #!/bin/bash if [[ -f ~/target/release/exa ]]; then ~/target/release/exa "$@" else echo -e "Release exa binary does not exist!" echo -e "Run \033[32;1mb --release\033[0m or \033[32;1mbuild-exa --release\033[0m to create it" fi ================================================ FILE: devtools/dev-set-up-environment.sh ================================================ #!/bin/bash if [[ ! -d "/vagrant" ]]; then echo "This script should be run in the Vagrant environment" exit 1 fi if [[ $EUID -ne 0 ]]; then echo "This script should be run as root" exit 1 fi source "/vagrant/devtools/dev-fixtures.sh" # create our test users if id -u $FIXED_USER &>/dev/null; then echo "Normal user already exists" else echo "Creating normal user" useradd $FIXED_USER fi if id -u $FIXED_LONG_USER &>/dev/null; then echo "Long user already exists" else echo "Creating long user" useradd $FIXED_LONG_USER fi # locale generation # remove most of this file, it slows down locale-gen if grep -F -q "en_GB.UTF-8 UTF-8" /var/lib/locales/supported.d/en; then echo "Removing existing locales" echo "en_US.UTF-8 UTF-8" > /var/lib/locales/supported.d/en fi # uncomment these from the config file if grep -F -q "# fr_FR.UTF-8" /etc/locale.gen; then sed -i '/fr_FR.UTF-8/s/^# //g' /etc/locale.gen fi if grep -F -q "# ja_JP.UTF-8" /etc/locale.gen; then sed -i '/ja_JP.UTF-8/s/^# //g' /etc/locale.gen fi # only regenerate locales if the config files are newer than the locale archive if [[ ( /var/lib/locales/supported.d/en -nt /usr/lib/locale/locale-archive ) || \ ( /etc/locale_gen -nt /usr/lib/locale/locale-archive ) ]]; then locale-gen else echo "Locales already generated" fi ================================================ FILE: devtools/dev-versions.sh ================================================ # Displays the installed versions of Rust and Cargo. # This gets run from ‘dev-bash.sh’, which gets run from ‘~/.bash_profile’, so # the versions gets displayed after the help text for a new Vagrant session. echo -e "\\033[4mVersions\\033[0m" rustc --version cargo --version echo ================================================ FILE: devtools/local-package-for-macos.sh ================================================ set -e # This script builds a publishable release-worthy version of exa. # It gets the version number, builds exa using cargo, tests it, strips the # binary, and compresses it into a zip. # # It’s *mostly* the same as dev-package-for-linux.sh, except with some # Mach-specific things (otool instead of ldd), BSD-coreutils-specific things, # and it doesn’t run the xtests. # Virtualising macOS is a legal minefield, so this script is ‘local’ instead # of ‘dev’: I run it from my actual machine, rather than from a VM. uname=$(uname -s) if [[ "$uname" != "Darwin" ]]; then echo "Gotta be on Darwin to run this (detected '$uname')!" exit 1 fi # First, we need to get the version number to figure out what to call the zip. # We do this by getting the first line from the Cargo.toml that matches # /version/, removing its whitespace, and building a command out of it, so the # shell executes something like `exa_version="0.8.0"`, which it understands as # a variable definition. Hey, it’s not a hack if it works. # # Because this can’t use the absolute /vagrant path, this has to use what this # SO answer calls a “quoting disaster”: https://stackoverflow.com/a/20196098/3484614 # You will also need GNU coreutils: https://stackoverflow.com/a/4031502/3484614 exa_root="$(dirname "$(dirname "$(greadlink -fm "$0")")")" toml_file="$exa_root"/Cargo.toml eval exa_$(grep version $toml_file | head -n 1 | sed "s/ //g") if [ -z "$exa_version" ]; then echo "Failed to parse version number! Can't build exa!" exit 1 fi # Weekly builds have a bit more information in their version number (see build.rs). if [[ "$1" == "--weekly" ]]; then git_hash=$(GIT_DIR=$exa_root/.git git rev-parse --short --verify HEAD) date=$(date +"%Y-%m-%d") echo "Building exa weekly v$exa_version, date $date, Git hash $git_hash" else echo "Building exa v$exa_version" fi # Compilation is done in --release mode, which takes longer but produces a # faster binary. echo -e "\n\033[4mCompiling release version of exa...\033[0m" exa_macos_binary="$exa_root/exa-macos-x86_64" rm -vf "$exa_macos_binary" | sed 's/^/removing /' cargo build --release --manifest-path "$toml_file" cargo test --release --manifest-path "$toml_file" --lib -- --quiet # we can’t run the xtests outside the VM! #/vagrant/xtests/run.sh --release cp "$exa_root"/target/release/exa "$exa_macos_binary" # Stripping the binary before distributing it removes a bunch of debugging # symbols, saving some space. echo -e "\n\033[4mStripping binary...\033[0m" strip "$exa_macos_binary" echo "strip $exa_macos_binary" # Compress the binary for upload. The ‘-j’ flag is necessary to avoid the # current path being in the zip too. Only the zip gets the version number, so # the binaries can have consistent names, and it’s still possible to tell # different *downloads* apart. echo -e "\n\033[4mZipping binary...\033[0m" if [[ "$1" == "--weekly" ]]; then exa_macos_zip="$exa_root/exa-macos-x86_64-${exa_version}-${date}-${git_hash}.zip" else exa_macos_zip="$exa_root/exa-macos-x86_64-${exa_version}.zip" fi rm -vf "$exa_macos_zip" | sed 's/^/removing /' zip -j "$exa_macos_zip" "$exa_macos_binary" # There was a problem a while back where a library was getting unknowingly # *dynamically* linked, which broke the whole ‘self-contained binary’ concept. # So dump the linker table, in case anything unscrupulous shows up. echo -e "\n\033[4mLibraries linked:\033[0m" otool -L "$exa_macos_binary" | sed 's/^[[:space:]]*//' # Might as well use it to test itself, right? echo -e "\n\033[4mAll done! Files produced:\033[0m" "$exa_macos_binary" "$exa_macos_binary" "$exa_macos_zip" -lB ================================================ FILE: man/exa.1.md ================================================ % exa(1) v0.9.0 NAME ==== exa — a modern replacement for ls SYNOPSIS ======== `exa [options] [files...]` **exa** is a modern replacement for `ls`. It uses colours for information by default, helping you distinguish between many types of files, such as whether you are the owner, or in the owning group. It also has extra features not present in the original `ls`, such as viewing the Git status for a directory, or recursing into directories with a tree view. EXAMPLES ======== `exa` : Lists the contents of the current directory in a grid. `exa --oneline --reverse --sort=size` : Displays a list of files with the largest at the top. `exa --long --header --inode --git` : Displays a table of files with a header, showing each file’s metadata, inode, and Git status. `exa --long --tree --level=3` : Displays a tree of files, three levels deep, as well as each file’s metadata. DISPLAY OPTIONS =============== `-1`, `--oneline` : Display one entry per line. `-F`, `--classify` : Display file kind indicators next to file names. `-G`, `--grid` : Display entries as a grid (default). `-l`, `--long` : Display extended file metadata as a table. `-R`, `--recurse` : Recurse into directories. `-T`, `--tree` : Recurse into directories as a tree. `-x`, `--across` : Sort the grid across, rather than downwards. `--color`, `--colour=WHEN` : When to use terminal colours. Valid settings are ‘`always`’, ‘`automatic`’, and ‘`never`’. `--color-scale`, `--colour-scale` : Colour file sizes on a scale. `--icons` : Display icons next to file names. `--no-icons` : Don't display icons. (Always overrides --icons) FILTERING AND SORTING OPTIONS ============================= `-a`, `--all` : Show hidden and “dot” files. Use this twice to also show the ‘`.`’ and ‘`..`’ directories. `-d`, `--list-dirs` : List directories as regular files, rather than recursing and listing their contents. `-L`, `--level=DEPTH` : Limit the depth of recursion. `-r`, `--reverse` : Reverse the sort order. `-s`, `--sort=SORT_FIELD` : Which field to sort by. Valid sort fields are ‘`name`’, ‘`Name`’, ‘`extension`’, ‘`Extension`’, ‘`size`’, ‘`modified`’, ‘`changed`’, ‘`accessed`’, ‘`created`’, ‘`inode`’, ‘`type`’, and ‘`none`’. The `modified` sort field has the aliases ‘`date`’, ‘`time`’, and ‘`newest`’, and its reverse order has the aliases ‘`age`’ and ‘`oldest`’. Sort fields starting with a capital letter will sort uppercase before lowercase: ‘A’ then ‘B’ then ‘a’ then ‘b’. Fields starting with a lowercase letter will mix them: ‘A’ then ‘a’ then ‘B’ then ‘b’. `-I`, `--ignore-glob=GLOBS` : Glob patterns, pipe-separated, of files to ignore. `--git-ignore` [if exa was built with git support] : Do not list files that are ignored by Git. `--group-directories-first` : List directories before other files. `-D`, `--only-dirs` : List only directories, not files. LONG VIEW OPTIONS ================= These options are available when running with `--long` (`-l`): `-b`, `--binary` : List file sizes with binary prefixes. `-B`, `--bytes` : List file sizes in bytes, without any prefixes. `--changed` : Use the changed timestamp field. `-g`, `--group` : List each file’s group. `-h`, `--header` : Add a header row to each column. `-H`, `--links` : List each file’s number of hard links. `-i`, `--inode` : List each file’s inode number. `-m`, `--modified` : Use the modified timestamp field. `-n`, `--numeric` : List numeric user and group IDs. `-S`, `--blocks` : List each file’s number of file system blocks. `-t`, `--time=WORD` : Which timestamp field to list. : Valid timestamp fields are ‘`modified`’, ‘`changed`’, ‘`accessed`’, and ‘`created`’. `--time-style=STYLE` : How to format timestamps. : Valid timestamp styles are ‘`default`’, ‘`iso`’, ‘`long-iso`’, and ‘`full-iso`’. `-u`, `--accessed` : Use the accessed timestamp field. `-U`, `--created` : Use the created timestamp field. `--no-permissions` : Suppress the permissions field. `--no-filesize` : Suppress the file size field. `--no-user` : Suppress the user field. `--no-time` : Suppress the time field. `-@`, `--extended` : List each file’s extended attributes and sizes. `--git` [if exa was built with git support] : List each file’s Git status, if tracked. This adds a two-character column indicating the staged and unstaged statuses respectively. The status character can be ‘`-`’ for not modified, ‘`M`’ for a modified file, ‘`N`’ for a new file, ‘`D`’ for deleted, ‘`R`’ for renamed, ‘`T`’ for type-change, ‘`I`’ for ignored, and ‘`U`’ for conflicted. Directories will be shown to have the status of their contents, which is how ‘deleted’ is possible: if a directory contains a file that has a certain status, it will be shown to have that status. ENVIRONMENT VARIABLES ===================== exa responds to the following environment variables: ## `COLUMNS` Overrides the width of the terminal, in characters. For example, ‘`COLUMNS=80 exa`’ will show a grid view with a maximum width of 80 characters. This option won’t do anything when exa’s output doesn’t wrap, such as when using the `--long` view. ## `EXA_STRICT` Enables _strict mode_, which will make exa error when two command-line options are incompatible. Usually, options can override each other going right-to-left on the command line, so that exa can be given aliases: creating an alias ‘`exa=exa --sort=ext`’ then running ‘`exa --sort=size`’ with that alias will run ‘`exa --sort=ext --sort=size`’, and the sorting specified by the user will override the sorting specified by the alias. In strict mode, the two options will not co-operate, and exa will error. This option is intended for use with automated scripts and other situations where you want to be certain you’re typing in the right command. ## `EXA_GRID_ROWS` Limits the grid-details view (‘`exa --grid --long`’) so it’s only activated when at least the given number of rows of output would be generated. With widescreen displays, it’s possible for the grid to look very wide and sparse, on just one or two lines with none of the columns lining up. By specifying a minimum number of rows, you can only use the view if it’s going to be worth using. ## `EXA_ICON_SPACING` Specifies the number of spaces to print between an icon (see the ‘`--icons`’ option) and its file name. Different terminals display icons differently, as they usually take up more than one character width on screen, so there’s no “standard” number of spaces that exa can use to separate an icon from text. One space may place the icon too close to the text, and two spaces may place it too far away. So the choice is left up to the user to configure depending on their terminal emulator. ## `NO_COLOR` Disables colours in the output (regardless of its value). Can be overridden by `--color` option. See `https://no-color.org/` for details. ## `LS_COLORS`, `EXA_COLORS` Specifies the colour scheme used to highlight files based on their name and kind, as well as highlighting metadata and parts of the UI. For more information on the format of these environment variables, see the `exa_colors(5)` manual page. EXIT STATUSES ============= 0 : If everything goes OK. 1 : If there was an I/O error during operation. 3 : If there was a problem with the command-line arguments. AUTHOR ====== exa is maintained by Benjamin ‘ogham’ Sago and many other contributors. **Website:** `https://the.exa.website/` \ **Source code:** `https://github.com/ogham/exa` \ **Contributors:** `https://github.com/ogham/exa/graphs/contributors` SEE ALSO ======== - `exa_colors(5)` ================================================ FILE: man/exa_colors.5.md ================================================ % exa_colors(5) v0.9.0 NAME ==== exa_colors — customising the file and UI colours of exa SYNOPSIS ======== The `EXA_COLORS` environment variable can be used to customise the colours that `exa` uses to highlight file names, file metadata, and parts of the UI. You can use the `dircolors` program to generate a script that sets the variable from an input file, or if you don’t mind editing long strings of text, you can just type it out directly. These variables have the following structure: - A list of key-value pairs separated by ‘`=`’, such as ‘`*.txt=32`’. - Multiple ANSI formatting codes are separated by ‘`;`’, such as ‘`*.txt=32;1;4`’. - Finally, multiple pairs are separated by ‘`:`’, such as ‘`*.txt=32:*.mp3=1;35`’. The key half of the pair can either be a two-letter code or a file glob, and anything that’s not a valid code will be treated as a glob, including keys that happen to be two letters long. EXAMPLES ======== `EXA_COLORS="uu=0:gu=0"` : Disable the “current user” highlighting `EXA_COLORS="da=32"` : Turn the date column green `EXA_COLORS="Vagrantfile=1;4;33"` : Highlight Vagrantfiles `EXA_COLORS="*.zip=38;5;125"` : Override the existing zip colour `EXA_COLORS="*.md=38;5;121:*.log=38;5;248"` : Markdown files a shade of green, log files a shade of grey LIST OF CODES ============= `LS_COLORS` can use these ten codes: `di` : directories `ex` : executable files `fi` : regular files `pi` : named pipes `so` : sockets `bd` : block devices `cd` : character devices `ln` : symlinks `or` : symlinks with no target `EXA_COLORS` can use many more: `ur` : the user-read permission bit `uw` : the user-write permission bit `ux` : the user-execute permission bit for regular files `ue` : the user-execute for other file kinds `gr` : the group-read permission bit `gw` : the group-write permission bit `gx` : the group-execute permission bit `tr` : the others-read permission bit `tw` : the others-write permission bit `tx` : the others-execute permission bit `su` : setuid, setgid, and sticky permission bits for files `sf` : setuid, setgid, and sticky for other file kinds `xa` : the extended attribute indicator `sn` : the numbers of a file’s size (sets `nb`, `nk`, `nm`, `ng` and `nh`) `nb` : the numbers of a file’s size if it is lower than 1 KB/Kib `nk` : the numbers of a file’s size if it is between 1 KB/KiB and 1 MB/MiB `nm` : the numbers of a file’s size if it is between 1 MB/MiB and 1 GB/GiB `ng` : the numbers of a file’s size if it is between 1 GB/GiB and 1 TB/TiB `nt` : the numbers of a file’s size if it is 1 TB/TiB or higher `sb` : the units of a file’s size (sets `ub`, `uk`, `um`, `ug` and `uh`) `ub` : the units of a file’s size if it is lower than 1 KB/Kib `uk` : the units of a file’s size if it is between 1 KB/KiB and 1 MB/MiB `um` : the units of a file’s size if it is between 1 MB/MiB and 1 GB/GiB `ug` : the units of a file’s size if it is between 1 GB/GiB and 1 TB/TiB `ut` : the units of a file’s size if it is 1 TB/TiB or higher `df` : a device’s major ID `ds` : a device’s minor ID `uu` : a user that’s you `un` : a user that’s someone else `gu` : a group that you belong to `gn` : a group you aren’t a member of `lc` : a number of hard links `lm` : a number of hard links for a regular file with at least two `ga` : a new flag in Git `gm` : a modified flag in Git `gd` : a deleted flag in Git `gv` : a renamed flag in Git `gt` : a modified metadata flag in Git `xx` : “punctuation”, including many background UI elements `da` : a file’s date `in` : a file’s inode number `bl` : a file’s number of blocks `hd` : the header row of a table `lp` : the path of a symlink `cc` : an escaped character in a filename `bO` : the overlay style for broken symlink paths Values in `EXA_COLORS` override those given in `LS_COLORS`, so you don’t need to re-write an existing `LS_COLORS` variable with proprietary extensions. LIST OF STYLES ============== Unlike some versions of `ls`, the given ANSI values must be valid colour codes: exa won’t just print out whichever characters are given. The codes accepted by exa are: `1` : for bold `4` : for underline `31` : for red text `32` : for green text `33` : for yellow text `34` : for blue text `35` : for purple text `36` : for cyan text `37` : for white text `38;5;nnn` : for a colour from 0 to 255 (replace the `nnn` part) Many terminals will treat bolded text as a different colour, or at least provide the option to. exa provides its own built-in set of file extension mappings that cover a large range of common file extensions, including documents, archives, media, and temporary files. Any mappings in the environment variables will override this default set: running exa with `LS_COLORS="*.zip=32"` will turn zip files green but leave the colours of other compressed files alone. You can also disable this built-in set entirely by including a `reset` entry at the beginning of `EXA_COLORS`. So setting `EXA_COLORS="reset:*.txt=31"` will highlight only text files; setting `EXA_COLORS="reset"` will highlight nothing. AUTHOR ====== exa is maintained by Benjamin ‘ogham’ Sago and many other contributors. **Website:** `https://the.exa.website/` \ **Source code:** `https://github.com/ogham/exa` \ **Contributors:** `https://github.com/ogham/exa/graphs/contributors` SEE ALSO ======== - `exa(1)` ================================================ FILE: rust-toolchain.toml ================================================ [toolchain] channel = "1.66.1" ================================================ FILE: snap/.gitignore ================================================ .snapcraft ================================================ FILE: snap/snapcraft.yaml ================================================ name: exa version: 'latest' summary: Replacement for 'ls' written in Rust description: | It uses colours for information by default, helping you distinguish between many types of files, such as whether you are the owner, or in the owning group. It also has extra features not present in the original ls, such as viewing the Git status for a directory, or recursing into directories with a tree view. exa is written in Rust, so it’s small, fast, and portable. grade: stable confinement: classic apps: exa: command: exa parts: exa: plugin: rust source: . stage-packages: - libgit2-24 - cmake - libz-dev ================================================ FILE: src/fs/dir.rs ================================================ use crate::fs::feature::git::GitCache; use crate::fs::fields::GitStatus; use std::io; use std::fs; use std::path::{Path, PathBuf}; use std::slice::Iter as SliceIter; use log::*; use crate::fs::File; /// A **Dir** provides a cached list of the file paths in a directory that’s /// being listed. /// /// This object gets passed to the Files themselves, in order for them to /// check the existence of surrounding files, then highlight themselves /// accordingly. (See `File#get_source_files`) pub struct Dir { /// A vector of the files that have been read from this directory. contents: Vec, /// The path that was read. pub path: PathBuf, } impl Dir { /// Create a new Dir object filled with all the files in the directory /// pointed to by the given path. Fails if the directory can’t be read, or /// isn’t actually a directory, or if there’s an IO error that occurs at /// any point. /// /// The `read_dir` iterator doesn’t actually yield the `.` and `..` /// entries, so if the user wants to see them, we’ll have to add them /// ourselves after the files have been read. pub fn read_dir(path: PathBuf) -> io::Result { info!("Reading directory {:?}", &path); let contents = fs::read_dir(&path)? .map(|result| result.map(|entry| entry.path())) .collect::>()?; Ok(Self { contents, path }) } /// Produce an iterator of IO results of trying to read all the files in /// this directory. pub fn files<'dir, 'ig>(&'dir self, dots: DotFilter, git: Option<&'ig GitCache>, git_ignoring: bool) -> Files<'dir, 'ig> { Files { inner: self.contents.iter(), dir: self, dotfiles: dots.shows_dotfiles(), dots: dots.dots(), git, git_ignoring, } } /// Whether this directory contains a file with the given path. pub fn contains(&self, path: &Path) -> bool { self.contents.iter().any(|p| p.as_path() == path) } /// Append a path onto the path specified by this directory. pub fn join(&self, child: &Path) -> PathBuf { self.path.join(child) } } /// Iterator over reading the contents of a directory as `File` objects. pub struct Files<'dir, 'ig> { /// The internal iterator over the paths that have been read already. inner: SliceIter<'dir, PathBuf>, /// The directory that begat those paths. dir: &'dir Dir, /// Whether to include dotfiles in the list. dotfiles: bool, /// Whether the `.` or `..` directories should be produced first, before /// any files have been listed. dots: DotsNext, git: Option<&'ig GitCache>, git_ignoring: bool, } impl<'dir, 'ig> Files<'dir, 'ig> { fn parent(&self) -> PathBuf { // We can’t use `Path#parent` here because all it does is remove the // last path component, which is no good for us if the path is // relative. For example, while the parent of `/testcases/files` is // `/testcases`, the parent of `.` is an empty path. Adding `..` on // the end is the only way to get to the *actual* parent directory. self.dir.path.join("..") } /// Go through the directory until we encounter a file we can list (which /// varies depending on the dotfile visibility flag) fn next_visible_file(&mut self) -> Option, (PathBuf, io::Error)>> { loop { if let Some(path) = self.inner.next() { let filename = File::filename(path); if ! self.dotfiles && filename.starts_with('.') { continue; } // Also hide _prefix files on Windows because it's used by old applications // as an alternative to dot-prefix files. #[cfg(windows)] if ! self.dotfiles && filename.starts_with('_') { continue; } if self.git_ignoring { let git_status = self.git.map(|g| g.get(path, false)).unwrap_or_default(); if git_status.unstaged == GitStatus::Ignored { continue; } } return Some(File::from_args(path.clone(), self.dir, filename) .map_err(|e| (path.clone(), e))) } return None } } } /// The dot directories that need to be listed before actual files, if any. /// If these aren’t being printed, then `FilesNext` is used to skip them. enum DotsNext { /// List the `.` directory next. Dot, /// List the `..` directory next. DotDot, /// Forget about the dot directories and just list files. Files, } impl<'dir, 'ig> Iterator for Files<'dir, 'ig> { type Item = Result, (PathBuf, io::Error)>; fn next(&mut self) -> Option { match self.dots { DotsNext::Dot => { self.dots = DotsNext::DotDot; Some(File::new_aa_current(self.dir) .map_err(|e| (Path::new(".").to_path_buf(), e))) } DotsNext::DotDot => { self.dots = DotsNext::Files; Some(File::new_aa_parent(self.parent(), self.dir) .map_err(|e| (self.parent(), e))) } DotsNext::Files => { self.next_visible_file() } } } } /// Usually files in Unix use a leading dot to be hidden or visible, but two /// entries in particular are “extra-hidden”: `.` and `..`, which only become /// visible after an extra `-a` option. #[derive(PartialEq, Eq, Debug, Copy, Clone)] pub enum DotFilter { /// Shows files, dotfiles, and `.` and `..`. DotfilesAndDots, /// Show files and dotfiles, but hide `.` and `..`. Dotfiles, /// Just show files, hiding anything beginning with a dot. JustFiles, } impl Default for DotFilter { fn default() -> Self { Self::JustFiles } } impl DotFilter { /// Whether this filter should show dotfiles in a listing. fn shows_dotfiles(self) -> bool { match self { Self::JustFiles => false, Self::Dotfiles => true, Self::DotfilesAndDots => true, } } /// Whether this filter should add dot directories to a listing. fn dots(self) -> DotsNext { match self { Self::JustFiles => DotsNext::Files, Self::Dotfiles => DotsNext::Files, Self::DotfilesAndDots => DotsNext::Dot, } } } ================================================ FILE: src/fs/dir_action.rs ================================================ //! What to do when encountering a directory? /// The action to take when trying to list a file that turns out to be a /// directory. /// /// By default, exa will display the information about files passed in as /// command-line arguments, with one file per entry. However, if a directory /// is passed in, exa assumes that the user wants to see its contents, rather /// than the directory itself. /// /// This can get annoying sometimes: if a user does `exa ~/Downloads/img-*` /// to see the details of every file starting with `img-`, any directories /// that happen to start with the same will be listed after the files at /// the end in a separate block. By listing directories as files, their /// directory status will be ignored, and both will be listed side-by-side. /// /// These two modes have recursive analogues in the “recurse” and “tree” /// modes. Here, instead of just listing the directories, exa will descend /// into them and print out their contents. The recurse mode does this by /// having extra output blocks at the end, while the tree mode will show /// directories inline, with their contents immediately underneath. #[derive(PartialEq, Eq, Debug, Copy, Clone)] pub enum DirAction { /// This directory should be listed along with the regular files, instead /// of having its contents queried. AsFile, /// This directory should not be listed, and should instead be opened and /// *its* files listed separately. This is the default behaviour. List, /// This directory should be listed along with the regular files, and then /// its contents should be listed afterward. The recursive contents of /// *those* contents are dictated by the options argument. Recurse(RecurseOptions), } impl DirAction { /// Gets the recurse options, if this dir action has any. pub fn recurse_options(self) -> Option { match self { Self::Recurse(o) => Some(o), _ => None, } } /// Whether to treat directories as regular files or not. pub fn treat_dirs_as_files(self) -> bool { match self { Self::AsFile => true, Self::Recurse(o) => o.tree, Self::List => false, } } } /// The options that determine how to recurse into a directory. #[derive(PartialEq, Eq, Debug, Copy, Clone)] pub struct RecurseOptions { /// Whether recursion should be done as a tree or as multiple individual /// views of files. pub tree: bool, /// The maximum number of times that recursion should descend to, if one /// is specified. pub max_depth: Option, } impl RecurseOptions { /// Returns whether a directory of the given depth would be too deep. pub fn is_too_deep(self, depth: usize) -> bool { match self.max_depth { None => false, Some(d) => d <= depth } } } ================================================ FILE: src/fs/feature/git.rs ================================================ //! Getting the Git status of files and directories. use std::ffi::OsStr; #[cfg(target_family = "unix")] use std::os::unix::ffi::OsStrExt; use std::path::{Path, PathBuf}; use std::sync::Mutex; use log::*; use crate::fs::fields as f; /// A **Git cache** is assembled based on the user’s input arguments. /// /// This uses vectors to avoid the overhead of hashing: it’s not worth it when the /// expected number of Git repositories per exa invocation is 0 or 1... pub struct GitCache { /// A list of discovered Git repositories and their paths. repos: Vec, /// Paths that we’ve confirmed do not have Git repositories underneath them. misses: Vec, } impl GitCache { pub fn has_anything_for(&self, index: &Path) -> bool { self.repos.iter().any(|e| e.has_path(index)) } pub fn get(&self, index: &Path, prefix_lookup: bool) -> f::Git { self.repos.iter() .find(|e| e.has_path(index)) .map(|repo| repo.search(index, prefix_lookup)) .unwrap_or_default() } } use std::iter::FromIterator; impl FromIterator for GitCache { fn from_iter(iter: I) -> Self where I: IntoIterator { let iter = iter.into_iter(); let mut git = Self { repos: Vec::with_capacity(iter.size_hint().0), misses: Vec::new(), }; for path in iter { if git.misses.contains(&path) { debug!("Skipping {:?} because it already came back Gitless", path); } else if git.repos.iter().any(|e| e.has_path(&path)) { debug!("Skipping {:?} because we already queried it", path); } else { match GitRepo::discover(path) { Ok(r) => { if let Some(r2) = git.repos.iter_mut().find(|e| e.has_workdir(&r.workdir)) { debug!("Adding to existing repo (workdir matches with {:?})", r2.workdir); r2.extra_paths.push(r.original_path); continue; } debug!("Discovered new Git repo"); git.repos.push(r); } Err(miss) => { git.misses.push(miss) } } } } git } } /// A **Git repository** is one we’ve discovered somewhere on the filesystem. pub struct GitRepo { /// The queryable contents of the repository: either a `git2` repo, or the /// cached results from when we queried it last time. contents: Mutex, /// The working directory of this repository. /// This is used to check whether two repositories are the same. workdir: PathBuf, /// The path that was originally checked to discover this repository. /// This is as important as the extra_paths (it gets checked first), but /// is separate to avoid having to deal with a non-empty Vec. original_path: PathBuf, /// Any other paths that were checked only to result in this same /// repository. extra_paths: Vec, } /// A repository’s queried state. enum GitContents { /// All the interesting Git stuff goes through this. Before { repo: git2::Repository, }, /// Temporary value used in `repo_to_statuses` so we can move the /// repository out of the `Before` variant. Processing, /// The data we’ve extracted from the repository, but only after we’ve /// actually done so. After { statuses: Git, }, } impl GitRepo { /// Searches through this repository for a path (to a file or directory, /// depending on the prefix-lookup flag) and returns its Git status. /// /// Actually querying the `git2` repository for the mapping of paths to /// Git statuses is only done once, and gets cached so we don’t need to /// re-query the entire repository the times after that. /// /// The temporary `Processing` enum variant is used after the `git2` /// repository is moved out, but before the results have been moved in! /// See fn search(&self, index: &Path, prefix_lookup: bool) -> f::Git { use std::mem::replace; let mut contents = self.contents.lock().unwrap(); if let GitContents::After { ref statuses } = *contents { debug!("Git repo {:?} has been found in cache", &self.workdir); return statuses.status(index, prefix_lookup); } debug!("Querying Git repo {:?} for the first time", &self.workdir); let repo = replace(&mut *contents, GitContents::Processing).inner_repo(); let statuses = repo_to_statuses(&repo, &self.workdir); let result = statuses.status(index, prefix_lookup); let _processing = replace(&mut *contents, GitContents::After { statuses }); result } /// Whether this repository has the given working directory. fn has_workdir(&self, path: &Path) -> bool { self.workdir == path } /// Whether this repository cares about the given path at all. fn has_path(&self, path: &Path) -> bool { path.starts_with(&self.original_path) || self.extra_paths.iter().any(|e| path.starts_with(e)) } /// Searches for a Git repository at any point above the given path. /// Returns the original buffer if none is found. fn discover(path: PathBuf) -> Result { info!("Searching for Git repository above {:?}", path); let repo = match git2::Repository::discover(&path) { Ok(r) => r, Err(e) => { error!("Error discovering Git repositories: {:?}", e); return Err(path); } }; if let Some(workdir) = repo.workdir() { let workdir = workdir.to_path_buf(); let contents = Mutex::new(GitContents::Before { repo }); Ok(Self { contents, workdir, original_path: path, extra_paths: Vec::new() }) } else { warn!("Repository has no workdir?"); Err(path) } } } impl GitContents { /// Assumes that the repository hasn’t been queried, and extracts it /// (consuming the value) if it has. This is needed because the entire /// enum variant gets replaced when a repo is queried (see above). fn inner_repo(self) -> git2::Repository { if let Self::Before { repo } = self { repo } else { unreachable!("Tried to extract a non-Repository") } } } /// Iterates through a repository’s statuses, consuming it and returning the /// mapping of files to their Git status. /// We will have already used the working directory at this point, so it gets /// passed in rather than deriving it from the `Repository` again. fn repo_to_statuses(repo: &git2::Repository, workdir: &Path) -> Git { let mut statuses = Vec::new(); info!("Getting Git statuses for repo with workdir {:?}", workdir); match repo.statuses(None) { Ok(es) => { for e in es.iter() { #[cfg(target_family = "unix")] let path = workdir.join(Path::new(OsStr::from_bytes(e.path_bytes()))); // TODO: handle non Unix systems better: // https://github.com/ogham/exa/issues/698 #[cfg(not(target_family = "unix"))] let path = workdir.join(Path::new(e.path().unwrap())); let elem = (path, e.status()); statuses.push(elem); } } Err(e) => { error!("Error looking up Git statuses: {:?}", e); } } Git { statuses } } // The `repo.statuses` call above takes a long time. exa debug output: // // 20.311276 INFO:exa::fs::feature::git: Getting Git statuses for repo with workdir "/vagrant/" // 20.799610 DEBUG:exa::output::table: Getting Git status for file "./Cargo.toml" // // Even inserting another logging line immediately afterwards doesn’t make it // look any faster. /// Container of Git statuses for all the files in this folder’s Git repository. struct Git { statuses: Vec<(PathBuf, git2::Status)>, } impl Git { /// Get either the file or directory status for the given path. /// “Prefix lookup” means that it should report an aggregate status of all /// paths starting with the given prefix (in other words, a directory). fn status(&self, index: &Path, prefix_lookup: bool) -> f::Git { if prefix_lookup { self.dir_status(index) } else { self.file_status(index) } } /// Get the user-facing status of a file. /// We check the statuses directly applying to a file, and for the ignored /// status we check if any of its parents directories is ignored by git. fn file_status(&self, file: &Path) -> f::Git { let path = reorient(file); let s = self.statuses.iter() .filter(|p| if p.1 == git2::Status::IGNORED { path.starts_with(&p.0) } else { p.0 == path }) .fold(git2::Status::empty(), |a, b| a | b.1); let staged = index_status(s); let unstaged = working_tree_status(s); f::Git { staged, unstaged } } /// Get the combined, user-facing status of a directory. /// Statuses are aggregating (for example, a directory is considered /// modified if any file under it has the status modified), except for /// ignored status which applies to files under (for example, a directory /// is considered ignored if one of its parent directories is ignored). fn dir_status(&self, dir: &Path) -> f::Git { let path = reorient(dir); let s = self.statuses.iter() .filter(|p| if p.1 == git2::Status::IGNORED { path.starts_with(&p.0) } else { p.0.starts_with(&path) }) .fold(git2::Status::empty(), |a, b| a | b.1); let staged = index_status(s); let unstaged = working_tree_status(s); f::Git { staged, unstaged } } } /// Converts a path to an absolute path based on the current directory. /// Paths need to be absolute for them to be compared properly, otherwise /// you’d ask a repo about “./README.md” but it only knows about /// “/vagrant/README.md”, prefixed by the workdir. #[cfg(unix)] fn reorient(path: &Path) -> PathBuf { use std::env::current_dir; // TODO: I’m not 100% on this func tbh let path = match current_dir() { Err(_) => Path::new(".").join(&path), Ok(dir) => dir.join(&path), }; path.canonicalize().unwrap_or(path) } #[cfg(windows)] fn reorient(path: &Path) -> PathBuf { let unc_path = path.canonicalize().unwrap(); // On Windows UNC path is returned. We need to strip the prefix for it to work. let normal_path = unc_path.as_os_str().to_str().unwrap().trim_left_matches("\\\\?\\"); return PathBuf::from(normal_path); } /// The character to display if the file has been modified, but not staged. fn working_tree_status(status: git2::Status) -> f::GitStatus { match status { s if s.contains(git2::Status::WT_NEW) => f::GitStatus::New, s if s.contains(git2::Status::WT_MODIFIED) => f::GitStatus::Modified, s if s.contains(git2::Status::WT_DELETED) => f::GitStatus::Deleted, s if s.contains(git2::Status::WT_RENAMED) => f::GitStatus::Renamed, s if s.contains(git2::Status::WT_TYPECHANGE) => f::GitStatus::TypeChange, s if s.contains(git2::Status::IGNORED) => f::GitStatus::Ignored, s if s.contains(git2::Status::CONFLICTED) => f::GitStatus::Conflicted, _ => f::GitStatus::NotModified, } } /// The character to display if the file has been modified and the change /// has been staged. fn index_status(status: git2::Status) -> f::GitStatus { match status { s if s.contains(git2::Status::INDEX_NEW) => f::GitStatus::New, s if s.contains(git2::Status::INDEX_MODIFIED) => f::GitStatus::Modified, s if s.contains(git2::Status::INDEX_DELETED) => f::GitStatus::Deleted, s if s.contains(git2::Status::INDEX_RENAMED) => f::GitStatus::Renamed, s if s.contains(git2::Status::INDEX_TYPECHANGE) => f::GitStatus::TypeChange, _ => f::GitStatus::NotModified, } } ================================================ FILE: src/fs/feature/mod.rs ================================================ pub mod xattr; #[cfg(feature = "git")] pub mod git; #[cfg(not(feature = "git"))] pub mod git { use std::iter::FromIterator; use std::path::{Path, PathBuf}; use crate::fs::fields as f; pub struct GitCache; impl FromIterator for GitCache { fn from_iter(_iter: I) -> Self where I: IntoIterator { Self } } impl GitCache { pub fn has_anything_for(&self, _index: &Path) -> bool { false } pub fn get(&self, _index: &Path, _prefix_lookup: bool) -> f::Git { unreachable!(); } } } ================================================ FILE: src/fs/feature/xattr.rs ================================================ //! Extended attribute support for Darwin and Linux systems. #![allow(trivial_casts)] // for ARM use std::cmp::Ordering; use std::io; use std::path::Path; pub const ENABLED: bool = cfg!(any(target_os = "macos", target_os = "linux")); pub trait FileAttributes { fn attributes(&self) -> io::Result>; fn symlink_attributes(&self) -> io::Result>; } #[cfg(any(target_os = "macos", target_os = "linux"))] impl FileAttributes for Path { fn attributes(&self) -> io::Result> { list_attrs(&lister::Lister::new(FollowSymlinks::Yes), self) } fn symlink_attributes(&self) -> io::Result> { list_attrs(&lister::Lister::new(FollowSymlinks::No), self) } } #[cfg(not(any(target_os = "macos", target_os = "linux")))] impl FileAttributes for Path { fn attributes(&self) -> io::Result> { Ok(Vec::new()) } fn symlink_attributes(&self) -> io::Result> { Ok(Vec::new()) } } /// Attributes which can be passed to `Attribute::list_with_flags` #[cfg(any(target_os = "macos", target_os = "linux"))] #[derive(Copy, Clone)] pub enum FollowSymlinks { Yes, No, } /// Extended attribute #[derive(Debug, Clone)] pub struct Attribute { pub name: String, pub size: usize, } #[cfg(any(target_os = "macos", target_os = "linux"))] pub fn list_attrs(lister: &lister::Lister, path: &Path) -> io::Result> { use std::ffi::CString; let c_path = match path.to_str().and_then(|s| CString::new(s).ok()) { Some(cstring) => cstring, None => { return Err(io::Error::new(io::ErrorKind::Other, "Error: path somehow contained a NUL?")); } }; let bufsize = lister.listxattr_first(&c_path); match bufsize.cmp(&0) { Ordering::Less => return Err(io::Error::last_os_error()), Ordering::Equal => return Ok(Vec::new()), Ordering::Greater => {}, } let mut buf = vec![0_u8; bufsize as usize]; let err = lister.listxattr_second(&c_path, &mut buf, bufsize); match err.cmp(&0) { Ordering::Less => return Err(io::Error::last_os_error()), Ordering::Equal => return Ok(Vec::new()), Ordering::Greater => {}, } let mut names = Vec::new(); if err > 0 { // End indices of the attribute names // the buffer contains 0-terminated c-strings let idx = buf.iter().enumerate().filter_map(|(i, v)| if *v == 0 { Some(i) } else { None } ); let mut start = 0; for end in idx { let c_end = end + 1; // end of the c-string (including 0) let size = lister.getxattr(&c_path, &buf[start..c_end]); if size > 0 { names.push(Attribute { name: lister.translate_attribute_name(&buf[start..end]), size: size as usize, }); } start = c_end; } } Ok(names) } #[cfg(target_os = "macos")] mod lister { use super::FollowSymlinks; use libc::{c_int, size_t, ssize_t, c_char, c_void}; use std::ffi::CString; use std::ptr; extern "C" { fn listxattr( path: *const c_char, namebuf: *mut c_char, size: size_t, options: c_int, ) -> ssize_t; fn getxattr( path: *const c_char, name: *const c_char, value: *mut c_void, size: size_t, position: u32, options: c_int, ) -> ssize_t; } pub struct Lister { c_flags: c_int, } impl Lister { pub fn new(do_follow: FollowSymlinks) -> Self { let c_flags: c_int = match do_follow { FollowSymlinks::Yes => 0x0001, FollowSymlinks::No => 0x0000, }; Self { c_flags } } pub fn translate_attribute_name(&self, input: &[u8]) -> String { unsafe { std::str::from_utf8_unchecked(input).into() } } pub fn listxattr_first(&self, c_path: &CString) -> ssize_t { unsafe { listxattr( c_path.as_ptr(), ptr::null_mut(), 0, self.c_flags, ) } } pub fn listxattr_second(&self, c_path: &CString, buf: &mut Vec, bufsize: ssize_t) -> ssize_t { unsafe { listxattr( c_path.as_ptr(), buf.as_mut_ptr().cast::(), bufsize as size_t, self.c_flags, ) } } pub fn getxattr(&self, c_path: &CString, buf: &[u8]) -> ssize_t { unsafe { getxattr( c_path.as_ptr(), buf.as_ptr().cast::(), ptr::null_mut(), 0, 0, self.c_flags, ) } } } } #[cfg(target_os = "linux")] mod lister { use std::ffi::CString; use libc::{size_t, ssize_t, c_char, c_void}; use super::FollowSymlinks; use std::ptr; extern "C" { fn listxattr( path: *const c_char, list: *mut c_char, size: size_t, ) -> ssize_t; fn llistxattr( path: *const c_char, list: *mut c_char, size: size_t, ) -> ssize_t; fn getxattr( path: *const c_char, name: *const c_char, value: *mut c_void, size: size_t, ) -> ssize_t; fn lgetxattr( path: *const c_char, name: *const c_char, value: *mut c_void, size: size_t, ) -> ssize_t; } pub struct Lister { follow_symlinks: FollowSymlinks, } impl Lister { pub fn new(follow_symlinks: FollowSymlinks) -> Lister { Lister { follow_symlinks } } pub fn translate_attribute_name(&self, input: &[u8]) -> String { String::from_utf8_lossy(input).into_owned() } pub fn listxattr_first(&self, c_path: &CString) -> ssize_t { let listxattr = match self.follow_symlinks { FollowSymlinks::Yes => listxattr, FollowSymlinks::No => llistxattr, }; unsafe { listxattr( c_path.as_ptr().cast(), ptr::null_mut(), 0, ) } } pub fn listxattr_second(&self, c_path: &CString, buf: &mut Vec, bufsize: ssize_t) -> ssize_t { let listxattr = match self.follow_symlinks { FollowSymlinks::Yes => listxattr, FollowSymlinks::No => llistxattr, }; unsafe { listxattr( c_path.as_ptr().cast(), buf.as_mut_ptr().cast(), bufsize as size_t, ) } } pub fn getxattr(&self, c_path: &CString, buf: &[u8]) -> ssize_t { let getxattr = match self.follow_symlinks { FollowSymlinks::Yes => getxattr, FollowSymlinks::No => lgetxattr, }; unsafe { getxattr( c_path.as_ptr().cast(), buf.as_ptr().cast(), ptr::null_mut(), 0, ) } } } } ================================================ FILE: src/fs/fields.rs ================================================ //! Wrapper types for the values returned from `File`s. //! //! The methods of `File` that return information about the entry on the //! filesystem -- size, modification date, block count, or Git status -- used //! to just return these as formatted strings, but this became inflexible once //! customisable output styles landed. //! //! Instead, they will return a wrapper type from this module, which tags the //! type with what field it is while containing the actual raw value. //! //! The `output::details` module, among others, uses these types to render and //! display the information as formatted strings. // C-style `blkcnt_t` types don’t follow Rust’s rules! #![allow(non_camel_case_types)] #![allow(clippy::struct_excessive_bools)] /// The type of a file’s block count. pub type blkcnt_t = u64; /// The type of a file’s group ID. pub type gid_t = u32; /// The type of a file’s inode. pub type ino_t = u64; /// The type of a file’s number of links. pub type nlink_t = u64; /// The type of a file’s timestamp (creation, modification, access, etc). pub type time_t = i64; /// The type of a file’s user ID. pub type uid_t = u32; /// The file’s base type, which gets displayed in the very first column of the /// details output. /// /// This type is set entirely by the filesystem, rather than relying on a /// file’s contents. So “link” is a type, but “image” is just a type of /// regular file. (See the `filetype` module for those checks.) /// /// Its ordering is used when sorting by type. #[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone)] pub enum Type { Directory, File, Link, Pipe, Socket, CharDevice, BlockDevice, Special, } impl Type { pub fn is_regular_file(self) -> bool { matches!(self, Self::File) } } /// The file’s Unix permission bitfield, with one entry per bit. #[derive(Copy, Clone)] pub struct Permissions { pub user_read: bool, pub user_write: bool, pub user_execute: bool, pub group_read: bool, pub group_write: bool, pub group_execute: bool, pub other_read: bool, pub other_write: bool, pub other_execute: bool, pub sticky: bool, pub setgid: bool, pub setuid: bool, } /// The file's FileAttributes field, available only on Windows. #[derive(Copy, Clone)] pub struct Attributes { pub archive: bool, pub directory: bool, pub readonly: bool, pub hidden: bool, pub system: bool, pub reparse_point: bool, } /// The three pieces of information that are displayed as a single column in /// the details view. These values are fused together to make the output a /// little more compressed. #[derive(Copy, Clone)] pub struct PermissionsPlus { pub file_type: Type, #[cfg(unix)] pub permissions: Permissions, #[cfg(windows)] pub attributes: Attributes, pub xattrs: bool, } /// The permissions encoded as octal values #[derive(Copy, Clone)] pub struct OctalPermissions { pub permissions: Permissions, } /// A file’s number of hard links on the filesystem. /// /// Under Unix, a file can exist on the filesystem only once but appear in /// multiple directories. However, it’s rare (but occasionally useful!) for a /// regular file to have a link count greater than 1, so we highlight the /// block count specifically for this case. #[derive(Copy, Clone)] pub struct Links { /// The actual link count. pub count: nlink_t, /// Whether this file is a regular file with more than one hard link. pub multiple: bool, } /// A file’s inode. Every directory entry on a Unix filesystem has an inode, /// including directories and links, so this is applicable to everything exa /// can deal with. #[derive(Copy, Clone)] pub struct Inode(pub ino_t); /// The number of blocks that a file takes up on the filesystem, if any. #[derive(Copy, Clone)] pub enum Blocks { /// This file has the given number of blocks. Some(blkcnt_t), /// This file isn’t of a type that can take up blocks. None, } /// The ID of the user that owns a file. This will only ever be a number; /// looking up the username is done in the `display` module. #[derive(Copy, Clone)] pub struct User(pub uid_t); /// The ID of the group that a file belongs to. #[derive(Copy, Clone)] pub struct Group(pub gid_t); /// A file’s size, in bytes. This is usually formatted by the `number_prefix` /// crate into something human-readable. #[derive(Copy, Clone)] pub enum Size { /// This file has a defined size. Some(u64), /// This file has no size, or has a size but we aren’t interested in it. /// /// Under Unix, directory entries that aren’t regular files will still /// have a file size. For example, a directory will just contain a list of /// its files as its “contents” and will be specially flagged as being a /// directory, rather than a file. However, seeing the “file size” of this /// data is rarely useful — I can’t think of a time when I’ve seen it and /// learnt something. So we discard it and just output “-” instead. /// /// See this answer for more: None, /// This file is a block or character device, so instead of a size, print /// out the file’s major and minor device IDs. /// /// This is what ls does as well. Without it, the devices will just have /// file sizes of zero. DeviceIDs(DeviceIDs), } /// The major and minor device IDs that gets displayed for device files. /// /// You can see what these device numbers mean: /// - /// - #[derive(Copy, Clone)] pub struct DeviceIDs { pub major: u8, pub minor: u8, } /// One of a file’s timestamps (created, accessed, or modified). #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Time { pub seconds: time_t, pub nanoseconds: time_t, } /// A file’s status in a Git repository. Whether a file is in a repository or /// not is handled by the Git module, rather than having a “null” variant in /// this enum. #[derive(PartialEq, Eq, Copy, Clone)] pub enum GitStatus { /// This file hasn’t changed since the last commit. NotModified, /// This file didn’t exist for the last commit, and is not specified in /// the ignored files list. New, /// A file that’s been modified since the last commit. Modified, /// A deleted file. This can’t ever be shown, but it’s here anyway! Deleted, /// A file that Git has tracked a rename for. Renamed, /// A file that’s had its type (such as the file permissions) changed. TypeChange, /// A file that’s ignored (that matches a line in .gitignore) Ignored, /// A file that’s updated but unmerged. Conflicted, } /// A file’s complete Git status. It’s possible to make changes to a file, add /// it to the staging area, then make *more* changes, so we need to list each /// file’s status for both of these. #[derive(Copy, Clone)] pub struct Git { pub staged: GitStatus, pub unstaged: GitStatus, } impl Default for Git { /// Create a Git status for a file with nothing done to it. fn default() -> Self { Self { staged: GitStatus::NotModified, unstaged: GitStatus::NotModified, } } } ================================================ FILE: src/fs/file.rs ================================================ //! Files, and methods and fields to access their metadata. use std::io; #[cfg(unix)] use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt}; #[cfg(windows)] use std::os::windows::fs::MetadataExt; use std::path::{Path, PathBuf}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use log::*; use crate::fs::dir::Dir; use crate::fs::fields as f; /// A **File** is a wrapper around one of Rust’s `PathBuf` values, along with /// associated data about the file. /// /// Each file is definitely going to have its filename displayed at least /// once, have its file extension extracted at least once, and have its metadata /// information queried at least once, so it makes sense to do all this at the /// start and hold on to all the information. pub struct File<'dir> { /// The filename portion of this file’s path, including the extension. /// /// This is used to compare against certain filenames (such as checking if /// it’s “Makefile” or something) and to highlight only the filename in /// colour when displaying the path. pub name: String, /// The file’s name’s extension, if present, extracted from the name. /// /// This is queried many times over, so it’s worth caching it. pub ext: Option, /// The path that begat this file. /// /// Even though the file’s name is extracted, the path needs to be kept /// around, as certain operations involve looking up the file’s absolute /// location (such as searching for compiled files) or using its original /// path (following a symlink). pub path: PathBuf, /// A cached `metadata` (`stat`) call for this file. /// /// This too is queried multiple times, and is *not* cached by the OS, as /// it could easily change between invocations — but exa is so short-lived /// it’s better to just cache it. pub metadata: std::fs::Metadata, /// A reference to the directory that contains this file, if any. /// /// Filenames that get passed in on the command-line directly will have no /// parent directory reference — although they technically have one on the /// filesystem, we’ll never need to look at it, so it’ll be `None`. /// However, *directories* that get passed in will produce files that /// contain a reference to it, which is used in certain operations (such /// as looking up compiled files). pub parent_dir: Option<&'dir Dir>, /// Whether this is one of the two `--all all` directories, `.` and `..`. /// /// Unlike all other entries, these are not returned as part of the /// directory’s children, and are in fact added specifically by exa; this /// means that they should be skipped when recursing. pub is_all_all: bool, } impl<'dir> File<'dir> { pub fn from_args(path: PathBuf, parent_dir: PD, filename: FN) -> io::Result> where PD: Into>, FN: Into> { let parent_dir = parent_dir.into(); let name = filename.into().unwrap_or_else(|| File::filename(&path)); let ext = File::ext(&path); debug!("Statting file {:?}", &path); let metadata = std::fs::symlink_metadata(&path)?; let is_all_all = false; Ok(File { name, ext, path, metadata, parent_dir, is_all_all }) } pub fn new_aa_current(parent_dir: &'dir Dir) -> io::Result> { let path = parent_dir.path.clone(); let ext = File::ext(&path); debug!("Statting file {:?}", &path); let metadata = std::fs::symlink_metadata(&path)?; let is_all_all = true; let parent_dir = Some(parent_dir); Ok(File { path, parent_dir, metadata, ext, name: ".".into(), is_all_all }) } pub fn new_aa_parent(path: PathBuf, parent_dir: &'dir Dir) -> io::Result> { let ext = File::ext(&path); debug!("Statting file {:?}", &path); let metadata = std::fs::symlink_metadata(&path)?; let is_all_all = true; let parent_dir = Some(parent_dir); Ok(File { path, parent_dir, metadata, ext, name: "..".into(), is_all_all }) } /// A file’s name is derived from its string. This needs to handle directories /// such as `/` or `..`, which have no `file_name` component. So instead, just /// use the last component as the name. pub fn filename(path: &Path) -> String { if let Some(back) = path.components().next_back() { back.as_os_str().to_string_lossy().to_string() } else { // use the path as fallback error!("Path {:?} has no last component", path); path.display().to_string() } } /// Extract an extension from a file path, if one is present, in lowercase. /// /// The extension is the series of characters after the last dot. This /// deliberately counts dotfiles, so the “.git” folder has the extension “git”. /// /// ASCII lowercasing is used because these extensions are only compared /// against a pre-compiled list of extensions which are known to only exist /// within ASCII, so it’s alright. fn ext(path: &Path) -> Option { let name = path.file_name().map(|f| f.to_string_lossy().to_string())?; name.rfind('.') .map(|p| name[p + 1 ..] .to_ascii_lowercase()) } /// Whether this file is a directory on the filesystem. pub fn is_directory(&self) -> bool { self.metadata.is_dir() } /// Whether this file is a directory, or a symlink pointing to a directory. pub fn points_to_directory(&self) -> bool { if self.is_directory() { return true; } if self.is_link() { let target = self.link_target(); if let FileTarget::Ok(target) = target { return target.points_to_directory(); } } false } /// If this file is a directory on the filesystem, then clone its /// `PathBuf` for use in one of our own `Dir` values, and read a list of /// its contents. /// /// Returns an IO error upon failure, but this shouldn’t be used to check /// if a `File` is a directory or not! For that, just use `is_directory()`. pub fn to_dir(&self) -> io::Result { Dir::read_dir(self.path.clone()) } /// Whether this file is a regular file on the filesystem — that is, not a /// directory, a link, or anything else treated specially. pub fn is_file(&self) -> bool { self.metadata.is_file() } /// Whether this file is both a regular file *and* executable for the /// current user. An executable file has a different purpose from an /// executable directory, so they should be highlighted differently. #[cfg(unix)] pub fn is_executable_file(&self) -> bool { let bit = modes::USER_EXECUTE; self.is_file() && (self.metadata.permissions().mode() & bit) == bit } /// Whether this file is a symlink on the filesystem. pub fn is_link(&self) -> bool { self.metadata.file_type().is_symlink() } /// Whether this file is a named pipe on the filesystem. #[cfg(unix)] pub fn is_pipe(&self) -> bool { self.metadata.file_type().is_fifo() } /// Whether this file is a char device on the filesystem. #[cfg(unix)] pub fn is_char_device(&self) -> bool { self.metadata.file_type().is_char_device() } /// Whether this file is a block device on the filesystem. #[cfg(unix)] pub fn is_block_device(&self) -> bool { self.metadata.file_type().is_block_device() } /// Whether this file is a socket on the filesystem. #[cfg(unix)] pub fn is_socket(&self) -> bool { self.metadata.file_type().is_socket() } /// Re-prefixes the path pointed to by this file, if it’s a symlink, to /// make it an absolute path that can be accessed from whichever /// directory exa is being run from. fn reorient_target_path(&self, path: &Path) -> PathBuf { if path.is_absolute() { path.to_path_buf() } else if let Some(dir) = self.parent_dir { dir.join(path) } else if let Some(parent) = self.path.parent() { parent.join(path) } else { self.path.join(path) } } /// Again assuming this file is a symlink, follows that link and returns /// the result of following it. /// /// For a working symlink that the user is allowed to follow, /// this will be the `File` object at the other end, which can then have /// its name, colour, and other details read. /// /// For a broken symlink, returns where the file *would* be, if it /// existed. If this file cannot be read at all, returns the error that /// we got when we tried to read it. pub fn link_target(&self) -> FileTarget<'dir> { // We need to be careful to treat the path actually pointed to by // this file — which could be absolute or relative — to the path // we actually look up and turn into a `File` — which needs to be // absolute to be accessible from any directory. debug!("Reading link {:?}", &self.path); let path = match std::fs::read_link(&self.path) { Ok(p) => p, Err(e) => return FileTarget::Err(e), }; let absolute_path = self.reorient_target_path(&path); // Use plain `metadata` instead of `symlink_metadata` - we *want* to // follow links. match std::fs::metadata(&absolute_path) { Ok(metadata) => { let ext = File::ext(&path); let name = File::filename(&path); let file = File { parent_dir: None, path, ext, metadata, name, is_all_all: false }; FileTarget::Ok(Box::new(file)) } Err(e) => { error!("Error following link {:?}: {:#?}", &path, e); FileTarget::Broken(path) } } } /// This file’s number of hard links. /// /// It also reports whether this is both a regular file, and a file with /// multiple links. This is important, because a file with multiple links /// is uncommon, while you come across directories and other types /// with multiple links much more often. Thus, it should get highlighted /// more attentively. #[cfg(unix)] pub fn links(&self) -> f::Links { let count = self.metadata.nlink(); f::Links { count, multiple: self.is_file() && count > 1, } } /// This file’s inode. #[cfg(unix)] pub fn inode(&self) -> f::Inode { f::Inode(self.metadata.ino()) } /// This file’s number of filesystem blocks. /// /// (Not the size of each block, which we don’t actually report on) #[cfg(unix)] pub fn blocks(&self) -> f::Blocks { if self.is_file() || self.is_link() { f::Blocks::Some(self.metadata.blocks()) } else { f::Blocks::None } } /// The ID of the user that own this file. #[cfg(unix)] pub fn user(&self) -> f::User { f::User(self.metadata.uid()) } /// The ID of the group that owns this file. #[cfg(unix)] pub fn group(&self) -> f::Group { f::Group(self.metadata.gid()) } /// This file’s size, if it’s a regular file. /// /// For directories, no size is given. Although they do have a size on /// some filesystems, I’ve never looked at one of those numbers and gained /// any information from it. So it’s going to be hidden instead. /// /// Block and character devices return their device IDs, because they /// usually just have a file size of zero. #[cfg(unix)] pub fn size(&self) -> f::Size { if self.is_directory() { f::Size::None } else if self.is_char_device() || self.is_block_device() { let device_ids = self.metadata.rdev().to_be_bytes(); // In C-land, getting the major and minor device IDs is done with // preprocessor macros called `major` and `minor` that depend on // the size of `dev_t`, but we just take the second-to-last and // last bytes. f::Size::DeviceIDs(f::DeviceIDs { major: device_ids[6], minor: device_ids[7], }) } else { f::Size::Some(self.metadata.len()) } } #[cfg(windows)] pub fn size(&self) -> f::Size { if self.is_directory() { f::Size::None } else { f::Size::Some(self.metadata.len()) } } /// This file’s last modified timestamp, if available on this platform. pub fn modified_time(&self) -> Option { self.metadata.modified().ok() } /// This file’s last changed timestamp, if available on this platform. #[cfg(unix)] pub fn changed_time(&self) -> Option { let (mut sec, mut nanosec) = (self.metadata.ctime(), self.metadata.ctime_nsec()); if sec < 0 { if nanosec > 0 { sec += 1; nanosec -= 1_000_000_000; } let duration = Duration::new(sec.unsigned_abs(), nanosec.unsigned_abs() as u32); Some(UNIX_EPOCH - duration) } else { let duration = Duration::new(sec as u64, nanosec as u32); Some(UNIX_EPOCH + duration) } } #[cfg(windows)] pub fn changed_time(&self) -> Option { return self.modified_time() } /// This file’s last accessed timestamp, if available on this platform. pub fn accessed_time(&self) -> Option { self.metadata.accessed().ok() } /// This file’s created timestamp, if available on this platform. pub fn created_time(&self) -> Option { self.metadata.created().ok() } /// This file’s ‘type’. /// /// This is used a the leftmost character of the permissions column. /// The file type can usually be guessed from the colour of the file, but /// ls puts this character there. #[cfg(unix)] pub fn type_char(&self) -> f::Type { if self.is_file() { f::Type::File } else if self.is_directory() { f::Type::Directory } else if self.is_pipe() { f::Type::Pipe } else if self.is_link() { f::Type::Link } else if self.is_char_device() { f::Type::CharDevice } else if self.is_block_device() { f::Type::BlockDevice } else if self.is_socket() { f::Type::Socket } else { f::Type::Special } } #[cfg(windows)] pub fn type_char(&self) -> f::Type { if self.is_file() { f::Type::File } else if self.is_directory() { f::Type::Directory } else { f::Type::Special } } /// This file’s permissions, with flags for each bit. #[cfg(unix)] pub fn permissions(&self) -> f::Permissions { let bits = self.metadata.mode(); let has_bit = |bit| bits & bit == bit; f::Permissions { user_read: has_bit(modes::USER_READ), user_write: has_bit(modes::USER_WRITE), user_execute: has_bit(modes::USER_EXECUTE), group_read: has_bit(modes::GROUP_READ), group_write: has_bit(modes::GROUP_WRITE), group_execute: has_bit(modes::GROUP_EXECUTE), other_read: has_bit(modes::OTHER_READ), other_write: has_bit(modes::OTHER_WRITE), other_execute: has_bit(modes::OTHER_EXECUTE), sticky: has_bit(modes::STICKY), setgid: has_bit(modes::SETGID), setuid: has_bit(modes::SETUID), } } #[cfg(windows)] pub fn attributes(&self) -> f::Attributes { let bits = self.metadata.file_attributes(); let has_bit = |bit| bits & bit == bit; // https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants f::Attributes { directory: has_bit(0x10), archive: has_bit(0x20), readonly: has_bit(0x1), hidden: has_bit(0x2), system: has_bit(0x4), reparse_point: has_bit(0x400), } } /// Whether this file’s extension is any of the strings that get passed in. /// /// This will always return `false` if the file has no extension. pub fn extension_is_one_of(&self, choices: &[&str]) -> bool { match &self.ext { Some(ext) => choices.contains(&&ext[..]), None => false, } } /// Whether this file’s name, including extension, is any of the strings /// that get passed in. pub fn name_is_one_of(&self, choices: &[&str]) -> bool { choices.contains(&&self.name[..]) } } impl<'a> AsRef> for File<'a> { fn as_ref(&self) -> &File<'a> { self } } /// The result of following a symlink. pub enum FileTarget<'dir> { /// The symlink pointed at a file that exists. Ok(Box>), /// The symlink pointed at a file that does not exist. Holds the path /// where the file would be, if it existed. Broken(PathBuf), /// There was an IO error when following the link. This can happen if the /// file isn’t a link to begin with, but also if, say, we don’t have /// permission to follow it. Err(io::Error), // Err is its own variant, instead of having the whole thing be inside an // `io::Result`, because being unable to follow a symlink is not a serious // error — we just display the error message and move on. } impl<'dir> FileTarget<'dir> { /// Whether this link doesn’t lead to a file, for whatever reason. This /// gets used to determine how to highlight the link in grid views. pub fn is_broken(&self) -> bool { matches!(self, Self::Broken(_) | Self::Err(_)) } } /// More readable aliases for the permission bits exposed by libc. #[allow(trivial_numeric_casts)] #[cfg(unix)] mod modes { // The `libc::mode_t` type’s actual type varies, but the value returned // from `metadata.permissions().mode()` is always `u32`. pub type Mode = u32; pub const USER_READ: Mode = libc::S_IRUSR as Mode; pub const USER_WRITE: Mode = libc::S_IWUSR as Mode; pub const USER_EXECUTE: Mode = libc::S_IXUSR as Mode; pub const GROUP_READ: Mode = libc::S_IRGRP as Mode; pub const GROUP_WRITE: Mode = libc::S_IWGRP as Mode; pub const GROUP_EXECUTE: Mode = libc::S_IXGRP as Mode; pub const OTHER_READ: Mode = libc::S_IROTH as Mode; pub const OTHER_WRITE: Mode = libc::S_IWOTH as Mode; pub const OTHER_EXECUTE: Mode = libc::S_IXOTH as Mode; pub const STICKY: Mode = libc::S_ISVTX as Mode; pub const SETGID: Mode = libc::S_ISGID as Mode; pub const SETUID: Mode = libc::S_ISUID as Mode; } #[cfg(test)] mod ext_test { use super::File; use std::path::Path; #[test] fn extension() { assert_eq!(Some("dat".to_string()), File::ext(Path::new("fester.dat"))) } #[test] fn dotfile() { assert_eq!(Some("vimrc".to_string()), File::ext(Path::new(".vimrc"))) } #[test] fn no_extension() { assert_eq!(None, File::ext(Path::new("jarlsberg"))) } } #[cfg(test)] mod filename_test { use super::File; use std::path::Path; #[test] fn file() { assert_eq!("fester.dat", File::filename(Path::new("fester.dat"))) } #[test] fn no_path() { assert_eq!("foo.wha", File::filename(Path::new("/var/cache/foo.wha"))) } #[test] fn here() { assert_eq!(".", File::filename(Path::new("."))) } #[test] fn there() { assert_eq!("..", File::filename(Path::new(".."))) } #[test] fn everywhere() { assert_eq!("..", File::filename(Path::new("./.."))) } #[test] #[cfg(unix)] fn topmost() { assert_eq!("/", File::filename(Path::new("/"))) } } ================================================ FILE: src/fs/filter.rs ================================================ //! Filtering and sorting the list of files before displaying them. use std::cmp::Ordering; use std::iter::FromIterator; #[cfg(unix)] use std::os::unix::fs::MetadataExt; use crate::fs::DotFilter; use crate::fs::File; /// The **file filter** processes a list of files before displaying them to /// the user, by removing files they don’t want to see, and putting the list /// in the desired order. /// /// Usually a user does not want to see *every* file in the list. The most /// common case is to remove files starting with `.`, which are designated /// as ‘hidden’ files. /// /// The special files `.` and `..` files are not actually filtered out, but /// need to be inserted into the list, in a special case. /// /// The filter also governs sorting the list. After being filtered, pairs of /// files are compared and sorted based on the result, with the sort field /// performing the comparison. #[derive(PartialEq, Eq, Debug, Clone)] pub struct FileFilter { /// Whether directories should be listed first, and other types of file /// second. Some users prefer it like this. pub list_dirs_first: bool, /// The metadata field to sort by. pub sort_field: SortField, /// Whether to reverse the sorting order. This would sort the largest /// files first, or files starting with Z, or the most-recently-changed /// ones, depending on the sort field. pub reverse: bool, /// Whether to only show directories. pub only_dirs: bool, /// Which invisible “dot” files to include when listing a directory. /// /// Files starting with a single “.” are used to determine “system” or /// “configuration” files that should not be displayed in a regular /// directory listing, and the directory entries “.” and “..” are /// considered extra-special. /// /// This came about more or less by a complete historical accident, /// when the original `ls` tried to hide `.` and `..`: /// /// [Linux History: How Dot Files Became Hidden Files](https://linux-audit.com/linux-history-how-dot-files-became-hidden-files/) pub dot_filter: DotFilter, /// Glob patterns to ignore. Any file name that matches *any* of these /// patterns won’t be displayed in the list. pub ignore_patterns: IgnorePatterns, /// Whether to ignore Git-ignored patterns. pub git_ignore: GitIgnore, } impl FileFilter { /// Remove every file in the given vector that does *not* pass the /// filter predicate for files found inside a directory. pub fn filter_child_files(&self, files: &mut Vec>) { files.retain(|f| ! self.ignore_patterns.is_ignored(&f.name)); if self.only_dirs { files.retain(File::is_directory); } } /// Remove every file in the given vector that does *not* pass the /// filter predicate for file names specified on the command-line. /// /// The rules are different for these types of files than the other /// type because the ignore rules can be used with globbing. For /// example, running `exa -I='*.tmp' .vimrc` shouldn’t filter out the /// dotfile, because it’s been directly specified. But running /// `exa -I='*.ogg' music/*` should filter out the ogg files obtained /// from the glob, even though the globbing is done by the shell! pub fn filter_argument_files(&self, files: &mut Vec>) { files.retain(|f| { ! self.ignore_patterns.is_ignored(&f.name) }); } /// Sort the files in the given vector based on the sort field option. pub fn sort_files<'a, F>(&self, files: &mut [F]) where F: AsRef> { files.sort_by(|a, b| { self.sort_field.compare_files(a.as_ref(), b.as_ref()) }); if self.reverse { files.reverse(); } if self.list_dirs_first { // This relies on the fact that `sort_by` is *stable*: it will keep // adjacent elements next to each other. files.sort_by(|a, b| { b.as_ref().points_to_directory() .cmp(&a.as_ref().points_to_directory()) }); } } } /// User-supplied field to sort by. #[derive(PartialEq, Eq, Debug, Copy, Clone)] pub enum SortField { /// Don’t apply any sorting. This is usually used as an optimisation in /// scripts, where the order doesn’t matter. Unsorted, /// The file name. This is the default sorting. Name(SortCase), /// The file’s extension, with extensionless files being listed first. Extension(SortCase), /// The file’s size, in bytes. Size, /// The file’s inode, which usually corresponds to the order in which /// files were created on the filesystem, more or less. #[cfg(unix)] FileInode, /// The time the file was modified (the “mtime”). /// /// As this is stored as a Unix timestamp, rather than a local time /// instance, the time zone does not matter and will only be used to /// display the timestamps, not compare them. ModifiedDate, /// The time the file was accessed (the “atime”). /// /// Oddly enough, this field rarely holds the *actual* accessed time. /// Recording a read time means writing to the file each time it’s read /// slows the whole operation down, so many systems will only update the /// timestamp in certain circumstances. This has become common enough that /// it’s now expected behaviour! /// AccessedDate, /// The time the file was changed (the “ctime”). /// /// This field is used to mark the time when a file’s metadata /// changed — its permissions, owners, or link count. /// /// In original Unix, this was, however, meant as creation time. /// ChangedDate, /// The time the file was created (the “btime” or “birthtime”). CreatedDate, /// The type of the file: directories, links, pipes, regular, files, etc. /// /// Files are ordered according to the `PartialOrd` implementation of /// `fs::fields::Type`, so changing that will change this. FileType, /// The “age” of the file, which is the time it was modified sorted /// backwards. The reverse of the `ModifiedDate` ordering! /// /// It turns out that listing the most-recently-modified files first is a /// common-enough use case that it deserves its own variant. This would be /// implemented by just using the modified date and setting the reverse /// flag, but this would make reversing *that* output not work, which is /// bad, even though that’s kind of nonsensical. So it’s its own variant /// that can be reversed like usual. ModifiedAge, /// The file's name, however if the name of the file begins with `.` /// ignore the leading `.` and then sort as Name NameMixHidden(SortCase), } /// Whether a field should be sorted case-sensitively or case-insensitively. /// This determines which of the `natord` functions to use. /// /// I kept on forgetting which one was sensitive and which one was /// insensitive. Would a case-sensitive sort put capital letters first because /// it takes the case of the letters into account, or intermingle them with /// lowercase letters because it takes the difference between the two cases /// into account? I gave up and just named these two variants after the /// effects they have. #[derive(PartialEq, Eq, Debug, Copy, Clone)] pub enum SortCase { /// Sort files case-sensitively with uppercase first, with ‘A’ coming /// before ‘a’. ABCabc, /// Sort files case-insensitively, with ‘A’ being equal to ‘a’. AaBbCc, } impl SortField { /// Compares two files to determine the order they should be listed in, /// depending on the search field. /// /// The `natord` crate is used here to provide a more *natural* sorting /// order than just sorting character-by-character. This splits filenames /// into groups between letters and numbers, and then sorts those blocks /// together, so `file10` will sort after `file9`, instead of before it /// because of the `1`. pub fn compare_files(self, a: &File<'_>, b: &File<'_>) -> Ordering { use self::SortCase::{ABCabc, AaBbCc}; match self { Self::Unsorted => Ordering::Equal, Self::Name(ABCabc) => natord::compare(&a.name, &b.name), Self::Name(AaBbCc) => natord::compare_ignore_case(&a.name, &b.name), Self::Size => a.metadata.len().cmp(&b.metadata.len()), #[cfg(unix)] Self::FileInode => a.metadata.ino().cmp(&b.metadata.ino()), Self::ModifiedDate => a.modified_time().cmp(&b.modified_time()), Self::AccessedDate => a.accessed_time().cmp(&b.accessed_time()), Self::ChangedDate => a.changed_time().cmp(&b.changed_time()), Self::CreatedDate => a.created_time().cmp(&b.created_time()), Self::ModifiedAge => b.modified_time().cmp(&a.modified_time()), // flip b and a Self::FileType => match a.type_char().cmp(&b.type_char()) { // todo: this recomputes Ordering::Equal => natord::compare(&*a.name, &*b.name), order => order, }, Self::Extension(ABCabc) => match a.ext.cmp(&b.ext) { Ordering::Equal => natord::compare(&*a.name, &*b.name), order => order, }, Self::Extension(AaBbCc) => match a.ext.cmp(&b.ext) { Ordering::Equal => natord::compare_ignore_case(&*a.name, &*b.name), order => order, }, Self::NameMixHidden(ABCabc) => natord::compare( Self::strip_dot(&a.name), Self::strip_dot(&b.name) ), Self::NameMixHidden(AaBbCc) => natord::compare_ignore_case( Self::strip_dot(&a.name), Self::strip_dot(&b.name) ) } } fn strip_dot(n: &str) -> &str { match n.strip_prefix('.') { Some(s) => s, None => n, } } } /// The **ignore patterns** are a list of globs that are tested against /// each filename, and if any of them match, that file isn’t displayed. /// This lets a user hide, say, text files by ignoring `*.txt`. #[derive(PartialEq, Eq, Default, Debug, Clone)] pub struct IgnorePatterns { patterns: Vec, } impl FromIterator for IgnorePatterns { fn from_iter(iter: I) -> Self where I: IntoIterator { let patterns = iter.into_iter().collect(); Self { patterns } } } impl IgnorePatterns { /// Create a new list from the input glob strings, turning the inputs that /// are valid glob patterns into an `IgnorePatterns`. The inputs that /// don’t parse correctly are returned separately. pub fn parse_from_iter<'a, I: IntoIterator>(iter: I) -> (Self, Vec) { let iter = iter.into_iter(); // Almost all glob patterns are valid, so it’s worth pre-allocating // the vector with enough space for all of them. let mut patterns = match iter.size_hint() { (_, Some(count)) => Vec::with_capacity(count), _ => Vec::new(), }; // Similarly, assume there won’t be any errors. let mut errors = Vec::new(); for input in iter { match glob::Pattern::new(input) { Ok(pat) => patterns.push(pat), Err(e) => errors.push(e), } } (Self { patterns }, errors) } /// Create a new empty set of patterns that matches nothing. pub fn empty() -> Self { Self { patterns: Vec::new() } } /// Test whether the given file should be hidden from the results. fn is_ignored(&self, file: &str) -> bool { self.patterns.iter().any(|p| p.matches(file)) } } /// Whether to ignore or display files that Git would ignore. #[derive(PartialEq, Eq, Debug, Copy, Clone)] pub enum GitIgnore { /// Ignore files that Git would ignore. CheckAndIgnore, /// Display files, even if Git would ignore them. Off, } #[cfg(test)] mod test_ignores { use super::*; #[test] fn empty_matches_nothing() { let pats = IgnorePatterns::empty(); assert!(!pats.is_ignored("nothing")); assert!(!pats.is_ignored("test.mp3")); } #[test] fn ignores_a_glob() { let (pats, fails) = IgnorePatterns::parse_from_iter(vec![ "*.mp3" ]); assert!(fails.is_empty()); assert!(!pats.is_ignored("nothing")); assert!(pats.is_ignored("test.mp3")); } #[test] fn ignores_an_exact_filename() { let (pats, fails) = IgnorePatterns::parse_from_iter(vec![ "nothing" ]); assert!(fails.is_empty()); assert!(pats.is_ignored("nothing")); assert!(!pats.is_ignored("test.mp3")); } #[test] fn ignores_both() { let (pats, fails) = IgnorePatterns::parse_from_iter(vec![ "nothing", "*.mp3" ]); assert!(fails.is_empty()); assert!(pats.is_ignored("nothing")); assert!(pats.is_ignored("test.mp3")); } } ================================================ FILE: src/fs/mod.rs ================================================ mod dir; pub use self::dir::{Dir, DotFilter}; mod file; pub use self::file::{File, FileTarget}; pub mod dir_action; pub mod feature; pub mod fields; pub mod filter; ================================================ FILE: src/info/filetype.rs ================================================ //! Tests for various types of file (video, image, compressed, etc). //! //! Currently this is dependent on the file’s name and extension, because //! those are the only metadata that we have access to without reading the //! file’s contents. use ansi_term::Style; use crate::fs::File; use crate::output::icons::FileIcon; use crate::theme::FileColours; #[derive(Debug, Default, PartialEq, Eq)] pub struct FileExtensions; impl FileExtensions { /// An “immediate” file is something that can be run or activated somehow /// in order to kick off the build of a project. It’s usually only present /// in directories full of source code. #[allow(clippy::case_sensitive_file_extension_comparisons)] fn is_immediate(&self, file: &File<'_>) -> bool { file.name.to_lowercase().starts_with("readme") || file.name.ends_with(".ninja") || file.name_is_one_of( &[ "Makefile", "Cargo.toml", "SConstruct", "CMakeLists.txt", "build.gradle", "pom.xml", "Rakefile", "package.json", "Gruntfile.js", "Gruntfile.coffee", "BUILD", "BUILD.bazel", "WORKSPACE", "build.xml", "Podfile", "webpack.config.js", "meson.build", "composer.json", "RoboFile.php", "PKGBUILD", "Justfile", "Procfile", "Dockerfile", "Containerfile", "Vagrantfile", "Brewfile", "Gemfile", "Pipfile", "build.sbt", "mix.exs", "bsconfig.json", "tsconfig.json", ]) } fn is_image(&self, file: &File<'_>) -> bool { file.extension_is_one_of( &[ "png", "jfi", "jfif", "jif", "jpe", "jpeg", "jpg", "gif", "bmp", "tiff", "tif", "ppm", "pgm", "pbm", "pnm", "webp", "raw", "arw", "svg", "stl", "eps", "dvi", "ps", "cbr", "jpf", "cbz", "xpm", "ico", "cr2", "orf", "nef", "heif", "avif", "jxl", "j2k", "jp2", "j2c", "jpx", ]) } fn is_video(&self, file: &File<'_>) -> bool { file.extension_is_one_of( &[ "avi", "flv", "m2v", "m4v", "mkv", "mov", "mp4", "mpeg", "mpg", "ogm", "ogv", "vob", "wmv", "webm", "m2ts", "heic", ]) } fn is_music(&self, file: &File<'_>) -> bool { file.extension_is_one_of( &[ "aac", "m4a", "mp3", "ogg", "wma", "mka", "opus", ]) } // Lossless music, rather than any other kind of data... fn is_lossless(&self, file: &File<'_>) -> bool { file.extension_is_one_of( &[ "alac", "ape", "flac", "wav", ]) } fn is_crypto(&self, file: &File<'_>) -> bool { file.extension_is_one_of( &[ "asc", "enc", "gpg", "pgp", "sig", "signature", "pfx", "p12", ]) } fn is_document(&self, file: &File<'_>) -> bool { file.extension_is_one_of( &[ "djvu", "doc", "docx", "dvi", "eml", "eps", "fotd", "key", "keynote", "numbers", "odp", "odt", "pages", "pdf", "ppt", "pptx", "rtf", "xls", "xlsx", ]) } fn is_compressed(&self, file: &File<'_>) -> bool { file.extension_is_one_of( &[ "zip", "tar", "Z", "z", "gz", "bz2", "a", "ar", "7z", "iso", "dmg", "tc", "rar", "par", "tgz", "xz", "txz", "lz", "tlz", "lzma", "deb", "rpm", "zst", "lz4", "cpio", ]) } fn is_temp(&self, file: &File<'_>) -> bool { file.name.ends_with('~') || (file.name.starts_with('#') && file.name.ends_with('#')) || file.extension_is_one_of( &[ "tmp", "swp", "swo", "swn", "bak", "bkp", "bk" ]) } fn is_compiled(&self, file: &File<'_>) -> bool { if file.extension_is_one_of( &[ "class", "elc", "hi", "o", "pyc", "zwc", "ko" ]) { true } else if let Some(dir) = file.parent_dir { file.get_source_files().iter().any(|path| dir.contains(path)) } else { false } } } impl FileColours for FileExtensions { fn colour_file(&self, file: &File<'_>) -> Option