From c9b75fe115075c23eb456df5b1af8f4491834aaf Mon Sep 17 00:00:00 2001 From: David Knaack Date: Thu, 24 Mar 2022 20:06:24 +0100 Subject: [PATCH] fix(init): Change Nushell init for nu 0.60 (#3773) --- .github/ISSUE_TEMPLATE/Bug_report.md | 4 ++-- Cargo.lock | 12 +----------- Cargo.toml | 2 +- README.md | 21 +++++++++++++-------- docs/README.md | 23 ++++++++++++----------- docs/config/README.md | 10 ---------- install/install.sh | 18 ++++++++---------- src/bug_report.rs | 5 ++--- src/init/starship.nu | 15 ++++++++++++--- src/utils.rs | 2 +- 10 files changed, 52 insertions(+), 60 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md index def3c3020..eff1bff60 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -41,7 +41,7 @@ assignees: '' - Operating system: [e.g. macOS 10.13.4, Windows 10] #### Relevant Shell Configuration - diff --git a/Cargo.lock b/Cargo.lock index 6071b8ecb..d31d61e7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -437,16 +437,6 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "directories-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" -dependencies = [ - "cfg-if", - "dirs-sys-next", -] - [[package]] name = "dirs-next" version = "2.0.0" @@ -1564,7 +1554,7 @@ dependencies = [ "chrono", "clap", "clap_complete", - "directories-next", + "dirs-next", "dunce", "gethostname", "git2", diff --git a/Cargo.toml b/Cargo.toml index 0c5e413f2..6e92e4118 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ byte-unit = "4.0.14" chrono = "0.4.19" clap = { version = "3.1.6", features = ["derive", "cargo", "unicode"] } clap_complete = "3.1.1" -directories-next = "2.0.0" +dirs-next = "2.0.0" dunce = "1.0.2" gethostname = "0.2.3" git2 = { version = "0.14.2", default-features = false } diff --git a/README.md b/README.md index d81944c9d..5361bcf45 100644 --- a/README.md +++ b/README.md @@ -327,17 +327,22 @@ eval $(starship init ion)
Nushell -Add the following to the end of your Nushell configuration (find it by running `config path`): +Run the following: -```toml -startup = [ - "mkdir ~/.cache/starship", - "starship init nu | save ~/.cache/starship/init.nu", - "source ~/.cache/starship/init.nu", -] -prompt = "starship_prompt" +```sh +mkdir ~/.cache/starship +starship init nu | save ~/.cache/starship/init.nu ``` +And add the following to the end of your Nushell configuration (find it by running `$nu.config-path`): + +```sh +starship init nu | save ~/.cache/starship/init.nu +source ~/.cache/starship/init.nu +``` + +Note: Only Nushell v0.60+ is supported +
diff --git a/docs/README.md b/docs/README.md index dd16c17ad..e519436f6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -136,20 +136,21 @@ description: Starship is the minimal, blazing fast, and extremely customizable p ::: warning This will change in the future. - Only nu version v0.33 or higher is supported. + Only Nushell v0.60+ is supported. ::: - Add the following to your nu config file. You can check the location of this - file by running `config path` in nu. - - ```toml - startup = [ - "mkdir ~/.cache/starship", - "starship init nu | save ~/.cache/starship/init.nu", - "source ~/.cache/starship/init.nu", - ] - prompt = "starship_prompt" + Run the following: + ```sh + mkdir ~/.cache/starship + starship init nu | save ~/.cache/starship/init.nu ``` + And add the following to the end of your Nushell configuration (find it by running `$nu.config-path`): + + ```sh + mkdir ~/.cache/starship + starship init nu | save ~/.cache/starship/init.nu + source ~/.cache/starship/init.nu + ``` #### Xonsh Add the following to the end of `~/.xonshrc`: diff --git a/docs/config/README.md b/docs/config/README.md index c67dc6816..edcdae043 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -512,12 +512,6 @@ look at [this example](#with-custom-error-shape). ::: warning -`error_symbol` is not supported on nu shell. - -::: - -::: warning - `vicmd_symbol` is only supported in cmd, fish and zsh. ::: @@ -3129,10 +3123,6 @@ To enable it, set `disabled` to `false` in your configuration file. ::: -::: warning -This module is not supported on nu shell. -::: - ### Options | Option | Default | Description | diff --git a/install/install.sh b/install/install.sh index 1b5a211a9..7fa235467 100755 --- a/install/install.sh +++ b/install/install.sh @@ -297,7 +297,7 @@ print_install() { # we don't want these '~' expanding config_file="~/.${s}rc" config_cmd="eval \"\$(starship init ${s})\"" - + case ${s} in ion ) # shellcheck disable=SC2088 @@ -336,16 +336,14 @@ print_install() { ;; nushell ) # shellcheck disable=SC2088 - config_file="your nu config file." - config_cmd="startup = [ - \"mkdir ~/.cache/starship\", - \"starship init nu | save ~/.cache/starship/init.nu\", - \"source ~/.cache/starship/init.nu\" - ] - prompt = \"starship_prompt\"" + config_file="your nu config file" + config_cmd="mkdir ~/.cache/starship + starship init nu | save ~/.cache/starship/init.nu + source ~/.cache/starship/init.nu" warning="${warning} This will change in the future. - Only nu version v0.33 or higher is supported. - You can check the location of this your config file by running config path in nu" + Only Nushell v0.60 or higher is supported. + You can check the location of this your config file by running \$nu.config-path in nu. + ${BOLD}First run${NO_COLOR} \"mkdir ~/.cache/starship; starship init nu | save ~/.cache/starship/init.nu\"" ;; esac printf " %s\n %s\n Add the following to the end of %s:\n\n\t%s\n\n" \ diff --git a/src/bug_report.rs b/src/bug_report.rs index c2ed9a127..9a89eb6ec 100644 --- a/src/bug_report.rs +++ b/src/bug_report.rs @@ -1,7 +1,6 @@ use crate::shadow; use crate::utils::{self, exec_cmd}; -use directories_next::ProjectDirs; use std::fs; use std::path::PathBuf; use std::time::Duration; @@ -181,8 +180,8 @@ fn get_terminal_info() -> TerminalInfo { fn get_config_path(shell: &str) -> Option { if shell == "nu" { - return ProjectDirs::from("org", "nushell", "nu") - .map(|project_dirs| project_dirs.config_dir().join("config.toml")); + return dirs_next::config_dir() + .map(|config_dir| config_dir.join("nushell").join("config.nu")); } utils::home_dir().and_then(|home_dir| { diff --git a/src/init/starship.nu b/src/init/starship.nu index b7fb93a36..f31729142 100644 --- a/src/init/starship.nu +++ b/src/init/starship.nu @@ -1,8 +1,17 @@ let-env STARSHIP_SHELL = "nu" let-env STARSHIP_SESSION_KEY = (random chars -l 16) +let-env PROMPT_MULTILINE_INDICATOR = (^::STARSHIP:: prompt --continuation) -def starship_prompt [] { +# Does not play well with default character module. +# TODO: Also Use starship vi mode indicators? +let-env PROMPT_INDICATOR = "" + +let-env PROMPT_COMMAND = { # jobs are not supported - # status is not supported - ^::STARSHIP:: prompt --cmd-duration $nu.env.CMD_DURATION_MS + ^::STARSHIP:: prompt --cmd-duration $env.CMD_DURATION_MS --status $env.LAST_EXIT_CODE } + +# Not well-suited for `starship prompt --right`. +# Built-in right prompt is equivalent to $fill$right_format in the first prompt line. +# Thus does not play well with default `add_newline = True`. +let-env PROMPT_COMMAND_RIGHT = {''} diff --git a/src/utils.rs b/src/utils.rs index db78172ce..b6820124d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -516,7 +516,7 @@ fn render_time_component((component, suffix): (&u128, &&str)) -> String { } pub fn home_dir() -> Option { - directories_next::BaseDirs::new().map(|base_dirs| base_dirs.home_dir().to_owned()) + dirs_next::home_dir() } const HEXTABLE: &[char] = &[