fixup! Add POSIX shell support

This commit is contained in:
Cole Helbling 2020-03-29 14:05:21 -07:00
parent ab0b558c21
commit 2a890aee27
No known key found for this signature in database
GPG Key ID: B37E0F2371016A4C
2 changed files with 14 additions and 8 deletions

View File

@ -27,7 +27,7 @@ pub fn main() -> Result<()> {
match opt { match opt {
Zoxide::Add(add) => add.run(&env)?, Zoxide::Add(add) => add.run(&env)?,
Zoxide::Init(init) => init.run(), Zoxide::Init(init) => init.run()?,
Zoxide::Migrate(migrate) => migrate.run(&env)?, Zoxide::Migrate(migrate) => migrate.run(&env)?,
Zoxide::Query(query) => query.run(&env)?, Zoxide::Query(query) => query.run(&env)?,
Zoxide::Remove(remove) => remove.run(&env)?, Zoxide::Remove(remove) => remove.run(&env)?,

View File

@ -1,7 +1,9 @@
use anyhow::{bail, Result};
use clap::arg_enum; use clap::arg_enum;
use std::io::{self, Write};
use structopt::StructOpt; use structopt::StructOpt;
use std::io::{self, Write};
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
#[structopt(about = "Generates shell configuration")] #[structopt(about = "Generates shell configuration")]
pub struct Init { pub struct Init {
@ -25,7 +27,7 @@ pub struct Init {
} }
impl Init { impl Init {
pub fn run(&self) { pub fn run(&self) -> Result<()> {
let config = match self.shell { let config = match self.shell {
Shell::bash => BASH_CONFIG, Shell::bash => BASH_CONFIG,
Shell::fish => FISH_CONFIG, Shell::fish => FISH_CONFIG,
@ -36,20 +38,24 @@ impl Init {
let stdout = io::stdout(); let stdout = io::stdout();
let mut handle = stdout.lock(); let mut handle = stdout.lock();
writeln!(handle, "{}", config.z).unwrap(); writeln!(handle, "{}", config.z)?;
if !self.no_define_aliases { if !self.no_define_aliases {
writeln!(handle, "{}", config.alias).unwrap(); writeln!(handle, "{}", config.alias)?;
} }
match self.hook { match self.hook {
Hook::none => (), Hook::none => (),
Hook::prompt => writeln!(handle, "{}", config.hook.prompt).unwrap(), Hook::prompt => writeln!(handle, "{}", config.hook.prompt)?,
Hook::pwd => { Hook::pwd => {
if let Some(pwd_hook) = config.hook.pwd { if let Some(pwd_hook) = config.hook.pwd {
writeln!(handle, "{}", pwd_hook).unwrap(); writeln!(handle, "{}", pwd_hook)?;
} else {
bail!("PWD hooks are currently unsupported on this shell.");
} }
} }
}; }
Ok(())
} }
} }