dotfiles/lib/functions.zsh

36 lines
433 B
Bash
Raw Normal View History

2018-06-15 13:43:04 +00:00
#!/usr/bin/env zsh
2018-02-23 09:38:24 +00:00
is_linux() {
2018-07-04 20:55:45 +00:00
[[ "$OSTYPE" == linux* ]]
2018-02-23 09:38:24 +00:00
}
is_macos() {
2018-07-04 20:55:45 +00:00
[[ "$OSTYPE" == darwin* ]]
2018-02-23 09:38:24 +00:00
}
2018-08-23 20:46:00 +00:00
is_android() {
[[ "$OSTYPE" == linux-android ]]
}
2018-02-23 09:38:24 +00:00
command_exists() {
command -v "$1" >/dev/null 2>&1
}
source_if_exists() {
2018-07-04 20:55:45 +00:00
[[ -f "$1" ]] && source "$1"
2018-02-23 09:38:24 +00:00
}
run_before() {
local command="$1"
local init_command="$2"
eval "$(cat <<EOF
$command() {
unfunction $command
$init_command
$command \$@
}
EOF
)"
}