tUse pathes to choose the file to save/restore - scripts - various script and utils
(HTM) git clone git://z3bra.org/scripts
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit ab8995d8af31c4346c3b7bab4f0c7f68f0f5c08d
(DIR) parent 731b09cdcd5b30bdfe241e1d415f554797a6b68b
(HTM) Author: z3bra <willy@mailoo.org>
Date: Tue, 27 May 2014 09:03:41 +0200
Use pathes to choose the file to save/restore
Diffstat:
M hmgr | 50 +++++++++++++++++++------------
1 file changed, 31 insertions(+), 19 deletions(-)
---
(DIR) diff --git a/hmgr b/hmgr
t@@ -20,39 +20,56 @@ color_dirs='0;33' # colors for directory names
usage() {
-echo "usage: $(basename $0) [-hu] [-l [dir]] [-din <file>] [-csr <dir>]"
+echo "usage: $(basename $0) [-hu] [-l [dir]] [-di <file>] [-csr <dir>/<name>]"
test -z "$1" && return
cat <<EOF
- -h : help
- -u : shortcut for -n ${USER}.h
+ -h : help
+ -u : shortcut for -n ${USER}.h
- -l [dir] : list currently managed applications/files
+ -l [dir] : list currently managed applications/files
- -d <dir>/<name> : remove <name> from managed configs
- -i <file> : input file to use (defaults to ./config.h)
- -n <name> : deal with file as <name> (defaults to config.def.h)
+ -d <dir>/<name> : remove <name> from managed configs
+ -i <file> : input file to use (defaults to ./config.h)
- -c <dir> : check which config is in use
- -s <dir> : store \`config.h\` to <dir>
- -r <dir> : restore \`config.h\` from <dir>
+ -c <dir> : check which config is in use
+ -s <dir>/<name> : store \`config.h\` to <dir>/<name>
+ -r <dir>/<name> : restore \`config.h\` from <dir>/<name>
EOF
}
store() {
test -z "$1" && return 1
- test ! -d ${basedir}/$1 && mkdir ${basedir}/$1
+
+ # check if the user gave a filename or not
+ # and deduct filepath from that
+ if test `dirname $1` = '.'; then
+ dir=$1
+ filepath=${basedir}/${dir}/${default}
+ else
+ dir=`dirname $1`
+ filepath=${basedir}/$1
+ fi
+
+ # create directory if it does not exist
+ test ! -d ${basedir}/${dir} && mkdir -p $dir
# Copy from current dir to base directory
- cp -i ${cin} ${basedir}/$1/${cout}
+ cp -i ${cin} ${filepath}
}
restore() {
test -z "$1" && return 1
+ if test -f ${basedir}/$1; then
+ filepath=${basedir}/$1
+ else
+ filepath=${basedir}/$1/${default}
+ fi
+
# Copy from base dir to current directory
- cp ${basedir}/$1/${cout} ${cin}
+ cp ${filepath} ${cin}
}
list() {
t@@ -88,7 +105,6 @@ test ! -d ${basedir} && mkdir ${basedir}
# Set the default file names
cin=config.h
-cout=${default}
list=0
# standardize colors for shell output
t@@ -101,15 +117,11 @@ LS_COLORS="di=${color_dirs}:*.h=${color_conf}"
export LS_COLORS
# Parse options
-while getopts "chi:ld:n:s:r:u" opt; do
+while getopts "chi:ld:s:r:u" opt; do
case $opt in
# Check which config is in use
c) check;;
- # Wether to use default config or user config
- u) cout=${usercfg};;
- n) cout=${OPTARG};;
-
# Wipe the config given as argument
d) rm ${basedir}/$OPTARG;;