repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

nushell: simpler prompt

fd632114ddbac902f72a5601258c914c4fc5f2e9

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (1)

nushell/scripts/prompt.nu

Modified
25 -# Uses a special escape code to set the window title of the terminal emulator.
26 -# This will be ignored in terminal emulator, that do not support that escape code.
27 -# The title to be set is derived from the current working directory.
28 -# Special types of directories, e.g. HOME, get custom icons.
29 -def set-window-title [] {
30 - # Some terminals freeze, if they do not support this OSC
31 - if ($env | get -i TERM_PROGRAM) == WezTerm {
32 - # normalize path
33 - let pwd = ( $env.PWD | path expand )
34 - let icon = if (icons | any { |icon| $icon.path == $pwd } ) { ( icons | where path == $pwd | get icon.0 ) } else { $"(char nf_folder1)" }
35 - echo ([ (ansi title) $icon " " ( $pwd | path basename ) (ansi reset) ] | str join)
36 - }
39 25 def prompt-git-branch [] {
58 44 def create_left_prompt [] {
59 - set-window-title
61 45 # normalize path
62 46 let pwd = ($env.PWD | path expand)
63 47 let pwd = ( (icons) | reduce --fold $pwd { |item, accumulator| $accumulator | str replace $item.path $item.icon })
80 64 def create_right_prompt [] {
81 - let time_segment = ([
82 - (date now | format date '%d.%m %R')
83 - ] | str join)
85 65 let command_status_segment = if $env.LAST_EXIT_CODE == 0 { $" (char -u '2713') " } else { $"(ansi red) (char failed) (ansi reset)" }
86 - let command_duration_segment = if ( $env.CMD_DURATION_MS | into int) > 0 { $"($env.CMD_DURATION_MS)ms" | into duration }
89 68 (ansi dark_gray_dimmed)
90 - $command_duration_segment
91 - (ansi reset)
92 - (ansi dark_gray)
93 69 $command_status_segment
94 70 (ansi reset)
95 - (ansi dark_gray)
96 - ( $time_segment )
97 - (ansi reset)
98 71 ] | str join
106 79 # The prompt indicators are environmental variables that represent
107 80 # the state of the prompt
108 - $env.PROMPT_INDICATOR = $"(ansi green) (char prompt) (ansi reset)"
81 + $env.PROMPT_INDICATOR = $"(ansi green) ⚈ (ansi reset)"
109 82 $env.PROMPT_INDICATOR_VI_INSERT = $"(ansi magenta) (char pipe) (ansi reset)"
110 83 $env.PROMPT_INDICATOR_VI_NORMAL = $"(ansi magenta) (char prompt) (ansi reset)"
111 84 $env.PROMPT_MULTILINE_INDICATOR = $"(ansi magenta) (char prompt)(char prompt) (ansi reset)"