Clobber conflicting definitions in shells
This commit is contained in:
parent
c0a1a78c29
commit
bc17c25cf6
|
@ -15,6 +15,7 @@ jobs:
|
|||
- run: sudo apt update
|
||||
- run: sudo add-apt-repository universe
|
||||
- run: sudo apt install bash dash fish powershell shellcheck xonsh zsh
|
||||
- run: sudo snap install shfmt
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
|
|
|
@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- `zoxide init --no-aliases` no longer generates `z` or `zi`.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Clobber conflicting alias definitions in Bash/POSIX/Zsh shells.
|
||||
|
||||
### Removed
|
||||
|
||||
- Deprecated PWD hooks for POSIX shells.
|
||||
|
|
|
@ -31,6 +31,10 @@ pub struct Opts<'a> {
|
|||
pub resolve_symlinks: bool,
|
||||
}
|
||||
|
||||
impl Opts<'_> {
|
||||
pub const DEVNULL: &'static str = if cfg!(windows) { "NUL" } else { "/dev/null" };
|
||||
}
|
||||
|
||||
#[derive(Debug, Template)]
|
||||
#[template(path = "bash.txt")]
|
||||
pub struct Bash<'a>(pub &'a Opts<'a>);
|
||||
|
|
|
@ -119,16 +119,48 @@ function __zoxide_zri() {
|
|||
{%- match cmd %}
|
||||
{%- when Some with (cmd) %}
|
||||
|
||||
alias {{cmd}}='__zoxide_z'
|
||||
alias {{cmd}}i='__zoxide_zi'
|
||||
# Remove definitions.
|
||||
function __zoxide_unset() {
|
||||
# shellcheck disable=SC1001
|
||||
\unset -f "$@" &>{{ Opts::DEVNULL }}
|
||||
# shellcheck disable=SC1001
|
||||
\unset -v "$@" &>{{ Opts::DEVNULL }}
|
||||
}
|
||||
|
||||
alias {{cmd}}a='__zoxide_za'
|
||||
__zoxide_unset '{{cmd}}'
|
||||
function {{cmd}}() {
|
||||
__zoxide_z "$@"
|
||||
}
|
||||
|
||||
alias {{cmd}}q='__zoxide_zq'
|
||||
alias {{cmd}}qi='__zoxide_zqi'
|
||||
__zoxide_unset '{{cmd}}i'
|
||||
function {{cmd}}i() {
|
||||
__zoxide_zi "$@"
|
||||
}
|
||||
|
||||
alias {{cmd}}r='__zoxide_zr'
|
||||
alias {{cmd}}ri='__zoxide_zri'
|
||||
__zoxide_unset '{{cmd}}a'
|
||||
function {{cmd}}a() {
|
||||
__zoxide_za "$@"
|
||||
}
|
||||
|
||||
__zoxide_unset '{{cmd}}q'
|
||||
function {{cmd}}q() {
|
||||
__zoxide_zq "$@"
|
||||
}
|
||||
|
||||
__zoxide_unset '{{cmd}}qi'
|
||||
function {{cmd}}qi() {
|
||||
__zoxide_zqi "$@"
|
||||
}
|
||||
|
||||
__zoxide_unset '{{cmd}}r'
|
||||
function {{cmd}}r() {
|
||||
__zoxide_zr "$@"
|
||||
}
|
||||
|
||||
__zoxide_unset '{{cmd}}ri'
|
||||
function {{cmd}}ri() {
|
||||
__zoxide_zri "$@"
|
||||
}
|
||||
|
||||
{%- when None %}
|
||||
{{ NOT_CONFIGURED }}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
# Utility functions for zoxide.
|
||||
#
|
||||
|
||||
# Remove definitions.
|
||||
|
||||
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
|
||||
function __zoxide_pwd
|
||||
{%- if resolve_symlinks %}
|
||||
|
@ -99,30 +101,44 @@ end
|
|||
{%- match cmd %}
|
||||
{%- when Some with (cmd) %}
|
||||
|
||||
# Remove definitions.
|
||||
function __zoxide_unset
|
||||
set --erase $argv > {{ Opts::DEVNULL }} 2>&1
|
||||
abbr --erase $argv > {{ Opts::DEVNULL }} 2>&1
|
||||
functions --erase $argv > {{ Opts::DEVNULL }} 2>&1
|
||||
end
|
||||
|
||||
__zoxide_unset '{{cmd}}'
|
||||
function {{cmd}}
|
||||
__zoxide_z $argv
|
||||
end
|
||||
|
||||
__zoxide_unset '{{cmd}}i'
|
||||
function {{cmd}}i
|
||||
__zoxide_zi $argv
|
||||
end
|
||||
|
||||
__zoxide_unset '{{cmd}}a'
|
||||
function {{cmd}}a
|
||||
__zoxide_za $argv
|
||||
end
|
||||
|
||||
__zoxide_unset '{{cmd}}q'
|
||||
function {{cmd}}q
|
||||
__zoxide_zq $argv
|
||||
end
|
||||
|
||||
__zoxide_unset '{{cmd}}qi'
|
||||
function {{cmd}}qi
|
||||
__zoxide_zqi $argv
|
||||
end
|
||||
|
||||
__zoxide_unset '{{cmd}}r'
|
||||
function {{cmd}}r
|
||||
__zoxide_zr $argv
|
||||
end
|
||||
|
||||
__zoxide_unset '{{cmd}}ri'
|
||||
function {{cmd}}ri
|
||||
__zoxide_zri $argv
|
||||
end
|
||||
|
|
|
@ -119,16 +119,48 @@ __zoxide_zri() {
|
|||
{%- match cmd %}
|
||||
{%- when Some with (cmd) %}
|
||||
|
||||
alias {{cmd}}='__zoxide_z'
|
||||
alias {{cmd}}i='__zoxide_zi'
|
||||
# Remove definitions.
|
||||
__zoxide_unset() {
|
||||
# shellcheck disable=SC1001
|
||||
\unset -f "$@" >{{ Opts::DEVNULL }} 2>&1
|
||||
# shellcheck disable=SC1001
|
||||
\unset -v "$@" >{{ Opts::DEVNULL }} 2>&1
|
||||
}
|
||||
|
||||
alias {{cmd}}a='__zoxide_za'
|
||||
__zoxide_unset '{{cmd}}'
|
||||
{{cmd}}() {
|
||||
__zoxide_z "$@"
|
||||
}
|
||||
|
||||
alias {{cmd}}q='__zoxide_zq'
|
||||
alias {{cmd}}qi='__zoxide_zqi'
|
||||
__zoxide_unset '{{cmd}}i'
|
||||
{{cmd}}i() {
|
||||
__zoxide_zi "$@"
|
||||
}
|
||||
|
||||
alias {{cmd}}r='__zoxide_zr'
|
||||
alias {{cmd}}ri='__zoxide_zri'
|
||||
__zoxide_unset '{{cmd}}a'
|
||||
{{cmd}}a() {
|
||||
__zoxide_za "$@"
|
||||
}
|
||||
|
||||
__zoxide_unset '{{cmd}}q'
|
||||
{{cmd}}q() {
|
||||
__zoxide_zq "$@"
|
||||
}
|
||||
|
||||
__zoxide_unset '{{cmd}}qi'
|
||||
{{cmd}}qi() {
|
||||
__zoxide_zqi "$@"
|
||||
}
|
||||
|
||||
__zoxide_unset '{{cmd}}r'
|
||||
{{cmd}}r() {
|
||||
__zoxide_zr "$@"
|
||||
}
|
||||
|
||||
__zoxide_unset '{{cmd}}ri'
|
||||
{{cmd}}ri() {
|
||||
__zoxide_zri "$@"
|
||||
}
|
||||
|
||||
{%- when None %}
|
||||
{{ NOT_CONFIGURED }}
|
||||
|
|
|
@ -106,16 +106,47 @@ function __zoxide_zri() {
|
|||
{%- match cmd %}
|
||||
{%- when Some with (cmd) %}
|
||||
|
||||
alias {{cmd}}='__zoxide_z'
|
||||
alias {{cmd}}i='__zoxide_zi'
|
||||
# Remove definitions.
|
||||
function __zoxide_unset() {
|
||||
\unalias "$@" &>{{ Opts::DEVNULL }}
|
||||
\unfunction "$@" &>{{ Opts::DEVNULL }}
|
||||
\unset "$@" &>{{ Opts::DEVNULL }}
|
||||
}
|
||||
|
||||
alias {{cmd}}a='__zoxide_za'
|
||||
__zoxide_unset '{{cmd}}'
|
||||
function {{cmd}}() {
|
||||
__zoxide_z "$@"
|
||||
}
|
||||
|
||||
alias {{cmd}}q='__zoxide_zq'
|
||||
alias {{cmd}}qi='__zoxide_zqi'
|
||||
__zoxide_unset '{{cmd}}i'
|
||||
function {{cmd}}i() {
|
||||
__zoxide_zi "$@"
|
||||
}
|
||||
|
||||
alias {{cmd}}r='__zoxide_zr'
|
||||
alias {{cmd}}ri='__zoxide_zri'
|
||||
__zoxide_unset '{{cmd}}a'
|
||||
function {{cmd}}a() {
|
||||
__zoxide_za "$@"
|
||||
}
|
||||
|
||||
__zoxide_unset '{{cmd}}q'
|
||||
function {{cmd}}q() {
|
||||
__zoxide_zq "$@"
|
||||
}
|
||||
|
||||
__zoxide_unset '{{cmd}}qi'
|
||||
function {{cmd}}qi() {
|
||||
__zoxide_zqi "$@"
|
||||
}
|
||||
|
||||
__zoxide_unset '{{cmd}}r'
|
||||
function {{cmd}}r() {
|
||||
__zoxide_zr "$@"
|
||||
}
|
||||
|
||||
__zoxide_unset '{{cmd}}ri'
|
||||
function {{cmd}}ri() {
|
||||
__zoxide_zri "$@"
|
||||
}
|
||||
|
||||
{%- when None %}
|
||||
{{ NOT_CONFIGURED }}
|
||||
|
|
|
@ -124,6 +124,36 @@ fn test_shellcheck_sh() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shfmt_bash() {
|
||||
for opts in opts() {
|
||||
let source = crate::Bash(opts).render().unwrap();
|
||||
Command::new("shfmt")
|
||||
.args(&["-d", "-s", "-ln", "bash", "-i", "4", "-ci", "-"])
|
||||
.write_stdin(source.as_bytes())
|
||||
.write_stdin(b"\n".as_ref())
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("")
|
||||
.stderr("");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shfmt_posix() {
|
||||
for opts in opts() {
|
||||
let source = crate::Posix(opts).render().unwrap();
|
||||
Command::new("shfmt")
|
||||
.args(&["-d", "-s", "-ln", "posix", "-i", "4", "-ci", "-"])
|
||||
.write_stdin(source.as_bytes())
|
||||
.write_stdin(b"\n".as_ref())
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("")
|
||||
.stderr("");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_xonsh() {
|
||||
for opts in opts() {
|
||||
|
|
|
@ -20,9 +20,10 @@ fn env_help() -> &'static str {
|
|||
format!(
|
||||
"\
|
||||
ENVIRONMENT VARIABLES:
|
||||
_ZO_DATA_DIR Path for zoxide data files (current: `{data_dir}`)
|
||||
_ZO_DATA_DIR Path for zoxide data files
|
||||
[current: {data_dir}]
|
||||
_ZO_ECHO Prints the matched directory before navigating to it when set to 1
|
||||
_ZO_EXCLUDE_DIRS List of directories to be excluded, separated by `{split_paths_separator}`
|
||||
_ZO_EXCLUDE_DIRS List of directory globs to be excluded, separated by '{split_paths_separator}'
|
||||
_ZO_FZF_OPTS Custom flags to pass to fzf
|
||||
_ZO_MAXAGE Maximum total age after which entries start getting deleted
|
||||
_ZO_RESOLVE_SYMLINKS Resolve symlinks when storing paths",
|
||||
|
@ -37,7 +38,6 @@ ENVIRONMENT VARIABLES:
|
|||
#[clap(
|
||||
about,
|
||||
author,
|
||||
global_setting(AppSettings::ColoredHelp),
|
||||
global_setting(AppSettings::GlobalVersion),
|
||||
global_setting(AppSettings::VersionlessSubcommands),
|
||||
version = env!("ZOXIDE_VERSION"))]
|
||||
|
|
Loading…
Reference in New Issue