diff --git a/docs/src/setup.md b/docs/src/setup.md index f4cd2ac..cf3600f 100644 --- a/docs/src/setup.md +++ b/docs/src/setup.md @@ -89,3 +89,22 @@ Default: `y` Configure this to disable lacy's built in UI selector and replace it with your own command. (e.g. `--custom-fuzzy=fzf`) Default: *none* + +## Environment variables + +### `$LACY_NO_ARGS_PATH` + +Controls where you will jump if you use the lacy command without extra arguments. + +Default: `~` + +### `$LACY_FILTER_CWD` + +Controls whether current directory (or its parents) would be ignored when matching. + +For example, say you're in `~/git`, you also have `~/Games`, and you use `y .. g`. +- `0` would prompt you to choose between `~/git` and `~/Games`. +- `1` would just jump to `Games`. +- `2` would exclude `git` even if you were in `~/git/lacy` and used `y ... g`. + +Default: `1` diff --git a/src/query.rs b/src/query.rs index 1620afe..8271b44 100644 --- a/src/query.rs +++ b/src/query.rs @@ -1,4 +1,7 @@ -use std::path::{Path, PathBuf}; +use std::{ + env, fs, + path::{Path, PathBuf}, +}; use crate::{ directory::{sub_directories, Directory}, @@ -58,6 +61,16 @@ impl Query { directories = part.matching_directories(&directories); } + // https://lacy.tiimo.space/setup.html#LACY_FILTER_CWD + match env::var("LACY_FILTER_CWD").as_deref() { + Ok("0") => (), + Ok("2") => directories.retain(|dir| { + !fs::canonicalize(dir.location()).is_ok_and(|dir| cwd.starts_with(dir)) + }), + Ok("1") | Ok(_) | Err(_) => directories + .retain(|dir| !fs::canonicalize(dir.location()).is_ok_and(|dir| dir == cwd)), + } + directories .iter() .map(|dir| dir.location().clone())