rofi-pass/addpass

64 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
source $HOME/.config/rofi-pass/config
if [[ -n "$2" && "$1" == "--root" ]]; then
root="${2}"
elif [[ -n $root ]]; then
root=$root
elif [[ -n $PASSWORD_STORE_DIR ]]; then
root=$PASSWORD_STORE_DIR
else
root="$HOME/.password-store"
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\" Absolute path to password store"
echo " Needs to be first option."
echo " Leave empty to use top level)"
echo ""
echo "+name \"foobar\" Needed field - filename of password file"
echo ""
echo " Every field name has to start with \"-\""
echo " Values should be quoted"
echo ""
echo "Example:"
echo "adduser --root private +user \"Richard\" +foo \"bar\" +autotype \"foo :tab user :tab pass\""
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
cd "${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}"
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:|--root|root:|^:' #${fieldsArray[$i]}";
done
}
printEntry | pass insert -m "${group}/${Name}"