Skip to content

Commit

Permalink
Use array for default users
Browse files Browse the repository at this point in the history
This also avoids shelling out to `whoami` always, and only uses `$USER`
by default.
  • Loading branch information
blueyed committed Nov 4, 2018
1 parent a2f1c3e commit 982a022
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
6 changes: 3 additions & 3 deletions config.example
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ clip_clear=45
# open new password entries in editor
edit_new_pass="true"

# default_user is also used for password files that have no user field.
#default_user="${ROFI_PASS_DEFAULT_USER-$(whoami)}"
#default_user2=mary_ann
# The first entry from default_users is also used for password files that have
# no user field.
#default_users=(${ROFI_PASS_DEFAULT_USER-$(whoami)})
#password_length=12

# Custom Keybindings
Expand Down
38 changes: 25 additions & 13 deletions rofi-pass
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ notify='false'
help_color=""
clip=primary
clip_clear=45
default_user="${ROFI_PASS_DEFAULT_USER-$(whoami)}"
default_user2=john_doe
default_users=("${ROFI_PASS_DEFAULT_USER-$(whoami)}")
password_length=12
fix_layout=false

Expand Down Expand Up @@ -418,12 +417,12 @@ mainMenu () {
fi
fi
if [[ -z "${stuff["${USERNAME_field}"]}" ]]; then
if [[ -n $default_user ]]; then
if [[ "$default_user" == ":filename" ]]; then
stuff["${USERNAME_field}"]="$(basename $selected_password)"
else
stuff["${USERNAME_field}"]="${default_user}"
fi
if [[ -n ${default_users[0]} ]]; then
if [[ "${default_users[0]}" == ":filename" ]]; then
stuff["${USERNAME_field}"]="$(basename $selected_password)"
else
stuff["${USERNAME_field}"]="${default_users[0]}"
fi
fi
fi
pass_content="$(for key in "${!stuff[@]}"; do printf '%s\n' "${key}: ${stuff[$key]}"; done)"
Expand Down Expand Up @@ -690,11 +689,7 @@ insertPass () {
exit
fi

user_content=("${default_user2}"
"${USER}"
"${default_user}")

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

if [[ $val -eq 1 ]]; then
Expand Down Expand Up @@ -791,6 +786,23 @@ main () {
config_file="$(get_config_file)"
[[ ! -z "$config_file" ]] && source "$config_file"

# Handle deprecated default_user/default_user2 config.
if [[ -z "${default_users[*]}" ]]; then
# shellcheck disable=SC2154
if [[ -n "$default_user" ]]; then
default_users+=("$default_user")
fi
# shellcheck disable=SC2154
if [[ -n "$default_user2" ]]; then
default_users+=("$default_user2")
fi
if [[ ${#default_users[@]} -eq 0 ]]; then
default_users=("$USER")
fi
else
default_users=("$USER")
fi

# create tmp dir
if [[ ! -d "$HOME/.cache/rofi-pass" ]]; then
mkdir "$HOME/.cache/rofi-pass"
Expand Down

0 comments on commit 982a022

Please sign in to comment.