From 60632a0ed4d83676756396ba0d04cac6a486ca89 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 11 Mar 2023 17:47:55 +0530 Subject: dpass: initial commit: dmenu wrapper for the standard unix password manager --- README.md | 4 +++ dpass | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100755 dpass diff --git a/README.md b/README.md index fed024e..ed94b18 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ they work on both xorg and wayland using dmenu and wmenu respectively. these scripts might use [nerd fonts](https://www.nerdfonts.com/), make sure you've installed them for the best experience. you can find more info about them below. +## dpass +dpass is the dmenu wrapper for the standard unix password manager, +run dpass -h from a terminal to see what it's capable of + ## damb - dmenu ambience listen to ambient music while working on somthing fun. audio files should be stored at ~/.local/share/damb/. damb also has a config file located diff --git a/dpass b/dpass new file mode 100755 index 0000000..e1592b2 --- /dev/null +++ b/dpass @@ -0,0 +1,111 @@ +#!/bin/sh + +pass_store_dir="${PASSWORD_STORE_DIR:-$HOME/.pass}" +menu="wmenu" + +die() +{ + : "${1:?}" + + command -v notify-send > /dev/null && + notify-send " dpass" "$1" + + printf "\033[31;1merr: %b\033[0m\n" "$1" + exit "${2:-1}" +} + +dep_check() +{ + : "${1:?}" + + for dep; do + command -v "$dep" 1>/dev/null || + die "$dep not found, please install it" 127 + done + + unset dep +} + +note() +{ + : "${1:?}" + + command -v notify-send > /dev/null && + notify-send "󰟵 dpass" "$1" +} + +search() +{ + # usage: search directory + pass_path="${1:?}" + + while [ -d "$pass_path" ] + do + pass_path="${pass_path}/$(printf '%s\n' "$pass_path"/* | + sed 's/.*\///g' | + "$menu" -l 25 -p "󰟵 ${pass_path##*/} ")" + + [ "$?" != 0 ] && + die "noting selected" + done + + pass_path="${pass_path#"${pass_store_dir}"/}" + pass_path="${pass_path%.gpg}" +} + +main() +{ + pass_path= + + [ -z "$WAYLAND_DISPLAY" ] && + menu="dmenu" + + dep_check "$menu" "pass" + + case "$1" in + -o) + search "$pass_store_dir" + pass "$pass_path" + ;; + -c) + if [ -z "$WAYLAND_DISPLAY" ] + then + dep_check "xclip" + else + dep_check "wl-copy" + fi + + search "$pass_store_dir" + pass --clip "$pass_path" + note "password copied to clipboard, will clear in 45 seconds." + ;; + -h|--help) + cat <<- EOF + Usage: dpass command + dmenu wrapper for the standard unix password manager + Commands: + -h show this help cruft + -o print the password to stdout + -c coppy the password to clipboard + -t type the password (default behaviour) + EOF + ;; + ""|-t) + if [ -z "$WAYLAND_DISPLAY" ] + then + dep_check "xdotool" + search "$pass_store_dir" + xdotool type --delay 20 "$(pass "$pass_path")" + else + dep_check "wtype" + search "$pass_store_dir" + wtype -d 20 "$(pass "$pass_path")" + fi + ;; + *) + die "${0##*/} $1, invalid usage" + ;; + esac +} + +main "$@" -- cgit v1.2.3