commit d5aae23753d6567e53ab612c14c55bc48ebe3fb0
parent 50d7d9a8214dd4e1d268800d48aa8364a831b95e
Author: Wim Dupont <wim@wimdupont.com>
Date: Tue, 2 Aug 2022 20:36:03 +0200
encr & otp - allow pwd file as argument
Diffstat:
M | README.adoc | | | 9 | +++++---- |
M | bin/otp | | | 31 | ++++++++++++++++++++++++++++++- |
M | bin/pwu | | | 74 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- |
3 files changed, 107 insertions(+), 7 deletions(-)
diff --git a/README.adoc b/README.adoc
@@ -21,7 +21,7 @@ Decrypts a GPG encrypted TAR file.
== ./bin/encr
Archives a given file or directory as a TAR file and encrypts it with GPG using symmetric or asymmetric encryption. By default it uses symmetric encryption and looks for encrypted
-file "~/sym-pwd.gpg" to use its content as password.
+file "~/.sym-pwd.gpg" to use its content as password.
== ./bin/mpvd
@@ -35,7 +35,7 @@ Uses dmenu to browse through music directory, including option to shuffle when c
== ./bin/otp
-Lists files safed under the "~/.password-store/totp/" directory in dmenu and generates TOTP codes based on chosen file.
+Lists files safed under the "~/.password-store/totp/" directory in dmenu or as argument and generates TOTP code based on chosen file.
.Requires:
@@ -45,12 +45,13 @@ Lists files safed under the "~/.password-store/totp/" directory in dmenu and gen
== ./bin/pwu
-Lists files safed under the "~/.password-store/" directory in dmenu. The chosen file gets opened using pass followed by:
+Lists files safed under the "~/.password-store/" directory in dmenu or as argument. The chosen file gets opened using pass followed by:
* password (first line) get saved in clipboard
* username (second line) gets saved in primary using xclip
* URL (third line) gets opened in default browser using xdg-open
-Only first line is mandatory for this script to be useful, usernames en URL's can be added to files where and when preferred.
+Only first line is mandatory for this script to be useful, usernames en URL's can be added to files where and when preferred. If there exists a file under the the "otp/" directory
+for the same name as the chosen file then pass-otp will be used to copy the OTP to the clipboard after a prompt.
.Requires:
diff --git a/bin/otp b/bin/otp
@@ -3,8 +3,9 @@
shopt -s nullglob globstar
font=$DMENU_FONT
-
+value=$1
typeit=0
+
if [[ $1 == "--type" ]]; then
typeit=1
shift
@@ -26,6 +27,34 @@ password_files=( "$prefix"/otp/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )
+function use_arg_file () {
+ pass otp -c "$1" 2>/dev/null
+ exit;
+}
+
+if [ -n "${value}" ]; then
+ shift
+ let i=0
+ for file in "${password_files[@]}"
+ do
+ if [[ "$file" =~ "${value}" ]] ; then
+ argFile="${file}"
+ let i++
+ fi
+ done
+
+ if [ "$i" == 1 ]; then
+ use_arg_file "${argFile}"
+ else
+ if [ "$i" == 0 ]; then
+ echo "Found no otp files for \"${value}\"."
+ fi
+ if [ "$i" -gt 1 ]; then
+ echo "Found more than one possible otp file for \"${value}\"."
+ fi
+ fi
+fi
+
password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" -fn "$font" -i "$@")
[[ -n $password ]] || exit
diff --git a/bin/pwu b/bin/pwu
@@ -2,9 +2,11 @@
shopt -s nullglob globstar
-font=$DMENU_FONT
+font=$DMENU_FONT
+value=$1
typeit=0
+
if [[ $1 == "--type" ]]; then
typeit=1
shift
@@ -26,6 +28,73 @@ password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )
+function use_arg_file () {
+ password=$1
+ pass -c "${password}"
+ creds=$(pass show "${password}")
+ echo "${creds}" | sed -n 2p | xclip
+ url=$(echo "${creds}" | sed -n 3p)
+
+ if [[ -n "$url" ]]; then
+ xdg-open "${url}" >/dev/null 2>&1 & disown
+ fi
+ use_otp -q $password
+ exit;
+}
+
+function use_otp () {
+ local OPTIND
+ quiet=0
+
+ while getopts "q" arg; do
+ case $arg in
+ q) quiet=1;;
+ esac
+ done
+ shift $((OPTIND-1))
+ file=$1
+
+ otp_files=( $( printf '%s\n' "${password_files[@]}" | grep 'otp/*' ) )
+ for otp_file in "${otp_files[@]}"
+ do
+ if [[ "$otp_file" == "otp/${file}" ]] ; then
+ if [[ $quiet == 0 ]]; then
+ read -p "Press enter to continue"
+ copyOtp=$(printf "yes\nno" | "$dmenu" -fn "$font" -i -p "Copy OTP to clipboard?")
+ if [[ "$copyOtp" == yes ]]; then
+ pass otp -c "$otp_file" 2>/dev/null
+ fi
+ else
+ read -p "Press enter to copy OTP to clipboard."
+ pass otp -c "$otp_file" 2>/dev/null
+ fi
+ fi
+ done
+}
+
+if [ -n "${value}" ]; then
+ shift
+ let i=0
+ for file in "${password_files[@]/#otp*}"
+ do
+ if [[ "$file" =~ "${value}" ]] ; then
+ argFile="${file}"
+ let i++
+ fi
+ done
+
+ if [ "$i" == 1 ]; then
+ use_arg_file "${argFile}"
+ else
+ if [ "$i" == 0 ]; then
+ echo "Found no password files for \"${value}\"."
+ fi
+ if [ "$i" -gt 1 ]; then
+ echo "Found more than one possible password file for \"${value}\"."
+ fi
+ fi
+fi
+
password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" -fn "$font" -i "$@")
[[ -n $password ]] || exit
@@ -46,9 +115,10 @@ if [[ $typeit -eq 0 ]]; then
if [[ "$url" ]]; then
openUrl=$(printf "yes\nno" | "$dmenu" -fn "$font" -i "$@" -p "Open $url in browser?")
if [[ "$openUrl" == yes ]]; then
- xdg-open "$url" & disown
+ xdg-open "$url" >/dev/null 2>&1 & disown
fi
fi
+ use_otp "$password"
fi
else
pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool