Rename --z-cmd flag to --cmd

This commit is contained in:
Ajeet D'Souza 2020-05-03 15:15:40 +05:30
parent f19aa07145
commit e0572a4569
4 changed files with 11 additions and 8 deletions

View File

@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Canonicalize to regular paths instead of UNC paths on Windows. - Canonicalize to regular paths instead of UNC paths on Windows.
- `zoxide init` now uses PWD hooks by default for better performance. - `zoxide init` now uses PWD hooks by default for better performance.
- `$_ZO_ECHO` now only works when set to `1`. - `$_ZO_ECHO` now only works when set to `1`.
- Using the `--z-cmd` flag now also renames the associated aliases.
- The `--z-cmd` flag has been renamed to `--cmd`.
### Fixed ### Fixed

View File

@ -15,9 +15,10 @@ pub struct Init {
#[structopt( #[structopt(
long, long,
help = "Changes the name of the 'z' command", help = "Changes the name of the 'z' command",
alias = "z-cmd",
default_value = "z" default_value = "z"
)] )]
z_cmd: String, cmd: String,
#[structopt( #[structopt(
long, long,
@ -48,11 +49,11 @@ impl Init {
let mut handle = stdout.lock(); let mut handle = stdout.lock();
let z = config.z; let z = config.z;
writeln!(handle, "{}", z(&self.z_cmd)).unwrap(); writeln!(handle, "{}", z(&self.cmd)).unwrap();
if !self.no_define_aliases { if !self.no_define_aliases {
let alias = config.alias; let alias = config.alias;
writeln!(handle, "{}", alias(&self.z_cmd)).unwrap(); writeln!(handle, "{}", alias(&self.cmd)).unwrap();
} }
match self.hook { match self.hook {

View File

@ -1,4 +1,4 @@
use super::{ShellConfig, HookConfig}; use super::{HookConfig, ShellConfig};
use anyhow::Result; use anyhow::Result;

View File

@ -14,7 +14,7 @@ pub const CONFIG: ShellConfig = ShellConfig {
}, },
}; };
fn z(z_cmd: &str) -> String { fn z(cmd: &str) -> String {
format!( format!(
r#" r#"
_z_cd() {{ _z_cd() {{
@ -45,11 +45,11 @@ _z_cd() {{
fi fi
}} }}
"#, "#,
z_cmd cmd
) )
} }
fn alias(z_cmd: &str) -> String { fn alias(cmd: &str) -> String {
format!( format!(
r#" r#"
alias {0}i='{0} -i' alias {0}i='{0} -i'
@ -62,7 +62,7 @@ alias {0}qi='zoxide query -i'
alias {0}r='zoxide remove' alias {0}r='zoxide remove'
alias {0}ri='zoxide remove -i' alias {0}ri='zoxide remove -i'
"#, "#,
z_cmd cmd
) )
} }