From 040fce18250f6a4febdfd33559a709adce39940e Mon Sep 17 00:00:00 2001
From: Salt <rehashedsalt@cock.li>
Date: Tue, 5 Feb 2019 12:38:56 -0600
Subject: [PATCH] .profile: Use wrapper function for command detection

---
 .profile | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/.profile b/.profile
index e21b617d..7e875e72 100755
--- a/.profile
+++ b/.profile
@@ -60,8 +60,14 @@ PATH="$desiredpath:$PATH"
 # Source ~/.functions, if it exists
 [ -r "$HOME/.functions" ] && [ "$_baseshell" != "sh" ] && . "$HOME/.functions"
 
+# Define a require function
+has() {
+	[ -z "$1" ] && return 1
+	command -v "$1" > /dev/null 2>&1
+}
+
 # Grab pip completion, if it exists
-if command -v pip > /dev/null 2>&1; then
+if has pip; then
 	case "$_baseshell" in
 		*bash)
 			if ! [ -f "$HOME/.pip-completion-bash" ]; then
@@ -83,13 +89,13 @@ if command -v pip > /dev/null 2>&1; then
 fi
 
 # Set up go, if we have it
-if command -v go > /dev/null 2>&1; then
+if has go; then
 	export GOPATH="$HOME/.local/go"
 	[ "${PATH#*$GOPATH}" = "$PATH" ] && export PATH="$PATH:$GOPATH/bin"
 fi
 
 # Grab dircolors, if it exists
-if command -v dircolors > /dev/null 2>&1; then
+if has dircolors; then
 	dircolorsfile="$HOME/.config/dircolors"
 	if [ -r "$dircolorsfile" ]; then
 		eval "$(dircolors "$dircolorsfile")"
@@ -108,27 +114,27 @@ done
 alias e='$EDITOR'
 
 # If emerge exists, add emerge aliases
-if command -v emerge > /dev/null 2>&1 ; then
+if has emerge; then
 	alias e-depclean='sudo emerge -a --depclean'
 	alias e-inst='sudo emerge -a --jobs --tree --quiet-build y'
 	alias e-upgrade='sudo emerge -DNUua --jobs --tree --quiet-build y --with-bdeps=y --keep-going --backtrack=1000 @world'
 	alias e-newuse='sudo emerge -Uva --jobs --tree --quiet-build y @world'
 	alias e-search='emerge -s'
 	alias e-sync='sudo emerge --sync'
-	if command -v eclean > /dev/null 2>&1; then
+	if has eclean; then
 		alias e-cleanup='sudo eclean -d distfiles && sudo eclean -d packages'
 	fi
 fi
 
 # If we have instantmusic, add aliases for that
-if command -v instantmusic > /dev/null 2>&1; then
+if has instantmusic; then
 	alias song='instantmusic -p -s'
 	alias songp='instantmusic -s'
 fi
 
 # Dictionary aliases
-if ! command -v define > /dev/null 2>&1; then
-	if command -v mate-dictionary > /dev/null 2>&1; then
+if ! has define; then
+	if has mate-dictionary; then
 		alias define='mate-dictionary -n --look-up'
 	fi
 fi
@@ -242,5 +248,6 @@ case "$_baseshell" in
 esac
 
 # Clean up
-unset _baseshell
+unset -v _baseshell
+unset -f has