sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

github265-prompt-path-level-colors.bash (993B)


      1 # blesh-contrib/config/github265-prompt-path-level-colors.bash (C) 2022, Koichi Murase <myoga.murase@gmail.com>
      2 #
      3 # Example:
      4 #
      5 #   ble-import /config/github265-prompt-path-level-colors
      6 #   PS1='[\u@\h \q{github265/pwd}]\$ '
      7 #
      8 _ble_contrib_config_github265_pwd_gspecs=(fg=27 fg=57 fg=141 fg=63)
      9 
     10 function ble/prompt/backslash:github265/pwd {
     11   ble/prompt/unit/add-hash '$PWD'
     12   ble/prompt/.update-working-directory
     13   local str=$prompt_cache_wd
     14 
     15   local -a dirs=()
     16   while ble/string#match "$str" '^([^/]*/|[^/]+$)'; do
     17     ble/array#push dirs "$BASH_REMATCH"
     18     str=${str:${#BASH_REMATCH}}
     19   done
     20 
     21   local count=${#dirs[@]}
     22   local n=${#_ble_contrib_config_github265_pwd_gspecs[@]} index ret
     23   for dir in "${dirs[@]}"; do
     24     ((index=--count,index<n||(index=n-1)))
     25     ble/prompt/process-prompt-string "\g{${_ble_contrib_config_github265_pwd_gspecs[index]}}"
     26     ble/prompt/.escape-control-characters "$dir"
     27     ble/prompt/print "$ret"
     28   done
     29   ble/prompt/print "$_ble_term_sgr0"
     30   return 0
     31 }