Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ with time! 😁
- [Usage](#usage)
- [Fuzzy Time](#fuzzy-time)
- [Icons](#icons)
- [Compatibility Mode](#compatibility-mode)
- [Configuration File](#configuration-file)
- [Aliases](#aliases)
- [Development](#development)
Expand Down Expand Up @@ -139,6 +140,44 @@ a Pull Request implementing it! 😁

You can disable the icons by using the `--no-icons` option.

### Compatibility Mode

`lsp` has two CLI modes:

- `native` - the default `lsplus` command-line interface
- `gnu` - a GNU `ls` compatibility mode intended for aliases and scripts

You can enable GNU compatibility mode in either of these ways:

```toml
compat_mode = "gnu"
```

or:

```sh
LSP_COMPAT_MODE=gnu lsp
```

The `LSP_COMPAT_MODE` environment variable takes precedence over the config
file.

At the moment, compatibility mode only changes the CLI surface and help output.
It does not yet implement the missing GNU meanings for the conflicting short
flags `-D`, `-I`, `-N`, and `-Z`; those flags are reserved in `gnu` mode and
will error until their GNU behavior is implemented.

The current `lsplus` features behind those four native short flags are still
available in `gnu` mode through their long forms only:

- `--group-directories-first` (replaces the original `--sort-dirs`)
- `--gitignore`
- `--no-color`
- `--fuzzy-time`

In `gnu` mode, `-p` uses the GNU-style long form `--indicator-style=slash`
instead of the native `--slash-dirs`.

### Configuration File

You can set options using the configuration file so they will apply to every run
Expand All @@ -154,6 +193,10 @@ The `lsp` command can be aliased to `ls` by adding the following line to your
alias ls='lsp'
```

If you want that alias to behave more like GNU `ls`, enable `gnu`
compatibility mode in your config file or set `LSP_COMPAT_MODE=gnu` in your
shell environment.

You will need to restart your shell or source your configuration file for the
alias to take effect.

Expand Down
6 changes: 6 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
- [ ] using the config file, allow extending the existing file and folder
mapping, or deleting specific maps.
- [ ] add a -R flag to recursively list files in a directory.
- [ ] Rework short-mode file indicators so symlinks use `@` independently of
`-p`, and implement the remaining GNU-style indicator modes together,
including their preferred GNU short forms where they exist
(`--indicator-style=file-type` / `--file-type`,
`--indicator-style=classify` / `-F`, and
`--indicator-style=none`).
- [ ] When adding recursion or tree-style output, revisit whether directory
traversal should move over to the `ignore` crate instead of the current
custom walker.
Expand Down
25 changes: 23 additions & 2 deletions docs/src/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,27 @@ location:
The configuration file is optional and if it is not found, `lsplus` will use the
default settings.

`lsplus` also supports an `LSP_COMPAT_MODE` environment variable. When set, it
overrides the `compat_mode` value from the config file.

## Available Options

The following options are available in the configuration file and correspond to
the relevant command line options:

### compat_mode

- Permitted values: `"native"` or `"gnu"`
- Default value: `"native"`

This option selects which command-line interface `lsp` uses at startup.
`native` keeps the standard `lsplus` CLI, while `gnu` enables the GNU `ls`
compatibility surface intended for aliases and scripts.

At the moment, `gnu` mode changes the CLI surface and help output only. The
conflicting GNU short flags `-D`, `-I`, `-N`, and `-Z` are reserved in that
mode and will error until their GNU behavior is implemented.

### show_all

- Permitted values: `true` or `false`
Expand All @@ -38,14 +54,18 @@ will display all files and directories if set to `true`, except for `.` and
- Default value: `false`

This option corresponds to the `-p` or `--slash-dirs` command line option and
will append a slash to directories if set to `true`.
will append a slash to directories if set to `true`. In `gnu` compatibility
mode, the equivalent long option is `--indicator-style=slash`.

### dirs_first

- Permitted values: `true` or `false`
- Default value: `false`

This option corresponds to the `--sort-dirs` command line option and will
This option corresponds to the `--sort-dirs` command line option and will sort
directories before files when set to `true`. In `gnu` compatibility mode, the
equivalent long option is `--group-directories-first` (replacing the original
`--sort-dirs`).

### long_format

Expand Down Expand Up @@ -103,6 +123,7 @@ The following is an example configuration file that sets several options. Any
options that are not set will use the default values:

```toml
# compat_mode = "native" # or "gnu" for GNU ls compatibility
show_all = true
append_slash = true
dirs_first = true
Expand Down
34 changes: 33 additions & 1 deletion docs/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,33 @@ When `-I` is enabled, `lsp` checks the same ignore sources Git normally uses:
merged `.gitignore` files in the worktree, `.git/info/exclude`, and the
configured global Git excludes file.

## Compatibility Mode

`lsp` has two CLI modes:

- `native` - the default `lsplus` command-line interface
- `gnu` - a GNU `ls` compatibility mode intended for aliases and scripts

You can enable GNU compatibility mode by setting `compat_mode = "gnu"` in the
config file or by setting `LSP_COMPAT_MODE=gnu` in the environment. The
environment variable takes precedence over the config file.

At the moment, `gnu` mode changes the CLI surface and help output only. It does
not yet implement the missing GNU meanings for the conflicting short flags
`-D`, `-I`, `-N`, and `-Z`; those flags are reserved in `gnu` mode and will
error until their GNU behavior is implemented.

The current `lsplus` features behind those four native short flags are still
available in `gnu` mode through their long forms only:

- `--group-directories-first` (replaces the original `--sort-dirs`)
- `--gitignore`
- `--no-color`
- `--fuzzy-time`

In `gnu` mode, `-p` uses the GNU-style long form `--indicator-style=slash`
instead of the native `--slash-dirs`.

## Fuzzy Time

The `-Z` option will show a fuzzy time for file modification times. This will
Expand All @@ -64,6 +91,10 @@ The `lsp` command can be aliased to `ls` by adding the following line to your
alias ls='lsp'
```

If you want that alias to behave more like GNU `ls`, enable `gnu`
compatibility mode in your config file or set `LSP_COMPAT_MODE=gnu` in your
shell environment.

You will need to restart your shell or source your configuration file for the
alias to take effect.

Expand All @@ -80,6 +111,7 @@ You can also use the configuration file to set the default options you want.

![lsp output](./images/screenshot.png)

If you add the '-D' option to the command, directories will be sorted first:
If you add the `-D` option to the command (native mode only; use
`--group-directories-first` in gnu mode), directories will be sorted first:

![lsp output](./images/screenshot2.png)
14 changes: 13 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ use crate::settings;
use crate::utils;
use crate::utils::file::collect_file_info;

/// Run `lsplus` using parsed CLI flags and config loaded from disk.
pub fn run_with_flags(args: cli::Flags) -> io::Result<()> {
let config = settings::load_config();
let params = Params::merge(&args, &config);
run_with_flags_and_config(args, &config)
}

/// Run `lsplus` using parsed CLI flags and an explicit config value.
///
/// This is primarily useful in tests and library-style entry points that want
/// to inject config without relying on filesystem state.
pub fn run_with_flags_and_config(
args: cli::Flags,
config: &Params,
) -> io::Result<()> {
let params = Params::merge(&args, config);
utils::color::configure_color_output(&params);
let patterns = patterns_from_args(args.paths);

Expand Down
Loading