From 62539db84df9c7ddb2253811c3162e98379b806a Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Fri, 2 Aug 2024 21:29:25 +0200 Subject: [PATCH] do flag thing help --- modules/shell/nu.nix | 8 +++- modules/shell/starship.nix | 1 + other/config.nu | 3 +- other/env.nu | 54 +++++++++++----------- other/scripts/desktop/shell-startup.nu | 20 +++++--- programs/jrnl/src/commands/list_entries.rs | 1 + 6 files changed, 51 insertions(+), 36 deletions(-) diff --git a/modules/shell/nu.nix b/modules/shell/nu.nix index 2d9aa98..30b4347 100644 --- a/modules/shell/nu.nix +++ b/modules/shell/nu.nix @@ -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; }; diff --git a/modules/shell/starship.nix b/modules/shell/starship.nix index 588ebe1..eea943f 100644 --- a/modules/shell/starship.nix +++ b/modules/shell/starship.nix @@ -2,6 +2,7 @@ home-manager.users.jade = {pkgs, ...}: { programs.starship = { enable = true; + enableNushellIntegration = false; settings = { format = "$all$directory$character"; character = { diff --git a/other/config.nu b/other/config.nu index 9435b28..c735edb 100644 --- a/other/config.nu +++ b/other/config.nu @@ -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 } diff --git a/other/env.nu b/other/env.nu index 57878d8..d5ca780 100644 --- a/other/env.nu +++ b/other/env.nu @@ -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 diff --git a/other/scripts/desktop/shell-startup.nu b/other/scripts/desktop/shell-startup.nu index af5e93a..961f702 100644 --- a/other/scripts/desktop/shell-startup.nu +++ b/other/scripts/desktop/shell-startup.nu @@ -10,11 +10,17 @@ const ENBY = [ FCF434 FFFFFF 9C59D1 2C2C2C ]; def flag [ colors: list + 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); } diff --git a/programs/jrnl/src/commands/list_entries.rs b/programs/jrnl/src/commands/list_entries.rs index b1f617b..d488932 100644 --- a/programs/jrnl/src/commands/list_entries.rs +++ b/programs/jrnl/src/commands/list_entries.rs @@ -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...");