diff --git a/pash-posix b/pash-posix index 0f38f03..14288f8 100755 --- a/pash-posix +++ b/pash-posix @@ -46,12 +46,12 @@ pw_copy() { if [ "$TMUX" ]; then tmux load-buffer "$pass" else - has xclip && echo "$pass" | xclip -selection clipboard + hash xclip && echo "$pass" | xclip -selection clipboard fi } pw_list() { - if has tree; then + if hash tree 2>/dev/null; then tree --noreport else find . -mindepth 1 @@ -83,6 +83,15 @@ yn() { 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() { printf 'error: %s\n' "$1" >&2 exit 1 @@ -104,20 +113,12 @@ Store location: export PASH_DIR=~/.local/share/pash exit 1 } -has() { - command -v "$1" >/dev/null 2>&1 -} - -glob() { - case $1 in $2) return 0; esac; return 1 -} - main() { [ "$1" = '-?' ] || [ -z "$1" ] && usage - has gpg && gpg=gpg - has gpg2 && gpg=gpg2 + hash gpg 2>/dev/null && gpg=gpg + hash gpg2 2>/dev/null && gpg=gpg2 [ "$gpg" ] || die "GPG not found."