sistema_progs

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

D1589-ConvertAirlineThemes.sh (5743B)


      1 #!/bin/bash
      2 
      3 if [[ ! ${BLE_VERSION-} ]]; then
      4   echo "This script needs to be sourced in a ble.sh session." >&2
      5   return 1 || exit 1
      6 fi
      7 
      8 year=$(date +%Y)
      9 
     10 declare -A name2color=([none]=-1 [lightmagenta]='#ffe0ff')
     11 function ble/lib/vim-airline/convert-theme/load-vim-rgb {
     12   local R G B name ret
     13   while builtin read -r R G B name || [[ $name ]]; do
     14     name=${name,,}
     15     name=${name//["$_ble_term_IFS"]}
     16     [[ $name ]] || continue
     17     printf -v ret '#%02x%02x%02x' "$R" "$G" "$B"
     18     name2color[$name]=$ret
     19   done < /usr/share/vim/vim82/rgb.txt
     20 }
     21 ble/lib/vim-airline/convert-theme/load-vim-rgb
     22 
     23 function ble/lib/vim-airline/convert-theme/decode-color {
     24   local cspec=${1,,} ret
     25   if [[ $cspec == '#'?????? ]]; then
     26     local R=$((16#${cspec:1:2}))
     27     local G=$((16#${cspec:3:2})) 
     28     local B=$((16#${cspec:5:2}))
     29     ble/color/convert-rgb24-to-color256 "$R" "$G" "$B"
     30     color256=$ret color24=$cspec
     31   elif [[ $cspec == '#'??? ]]; then
     32     local r=${cspec::1} g=${cspec:1:1} b=${cspec:2:1}
     33     ble/lib/vim-airline/convert-theme/decode-color "#$r$r$g$g$b$b"
     34   elif [[ $cspec && ! ${cspec//[0-9]} || $cspec == -1 ]]; then
     35     color256=$cspec color24=$cspec
     36   elif [[ ${name2color[$cspec]} ]]; then
     37     ble/lib/vim-airline/convert-theme/decode-color "${name2color[$cspec]}"
     38   else
     39     color256=unknown color24=unknown
     40     ble/util/print "$theme: unknown color spec '$cspec'" >&2
     41   fi
     42 }
     43 
     44 function face {
     45   local mode=$1 face=$2 fg=${3:-${5:-0}} bg=${4:-${6:-0}}
     46 
     47   # check mode
     48   case ${mode%_modified} in
     49   (normal|insert|replace|visual|commandline|inactive) ;;
     50   (accents|tabline|ctrlp|terminal) return 0 ;;
     51   (*_paste|insert_replace|normal_error|insert_error) return 0 ;;
     52   (*) ble/util/print "$theme: Unknown mode '$mode'" >&2
     53   esac
     54 
     55   # check face
     56   case $face in
     57   (airline_[abcxyz]|airline_error|airline_term|airline_warning) ;;
     58   (airline_*_to_airline_*) return 0 ;;
     59   (airline_file) return 0 ;; # ?????? itchyny/landscape.vim で使用
     60   (*) ble/util/print "$theme: Unknown face type '$face'" >&2
     61   esac
     62 
     63   local face_name=vim_${face}_$mode
     64 
     65   local color256 color24
     66   ble/lib/vim-airline/convert-theme/decode-color "$fg"
     67   fg256[$face_name]=$color256
     68   fg24[$face_name]=$color24
     69   ble/lib/vim-airline/convert-theme/decode-color "$bg"
     70   bg256[$face_name]=$color256
     71   bg24[$face_name]=$color24
     72 }
     73 
     74 function ble/lib/vim-airline/convert-theme/eq {
     75   local face1=$1 face2=$2
     76   [[ "${fg256[$face1]}" == "${fg256[$face2]}" ]] || return 1
     77   [[ "${bg256[$face1]}" == "${bg256[$face2]}" ]] || return 1
     78   [[ "${fg24[$face1]}" == "${fg24[$face2]}" ]] || return 1
     79   [[ "${bg24[$face1]}" == "${bg24[$face2]}" ]] || return 1
     80   return 0
     81 }
     82 
     83 function ble/lib/vim-airline/convert-theme/convert {
     84   local theme=$1
     85 
     86   local -A fg256=() bg256=() fg24=() bg24=()
     87 
     88   # default faces
     89   local f
     90   f=vim_airline_error_default   fg256[$f]=16  bg256[$f]=88  fg24[$f]='#000000' bg24[$f]='#990000'
     91   f=vim_airline_term_default    fg256[$f]=158 bg256[$f]=234 fg24[$f]='#9cffd3' bg24[$f]='#202020'
     92   f=vim_airline_warning_default fg256[$f]=16  bg256[$f]=166 fg24[$f]='#000000' bg24[$f]='#df5f00'
     93 
     94   source "tmp/airline/$theme.bash"
     95 
     96   [[ -d contrib/airline ]] || mkdir -p contrib/airline
     97   exec 5> "contrib/airline/$theme.bash"
     98   {
     99     if [[ $theme == dark ]]; then
    100       ble/util/print "# From github:vim-airline/vim-airline/autoload/airline/themes/dark.vim"
    101       ble/util/print "#   The MIT License (MIT)"
    102       ble/util/print "#   Copyright (c) 2013-2021 Bailey Ling et al."
    103       ble/util/print "#"
    104     elif [[ $theme == landscape ]]; then
    105       ble/util/print "# From github:itchyny/landscape.vim/autoload/airline/themes/$theme.vim"
    106       ble/util/print "#   The MIT License (MIT)"
    107       ble/util/print "#   Copyright (c) 2012-2015 itchyny."
    108       ble/util/print "#"
    109     else
    110       ble/util/print "# From github:vim-airline/vim-airline-themes/autoload/airline/themes/$theme.vim"
    111       ble/util/print "#   The MIT License (MIT)"
    112       ble/util/print "#   Copyright (C) 2013-$year Bailey Ling & Contributors."
    113       ble/util/print "#"
    114       ble/bin/sed '/^"/!Q;s//#/' ~/.vim/plugged/vim-airline-themes/autoload/airline/themes/"$theme".vim
    115     fi
    116     ble/util/print
    117     ble/util/print 'ble-import lib/vim-airline'
    118     ble/util/print
    119     ble/util/print "function ble/lib/vim-airline/theme:$theme/initialize {"
    120     ble/util/print '  ble-face -r vim_airline_@'
    121   } >&5
    122 
    123   local face
    124   for face in "${!fg256[@]}"; do
    125     local face2=$face
    126     case $face in
    127     (*_modified) ble/lib/vim-airline/convert-theme/eq "$face" "${face%_modified}" && continue ;;
    128     (vim_airline_x_*) ble/lib/vim-airline/convert-theme/eq "$face" "${face/x/c}" && continue ;;
    129     (vim_airline_y_*) ble/lib/vim-airline/convert-theme/eq "$face" "${face/y/b}" && continue ;;
    130     (vim_airline_z_*) ble/lib/vim-airline/convert-theme/eq "$face" "${face/z/a}" && continue ;;
    131     (*_replace) ble/lib/vim-airline/convert-theme/eq "$face" "${face%_*}_insert" && continue ;;
    132     (*_normal)
    133       face2=${face%_normal}
    134       ble/lib/vim-airline/convert-theme/eq "$face" "${face%_*}_default" && continue ;;
    135     (*_*) ble/lib/vim-airline/convert-theme/eq "$face" "${face%_*}_normal" && continue ;;
    136     (*) continue ;;
    137     esac
    138 
    139     printf '  ble-face -s %-40s %-13s # fg=%s,bg=%s\n' \
    140            "$face2" "fg=${fg256[$face]},bg=${bg256[$face]}" "${fg24[$face]}" "${bg24[$face]}"
    141   done | ble/bin/sort >&5
    142   ble/util/print '}' >&5
    143   exec 5>&-
    144 }
    145 
    146 function ble/lib/vim-airline/convert-theme/convert-all {
    147   local file theme
    148   for file in tmp/airline/*.bash; do
    149     theme=${file##*/}
    150     theme=${theme%.bash}
    151     #ble/util/print "Converting $theme..."
    152     ble/lib/vim-airline/convert-theme/convert "$theme"
    153   done
    154 }
    155 #ble/lib/vim-airline/convert-theme/convert-all
    156 ble/lib/vim-airline/convert-theme/convert dark