Skip to content

Commit 2dbd0f4

Browse files
committed
Clean config
Signed-off-by: Philippe Llerena <[email protected]>
1 parent a666f2d commit 2dbd0f4

File tree

4 files changed

+81
-78
lines changed

4 files changed

+81
-78
lines changed

crates/spfs/src/runtime/config.nu

Lines changed: 0 additions & 4 deletions
This file was deleted.

crates/spfs/src/runtime/config_nu.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
// https://github.com/spkenv/spk
44
// Warning Nuhshell version >=0.96
55

6-
use std::fs;
76

87
pub fn source<T>(_tmpdir: Option<&T>) -> String
98
where
109
T: AsRef<str>,
11-
{
12-
fs::read_to_string("/home/philippe.llerena/workspace/github.com/doubleailes/spk/crates/spfs/src/runtime/config.nu").unwrap()
13-
}
10+
{
11+
r#"
12+
$env.config = {
13+
show_banner: false,
14+
}
15+
$env.SPFS_SHELL_MESSAGE? | print
16+
"#
17+
.to_string()
18+
}
19+

crates/spfs/src/runtime/env.nu

Lines changed: 0 additions & 65 deletions
This file was deleted.

crates/spfs/src/runtime/env_nu.rs

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,77 @@
33
// https://github.com/spkenv/spk
44
// Warning Nuhshell version >=0.96
55

6-
use std::fs;
7-
86
pub fn source<T>(_tmpdir: Option<&T>) -> String
97
where
108
T: AsRef<str>,
11-
{
12-
fs::read_to_string("/home/philippe.llerena/workspace/github.com/doubleailes/spk/crates/spfs/src/runtime/env.nu").unwrap()
13-
}
9+
{
10+
r#"
11+
def create_left_prompt [] {
12+
let dir = match (do --ignore-shell-errors { $env.PWD | path relative-to $nu.home-path }) {
13+
null => $env.PWD
14+
'' => '~'
15+
$relative_pwd => ([~ $relative_pwd] | path join)
16+
}
17+
18+
let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold })
19+
let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold })
20+
let path_segment = $"($path_color)($dir)(ansi reset)"
21+
22+
$path_segment | str replace --all (char path_sep) $"($separator_color)(char path_sep)($path_color)"
23+
}
24+
25+
def create_right_prompt [] {
26+
# create a right prompt in magenta with green separators and am/pm underlined
27+
let time_segment = ([
28+
(ansi reset)
29+
(ansi magenta)
30+
(date now | format date '%x %X') # try to respect user's locale
31+
] | str join | str replace --regex --all "([/:])" $"(ansi green)${1}(ansi magenta)" |
32+
str replace --regex --all "([AP]M)" $"(ansi magenta_underline)${1}")
33+
34+
let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([
35+
(ansi rb)
36+
($env.LAST_EXIT_CODE)
37+
] | str join)
38+
} else { "" }
39+
40+
([$last_exit_code, (char space), $time_segment] | str join)
41+
}
42+
43+
# Use nushell functions to define your right and left prompt
44+
$env.PROMPT_COMMAND = {|| create_left_prompt }
45+
# FIXME: This default is not implemented in rust code as of 2023-09-08.
46+
$env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt }
47+
48+
# The prompt indicators are environmental variables that represent
49+
# the state of the prompt
50+
$env.PROMPT_INDICATOR = {|| "> " }
51+
$env.PROMPT_INDICATOR_VI_INSERT = {|| ": " }
52+
$env.PROMPT_INDICATOR_VI_NORMAL = {|| "> " }
53+
$env.PROMPT_MULTILINE_INDICATOR = {|| "::: " }
54+
55+
56+
$env.ENV_CONVERSIONS = {
57+
"PATH": {
58+
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
59+
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
60+
}
61+
"Path": {
62+
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
63+
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
64+
}
65+
}
66+
67+
let $spfs_startup_dir = if $nu.os-info.name == "windows" {
68+
"C:/spfs/etc/spfs/startup.d"
69+
} else if $nu.os-info.name == "linux" {
70+
"/spfs/etc/spfs/startup.d"
71+
} else {
72+
exit 1
73+
}
74+
75+
$env.NU_VENDOR_AUTOLOAD_DIR = ($spfs_startup_dir)
76+
"#
77+
.to_string()
78+
}
79+

0 commit comments

Comments
 (0)