From 960d8647437f7127a6de167b974b8f7aafc77130 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Thu, 19 Jan 2023 10:04:51 +0100 Subject: Added first few utilities --- bin/google-oauth2 | 20 ++++++++++++++++++++ bin/menu-contacts | 9 +++++++++ bin/menu-lesspass | 22 ++++++++++++++++++++++ bin/menu-pass | 24 ++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100755 bin/google-oauth2 create mode 100755 bin/menu-contacts create mode 100755 bin/menu-lesspass create mode 100755 bin/menu-pass (limited to 'bin') diff --git a/bin/google-oauth2 b/bin/google-oauth2 new file mode 100755 index 0000000..3ef43b9 --- /dev/null +++ b/bin/google-oauth2 @@ -0,0 +1,20 @@ +#!/bin/sh +# +# Reads client secret and client token from STDIN (slightly better than as +# args, which are public), one in each line respectively. +# +# Calls into Google's OAuth2 API with that info to retrieve an access token, +# which is output to STDOUT. +# +# CLIENT_ID is the only argument taken by this script. + +CLIENT_ID=$1 +read -r CLIENT_SECRET +read -r REFRESH_TOKEN + +curl --silent \ + --data client_id=$CLIENT_ID \ + --data client_secret=$CLIENT_SECRET \ + --data grant_type=refresh_token \ + --data refresh_token=$REFRESH_TOKEN \ + 'https://www.googleapis.com/oauth2/v4/token' | jq -r .access_token \ No newline at end of file diff --git a/bin/menu-contacts b/bin/menu-contacts new file mode 100755 index 0000000..f2f3454 --- /dev/null +++ b/bin/menu-contacts @@ -0,0 +1,9 @@ +#!/bin/sh + +# Search in contact list built by khard using bemenu, outputs the selected +# option as FirstName LastName
+ +khard email --remove-first-line --parsable \ + | cut -f 1,2 \ + | bemenu -i -s -c -l 20 -W 0.5 -p '@' \ + | awk -F "\t" '{printf "%s <%s>\n", $2, $1}' diff --git a/bin/menu-lesspass b/bin/menu-lesspass new file mode 100755 index 0000000..3abdfd0 --- /dev/null +++ b/bin/menu-lesspass @@ -0,0 +1,22 @@ +#!/bin/sh +# +# Search in logins list using bemenu. Assumes a .config/logins.db.asc file exists +# with: +# DOMAIN_1 USERNAME_1 +# DOMAIN_2 USERNAME_2 +# ... +# DOMAIN_N USERNAME_N +# pairs, one per line. + +SELECTION=`gpg --decrypt $HOME/.config/logins.db.asc 2>/dev/null | bemenu -i -s -c -l 20 -W 0.2 -p '*'` +DOMAIN=`echo $SELECTION | cut -f 1 -d ' '` +USERNAME=`echo $SELECTION | cut -f 2 -d ' '` +OPTIONS=`echo $SELECTION | cut -f 1,2 -d ' ' --complement` + +if [ -z $USERNAME ] || [ -z $DOMAIN ]; then + exit 1 +fi + +# -c copies to clipboard +export LESSPASS_MASTER_PASSWORD=`pass lesspass` +lesspass $DOMAIN $USERNAME $OPTIONS -c 2>&1 >/dev/null diff --git a/bin/menu-pass b/bin/menu-pass new file mode 100755 index 0000000..74468d6 --- /dev/null +++ b/bin/menu-pass @@ -0,0 +1,24 @@ +#!/bin/sh +# +# Select which password from pass(1) to copy into the clipboard using an interactive menu +# +# Inspired by +# https://github.com/ibizaman/pass-clip/blob/9ef6e932e1149c07e991c82f916d018f3fbf0694/clip.bash + +PASSWORD_STORE_DIR="${PASSWORD_STORE_DIR:-$HOME/.password-store}" + +passfile=$(find -L "${PASSWORD_STORE_DIR}" \ + -path '*/.git' \ + -prune \ + -o \ + -iname '*.gpg' \ + -printf '%P\n' \ + | sed -e 's/.gpg$//' \ + | bemenu -i -s -c -l 20 -W 0.2 -p '*') + +if [ -z $passfile ] +then + exit 1 +else + pass show -c $passfile +fi -- cgit v1.2.3