-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzinc.zsh-theme
59 lines (50 loc) · 1.56 KB
/
zinc.zsh-theme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# vim: ft=zsh ts=2 sw=2 et fenc=utf-8
#
# ZINC
# Set zrllink utility.
if (( ${+commands[readlink]} )) && [[ "$(uname)" != "Darwin" ]]; then
function _zinc_zrllink() {
readlink -f $1
}
elif (( ${+commands[python]} )); then
function _zinc_zrllink() {
python -c "import os; print(os.path.realpath('$1'))"
}
elif (( ${+commands[perl]} )); then
function _zinc_zrllink() {
perl -MCwd -le 'print Cwd::abs_path(shift)' $1
}
else
printf '%b\n' "\033[0;31mZINC: Couldn't find a valid symlink resolver! Please modify your fpath manually!\033[0m"
fi
### install location detection
_ZINC_SCRIPTPATH="${(%):-%N}"
# echo $_ZINC_SCRIPTPATH
_ZINC_INSTALL_LOC="$(_zinc_zrllink $_ZINC_SCRIPTPATH)"
# echo $_ZINC_INSTALL_LOC
ZINC_INSTALL_DIR="${_ZINC_INSTALL_LOC%/*}"
function zinc_selfdestruct_setup () {
# TODO check if exist then add, instead of type unique
(( ${fpath[(I)"$ZINC_INSTALL_DIR/zinc_functions"]} )) || {
fpath+=("$ZINC_INSTALL_DIR/zinc_functions")
fpath+=("$ZINC_INSTALL_DIR/segments")
}
# remove self from precmd
precmd_functions=("${(@)precmd_functions:#zinc_selfdestruct_setup}")
builtin unfunction zinc_selfdestruct_setup
autoload -Uz +X prompt_zinc_setup async
autoload -Uz +X promptinit 2>&1 >/dev/null && {
promptinit
prompt zinc
} || {
prompt_zinc_setup
}
prompt_zinc_preexec
prompt_zinc_precmd
zle && zle .reset-prompt
}
autoload -Uz add-zsh-hook
add-zsh-hook precmd zinc_selfdestruct_setup
fpath+=("$ZINC_INSTALL_DIR/zinc_functions")
fpath+=("$ZINC_INSTALL_DIR/segments")
autoload -Uz +X prompt_zinc_setup async