tMangage config.h files easily - scripts - various script and utils
(HTM) git clone git://z3bra.org/scripts
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit d3003be6bcd798bfcd0cfc2ec7cce391ca1d7f8d
(DIR) parent f6ad339aa74e327b8a4620964f36f492305fa97b
(HTM) Author: z3bra <willy@mailoo.org>
Date: Tue, 6 May 2014 14:53:09 +0200
Mangage config.h files easily
Diffstat:
A hmgr | 98 +++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/hmgr b/hmgr
t@@ -0,0 +1,98 @@
+#!/bin/sh
+#
+# z3bra - (c) wtfpl 2014
+# Manage your config.h files on a per program basis. Store defaults and user
+# configs, and restore them easily.
+
+# Directory where configs are saved
+basedir=~/.hmgr.d
+
+# Default names for configs
+default=config.def.h
+usercfg=${USER}.h
+
+# How to list files managed by hmgr
+#lister='ls --color=auto'
+lister='tree -L 1 --noreport'
+
+# Change output colors ?
+LS_COLORS="di=0;33:*.h=34"
+
+
+usage() {
+echo "usage: $(basename $0) [-duh] [-l [dir]] [-sr <dir>]"
+
+test -z "$1" && return
+
+cat <<EOF
+ -h : help
+ -d : deal with default config (by default)
+ -u : deal with user config
+ -l [dir] : list currently managed applications/files
+ -s <dir> : store \`config.h\` to <dir>
+ -r <dir> : restore \`config.h\` from <dir>
+EOF
+}
+
+store() {
+ test -z "$1" && return 1
+ test ! -d ${basedir}/$1 && mkdir ${basedir}/${subdir}
+
+ # Copy from current dir to base directory
+ cp ${cin} ${basedir}/$1/${cout}
+}
+
+restore() {
+ test -z "$1" && return 1
+
+ # Copy from base dir to current directory
+ cp ${basedir}/$1/${cout} ${cin}
+}
+
+list() {
+
+ # Go to the base directory
+ cd ${basedir}
+
+ # change colors, for fun!
+ export LS_COLORS
+
+ ${lister} $1
+}
+
+# No arguments? give usage
+test $# -eq 0 && usage && exit 0
+
+# Create $basedir if it does not exists
+test ! -d ${basedir} && mkdir ${basedir}
+
+# Set the default file names
+cin=config.h
+cout=${default}
+list=0
+
+# Parse options
+while getopts "dhls:r:u" opt; do
+ case $opt in
+ # Wether to use default config or user config
+ d) cout=${default};;
+ u) cout=${usercfg};;
+
+ # List currently managed config.h
+ l) list=1; break;;
+
+ # Whether to store or restore a config.h
+ s) store $OPTARG;;
+ r) restore $OPTARG;;
+
+ # WHAAT?!
+ h) usage full; exit 0;;
+ *) usage; exit 1;;
+ esac
+done
+
+# In case we want to list files managed...
+shift $(( OPTIND - 1 ))
+
+# List either the whole dir or a specific one
+test $list -eq 1 && list $1