From 5bb5e8c1b3364db74a84bf995d1bdcc65643ae70 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 17 Dec 2015 05:29:57 -0500 Subject: [PATCH] Move functions.zsh into zshenv; add zsh/functions/ --- zsh/functions.zsh | 31 ------------------------------- zsh/functions/cache | 13 +++++++++++++ zshenv | 12 ++++++++++++ 3 files changed, 25 insertions(+), 31 deletions(-) delete mode 100644 zsh/functions.zsh create mode 100755 zsh/functions/cache 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