use PASSWORD_STORE_DIR as fallback; use + for fieldnames

This commit is contained in:
Rasmus Steinke 2015-08-21 18:43:57 +02:00
parent 59f6a80e36
commit 6593af1cf1

20
addpass
View File

@ -4,29 +4,33 @@ source $HOME/.config/rofi-pass/config
if [[ -n "$2" && "$1" == "--root" ]]; then if [[ -n "$2" && "$1" == "--root" ]]; then
root="${2}" root="${2}"
elif [[ -n $root ]]; then
root=$root
elif [[ -n $PASSWORD_STORE_DIR ]]; then
root=$PASSWORD_STORE_DIR
else else
: root="$HOME/.password-store"
fi fi
if [[ $1 == "--help" || $1 == "=h" ]]; then if [[ $1 == "--help" || $1 == "=h" ]]; then
echo "add pass files for rofi-pass" echo "add pass files for rofi-pass"
echo "(C) 2015 Rasmus Steinke <rasi at xssn dot at>" echo "(C) 2015 Rasmus Steinke <rasi at xssn dot at>"
echo "" echo ""
echo "--root \"foobar\" Choose the database to use" echo "--root \"foobar\" Absolute path to password store"
echo " Needs to be first option." echo " Needs to be first option."
echo " Leave empty to use top level)" echo " Leave empty to use top level)"
echo "" echo ""
echo "-name \"foobar\" Needed field - filename of password file" echo "+name \"foobar\" Needed field - filename of password file"
echo "" echo ""
echo " Every field name has to start with \"-\"" echo " Every field name has to start with \"-\""
echo " Values should be quoted" echo " Values should be quoted"
echo "" echo ""
echo "Example:" echo "Example:"
echo "adduser --root private -user \"Richard\" -foo \"bar\" -autotype \"foo :tab user :tab pass\"" echo "adduser --root private +user \"Richard\" +foo \"bar\" +autotype \"foo :tab user :tab pass\""
exit exit
else else
if [[ $* != *"-name "* ]]; then if [[ $* != *"-name "* ]]; then
echo "Missing -name option. Try --help" echo "Missing +name option. Try --help"
exit exit
fi fi
fi fi
@ -34,14 +38,14 @@ fi
echo "Using database \"$root\"" echo "Using database \"$root\""
OIFS=$IFS; OIFS=$IFS;
IFS="-"; IFS="+";
fields="$@"; fields="$@";
fieldsArray=($fields); fieldsArray=($fields);
Name=$(printf '%s\n' "${fieldsArray[@]}" | grep "name " | cut -d ' ' -f 2- | sed -e 's/[[:blank:]]\+$//') Name=$(printf '%s\n' "${fieldsArray[@]}" | grep "name " | cut -d ' ' -f 2- | sed -e 's/[[:blank:]]\+$//')
read -p "Enter password for entry \"${Name}\" > " -s pass read -p "Enter password for entry \"${Name}\" > " -s pass
cd "${basedir}/${root}" cd "${root}"
group=$(find -type d -not -iwholename '*.git*' -printf '%d\t%P\n' | sort -r -nk1 | cut -f2- | rofi -dmenu -p "Choose Group > ") 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}"
@ -55,5 +59,5 @@ printEntry () {
done done
} }
printEntry | pass insert -m "${root}/${group}/${Name}" printEntry | pass insert -m "${group}/${Name}"