aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-02-28 10:09:54 +0800
committerAaron LI <aaronly.me@outlook.com>2017-02-28 10:09:54 +0800
commite50980f025cd460282ecb2b2a3bed7c72250416b (patch)
tree98f1e9cb4ca8da4bd3d5b664cb8eaf4eb8d57b60
parentf69127878fa2ae49359d54cc31643f1a8f983ccd (diff)
downloaddotfiles-e50980f025cd460282ecb2b2a3bed7c72250416b.tar.bz2
Update command existence check function
Credit: * Stackoverflow: Check if a program exists from a Bash script Credit: https://stackoverflow.com/a/677212/4856091
-rw-r--r--_profile3
-rw-r--r--_zsh/40-functions.zsh6
2 files changed, 7 insertions, 2 deletions
diff --git a/_profile b/_profile
index 9eda66f..c71bd0b 100644
--- a/_profile
+++ b/_profile
@@ -31,8 +31,9 @@ _path_append() {
}
## Check the existence/accessibility of a command
+# Credit: https://stackoverflow.com/a/677212/4856091
_exists() {
- which $1 &> /dev/null
+ command -v "$1" >/dev/null 2>&1
}
## Check whether the program is running
diff --git a/_zsh/40-functions.zsh b/_zsh/40-functions.zsh
index 77db01c..2b078ed 100644
--- a/_zsh/40-functions.zsh
+++ b/_zsh/40-functions.zsh
@@ -5,8 +5,12 @@
#
## Check the existence/accessibility of a command
+# Credit: https://stackoverflow.com/a/677212/4856091
function exists() {
- which $1 &> /dev/null
+ # 'command' is POSIX-compliant and more portable;
+ # 'hash' only searches for commands;
+ # while 'type' also considers builtins and keywords.
+ type "$1" >/dev/null 2>&1
}
## Check whether the program is running