Skip to content
Open
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
16 changes: 16 additions & 0 deletions contrib/completions/_zoxide

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions contrib/completions/_zoxide.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion contrib/completions/zoxide.bash

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions contrib/completions/zoxide.elv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions contrib/completions/zoxide.fish

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions contrib/completions/zoxide.nu

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions contrib/completions/zoxide.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/cmd/bookmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use anyhow::Result;

use super::{Bookmark, Run};
use crate::db::Database;

impl Run for Bookmark {
fn run(&self) -> Result<()> {
let mut db = crate::db::Database::open()?;
self.add_bookmark(&mut db).and(db.save())
}
}

impl Bookmark {
fn add_bookmark(&self, db: &mut Database) -> Result<()> {
db.add_bookmark(self.bookmark_id.clone(), self.path.clone());
Ok(())
}
}
9 changes: 9 additions & 0 deletions src/cmd/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub enum Cmd {
Init(Init),
Query(Query),
Remove(Remove),
Bookmark(Bookmark),
}

/// Add a new directory or increment its rank
Expand Down Expand Up @@ -202,3 +203,11 @@ pub struct Remove {
#[clap(value_hint = ValueHint::DirPath)]
pub paths: Vec<String>,
}

#[derive(Debug, Parser)]
#[clap(author, help_template = HelpTemplate)]
pub struct Bookmark {
pub bookmark_id: String,
#[clap(value_hint = ValueHint::DirPath)]
pub path: PathBuf,
}
2 changes: 2 additions & 0 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod add;
mod bookmark;
mod cmd;
mod edit;
mod import;
Expand All @@ -23,6 +24,7 @@ impl Run for Cmd {
Cmd::Init(cmd) => cmd.run(),
Cmd::Query(cmd) => cmd.run(),
Cmd::Remove(cmd) => cmd.run(),
Cmd::Bookmark(cmd) => cmd.run(),
}
}
}
22 changes: 22 additions & 0 deletions src/cmd/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ impl Run for Query {
impl Query {
fn query(&self, db: &mut Database) -> Result<()> {
let now = util::current_time()?;

if let Ok(is_mark) = self.try_bookmark(db) {
if is_mark {
return Ok(());
}
}

let mut stream = self.get_stream(db, now)?;

if self.interactive {
Expand All @@ -28,7 +35,22 @@ impl Query {
self.query_first(&mut stream, now)
}
}
fn try_bookmark(&self, db: &Database) -> Result<bool, ()> {
// NOTE We only assume bookmarking if they supply one keyword
// Could be trivially changed to iterate over keywords
if self.keywords.len() == 1 {
let keyword = &self.keywords[0];
if let Some(path) = db.get_bookmark(keyword) {
let handle = &mut io::stdout();
return match writeln!(handle, "{}", path.to_str().unwrap()).pipe_exit("stdout") {
Ok(_) => Ok(true),
Err(_) => Err(()),
};
}
}

Ok(false)
}
fn query_interactive(&self, stream: &mut Stream, now: Epoch) -> Result<()> {
let mut fzf = Self::get_fzf()?;
let selection = loop {
Expand Down
Loading
Loading