Merge pull request #48 from cole-h/exclude_dirs
Implement _ZO_EXCLUDE_DIRS
This commit is contained in:
commit
060f61eabe
|
|
@ -101,6 +101,9 @@ zoxide init fish | source
|
||||||
|
|
||||||
### Environment variables
|
### Environment variables
|
||||||
|
|
||||||
- `$_ZO_ECHO`: `z` will print the matched directory before navigating to it
|
|
||||||
- `$_ZO_DATA`: sets the location of the database (default: `~/.zo`)
|
- `$_ZO_DATA`: sets the location of the database (default: `~/.zo`)
|
||||||
|
- `$_ZO_ECHO`: `z` will print the matched directory before navigating to it
|
||||||
|
- `$_ZO_EXCLUDE_DIRS`: list of directories separated by platform-specific
|
||||||
|
characters (`:` on Linux and macOS, and `;` on Windows) to be excluded from
|
||||||
|
the database
|
||||||
- `$_ZO_MAXAGE`: sets the maximum total rank after which entries start getting deleted
|
- `$_ZO_MAXAGE`: sets the maximum total rank after which entries start getting deleted
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::types::Rank;
|
use crate::types::Rank;
|
||||||
|
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
@ -25,6 +26,13 @@ pub fn zo_data() -> Result<PathBuf> {
|
||||||
Ok(path)
|
Ok(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn zo_exclude_dirs() -> Vec<PathBuf> {
|
||||||
|
match env::var_os("_ZO_EXCLUDE_DIRS") {
|
||||||
|
Some(dirs_osstr) => env::split_paths(&dirs_osstr).collect(),
|
||||||
|
None => Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn zo_maxage() -> Result<Rank> {
|
pub fn zo_maxage() -> Result<Rank> {
|
||||||
match env::var_os("_ZO_MAXAGE") {
|
match env::var_os("_ZO_MAXAGE") {
|
||||||
Some(maxage_osstr) => match maxage_osstr.to_str() {
|
Some(maxage_osstr) => match maxage_osstr.to_str() {
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@ use crate::config;
|
||||||
use crate::util;
|
use crate::util;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use std::env;
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
#[structopt(about = "Add a new directory or increment its rank")]
|
#[structopt(about = "Add a new directory or increment its rank")]
|
||||||
pub struct Add {
|
pub struct Add {
|
||||||
path: Option<String>,
|
path: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Add {
|
impl Add {
|
||||||
|
|
@ -16,14 +18,17 @@ impl Add {
|
||||||
let mut db = util::get_db()?;
|
let mut db = util::get_db()?;
|
||||||
let now = util::get_current_time()?;
|
let now = util::get_current_time()?;
|
||||||
let maxage = config::zo_maxage()?;
|
let maxage = config::zo_maxage()?;
|
||||||
|
let excluded_dirs = config::zo_exclude_dirs();
|
||||||
|
|
||||||
match &self.path {
|
let path = match &self.path {
|
||||||
Some(path) => db.add(path, maxage, now),
|
Some(path) => path.clone(),
|
||||||
None => {
|
None => env::current_dir().context("unable to fetch current directory")?,
|
||||||
let current_dir =
|
};
|
||||||
env::current_dir().context("unable to fetch current directory")?;
|
|
||||||
db.add(current_dir, maxage, now)
|
if excluded_dirs.contains(&path) {
|
||||||
}
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db.add(path, maxage, now)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue