sistema_progs

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

find_font_terminator.sh (2680B)


      1 #!/usr/bin/env bash
      2 
      3 BASEDIR=$(dirname `readlink -f "$0"`)
      4 source ${BASEDIR}/../colors.sh
      5 
      6 if [ -n "$VERBOSE" ]; then
      7     echo -e "${CYAN}- TERMINATOR:${NORMAL}"
      8 fi
      9 
     10 GLOBAL_PROFILES=()
     11 
     12 # Print only the [[profiles]] section in the config file
     13 get_profiles() {
     14     PROFILE=0
     15     while IFS='' read -r LINE || [[ -n "$LINE" ]]; do
     16 	LINE=`echo $LINE | sed 's/^ *//;s/ *$//'`
     17 	case $LINE in
     18 	    "[global_config]"|"[keybindings]"|"[layouts]"|"[plugins]") PROFILE=0;;
     19 	    "[profiles]") PROFILE=1;;
     20 	esac
     21 	if [ $PROFILE -eq 1 -a "$LINE" != "[profiles]" ]; then
     22 	    echo "${LINE[0]}" | sed 's/ = /=/g'
     23 	    GLOBAL_PROFILES+=("${LINE[0]}")
     24 	fi
     25     done  < "$1"
     26 }
     27 
     28 # Print names of profiles
     29 get_names_of_profiles() {
     30     while IFS='' read -r LINE || [[ -n "$LINE" ]]; do
     31 	case $LINE in
     32 	    \[\[*\]\]) echo "$LINE";;
     33 	esac
     34     done
     35 }
     36 
     37 FOUND=0
     38 
     39 # For each section name, get the value of font and use_system_font
     40 read_profiles() {
     41     get_profiles $1 > /dev/null # Use to initialize GLOBAL_PROFILES
     42     NAMES=(`get_profiles $1 | get_names_of_profiles`) # because this line is executed in a subshell and doesn't modify GLOBAL_PROFILES
     43     for NAME in "${NAMES[@]}"; do
     44 	ON_PROFILE=0
     45 	USE_SYSTEM_FONT=1
     46 	FONT_NAME=""
     47 	for LINE_PROFILE in "${GLOBAL_PROFILES[@]}"; do
     48 	    case "$LINE_PROFILE" in
     49 		"$NAME") ON_PROFILE=1;;
     50 		\[\[*\]\]) ON_PROFILE=0;;
     51 	    esac
     52 	    LINE_PROFILE=`echo $LINE_PROFILE | sed 's/ = /=/g'`
     53 	    if [[ $ON_PROFILE -eq 1 ]]; then
     54 		case "$LINE_PROFILE" in
     55 		    font=*) FONT_NAME=`echo $LINE_PROFILE | sed 's/font=//g' | rev | cut -d ' ' -f 2- | rev`;;
     56 		    use_system_font=False) USE_SYSTEM_FONT=0 ;;
     57 		esac
     58 #		echo $LINE_PROFILE
     59 	    fi
     60 	done
     61 
     62 	if [ $USE_SYSTEM_FONT -eq 1 -o "$FONT_NAME" = "" ]; then
     63 	    FONT_NAME=`${BASEDIR}/find_font_system.sh`
     64 	fi
     65 
     66 	if [ -n "$VERBOSE" ]; then
     67 	    if [ $USE_SYSTEM_FONT -eq 1 ]; then
     68 		USE_SYSTEM_FONT="true"
     69 	    else
     70 		USE_SYSTEM_FONT="false"
     71 	    fi
     72 	    echo -e "    ${UNDERLINE}Profile '${NAME:2:-2}':${NORMAL}"
     73 	    echo -e "\tFont familly:\t\t${GREEN}$FONT_NAME${NORMAL}"
     74 	    echo -e "\tUse system font:\t$USE_SYSTEM_FONT"
     75 	else
     76 	    echo "$FONT_NAME"
     77 	fi
     78 
     79 	FOUND=1
     80 
     81     done
     82 }
     83 
     84 FILE_CONFIG=${XDG_CONFIG_HOME:-${HOME}/.config}/terminator/config
     85 
     86 if [ -e $FILE_CONFIG -a -r $FILE_CONFIG  ];then
     87     read_profiles "$FILE_CONFIG"
     88 fi
     89 
     90 if [ $FOUND -eq 0 ];then
     91 
     92     which terminator 2> /dev/null > /dev/null
     93     EXIST=$?
     94 
     95     if [ $EXIST -eq 0 -a -n "$VERBOSE" ];then
     96 	echo -e "Installed but no config file found:\nUse system font instead: \t${GREEN}`${BASEDIR}/find_font_system.sh` $NORMAL"
     97     elif [ $EXIST -eq 0 ]; then
     98 	./${BASEDIR}find_font_system.sh
     99     elif [ -n "$VERBOSE" ]; then
    100 	echo "No font found"
    101     fi
    102 fi