scripts

various script and utils
git clone git://z3bra.org/scripts
Log | Files | Refs

commit 11235faa0a8805750424cd8f1dcb12c021493fdd
parent c41b8d074d9ea92ebb67f55f0d93485a7b28e7aa
Author: z3bra <willy@mailoo.org>
Date:   Tue May  6 15:28:25 +0200

Merge branch 'master' of z3bra.org:scripts

Diffstat:
hmgr | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
prtmk | 5++---
2 files changed, 100 insertions(+), 3 deletions(-)
diff --git a/hmgr b/hmgr @@ -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 diff --git a/prtmk b/prtmk @@ -17,11 +17,10 @@ test -n "$1" && name=$1 || read -p 'Name : ' name read -p 'Description : ' description read -p 'Version : ' version read -p 'URL : ' url -read -p 'Maintainer : ' daddy -read -p 'Depends on : ' depends read -p 'Source : ' sources +read -p 'Depends on : ' depends -source=${source/$name/\$name} +source=${source//$name/\$name} source=${source/$version/\$version} PORTDIR=$PORTDIR/$name