-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathzshrc.zsh
84 lines (77 loc) · 2.12 KB
/
zshrc.zsh
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -----------------------------------------------------------------------------
#
# zsh-python-prompt/zshrc.sh
#
# -----------------------------------------------------------------------------
#
# Version : 0.0.1
# Author : Yonchu <[email protected]>
# License : The MIT License (MIT)
# Repository : https://github.com/yonchu/zsh-python-prompt
# Last Change : 31 May 2016.
#
# Copyright (c) 2014 yonchu
#
# -----------------------------------------------------------------------------
# USAGE
# -----
#
# 1.Source this file.
#
# source /path/to/zsh-python-prompt/zshrc.zsh
#
# 2.Set the environmental variable ZSH_PYTHON_PROMPT to PROMPT or RPROMPT
#
# PROMPT+='$ZSH_PYTHON_PROMPT'
#
# 3.Enable environmental variables in PROMPT
#
# setopt prompt_subst
#
#
# Customaize
# ----------
#
# Change pyenv symbol.
#
# zstyle ':zsh-python-prompt:pyenv:' symbol '⌘ '
#
# -----------------------------------------------------------------------------
# Initialize settings.
function(){
local pyenv_expire_sec pyenv_symbol
zstyle -s ':zsh-python-prompt:pyenv:' expire_sec pyenv_expire_sec
if [[ -z $pyenv_expire_sec ]]; then
zstyle ':zsh-python-prompt:pyenv:' expire_sec 30
fi
zstyle -s ':zsh-python-prompt:pyenv:' symbol pyenv_symbol
if [[ -z $pyenv_symbol ]]; then
zstyle ':zsh-python-prompt:pyenv:' symbol '⌘ '
fi
}
# Add fpath
autoload -Uz is-at-least
if is-at-least 4.3.10; then
fpath=(${${funcsourcetrace[1]%:*}:A:h}/functions(N-/) ${fpath})
else
fpath=(${${funcsourcetrace[1]%:*}:h}/functions(N-/) ${fpath})
fi
# autoload
autoload -Uz add-zsh-hook
autoload -Uz zsh-python-prompt
autoload -Uz zsh-python-prompt-update
# Add hook function to preexec
add-zsh-hook preexec _zsh_python_prompt_preexec_hook_func
function _zsh_python_prompt_preexec_hook_func() {
case "$2" in
pyenv*)
zstyle ':zsh-python-prompt:' prompt_cache ''
;;
esac
}
# Add hook function to precmd
add-zsh-hook precmd _zsh_python_prompt_precmd_hook_func
function _zsh_python_prompt_precmd_hook_func() {
zsh-python-prompt-update
ZSH_PYTHON_PROMPT=$(zsh-python-prompt)
}