aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRasmus Steinke <rasi@xssn.at>2015-07-17 03:38:48 +0200
committerRasmus Steinke <rasi@xssn.at>2015-07-17 03:38:48 +0200
commit28513f96d96fe41fda8772cfe470c4bdacccb593 (patch)
tree91952c145ec0a2ed0adfb9a058afeb3e3963e897
parent923cc37d9af8326fd5e824806ee56ff04562fe94 (diff)
downloadrofi-pass-28513f96d96fe41fda8772cfe470c4bdacccb593.tar.gz
add error handling
-rwxr-xr-xaddpass40
1 files changed, 33 insertions, 7 deletions
diff --git a/addpass b/addpass
index 1234ba0..725df3e 100755
--- a/addpass
+++ b/addpass
@@ -8,27 +8,53 @@ else
:
fi
+if [[ $1 == "--help" || $1 == "=h" ]]; then
+ echo "add pass files for rofi-pass"
+ echo "(C) 2015 Rasmus Steinke <rasi at xssn dot at>"
+ echo ""
+ echo "--root \"foobar\" Choose the database to use"
+ echo " Needs to be first option."
+ echo " Leave empty to use top level)"
+ echo ""
+ echo "-name \"foobar\" Needed field - filename of password field"
+ echo ""
+ echo " Every field name has to start with \"-\""
+ echo " Values should be quoted"
+ echo ""
+ echo ""
+ echo "Example:"
+ echo "adduser --root private -user \"Richard\" -foo \"bar\" -CustomOrder \"foo :tab user :tab password\""
+ exit
+else
+ if [[ $* != *"-name "* ]]; then
+ echo "Missing -name option. Try --help"
+ exit
+ fi
+fi
+
+echo "Using database \"$root\""
+
OIFS=$IFS;
IFS="-";
-
fields="$@";
fieldsArray=($fields);
-name=$(printf '%s\n' "${fieldsArray[@]}" | grep "name" | cut -d ' ' -f 2- | sed -e 's/[[:blank:]]\+$//')
-read -p "Enter password for entry ${name}> " -s pass
+Name=$(printf '%s\n' "${fieldsArray[@]}" | grep "name " | cut -d ' ' -f 2- | sed -e 's/[[:blank:]]\+$//')
+read -p "Enter password for entry \"${Name}\" > " -s pass
-cd "${basedir}"
+cd "${basedir}/${root}"
group=$(find -type d -not -iwholename '*.git*' -printf '%d\t%P\n' | sort -r -nk1 | cut -f2- | rofi -dmenu -p "Choose Group > ")
-echo -e "\n\nStoring file ${name} in group ${group}"
+echo -e "\n\nStoring file ${Name} in group ${group}"
printEntry () {
echo -e "$pass\n---"
for ((i=1; i<${#fieldsArray[@]}; ++i)); do
field=$(echo "${fieldsArray[$i]}" | awk -F' ' '{print $1}')
option=$(echo "${fieldsArray[$i]}" | cut -d ' ' -f 2- | sed -e 's/[[:blank:]]\+$//')
- echo "$field: $option" | grep -Ev 'name:' #${fieldsArray[$i]}";
+ echo "$field: $option" | grep -Ev 'name:|--root|root:|^:' #${fieldsArray[$i]}";
done
}
-printEntry | pass insert -m "${root}/${group}/${name}"
+printEntry | pass insert -m "${root}/${group}/${Name}"
+