Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 51 additions & 6 deletions rofi-pass
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ _image_viewer () {
feh -
}

_pwgen () {
pwgen "$@"
}

# We expect to find these fields in pass(1)'s output
URL_field='url'
USERNAME_field='user'
Expand All @@ -33,6 +37,7 @@ default_user="${ROFI_PASS_DEFAULT_USER-$(whoami)}"
default_user2=john_doe
password_length=12
fix_layout=false
edit_new_pass=false

# default shortcuts
autotype="Alt+1"
Expand Down Expand Up @@ -227,7 +232,10 @@ copyUser () {

copyField () {
checkIfPass
printf '%s' "${stuff[${copyfield}]}" | doClip
case $copyfield in
"OTP") printf '%s' $(generateOTP) | doClip ;;
*) printf '%s' "${stuff[${copyfield}]}" | doClip ;;
esac
clearUp
}

Expand Down Expand Up @@ -384,8 +392,17 @@ mainMenu () {

fields=$(printf '%s\n' "${password_temp[@]:1}" | awk '$1 ~ /:$/ || /otpauth:\/\// {$1=$1;print}')
declare -A stuff

# OTP entry is the first line
case "$password" in
"otpauth://"*|"${OTPmethod_field}"*)
stuff["OTP"]=""
;;
esac

stuff["pass"]=${password}


if [[ -n $fields ]]; then
while read -r LINE; do
unset _id _val
Expand Down Expand Up @@ -695,7 +712,7 @@ insertPass () {
"${USER}"
"${default_user}")

user=$(printf '%s\n' "${user_content[@]}" | _rofi -dmenu -mesg "Chose Username or type" -p "> ")
user=$(printf '%s\n' "${user_content[@]}" | _rofi -dmenu -mesg "Choose Username or type" -p "> ")
val=$?

if [[ $val -eq 1 ]]; then
Expand Down Expand Up @@ -727,30 +744,58 @@ insertPass () {
"---"
"${USERNAME_field}: ${user}"
"${URL_field}: ${url}")
printf '%s\n' "${pass_content[@]}" | PASSWORD_STORE_DIR="${root}" pass insert -m "${name}" > /dev/null && PASSWORD_STORE_DIR="${root}" pass edit "${name}"
printf '%s\n' "${pass_content[@]}" | PASSWORD_STORE_DIR="${root}" pass insert -m "${name}" > /dev/null
if [[ $edit_new_pass == "true" ]]; then
EDITOR=$EDITOR PASSWORD_STORE_DIR="${root}" pass edit "${name}"
fi

else
pass_content=("${pw}"
"---"
"${USERNAME_field}: ${user}")
printf '%s\n' "${pass_content[@]}" | PASSWORD_STORE_DIR="${root}" pass insert -m "${name}" > /dev/null && PASSWORD_STORE_DIR="${root}" pass edit "${name}"
printf '%s\n' "${pass_content[@]}" | PASSWORD_STORE_DIR="${root}" pass insert -m "${name}" > /dev/null
if [[ $edit_new_pass == "true" ]]; then
EDITOR=$EDITOR PASSWORD_STORE_DIR="${root}" pass edit "${name}"
fi
fi
else
if [[ $url == http* ]]; then
pass_content=("${pw}"
"---"
"${USERNAME_field}: ${user}"
"${URL_field}: ${url}")
printf '%s\n' "${pass_content[@]}" | PASSWORD_STORE_DIR="${root}" pass insert -m "${group}/${name}" > /dev/null && PASSWORD_STORE_DIR="${root}" pass edit "${group}/${name}"
printf '%s\n' "${pass_content[@]}" | PASSWORD_STORE_DIR="${root}" pass insert -m "${group}/${name}" > /dev/null
if [[ $edit_new_pass == "true" ]]; then
EDITOR=$EDITOR PASSWORD_STORE_DIR="${root}" pass edit "${group}/${name}"
fi

else
pass_content=("${pw}"
"---"
"${USERNAME_field}: ${user}")
printf '%s\n' "${pass_content[@]}" | PASSWORD_STORE_DIR="${root}" pass insert -m "${group}/${name}" > /dev/null
if [[ $edit_new_pass == "true" ]]; then
PASSWORD_STORE_DIR="${root}" pass edit "${group}/${name}"
EDITOR=$EDITOR PASSWORD_STORE_DIR="${root}" pass edit "${group}/${name}"
fi
fi
fi

askmenu_content=(
"Yes"
"No")

askGenMenu=$(printf '%s\n' "${askmenu_content[@]}" | _rofi -dmenu -p "Copy Password for ${name}? > ")
askgen_exit=$?

if [[ $askgen_exit -eq 1 ]]; then
exit
fi
if [[ $askGenMenu == "Yes" ]]; then
password=${pw}
copyPass
fi


}

help_msg () {
Expand Down