Skip to content

Commit

Permalink
Clean config
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Llerena <philippe.llerena@gmail.com>
  • Loading branch information
doubleailes committed Aug 19, 2024
1 parent a85ccfb commit 937f20b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 78 deletions.
4 changes: 0 additions & 4 deletions crates/spfs/src/runtime/config.nu

This file was deleted.

14 changes: 10 additions & 4 deletions crates/spfs/src/runtime/config_nu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
// https://github.com/spkenv/spk
// Warning Nuhshell version >=0.96

use std::fs;

pub fn source<T>(_tmpdir: Option<&T>) -> String
where
T: AsRef<str>,
{
fs::read_to_string("/home/philippe.llerena/workspace/github.com/doubleailes/spk/crates/spfs/src/runtime/config.nu").unwrap()
}
{
r#"
$env.config = {
show_banner: false,
}
$env.SPFS_SHELL_MESSAGE? | print
"#
.to_string()
}

65 changes: 0 additions & 65 deletions crates/spfs/src/runtime/env.nu

This file was deleted.

76 changes: 71 additions & 5 deletions crates/spfs/src/runtime/env_nu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,77 @@
// https://github.com/spkenv/spk
// Warning Nuhshell version >=0.96

use std::fs;

pub fn source<T>(_tmpdir: Option<&T>) -> String
where
T: AsRef<str>,
{
fs::read_to_string("/home/philippe.llerena/workspace/github.com/doubleailes/spk/crates/spfs/src/runtime/env.nu").unwrap()
}
{
r#"
def create_left_prompt [] {
let dir = match (do --ignore-shell-errors { $env.PWD | path relative-to $nu.home-path }) {
null => $env.PWD
'' => '~'
$relative_pwd => ([~ $relative_pwd] | path join)
}
let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold })
let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold })
let path_segment = $"($path_color)($dir)(ansi reset)"
$path_segment | str replace --all (char path_sep) $"($separator_color)(char path_sep)($path_color)"
}
def create_right_prompt [] {
# create a right prompt in magenta with green separators and am/pm underlined
let time_segment = ([
(ansi reset)
(ansi magenta)
(date now | format date '%x %X') # try to respect user's locale
] | str join | str replace --regex --all "([/:])" $"(ansi green)${1}(ansi magenta)" |
str replace --regex --all "([AP]M)" $"(ansi magenta_underline)${1}")
let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([
(ansi rb)
($env.LAST_EXIT_CODE)
] | str join)
} else { "" }
([$last_exit_code, (char space), $time_segment] | str join)
}
# Use nushell functions to define your right and left prompt
$env.PROMPT_COMMAND = {|| create_left_prompt }
# FIXME: This default is not implemented in rust code as of 2023-09-08.
$env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt }
# The prompt indicators are environmental variables that represent
# the state of the prompt
$env.PROMPT_INDICATOR = {|| "> " }
$env.PROMPT_INDICATOR_VI_INSERT = {|| ": " }
$env.PROMPT_INDICATOR_VI_NORMAL = {|| "> " }
$env.PROMPT_MULTILINE_INDICATOR = {|| "::: " }
$env.ENV_CONVERSIONS = {
"PATH": {
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
}
"Path": {
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
}
}
let $spfs_startup_dir = if $nu.os-info.name == "windows" {
"C:/spfs/etc/spfs/startup.d"
} else if $nu.os-info.name == "linux" {
"/spfs/etc/spfs/startup.d"
} else {
exit 1
}
$env.NU_VENDOR_AUTOLOAD_DIR = ($spfs_startup_dir)
"#
.to_string()
}

0 comments on commit 937f20b

Please sign in to comment.