fix(init): Change Nushell init for nu 0.60 (#3773)

This commit is contained in:
David Knaack 2022-03-24 20:06:24 +01:00 committed by GitHub
parent 1f22f76a81
commit c9b75fe115
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 52 additions and 60 deletions

View File

@ -49,7 +49,7 @@ assignees: ''
Fish: ~/.config/fish/config.fish Fish: ~/.config/fish/config.fish
Xonsh: ~/.config/xonsh/rc.xsh Xonsh: ~/.config/xonsh/rc.xsh
Elvish: ~/.config/elvish/rc.elv Elvish: ~/.config/elvish/rc.elv
Nushell: ~/.config/nu/config.toml Nushell: $nu.config-path
Ion: ~/.config/ion/initrc Ion: ~/.config/ion/initrc
--> -->

12
Cargo.lock generated
View File

@ -437,16 +437,6 @@ dependencies = [
"crypto-common", "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]] [[package]]
name = "dirs-next" name = "dirs-next"
version = "2.0.0" version = "2.0.0"
@ -1564,7 +1554,7 @@ dependencies = [
"chrono", "chrono",
"clap", "clap",
"clap_complete", "clap_complete",
"directories-next", "dirs-next",
"dunce", "dunce",
"gethostname", "gethostname",
"git2", "git2",

View File

@ -38,7 +38,7 @@ byte-unit = "4.0.14"
chrono = "0.4.19" chrono = "0.4.19"
clap = { version = "3.1.6", features = ["derive", "cargo", "unicode"] } clap = { version = "3.1.6", features = ["derive", "cargo", "unicode"] }
clap_complete = "3.1.1" clap_complete = "3.1.1"
directories-next = "2.0.0" dirs-next = "2.0.0"
dunce = "1.0.2" dunce = "1.0.2"
gethostname = "0.2.3" gethostname = "0.2.3"
git2 = { version = "0.14.2", default-features = false } git2 = { version = "0.14.2", default-features = false }

View File

@ -327,17 +327,22 @@ eval $(starship init ion)
<details> <details>
<summary>Nushell</summary> <summary>Nushell</summary>
Add the following to the end of your Nushell configuration (find it by running `config path`): Run the following:
```toml ```sh
startup = [ mkdir ~/.cache/starship
"mkdir ~/.cache/starship", starship init nu | save ~/.cache/starship/init.nu
"starship init nu | save ~/.cache/starship/init.nu",
"source ~/.cache/starship/init.nu",
]
prompt = "starship_prompt"
``` ```
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
</details> </details>
<details> <details>

View File

@ -136,20 +136,21 @@ description: Starship is the minimal, blazing fast, and extremely customizable p
::: warning ::: warning
This will change in the future. 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 Run the following:
file by running `config path` in nu. ```sh
mkdir ~/.cache/starship
```toml starship init nu | save ~/.cache/starship/init.nu
startup = [
"mkdir ~/.cache/starship",
"starship init nu | save ~/.cache/starship/init.nu",
"source ~/.cache/starship/init.nu",
]
prompt = "starship_prompt"
``` ```
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 #### Xonsh
Add the following to the end of `~/.xonshrc`: Add the following to the end of `~/.xonshrc`:

View File

@ -512,12 +512,6 @@ look at [this example](#with-custom-error-shape).
::: warning ::: warning
`error_symbol` is not supported on nu shell.
:::
::: warning
`vicmd_symbol` is only supported in cmd, fish and zsh. `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 ### Options
| Option | Default | Description | | Option | Default | Description |

View File

@ -336,16 +336,14 @@ print_install() {
;; ;;
nushell ) nushell )
# shellcheck disable=SC2088 # shellcheck disable=SC2088
config_file="your nu config file." config_file="your nu config file"
config_cmd="startup = [ config_cmd="mkdir ~/.cache/starship
\"mkdir ~/.cache/starship\", starship init nu | save ~/.cache/starship/init.nu
\"starship init nu | save ~/.cache/starship/init.nu\", source ~/.cache/starship/init.nu"
\"source ~/.cache/starship/init.nu\"
]
prompt = \"starship_prompt\""
warning="${warning} This will change in the future. warning="${warning} This will change in the future.
Only nu version v0.33 or higher is supported. Only Nushell v0.60 or higher is supported.
You can check the location of this your config file by running config path in nu" 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 esac
printf " %s\n %s\n Add the following to the end of %s:\n\n\t%s\n\n" \ printf " %s\n %s\n Add the following to the end of %s:\n\n\t%s\n\n" \

View File

@ -1,7 +1,6 @@
use crate::shadow; use crate::shadow;
use crate::utils::{self, exec_cmd}; use crate::utils::{self, exec_cmd};
use directories_next::ProjectDirs;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
use std::time::Duration; use std::time::Duration;
@ -181,8 +180,8 @@ fn get_terminal_info() -> TerminalInfo {
fn get_config_path(shell: &str) -> Option<PathBuf> { fn get_config_path(shell: &str) -> Option<PathBuf> {
if shell == "nu" { if shell == "nu" {
return ProjectDirs::from("org", "nushell", "nu") return dirs_next::config_dir()
.map(|project_dirs| project_dirs.config_dir().join("config.toml")); .map(|config_dir| config_dir.join("nushell").join("config.nu"));
} }
utils::home_dir().and_then(|home_dir| { utils::home_dir().and_then(|home_dir| {

View File

@ -1,8 +1,17 @@
let-env STARSHIP_SHELL = "nu" let-env STARSHIP_SHELL = "nu"
let-env STARSHIP_SESSION_KEY = (random chars -l 16) 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 # jobs are not supported
# status is not supported ^::STARSHIP:: prompt --cmd-duration $env.CMD_DURATION_MS --status $env.LAST_EXIT_CODE
^::STARSHIP:: prompt --cmd-duration $nu.env.CMD_DURATION_MS
} }
# 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 = {''}

View File

@ -516,7 +516,7 @@ fn render_time_component((component, suffix): (&u128, &&str)) -> String {
} }
pub fn home_dir() -> Option<PathBuf> { pub fn home_dir() -> Option<PathBuf> {
directories_next::BaseDirs::new().map(|base_dirs| base_dirs.home_dir().to_owned()) dirs_next::home_dir()
} }
const HEXTABLE: &[char] = &[ const HEXTABLE: &[char] = &[