From 7d9ca0de43f3b77a82993ef6074aa3e436930b83 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Wed, 21 Apr 2021 01:18:12 +0530 Subject: [PATCH 1/2] Compile-time warning when git is missing (#187) --- build.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/build.rs b/build.rs index d9f3e37..04c6a5f 100644 --- a/build.rs +++ b/build.rs @@ -1,16 +1,50 @@ +use std::env; use std::process::Command; -fn main() { - let git_describe = Command::new("git") - .args(&["describe", "--tags", "--broken"]) - .output() - .ok() - .and_then(|proc| String::from_utf8(proc.stdout).ok()); +macro_rules! warn { + ($fmt:tt) => ({ + ::std::println!(::std::concat!("cargo:warning=", $fmt)); + }); + ($fmt:tt, $($arg:tt)*) => ({ + ::std::println!(::std::concat!("cargo:warning=", $fmt), $($arg)*); + }); +} - let version_info = match git_describe { - Some(description) if !description.is_empty() => description, - _ => format!("v{}", env!("CARGO_PKG_VERSION")), +fn git_version() -> Option { + let mut git = Command::new("git"); + git.args(&["describe", "--tags", "--broken"]); + + let output = match git.output() { + Err(e) => { + warn!("when retrieving version: git failed to start: {}", e); + return None; + } + Ok(output) if !output.status.success() => { + warn!( + "when retrieving version: git exited with code: {:?}", + output.status.code() + ); + return None; + } + Ok(output) => output, }; - println!("cargo:rustc-env=ZOXIDE_VERSION={}", version_info); + match String::from_utf8(output.stdout) { + Ok(version) => Some(version), + Err(e) => { + warn!("when retrieving version: git returned invalid utf-8: {}", e); + None + } + } +} + +fn crate_version() -> String { + warn!("falling back to crate version"); + // unwrap is safe here, since Cargo will always supply this variable. + format!("v{}", env::var("CARGO_PKG_VERSION").unwrap()) +} + +fn main() { + let version = git_version().unwrap_or_else(crate_version); + println!("cargo:rustc-env=ZOXIDE_VERSION={}", version); } From 0f5fde5afa9ec04fcc88b83ea028755701788d3c Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Tue, 27 Apr 2021 17:37:38 +0530 Subject: [PATCH 2/2] Add default prompt for nushell (#191) --- CHANGELOG.md | 1 + README.md | 28 ++++++++++++++-------------- man/zoxide-init.1 | 31 +++++++++++++------------------ templates/bash.txt | 3 +-- templates/elvish.txt | 4 ++-- templates/fish.txt | 4 ++-- templates/nushell.txt | 25 +++++++++++++++++-------- templates/posix.txt | 3 +-- templates/powershell.txt | 4 ++-- templates/xonsh.txt | 3 +-- templates/zsh.txt | 3 +-- 11 files changed, 55 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca13c6d..64b79aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Manpages for each subcommand. +- Default prompt for Nushell. ### Fixed diff --git a/README.md b/README.md index 9b1a518..6f4b224 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ zoxide import --from autojump path/to/db #### `bash` -Add the following line to your configuration file (usually `~/.bashrc`): +Add this to your configuration (usually `~/.bashrc`): ```sh eval "$(zoxide init bash)" @@ -115,7 +115,7 @@ eval "$(zoxide init bash)" #### `elvish` -Add the following line to your configuration file (usually `~/.elvish/rc.elv`): +Add this to your configuration (usually `~/.elvish/rc.elv`): ```sh eval $(zoxide init elvish | slurp) @@ -123,8 +123,7 @@ eval $(zoxide init elvish | slurp) #### `fish` -Add the following line to your configuration file (usually -`~/.config/fish/config.fish`): +Add this to your configuration (usually `~/.config/fish/config.fish`): ```fish zoxide init fish | source @@ -138,16 +137,18 @@ Initialize zoxide's Nushell script: zoxide init nushell --hook prompt | save ~/.zoxide.nu ``` -Then, in your Nushell configuration file: +Add this to your configuration (usually `~/.config/nu/config.toml`): -- Prepend `__zoxide_hook;` to the `prompt` variable. -- Add the following lines to the `startup` variable: - - `zoxide init nushell --hook prompt | save ~/.zoxide.nu` - - `source ~/.zoxide.nu` +```toml +prompt = "__zoxide_hook;__zoxide_prompt" +startup = ["zoxide init nushell --hook prompt | save ~/.zoxide.nu", "source ~/.zoxide.nu"] +``` + +You can replace `__zoxide_prompt` with a custom prompt. #### `powershell` -Add the following line to your profile: +Add this to your configuration (the location is stored in `$profile`): ```powershell Invoke-Expression (& { @@ -158,7 +159,7 @@ Invoke-Expression (& { #### `xonsh` -Add the following line to your configuration file (usually `~/.xonshrc`): +Add this to your configuration (usually `~/.xonshrc`): ```python execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide') @@ -166,7 +167,7 @@ execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide') #### `zsh` -Add the following line to your configuration file (usually `~/.zshrc`): +Add this to your configuration (usually `~/.zshrc`): ```sh eval "$(zoxide init zsh)" @@ -174,8 +175,7 @@ eval "$(zoxide init zsh)" #### Any POSIX shell -Add the following line to your configuration file (usually -`~/.config/nu/config.toml`): +Add this to your configuration: ```sh eval "$(zoxide init posix --hook prompt)" diff --git a/man/zoxide-init.1 b/man/zoxide-init.1 index 0625ba7..91ed1a6 100644 --- a/man/zoxide-init.1 +++ b/man/zoxide-init.1 @@ -7,49 +7,44 @@ zoxide-init - generate shell configuration for zoxide To initialize zoxide on your shell: .TP .B bash -Add the following line to your configuration file (usually \fI~/.bashrc\fR): +Add this to your configuration (usually \fI~/.bashrc\fR): .sp .nf \fBeval "$(zoxide init bash)"\fR .fi .TP .B elvish -Add the following line to your configuration file (usually -\fI~/.elvish/rc.elv\fR): +Add this to your configuration (usually \fI~/.elvish/rc.elv\fR): .sp .nf \fBeval $(zoxide init elvish | slurp)\fR .fi .TP .B fish -Add the following line to your configuration file (usually -\fI~/.config/fish/config.fish\fR): +Add this to your configuration (usually \fI~/.config/fish/config.fish\fR): .sp .nf \fBzoxide init fish | source\fR .fi .TP .B nushell -Initialize zoxide's Nushell script: +Create a Nushell script: .sp .nf \fBzoxide init nushell --hook prompt | save ~/.zoxide.nu\fR .fi .sp -Then, in your Nushell configuration file (usually -\fI~/.config/nu/config.toml\fR): -.sp -* Prepend \fB__zoxide_hook;\fR to the \fBprompt\fR variable. -.sp -* Add the following lines to the \fBstartup\fR variable: +Add this to your configuration (usually \fI~/.config/nu/config.toml\fR): .sp .nf - \fBzoxide init nushell --hook prompt | save ~/.zoxide.nu - source ~/.zoxide.nu\fR + \fBprompt = "__zoxide_hook;__zoxide_prompt"\fR + \fBstartup = ["zoxide init nushell --hook prompt | save ~/.zoxide.nu", "source ~/.zoxide.nu"]\fR .fi +.sp +You can replace \fB__zoxide_prompt\fR with a custom prompt. .TP .B powershell -Add the following line to your profile: +Add this to your configuration (the location is stored in \fI$profile\fR): .sp .nf \fBInvoke-Expression (& { @@ -59,14 +54,14 @@ Add the following line to your profile: .fi .TP .B xonsh -Add the following line to your configuration file (usually \fI~/.xonshrc\fR): +Add this to your configuration (usually \fI~/.xonshrc\fR): .sp .nf \fBexecx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide')\fR .fi .TP .B zsh -Add the following line to your configuration file (usually \fI~/.zshrc\fR): +Add this to your configuration (usually \fI~/.zshrc\fR): .sp .nf \fBeval "$(zoxide init zsh)"\fR @@ -74,7 +69,7 @@ Add the following line to your configuration file (usually \fI~/.zshrc\fR): .TP .B Any POSIX shell .sp -Add the following line to your configuration file: +Add this to your configuration: .sp .nf \fBeval "$(zoxide init posix --hook prompt)"\fR diff --git a/templates/bash.txt b/templates/bash.txt index 7909716..e2245f6 100644 --- a/templates/bash.txt +++ b/templates/bash.txt @@ -120,7 +120,6 @@ function {{cmd}}i() { {%- endmatch %} {{ section }} -# To initialize zoxide with bash, add the following line to your bash -# configuration file (usually ~/.bashrc): +# To initialize zoxide, add this to your configuration (usually ~/.bashrc): # # eval "$(zoxide init bash)" diff --git a/templates/elvish.txt b/templates/elvish.txt index b4d2999..68d2593 100644 --- a/templates/elvish.txt +++ b/templates/elvish.txt @@ -80,7 +80,7 @@ edit:add-var zi~ $__zoxide_zi~ {%- endmatch %} {{ section }} -# To initialize zoxide with xonsh, add the following line to your elvish -# configuration file (usually ~/.elvish/rc.elv): +# To initialize zoxide, add this to your configuration (usually +# ~/.elvish/rc.elv): # # eval $(zoxide init elvish | slurp) diff --git a/templates/fish.txt b/templates/fish.txt index c970983..b71b4ff 100644 --- a/templates/fish.txt +++ b/templates/fish.txt @@ -104,7 +104,7 @@ end {%- endmatch %} {{ section }} -# To initialize zoxide with fish, add the following line to your fish -# configuration file (usually ~/.config/fish/config.fish): +# To initialize zoxide, add this to your configuration (usually +# ~/.config/fish/config.fish): # # zoxide init fish | source diff --git a/templates/nushell.txt b/templates/nushell.txt index da786c5..d90b033 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -1,6 +1,16 @@ {%- let section = "# =============================================================================\n#" -%} {%- let not_configured = "# -- not configured --" -%} +{{ section }} +# Utility functions for zoxide. +# + +# Default prompt for Nushell. +# Taken from: +def __zoxide_prompt [] { + build-string $(ansi gb) $(pwd) $(ansi reset) '(' $(ansi cb) $(do -i { git rev-parse --abbrev-ref HEAD } | str trim) $(ansi reset) ')' $(ansi yb) $(date format '%m/%d/%Y %I:%M:%S%.3f %p') $(ansi reset) '> ' +} + {{ section }} # Hook configuration for zoxide. # @@ -79,14 +89,13 @@ alias {{cmd}}i = __zoxide_zi '' {%- endmatch %} {{ section }} -# To initialize zoxide with Nushell: -# -# Initialize zoxide's Nushell script: +# To initialize zoxide, first create a Nushell script: # # zoxide init nushell --hook prompt | save ~/.zoxide.nu # -# Then, in your Nushell configuration file: -# - Prepend `__zoxide_hook;` to the `prompt` variable. -# - Add the following lines to the `startup` variable: -# - `zoxide init nushell --hook prompt | save ~/.zoxide.nu` -# - `source ~/.zoxide.nu` +# Add this to your configuration (usually ~/.config/nu/config.toml): +# +# prompt = "__zoxide_hook;__zoxide_prompt" +# startup = ["zoxide init nushell --hook prompt | save ~/.zoxide.nu", "source ~/.zoxide.nu"] +# +# You can replace __zoxide_prompt with a custom prompt. diff --git a/templates/posix.txt b/templates/posix.txt index f5788bc..9088b6b 100644 --- a/templates/posix.txt +++ b/templates/posix.txt @@ -115,7 +115,6 @@ __zoxide_unset '{{cmd}}i' {%- endmatch %} {{ section }} -# To initialize zoxide with your POSIX shell, add the following line to your -# shell configuration file: +# To initialize zoxide, add this to your configuration: # # eval "$(zoxide init posix --hook prompt)" diff --git a/templates/powershell.txt b/templates/powershell.txt index 74762eb..6379587 100644 --- a/templates/powershell.txt +++ b/templates/powershell.txt @@ -101,7 +101,7 @@ Set-Alias {{cmd}}i __zoxide_zi {%- endmatch %} {{ section }} -# To initialize zoxide with powershell, add the following line to your -# powershell configuration file (the location is stored in $profile): +# To initialize zoxide, add this to your configuration (the location is stored +# in $profile): # # Invoke-Expression (& { $hook = if ($PSVersionTable.PSVersion.Major -ge 6) { 'pwd' } else { 'prompt' } (zoxide init powershell --hook $hook) -join "`n" }) diff --git a/templates/xonsh.txt b/templates/xonsh.txt index dd19f6d..07f4d2d 100644 --- a/templates/xonsh.txt +++ b/templates/xonsh.txt @@ -163,7 +163,6 @@ aliases["{{cmd}}i"] = __zoxide_zi {%- endmatch %} {{ section }} -# To initialize zoxide with xonsh, add the following line to your xonsh -# configuration file (usually ~/.xonshrc): +# To initialize zoxide, add this to your configuration (usually ~/.xonshrc): # # execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide') diff --git a/templates/zsh.txt b/templates/zsh.txt index 5d004b2..b95f733 100644 --- a/templates/zsh.txt +++ b/templates/zsh.txt @@ -105,7 +105,6 @@ function {{cmd}}i() { {%- endmatch %} {{ section }} -# To initialize zoxide with zsh, add the following line to your zsh -# configuration file (usually ~/.zshrc): +# To initialize zoxide, add this to your configuration (usually ~/.zshrc): # # eval "$(zoxide init zsh)"