Skip to content

Commit

Permalink
add qrcode support
Browse files Browse the repository at this point in the history
  • Loading branch information
carnager committed Mar 22, 2018
1 parent 8a5a12e commit 75bda54
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.example
Expand Up @@ -7,6 +7,14 @@ _rofi () {
rofi -i -no-auto-select "$@"
}

# rofi-pass can create a qrcode for selected entry.
# This needs qrencode to be installed and an image
# viewer that supports reading from a pipe.
# Working viewers are feh and display
_image_viewer () {
feh -
}

# xdotool needs the keyboard layout to be set using setxkbmap
# You can do this in your autostart scripts (e.g. xinitrc)

Expand Down
40 changes: 40 additions & 0 deletions rofi-pass
Expand Up @@ -9,6 +9,10 @@ _rofi () {
rofi -no-auto-select -i "$@"
}

_image_viewer () {
sxiv -
}

# We expect to find these fields in pass(1)'s output
URL_field='url'
USERNAME_field='user'
Expand Down Expand Up @@ -42,11 +46,17 @@ type_menu="Alt+t"
help="Alt+h"
switch="Alt+x"
insert_pass="Alt+n"
qrcode="Alt+q"
previous_root="Shift+Left"
next_root="Shift+Right"

# Safe permissions
umask 077
img_viewer="display"

has_qrencode() {
command -v qrencode >/dev/null 2>&1
}

# get all password files and create an array
list_passwords() {
Expand Down Expand Up @@ -95,6 +105,31 @@ autopass () {
clearUp
}

generateQrCode() {
has_qrencode
if [[ $? -eq "1" ]]
then
echo "qrencode not found" | _rofi -dmenu
exit_code=$?
if [[ $exit_code -eq "1" ]]
then
exit
fi
fi
checkIfPass
pass "$selected_password" | head -n 1 | qrencode -d 300 -v 8 -l H -o - | _image_viewer
if [[ $? -eq "1" ]]
then
echo "" | _rofi -dmenu -mesg "Image viewer not defined or cannot read from pipe"
exit_value=$?
if [[ $exit_value -eq "1" ]]
then
exit
fi
fi
clearUp
}

openURL () {
checkIfPass
$BROWSER "$(PASSWORD_STORE_DIR="${root}" pass "$selected_password" | grep "${URL_field}: " | gawk '{sub(/:/,"")}{print $2}1' | head -1)"; exit;
Expand Down Expand Up @@ -308,6 +343,8 @@ mainMenu () {
-kb-custom-16 "${help}"
-kb-custom-17 "${switch}"
-kb-custom-18 "${insert_pass}"
-kb-custom-19 "${qrcode}")
args+=(
-kb-mode-previous "" # These keyboard shortcut options are needed, because
-kb-mode-next "" # Shift+<Left|Right> are otherwise taken by rofi.
-select "$entry"
Expand Down Expand Up @@ -402,6 +439,7 @@ mainMenu () {
23) actionMenu;;
24) copyMenu;;
27) insertPass;;
28) generateQrCode;;
esac
clearUp
}
Expand All @@ -421,6 +459,7 @@ helpMenu () {
printf '%s' "${autotype}: Autotype
${type_user}: Type Username
${type_pass}: Type Password
${qrcode}: Generate and display qrcode
---
${copy_name}: Copy Username
${copy_pass}: Copy Password
Expand Down Expand Up @@ -805,3 +844,4 @@ main () {
}

main "$@"

0 comments on commit 75bda54

Please sign in to comment.