-
Notifications
You must be signed in to change notification settings - Fork 6
/
.sh_advanced_rc
104 lines (86 loc) · 2.47 KB
/
.sh_advanced_rc
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/not/executable/bash
if ! has declare; then
# the below stuff needs arrays, but we don't have any: bail
return 0
fi
# completions for travis, added by travis gem
. ~/.sh_lib/functions.d/trysource.sh
trysource ~/.travis/travis.sh
if [ "${BASH:-}" ]; then
# enable precmd_functions and chpwd_functions, for zsh compatibility
. ~/.sh_lib/bash-precmd.sh
. ~/.sh_lib/bash-chpwd.sh
fi
# Reset our state, so that we can (re-)source this file idempotently.
# Anything that's mutated (rather than overwritten) should be listed here.
typeset -ga preexec_functions=()
typeset -ga precmd_functions=()
# VCS detection
__vcs() {
return 0 # too slow!
candidate="$(git rev-parse --show-toplevel 2>&-)"
if [ $? -eq 0 ]; then
export VCS=git
else
candidate="$(hg showconfig bundle.mainreporoot)" # Too slow!
if [ $? -eq 0 ]; then
export VCS=hg
else
candidate="$(timeout -sINT -k2 1 p4 info | grep '^Client root:' | sed 's/.* //')"
if [ "$candidate" ]; then
export VCS=p4
else
TOP=/
unset VCS VCS_PROMPT1
return 0
fi
fi
fi
export VCS_TOP="$candidate"
VCS_PROMPT1="($VCS:$(basename "$(sed 's@'"$HOME"'@~@' <<< "$VCS_TOP")")"
}
__vcs_branch() {
return 0 # too slow!
if [ "$VCS" = "git" ]; then
export VCS_BRANCH="$(git branch-name 2>/dev/null)" # too slow!
elif [ "$VCS" = "hg" ]; then
export VCS_BRANCH="{hg-branch})"
# FIXME: hg too painfully slow. needs async, and hg optimization
#export VCS_BRANCH="$(hg id -btB | xargs -n1 | grep -Exv 'default|tip' | tr '\n' ' ')"
else
unset VCS_BRANCH
fi
if [ "$VCS_BRANCH" ]; then
VCS_PROMPT2=" $VCS_BRANCH) "
elif [ "$VCS" ]; then
VCS_PROMPT2=") "
else
VCS_PROMPT2=""
fi
}
precmd_functions+=(tmux_env __vcs_branch)
chpwd_functions+=(__vcs)
. ~/.sh_lib/functions.d/source_dir.sh
source_dir ~/.sh_plugins.d
# extra shell settings for work
trysource ~/private-dotfiles/.sh_advanced_rc
DIRENV="$HOMEBREW_PREFIX/bin/direnv"
if ! [[ -x "$DIRENV" ]]; then
cat >&2 <<'EOF'
NOTE: `direnv` is not installed. To fix:
brew install direnv
EOF
fi
_direnv_hook() {
if [[ -x "$DIRENV" ]]; then
trap -- '' SIGINT;
# They don't support 'export sh'. Weird.
eval "$("$DIRENV" export bash)";
trap - SIGINT;
fi
}
# always install the hook, so `brew install direnv` will "just work"
precmd_functions+=(_direnv_hook)
# this is in the default zsh setup, but I can't see any reason for it:
#chpwd_functions+=(_direnv_hook)
# vim:ft=sh