Move functions.zsh into zshenv; add zsh/functions/
This commit is contained in:
parent
aff9b4434a
commit
5bb5e8c1b3
|
@ -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
13
zsh/functions/cache
Executable 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
12
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
|
||||
|
|
Loading…
Reference in a new issue