q.sh/q-pass
2024-09-09 02:03:52 +01:00

39 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
ENV_pass=pass
ENV_find=find
ENV_sed=sed
ENV_wl_copy=wl-copy
if [[ -z "$@" ]]; then
# Return a regular expression that should trigger
# this subcommand. q.sh will then pass control to
# this script whenever the input line matches.
echo "^p .*$"
elif [[ "$1" == "--hint" ]]; then
# This subcommand has no hints
shift
elif [[ "$1" == "--complete" ]]; then
shift
# Return a list of all accounts for which we store
# passwords. This will be used to provide a list of
# completions.
cd ~/.password-store
$ENV_find . -name "*.gpg" | $ENV_sed -E 's/\.\/(.*)\.gpg/\1 p \1/'
elif [[ "$1" == "--preview" ]]; then
shift
# This information will be displayed in the preview
# pane on the right.
echo "Will get password for $1"
elif [[ "$1" == "--run" ]]; then
shift
# This will be triggered when enter is pressed on
# one of the options. We now decrypt the password
# and place it to the clipboard.
NAME="$1"
$ENV_pass "$NAME" | (nohup $ENV_wl_copy -n 2>/dev/null &)
# A short sleep is needed to wait for child process
# to spawn before exiting.
sleep 0.01
fi