scripts

Utilitity scripts
git clone git://gtms.dev:scripts
Log | Files | Refs

cht (1377B)


      1 #!/bin/zsh
      2 # Change colorscheme 
      3 
      4 local themes=(light dark)
      5 local curr_theme=${THEME:-$CONFIG/theme}
      6 local p_bg=0
      7 local scheme=''
      8 local theme=''
      9 
     10 function usage() {
     11       cat <<EOF
     12 Change colorscheme for environment
     13 
     14 USAGE:
     15   cht [FLAGS]
     16 
     17 FLAGS:
     18   -b    from background
     19   -c    from scheme (wal theme list)
     20   -t    theme <light|dark>
     21 EOF
     22 }
     23 
     24 local opt
     25 while getopts hbt:c: opt; do
     26   case $opt in
     27     b)
     28       p_bg=1
     29       ;;
     30     t)
     31       theme=$OPTARG
     32       ;;
     33     c)
     34       scheme=$OPTARG
     35       ;;
     36     h)
     37       usage
     38       exit 0
     39       ;;
     40   esac
     41 done
     42 
     43 if [[ -z "$theme" ]]; then
     44   theme="$(cat $curr_theme)"
     45 fi
     46 
     47 if (($themes[(Ie)$theme])); then
     48   echo "$theme" > $curr_theme
     49 
     50   if [[ $p_bg -eq 1 ]]; then
     51     img="$(cat $HOME/.fehbg | sed -n '2p' | cut -d ' ' -f 4)"
     52     img="${img[2,-2]}" # remove quotes
     53     if [[ ! -e "$img" ]]; then
     54       echo "Image not found inside $HOME/.fehbg!" >&2
     55       exit 1
     56     fi
     57 
     58     # Generate colors from wallpaper
     59     if [[ "$theme" == 'dark' ]]; then
     60       wal -n -i "$img" -o walset.zsh
     61     else
     62       wal -n -i "$img" -o walset.zsh -l
     63     fi
     64   else
     65     if [[ -n "$scheme" ]]; then
     66       # Generate colors from scheme
     67       if [[ "$theme" == 'dark' ]]; then
     68         wal --theme $scheme -o walset.zsh
     69       else
     70         wal --theme $scheme -o walset.zsh -l
     71       fi
     72     fi
     73   fi
     74 else
     75   echo "'$theme' is not a valid theme"
     76   usage
     77   exit 1
     78 fi