do flag thing help

This commit is contained in:
Schrottkatze 2024-08-02 21:29:25 +02:00
parent 3d2719f2f7
commit 62539db84d
No known key found for this signature in database
6 changed files with 51 additions and 36 deletions

View file

@ -12,6 +12,10 @@
home.packages = [
pkgs.pueue
];
home.file."shell-startup" = {
source = ../../other/scripts/desktop/shell-startup.nu;
target = ".config/nushell/shell-startup.nu";
};
programs.nushell = {
enable = true;
package = config.users.defaultUserShell;
@ -28,8 +32,10 @@
nu ${../../other/scripts/desktop/shell-startup.nu};
'';
extraEnv = ''
'';
};
programs.starship.enableNushellIntegration = true;
# programs.starship.enableNushellIntegration = true;
programs.carapace.enableNushellIntegration = true;
programs.direnv.enableNushellIntegration = true;
};

View file

@ -2,6 +2,7 @@
home-manager.users.jade = {pkgs, ...}: {
programs.starship = {
enable = true;
enableNushellIntegration = false;
settings = {
format = "$all$directory$character";
character = {

View file

@ -272,7 +272,8 @@ $env.config = {
render_right_prompt_on_last_line: false # true or false to enable or disable right prompt to be rendered on last line of the prompt.
hooks: {
pre_execution: [{ null }] # run before the repl input is run
pre_prompt: { null }
pre_execution: [{ $env.CMD_COUNT = $env.CMD_COUNT + 1; }] # run before the repl input is run
env_change: {
PWD: [{|before, after| null }] # run if the PWD environment is different since the last repl input
}

View file

@ -2,36 +2,18 @@
#
# version = "0.84.0"
def create_left_prompt [] {
mut home = ""
try {
if $nu.os-info.name == "windows" {
$home = $env.USERPROFILE
} else {
$home = $env.HOME
}
}
let dir = ([
($env.PWD | str substring 0..($home | str length) | str replace $home "~"),
($env.PWD | str substring ($home | str length)..)
] | str 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)"
$path_segment | str replace --all (char path_sep) $"($separator_color)/($path_color)"
}
source /home/jade/.config/nushell/shell-startup.nu;
$env.STARSHIP_SHELL = "nu";
$env.CMD_COUNT = 0;
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 '%Y/%m/%d %r')
] | str join | str replace --regex --all "([/:])" $"(ansi green)${1}(ansi magenta)" |
str replace --regex --all "([AP]M)" $"(ansi magenta_underline)${1}")
(ansi purple)
(date now | format date '%Y/%m/%d %R')
]) | str join;
let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([
(ansi rb)
@ -43,8 +25,26 @@ def create_right_prompt [] {
}
# Use nushell functions to define your right and left prompt
$env.PROMPT_COMMAND = {|| create_left_prompt }
# $env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt }
$env.PROMPT_COMMAND = {||
starship prompt --cmd-duration $env.CMD_DURATION_MS $'--status=($env.LAST_EXIT_CODE)'
| lines
| filter { is-not-empty }
| update 0 {|item|
let len = (term size | get columns) - ($item | ansi strip | str length --grapheme-clusters) - (create_right_prompt | ansi strip | str length --grapheme-clusters);
# $item | append (flag $TRANS "-" $len) | str join
let deco = if ($env.CMD_COUNT == 0) {
flag $LESBIAN "=" $len
} else if ($env.CMD_COUNT | is even) {
flag $LESBIAN "-" $len
} else {
flag $TRANS "-" $len
};
$item | append $deco | str join
}
| str join "\n"
}
$env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt }
# The prompt indicators are environmental variables that represent
# the state of the prompt

View file

@ -10,11 +10,17 @@ const ENBY = [ FCF434 FFFFFF 9C59D1 2C2C2C ];
def flag [
colors: list<string>
character = "="
width = -1,
] {
use std;
let col_size = (term size | get columns) / ($colors | length) | math floor;
mut rest = (term size | get columns) - ($col_size * ($colors | length));
let out_size = if ($width == -1) {
term size | get columns
} else { $width };
let col_size = $out_size / ($colors | length) | math floor;
mut rest = $out_size - ($col_size * ($colors | length));
mut cols = $colors | wrap color | insert width $col_size | flatten;
let last = ($colors | length) - 1;
@ -35,14 +41,14 @@ def flag [
$cols = ($cols | update 0 { $in | update width {|w| ($w.width + $amount) } } | update $last { $in | update width {|w| ($w.width + $amount) } });
print ($cols | each {|col|
"=" | std repeat $col.width | prepend (ansi {fg: $"#($col.color)" }) | str join
} | prepend (ansi attr_bold) | append (ansi reset) | str join)
$cols | each {|col|
$character | std repeat $col.width | prepend (ansi {fg: $"#($col.color)" }) | str join
} | prepend (ansi attr_bold) | append (ansi reset) | str join
}
def main [] {
flag $TRANS;
print (flag $TRANS);
print $"(ansi attr_bold) Hi jade, you're on HRT for ((date now) - ('2024-02-18T20:53' | into datetime) | format duration month)s now!";
flag $LESBIAN;
# print (flag $LESBIAN);
}

View file

@ -17,6 +17,7 @@ pub fn list_entries(path: PathBuf) -> io::Result<()> {
println!("{}{r}{padding}{}", n.cyan(), l.white())
}
println!("d");
Ok(())
} else {
eprintln!("Parsing error...");