penguin/utils

my env utils

commit 56a34a1f12a213c0c4548d9e097886768aed63c2

author斟酌 鵬兄 <tgckpg@gmail.com>
date2014-07-29T01:50:44Z
subjectAdded Cygxcolors & hostconf
commit 56a34a1f12a213c0c4548d9e097886768aed63c2
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2014-07-29T01:50:44Z

    Added Cygxcolors & hostconf
---
 .gitignore                      |  2 +-
 bash/cygxcolors/Solarized       | 32 +++++++++++++++++
 bash/cygxcolors/Xdefaults       |  3 ++
 bash/cygxcolors/applyXColors.sh | 80 +++++++++++++++++++++++++++++++++++++++++
 bash/hostconf/apply.sh          | 30 ++++++++++++++++
 bash/hostconf/noconf            |  7 ++++
 6 files changed, 153 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index 4ef2717..78fd271 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
-
+*.prod
 *.log
diff --git a/bash/cygxcolors/Solarized b/bash/cygxcolors/Solarized
new file mode 100644
index 0000000..4afa8a0
--- /dev/null
+++ b/bash/cygxcolors/Solarized
@@ -0,0 +1,32 @@
+! Common 
+
+#define S_yellow        #b58900
+#define S_orange        #cb4b16
+#define S_red           #dc322f
+#define S_magenta       #d33682
+#define S_violet        #6c71c4
+#define S_blue          #268bd2
+#define S_cyan          #2aa198
+#define S_green         #859900
+
+! Dark
+
+#define S_base03        #222222
+#define S_base02        #073642
+#define S_base01        #586e75
+#define S_base00        #657b83
+#define S_base0         #839496
+#define S_base1         #93a1a1
+#define S_base2         #eee8d5
+#define S_base3         #fdf6e3
+
+! Light
+
+! #define S_base03        #fdf6e3
+! #define S_base02        #eee8d5
+! #define S_base01        #93a1a1
+! #define S_base00        #839496
+! #define S_base0         #657b83
+! #define S_base1         #586e75
+! #define S_base2         #073642
+! #define S_base3         #002b36
diff --git a/bash/cygxcolors/Xdefaults b/bash/cygxcolors/Xdefaults
new file mode 100644
index 0000000..4f81afe
--- /dev/null
+++ b/bash/cygxcolors/Xdefaults
@@ -0,0 +1,3 @@
+XTerm*font:  9x15
+XTerm*saveLines:    1000
+XTerm*geometry: 145x35
diff --git a/bash/cygxcolors/applyXColors.sh b/bash/cygxcolors/applyXColors.sh
new file mode 100755
index 0000000..82563ac
--- /dev/null
+++ b/bash/cygxcolors/applyXColors.sh
@@ -0,0 +1,80 @@
+#!/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
diff --git a/bash/hostconf/apply.sh b/bash/hostconf/apply.sh
new file mode 100755
index 0000000..79aed6e
--- /dev/null
+++ b/bash/hostconf/apply.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+if [ -f $1 ]; then
+    source $1
+fi
+
+uname | grep -q Linux
+LINUX=$?
+
+if [ "$LINUX" -eq "0" ]; then
+    HOST=/etc/hosts
+else
+    HOST=/cygdrive/c/Windows/System32/drivers/etc/hosts
+fi
+
+if [ ${HOSTNAMES[0]+1} ]; then
+    for i in {0..99};
+    do
+        if [ ${HOSTNAMES[$i]+1} ]; then
+            XID="# Automated Host Def. Id. $i"
+            if grep -q "$XID" $HOST; then
+
+                REC=$( echo "s/.*$XID$/${HOSTNAMES[$i]}\	$XID/g" | sed "s/\ /\\\ /g" )
+                sed -i "$REC" $HOST
+            else
+                echo ${HOSTNAMES[$i]}	$XID >> $HOST
+            fi
+        fi
+    done
+fi
diff --git a/bash/hostconf/noconf b/bash/hostconf/noconf
new file mode 100644
index 0000000..58f237f
--- /dev/null
+++ b/bash/hostconf/noconf
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+HOSTNAMES=()
+
+for i in {0..99}; do
+    HOSTNAMES[$i]=""
+done