helm/shell/common.sh

43 lines
1 KiB
Bash
Raw Normal View History

2016-10-19 07:56:37 -07:00
CACHE_DIR="$DOTFILES/shell/zsh/cache"
is-callable() { command -v "$1" >/dev/null; }
is-interactive() { [[ $- == *i* ]]; }
is-root() { [[ "$UID" -eq 0 ]]; }
2016-11-10 09:35:33 -08:00
is-ssh() { [[ $SSH_CONNECTION ]]; }
2016-10-19 07:56:37 -07:00
info() { printf "\r[ \033[00;34m..\033[0m ] $1\n"; }
success() { printf "\r\033[2K[ \033[00;32mOK\033[0m ] $1\n"; }
fail() { printf "\r\033[2K[\033[0;31mFAIL\033[0m] $1\n"; echo; exit; }
2016-11-16 06:06:41 -08:00
load () { source "$DOTFILES/$1"; }
2016-10-19 07:56:37 -07:00
loadall () {
2016-11-16 06:06:41 -08:00
for file in "$DOTFILES"/.enabled.d/${1//\//_}/${2:-*.*sh}; do
2016-10-19 07:56:37 -07:00
source "$file"
done
}
cache() {
2016-11-10 09:35:33 -08:00
[[ -z "$CACHE_DIR" ]] && error "Cache not set!"
[[ -d "$CACHE_DIR" ]] || mkdir -p "$CACHE_DIR"
2016-10-19 07:56:37 -07:00
is-callable "$1" || return 1
local cache="${CACHE_DIR}/$1-$(basename $SHELL)"
2016-11-10 09:35:33 -08:00
if [[ ! -f "$cache" && -s "$cache" ]]; then
2016-10-19 07:56:37 -07:00
echo "Caching $1"
$@ > "$cache" 2> /dev/null
fi
source $cache
}
cache-clear() {
2016-11-10 09:35:33 -08:00
[[ -d $CACHE_DIR ]] && rm -f "$CACHE_DIR/*"
2016-10-19 07:56:37 -07:00
}
repo() {
2016-11-10 09:35:33 -08:00
[[ -d $2 ]] || git clone --recursive "https://github.com/$1" "$2"
2016-10-19 07:56:37 -07:00
}
2016-11-10 09:35:33 -08:00
#
2016-11-16 06:06:41 -08:00
load shell/env.sh