pash-posix: Swap to using hash

This commit is contained in:
Dylan Araps 2019-11-25 21:57:43 +00:00
parent 54b99259b7
commit c725ae97ee
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 13 additions and 12 deletions

View File

@ -46,12 +46,12 @@ pw_copy() {
if [ "$TMUX" ]; then if [ "$TMUX" ]; then
tmux load-buffer "$pass" tmux load-buffer "$pass"
else else
has xclip && echo "$pass" | xclip -selection clipboard hash xclip && echo "$pass" | xclip -selection clipboard
fi fi
} }
pw_list() { pw_list() {
if has tree; then if hash tree 2>/dev/null; then
tree --noreport tree --noreport
else else
find . -mindepth 1 find . -mindepth 1
@ -83,6 +83,15 @@ yn() {
glob "$REPLY" '[yY]' || return 1 && return 0 glob "$REPLY" '[yY]' || return 1 && return 0
} }
glob() {
# This is a simple wrapper around a case
# statement to allow for simple string
# comparisons against globs.
#
# Example: if glob "Hello World" '* World'; then
case $1 in $2) return 0; esac; return 1
}
die() { die() {
printf 'error: %s\n' "$1" >&2 printf 'error: %s\n' "$1" >&2
exit 1 exit 1
@ -104,20 +113,12 @@ Store location: export PASH_DIR=~/.local/share/pash
exit 1 exit 1
} }
has() {
command -v "$1" >/dev/null 2>&1
}
glob() {
case $1 in $2) return 0; esac; return 1
}
main() { main() {
[ "$1" = '-?' ] || [ -z "$1" ] && [ "$1" = '-?' ] || [ -z "$1" ] &&
usage usage
has gpg && gpg=gpg hash gpg 2>/dev/null && gpg=gpg
has gpg2 && gpg=gpg2 hash gpg2 2>/dev/null && gpg=gpg2
[ "$gpg" ] || die "GPG not found." [ "$gpg" ] || die "GPG not found."