81 lines
3.1 KiB
Nu
81 lines
3.1 KiB
Nu
export def --env "pj starship config" [name: string] {
|
|
if (which ^starship | is-empty) {
|
|
echo "starship is not installed."
|
|
return
|
|
}
|
|
let cfg = ($env.NU_POLYJUICE_PATH | path join ".." "starship" $"starship_($name).toml")
|
|
$env.STARSHIP_CONFIG = $cfg
|
|
}
|
|
|
|
export def --env "pj starship list" [] {
|
|
if (which ^starship | is-empty) {
|
|
echo "starship is not installed."
|
|
return
|
|
}
|
|
ls ($env.NU_POLYJUICE_PATH | path join ".." "starship") -s | get name | parse -r '^(starship_(?<name>.*).toml)$' | get name
|
|
}
|
|
|
|
export def "pj starship doctor" [] {
|
|
let installed = ((which ^starship | length) > 0)
|
|
let prompt_type = ($env.PROMPT_COMMAND? | describe)
|
|
let right_prompt_type = ($env.PROMPT_COMMAND_RIGHT? | describe)
|
|
let prompt_cmd = (($env.PROMPT_COMMAND? | to nuon --serialize) | default "<not-set>")
|
|
let right_prompt_cmd = (($env.PROMPT_COMMAND_RIGHT? | to nuon --serialize) | default "<not-set>")
|
|
let prompt_uses_starship = ($prompt_cmd | str contains "starship' prompt")
|
|
let right_prompt_uses_starship = ($right_prompt_cmd | str contains "starship' prompt")
|
|
|
|
{
|
|
starship_installed: $installed
|
|
starship_path: ((which ^starship | get path.0?) | default "<not-found>")
|
|
starship_version: (if $installed { (^starship --version | str trim) } else { "<not-installed>" })
|
|
STARSHIP_SHELL: ($env.STARSHIP_SHELL? | default "<not-set>")
|
|
STARSHIP_CONFIG: ($env.STARSHIP_CONFIG? | default "<not-set>")
|
|
prompt_command_type: $prompt_type
|
|
prompt_command_uses_starship: $prompt_uses_starship
|
|
prompt_command_right_type: $right_prompt_type
|
|
prompt_command_right_uses_starship: $right_prompt_uses_starship
|
|
}
|
|
}
|
|
|
|
export-env {
|
|
if (which ^starship | is-not-empty) {
|
|
$env.STARSHIP_SHELL = "nu"
|
|
load-env {
|
|
STARSHIP_SESSION_KEY: (random chars -l 16)
|
|
PROMPT_MULTILINE_INDICATOR: (
|
|
^'starship' prompt --continuation
|
|
)
|
|
|
|
# Does not play well with default character module.
|
|
# TODO: Also Use starship vi mode indicators?
|
|
PROMPT_INDICATOR: ""
|
|
|
|
PROMPT_COMMAND: {||
|
|
# jobs are not supported
|
|
(
|
|
^'starship' prompt
|
|
--cmd-duration $env.CMD_DURATION_MS
|
|
$"--status=($env.LAST_EXIT_CODE)"
|
|
--terminal-width (term size).columns
|
|
)
|
|
}
|
|
|
|
config: ($env.config? | default {} | merge {
|
|
render_right_prompt_on_last_line: true
|
|
})
|
|
|
|
PROMPT_COMMAND_RIGHT: {||
|
|
(
|
|
^'starship' prompt
|
|
--right
|
|
--cmd-duration $env.CMD_DURATION_MS
|
|
$"--status=($env.LAST_EXIT_CODE)"
|
|
--terminal-width (term size).columns
|
|
)
|
|
}
|
|
}
|
|
let default_cfg = ($env.NU_POLYJUICE_PATH | path join ".." "starship" $"starship_default.toml")
|
|
$env.STARSHIP_CONFIG = $default_cfg
|
|
}
|
|
}
|