* .local/bin/passmenu: Import from password-store.
[~bandali/configs] / .local / bin / passmenu
CommitLineData
060e8940
AB
1#!/usr/bin/env bash
2
3# Copyright (c) 2014-2021 password-store contributors
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18shopt -s nullglob globstar
19
20typeit=0
21if [[ $1 == "--type" ]]; then
22 typeit=1
23 shift
24fi
25
26if [[ -n $WAYLAND_DISPLAY ]]; then
27 dmenu=dmenu-wl
28 xdotool="ydotool type --file -"
29elif [[ -n $DISPLAY ]]; then
30 dmenu=dmenu
31 xdotool="xdotool type --clearmodifiers --file -"
32else
33 echo "Error: No Wayland or X11 display detected" >&2
34 exit 1
35fi
36
37prefix=${PASSWORD_STORE_DIR-~/.password-store}
38password_files=( "$prefix"/**/*.gpg )
39password_files=( "${password_files[@]#"$prefix"/}" )
40password_files=( "${password_files[@]%.gpg}" )
41
42password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" "$@")
43
44[[ -n $password ]] || exit
45
46if [[ $typeit -eq 0 ]]; then
47 pass show -c "$password" 2>/dev/null
48else
49 pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool
50fi