92 lines
2.8 KiB
Bash
92 lines
2.8 KiB
Bash
#!/usr/bin/env bash
|
|
# pass reveal - Password Store Extension (https://www.passwordstore.org/)
|
|
# Copyright (C) 2021
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
# []
|
|
|
|
VERSION="0.0.1"
|
|
PASSWORD_STORE_LOCATION="~/password-store"
|
|
|
|
cmd_reveal_usage() {
|
|
cat <<-_EOF
|
|
Usage:
|
|
$PROGRAM reveal [search-terms]
|
|
Searches and displays passwords from \$PASSWORD_STORE_LOCATION.
|
|
A simple wrapper over pass show, find, and grep.
|
|
Based on the pass reveal extension.
|
|
$PROGRAM reveal help
|
|
Prints this help message.
|
|
$PROGRAM reveal version
|
|
Prints the version number.
|
|
|
|
Example: $PROGRAM reveal web
|
|
Searches for any files in $PASSWORD_STORE_LOCATION whose filenames contain
|
|
the keyword "web"
|
|
For installation place this bash script file "reveal.bash" into
|
|
the passwordstore extension directory specified with \$PASSWORD_STORE_EXTENSIONS_DIR.
|
|
By default this is ~/.password-store/.extensions.
|
|
E.g. cp reveal.bash ~/.password-store/.extensions
|
|
Give the file execution permissions:
|
|
E.g. chmod 700 ~/.password-store/.extensions/reveal.bash
|
|
Set the variable PASSWORD_STORE_ENABLE_EXTENSIONS to true to enable extensions.
|
|
E.g. export PASSWORD_STORE_ENABLE_EXTENSIONS=true
|
|
Source the bash completion file "pass-reveal.bash.completion" for bash completion.
|
|
E.g. source ~/.password-store/.bash-completions/pass-reveal.bash.completion
|
|
Type "pass reveal query" to make your first query
|
|
E.g. pass reveal query
|
|
_EOF
|
|
exit 0
|
|
}
|
|
|
|
cmd_reveal_version() {
|
|
echo $VERSION
|
|
exit 0
|
|
}
|
|
|
|
cmd_reveal_reveal() {
|
|
## [[ $# -gt 1 ]] && die "Too many arguments. At most 1 argument allowed."
|
|
|
|
# expect 0 or 1 argument
|
|
# ignore 2nd argument and higher
|
|
if [ $# -eq 0 ]; then
|
|
echo "Error: Query is empty"
|
|
else
|
|
|
|
ARGS="$@"
|
|
BEST_FIT="$(find ~/.password-store -type f -printf "%P\n" | grep -v '^\.' | grep -i "$ARGS" | sed 's/.gpg//' | head -1)"
|
|
if [ -z "$BEST_FIT" ]; then
|
|
# $STRING is empty
|
|
echo "No match found for $ARGS"
|
|
else
|
|
echo "Best match: $BEST_FIT"
|
|
pass show "$BEST_FIT"
|
|
pass show -c "$BEST_FIT"
|
|
fi
|
|
|
|
fi
|
|
}
|
|
|
|
case "$1" in
|
|
help | --help | -h)
|
|
shift
|
|
cmd_reveal_usage "$@"
|
|
;;
|
|
version | --version | -v)
|
|
shift
|
|
cmd_reveal_version "$@"
|
|
;;
|
|
*) cmd_reveal_reveal "$@" ;;
|
|
esac
|
|
exit 0 |