tImproved hmgr to saved config under random names - scripts - various script and utils
 (HTM) git clone git://z3bra.org/scripts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit f320002bf9bfffc30098e5f053c29909ac3fa35c
 (DIR) parent 11235faa0a8805750424cd8f1dcb12c021493fdd
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Wed,  7 May 2014 10:37:17 +0200
       
       Improved hmgr to saved config under random names
       
       Diffstat:
         M hmgr                                |      67 ++++++++++++++++++++++---------
       
       1 file changed, 48 insertions(+), 19 deletions(-)
       ---
 (DIR) diff --git a/hmgr b/hmgr
       t@@ -9,37 +9,39 @@ 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'
       +#listcmd='ls -1 --color=auto'
       +listcmd='tree -L 1 --noreport'
        
        # Change output colors ?
       -LS_COLORS="di=0;33:*.h=34"
       +color_conf='1;37' # colors for config files
       +color_dirs='0;33' # colors for directory names
        
        
        usage() {
       -echo "usage: $(basename $0) [-duh] [-l [dir]] [-sr <dir>]"
       +echo "usage: $(basename $0) [-uh] [-l [dir]] [-ni <file>] [-csr <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>
       +    -h          : help
       +    -u          : shortcut for -n ${USER}.h
       +    -n <name>   : deal with file as <name> (defaults to config.def.h)
       +    -i <file>   : input file to use (defaults to ./config.h)
       +    -l [dir]    : list currently managed applications/files
       +    -c <dir>    : check which config is in use
       +    -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}
       +    test ! -d ${basedir}/$1 && mkdir ${basedir}/$1
        
            # Copy from current dir to base directory
       -    cp ${cin} ${basedir}/$1/${cout}
       +    cp -i ${cin} ${basedir}/$1/${cout}
        }
        
        restore() {
       t@@ -54,14 +56,26 @@ list() {
            # Go to the base directory
            cd ${basedir}
        
       -    # change colors, for fun!
       -    export LS_COLORS
       +    ${listcmd} $1
       +}
        
       -    ${lister} $1
       +check() {
       +    found=0
       +
       +    for dir in ${basedir}/*; do
       +        for file in ${dir}/*; do
       +            if diff $file ${cin} >/dev/null; then
       +                echo -en "${fgd}`basename ${dir}`${nofg}: "
       +                echo -e  "${fgh}`basename ${file}`${nofg}"
       +                found=1
       +            fi
       +        done
       +    done
       +    test ${found} -eq 0 && echo ${cin} is different from stored configs
        }
        
        # No arguments? give usage
       -test $# -eq 0 && usage && exit 0
       +test $# -eq 0 && list && exit 0
        
        # Create $basedir if it does not exists
        test ! -d ${basedir} && mkdir ${basedir}
       t@@ -71,12 +85,27 @@ cin=config.h
        cout=${default}
        list=0
        
       +# standardize colors for shell output
       +fgd="\e[${color_dirs}m"
       +fgh="\e[${color_conf}m"
       +nofg="\e[0m"
       +
       +# change colors, for fun!
       +LS_COLORS="di=${color_dirs}:*.h=${color_conf}"
       +export LS_COLORS
       +
        # Parse options
       -while getopts "dhls:r:u" opt; do
       +while getopts "chi:ln:s:r:u" opt; do
            case $opt in
       +        # Check which config is in use
       +        c) check;;
       +
                # Wether to use default config or user config
       -        d) cout=${default};;
                u) cout=${usercfg};;
       +        n) cout=${OPTARG};;
       +
       +        # Change the input file
       +        i) cin=$OPTARG;;
        
                # List currently managed config.h
                l) list=1; break;;