helm/.common.sh
Henrik Lissner c4be365696 Global bash/zsh aliases + new programs
+ add common.sh and common aliases
+ add bin/{since,til}
+ add bin/project-root
+ extract btl alias into bin/transmission-list
2015-12-21 01:30:42 -05:00

31 lines
667 B
Bash

#!/bin/bash
DOTFILES="$HOME/.dotfiles"
CACHE_DIR="$HOME/.cache"
is-callable() { command -v "$1" >/dev/null; }
is-interactive() { [[ $- == *i* ]]; }
is-root() { [[ "$UID" -eq 0 ]]; }
is-ssh() { [[ "$SSH_CONNECTION" != '' ]]; }
load() { source "$DOTFILES/$1"; }
iload() { is-interactive && load "$1"; }
cache() {
if [[ -z "$CACHE_DIR" ]]; then
>&2 echo "Cache not set!"
return 1
fi
[[ ! -d "$CACHE_DIR" ]] && mkdir -p "$CACHE_DIR"
is-callable "$1" || return 1
local cache="${CACHE_DIR}/$1"
if ! [[ -f "$cache" && -s "$cache" ]]; then
echo "Caching $1"
$@ > "$cache" 2> /dev/null
fi
source $cache
}