Move functions.zsh into zshenv; add zsh/functions/

This commit is contained in:
Henrik Lissner 2015-12-17 05:29:57 -05:00
parent aff9b4434a
commit 5bb5e8c1b3
3 changed files with 25 additions and 31 deletions

View file

@ -1,31 +0,0 @@
is-callable() {
(( $+commands[$1] )) || (( $+functions[$1] )) || (( $+aliases[$1] ))
}
ZSH_CACHE_DIR="$HOME/.zsh/cache/$(hostname)"
[[ ! -d "$ZSH_CACHE_DIR" ]] && mkdir -p "$ZSH_CACHE_DIR"
cache() {
is-callable "$1" || return 1
local cache="${ZSH_CACHE_DIR}/$1-cache"
if [[ ! -s "$cache" ]]; then
echo "Caching $1"
$@ >| "$cache" 2> /dev/null
fi
source $cache
unset cache
}
is-mac() {
[[ "$OSTYPE" == "darwin"* ]]
}
is-deb() {
[[ "$OSTYPE" == "linux-gnu" ]]
}
is-cygwin() {
[[ "$OSTYPE" == "cygwin"* ]]
}
fpath=("${0:h}/functions" $fpath)

13
zsh/functions/cache Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env zsh
[[ -z "$ZSH_CACHE_DIR" ]] && exit 1
[[ ! -d "$ZSH_CACHE_DIR" ]] && mkdir -p "$ZSH_CACHE_DIR"
is-callable "$1" || return 1
local cache="${ZSH_CACHE_DIR}/$1-cache"
if [[ ! -s "$cache" ]]; then
echo "Caching $1"
$@ >| "$cache" 2> /dev/null
fi
source $cache

12
zshenv
View file

@ -1,3 +1,8 @@
is-callable() { (( $+commands[$1] )) || (( $+functions[$1] )) || (( $+aliases[$1] )); }
is-mac() { [[ "$OSTYPE" == "darwin"* ]]; }
is-deb() { [[ "$OSTYPE" == "linux-gnu" ]]; }
is-cygwin() { [[ "$OSTYPE" == "cygwin"* ]]; }
# Browser
export BROWSER='open'
@ -65,7 +70,14 @@ path=(
$path
)
local FUNC_DIR="$HOME/.dotfiles/zsh/functions"
fpath=(
~/.zsh/completion
"$FUNC_DIR"
$fpath
)
# Load all scripts from ./zsh/functions/*
for func in "$FUNC_DIR"/*(N-.x:t); do
autoload -Uz $func
done