diff --git a/zsh/functions.zsh b/zsh/functions.zsh deleted file mode 100644 index 65cb98a6..00000000 --- a/zsh/functions.zsh +++ /dev/null @@ -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) diff --git a/zsh/functions/cache b/zsh/functions/cache new file mode 100755 index 00000000..fe2fec50 --- /dev/null +++ b/zsh/functions/cache @@ -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 diff --git a/zshenv b/zshenv index 1f4fd232..33f24321 100644 --- a/zshenv +++ b/zshenv @@ -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