#!/bin/bash CONF_FILE=$1 TARGET_X=~/.Xdefaults [ ! -f $CONF_FILE ] && exit; function getColor() { if [[ -n "$1" ]]; then grep -E "^[ ]*#define.+S_$1[ ]+" $CONF_FILE | awk '{print $3}' fi } X_BEGIN_STR="!! ~~~~ BEGIN COLOR SETTINGS ~~~~ !!" X_END_STR="!! ~~~~ END COLOR SETTINGS ~~~~ !!" ORIGX="" if [ -f $TARGET_X ]; then SKIP=false while read line; do if [ "$line" = "$X_BEGIN_STR" ]; then SKIP=true continue elif [ "$line" = "$X_END_STR" ]; then SKIP=false continue fi if [ $SKIP = false ] && [ -n "$line" ]; then ORIGX="$ORIGX$line\n" fi done < $TARGET_X fi CNAMES=( yellow orange red magenta violet blue cyan green base0 base1 base2 base3 base00 base01 base02 base03 ) declare -A COLORS=() for i in "${CNAMES[@]}" do COLORS[$i]=$( getColor $i ) done SETTINGS="" function push_val() { SETTINGS=$SETTINGS"$1\n" } push_val push_val "$X_BEGIN_STR" push_val "*VT100*background: ${COLORS['base03']}" push_val "*VT100*foreground: ${COLORS['base0']}" push_val "*VT100*fading: 40" push_val "*VT100*fadeColor: ${COLORS['base08']}" push_val "*VT100*cursorColor: ${COLORS['base1']}" push_val "*VT100*pointerColorBackground: ${COLORS['base01']}" push_val "*VT100*pointerColorForeground: ${COLORS['base1']}" push_val "*VT100*color0: ${COLORS['base02']}" push_val "*VT100*color1: ${COLORS['red']}" push_val "*VT100*color2: ${COLORS['green']}" push_val "*VT100*color3: ${COLORS['yellow']}" push_val "*VT100*color4: ${COLORS['blue']}" push_val "*VT100*color5: ${COLORS['magenta']}" push_val "*VT100*color6: ${COLORS['cyan']}" push_val "*VT100*color7: ${COLORS['base2']}" push_val "*VT100*color8: ${COLORS['base03']}" push_val "*VT100*color9: ${COLORS['orange']}" push_val "*VT100*color10: ${COLORS['base01']}" push_val "*VT100*color11: ${COLORS['base00']}" push_val "*VT100*color12: ${COLORS['base0']}" push_val "*VT100*color13: ${COLORS['violet']}" push_val "*VT100*color14: ${COLORS['base1']}" push_val "*VT100*color15: ${COLORS['base3']}" push_val "$X_END_STR" echo -e "$ORIGX\n$SETTINGS" > $TARGET_X