scripts

scripts
git clone git://git.wimdupont.com/scripts.git
Log | Files | Refs | README | LICENSE

commit a4a1493a43d4e31e14f8033b89b1917080918aa1
parent f9fdd69a192eb7d7bb233661b79257b9382376a9
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sat, 19 Mar 2022 19:58:32 +0100

added pass scripts

Diffstat:
Abin/otp | 37+++++++++++++++++++++++++++++++++++++
Abin/pwu | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 92 insertions(+), 0 deletions(-)

diff --git a/bin/otp b/bin/otp @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + + +shopt -s nullglob globstar +font=$DMENU_FONT + +typeit=0 +if [[ $1 == "--type" ]]; then + typeit=1 + shift +fi + +if [[ -n $WAYLAND_DISPLAY ]]; then + dmenu=dmenu-wl + xdotool="ydotool type --file -" +elif [[ -n $DISPLAY ]]; then + dmenu=dmenu + xdotool="xdotool type --clearmodifiers --file -" +else + echo "Error: No Wayland or X11 display detected" >&2 + exit 1 +fi + +prefix=${PASSWORD_STORE_DIR-~/.password-store} +password_files=( "$prefix"/otp/**/*.gpg ) +password_files=( "${password_files[@]#"$prefix"/}" ) +password_files=( "${password_files[@]%.gpg}" ) + +password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" -fn "$font" "$@") + +[[ -n $password ]] || exit + +if [[ $typeit -eq 0 ]]; then + pass otp -c "$password" 2>/dev/null +else + pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool +fi diff --git a/bin/pwu b/bin/pwu @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + + +shopt -s nullglob globstar +font=$DMENU_FONT + +typeit=0 +if [[ $1 == "--type" ]]; then + typeit=1 + shift +fi + +if [[ -n $WAYLAND_DISPLAY ]]; then + dmenu=dmenu-wl + xdotool="ydotool type --file -" +elif [[ -n $DISPLAY ]]; then + dmenu=dmenu + xdotool="xdotool type --clearmodifiers --file -" +else + echo "Error: No Wayland or X11 display detected" >&2 + exit 1 +fi + +prefix=${PASSWORD_STORE_DIR-~/.password-store} +password_files=( "$prefix"/**/*.gpg ) +password_files=( "${password_files[@]#"$prefix"/}" ) +password_files=( "${password_files[@]%.gpg}" ) + +password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" -fn "$font" "$@") + +[[ -n $password ]] || exit + +if [[ $typeit -eq 0 ]]; then + if [[ "$password" == otp/* ]]; then + pass otp -c "$password" + else + selection=$(pass show "$password") + if [[ -z "$selection" ]]; then + exit + fi + username=$(echo "$selection" | sed -n 2p) + echo "$username" + echo "$username" | xclip -l 1 + pass -c "$password" 2>/dev/null + url=$(echo "$selection" | sed -n 3p) + if [[ "$url" ]]; then + openUrl=$(printf "yes\nno" | "$dmenu" -fn "$font" "$@" -p "Open $url in browser?") + if [[ "$openUrl" == yes ]]; then + xdg-open "$url" & disown + fi + fi + fi +else + pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool +fi