diff --git a/CHANGELOG.md b/CHANGELOG.md index 64b79aa..33ceacb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Manpages for each subcommand. - Default prompt for Nushell. +### Changed + +- `$_ZO_EXCLUDE_DIRS` now defaults to `"$HOME"`. + ### Fixed - `cd -` on fish shells. diff --git a/README.md b/README.md index 691ecbd..8396814 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,7 @@ Be sure to set these before calling `zoxide init`. | ------------------- | --------- | ----------------------- | | Linux / macOS / BSD | `:` | `$HOME:$HOME/private/*` | | Windows | `;` | `$HOME;$HOME/private/*` | + - By default, this is set to `"$HOME"`. - `_ZO_FZF_OPTS` - Custom options to pass to [`fzf`][fzf]. See `man fzf` for the list of options. diff --git a/man/zoxide.1 b/man/zoxide.1 index b047754..5364ffe 100644 --- a/man/zoxide.1 +++ b/man/zoxide.1 @@ -84,8 +84,8 @@ T} Windows|\fI;\fR eg. $HOME;$HOME/private/* .TE .sp -After setting this up, you might need to use \fBzoxide-remove\fR(1) to remove -any existing entries from the database. +By default, this is set to \fI"$HOME"\fR. After setting this up, you might need +to use \fBzoxide-remove\fR(1) to remove any existing entries from the database. .TP .B _ZO_FZF_OPTS Custom options to pass to fzf. See \fBman fzf\fR for the list of options. diff --git a/src/config.rs b/src/config.rs index 690d549..d471891 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,6 +2,7 @@ use crate::db::Rank; use anyhow::{bail, Context, Result}; use dirs_next as dirs; +use glob::Pattern; use std::env; use std::ffi::OsString; @@ -29,18 +30,27 @@ pub fn zo_echo() -> bool { } } -pub fn zo_exclude_dirs() -> Result> { +pub fn zo_exclude_dirs() -> Result> { match env::var_os("_ZO_EXCLUDE_DIRS") { Some(dirs_osstr) => env::split_paths(&dirs_osstr) .map(|path| { let pattern = path .to_str() .context("invalid unicode in _ZO_EXCLUDE_DIRS")?; - glob::Pattern::new(&pattern) + Pattern::new(&pattern) .with_context(|| format!("invalid glob in _ZO_EXCLUDE_DIRS: {}", pattern)) }) .collect(), - None => Ok(Vec::new()), + None => { + let pattern = (|| { + let home = dirs::home_dir()?; + let home_str = home.to_str()?; + let home_esc = Pattern::escape(home_str); + Pattern::new(&home_esc).ok() + })(); + + Ok(pattern.into_iter().collect()) + } } }