mirror of
https://github.com/Llewellynvdm/zoxide.git
synced 2024-11-10 23:30:57 +00:00
Don't show error if fzf exits gracefully
This commit is contained in:
parent
2f73465d8d
commit
b21dbefa22
12
src/error.rs
Normal file
12
src/error.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SilentExit {
|
||||
pub code: i32,
|
||||
}
|
||||
|
||||
impl Display for SilentExit {
|
||||
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
22
src/main.rs
22
src/main.rs
@ -1,12 +1,17 @@
|
||||
mod config;
|
||||
mod db;
|
||||
mod dir;
|
||||
mod error;
|
||||
mod subcommand;
|
||||
mod util;
|
||||
|
||||
use crate::error::SilentExit;
|
||||
|
||||
use anyhow::Result;
|
||||
use structopt::StructOpt;
|
||||
|
||||
use std::process;
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(about = "A cd command that learns your habits", version = env!("ZOXIDE_VERSION"))]
|
||||
enum Zoxide {
|
||||
@ -20,13 +25,16 @@ enum Zoxide {
|
||||
pub fn main() -> Result<()> {
|
||||
let opt = Zoxide::from_args();
|
||||
|
||||
match opt {
|
||||
Zoxide::Add(add) => add.run()?,
|
||||
Zoxide::Import(import) => import.run()?,
|
||||
Zoxide::Init(init) => init.run()?,
|
||||
Zoxide::Query(query) => query.run()?,
|
||||
Zoxide::Remove(remove) => remove.run()?,
|
||||
let res = match opt {
|
||||
Zoxide::Add(add) => add.run(),
|
||||
Zoxide::Import(import) => import.run(),
|
||||
Zoxide::Init(init) => init.run(),
|
||||
Zoxide::Query(query) => query.run(),
|
||||
Zoxide::Remove(remove) => remove.run(),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
res.map_err(|e| match e.downcast::<SilentExit>() {
|
||||
Ok(SilentExit { code }) => process::exit(code),
|
||||
Err(e) => e,
|
||||
})
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
use crate::config;
|
||||
use crate::db::DB;
|
||||
use crate::dir::{Dir, Epoch};
|
||||
use crate::error::SilentExit;
|
||||
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
|
||||
@ -109,6 +110,7 @@ where
|
||||
Some(2) => bail!("fzf returned an error"),
|
||||
|
||||
// terminated by a signal
|
||||
Some(code @ 130) => bail!(SilentExit { code }),
|
||||
Some(128..=254) | None => bail!("fzf was terminated"),
|
||||
|
||||
// unknown
|
||||
|
Loading…
Reference in New Issue
Block a user