-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.zsh_functions
More file actions
129 lines (119 loc) · 3.74 KB
/
.zsh_functions
File metadata and controls
129 lines (119 loc) · 3.74 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
if [[ -f ~/.functions ]]; then
source ~/.functions
fi
# better ls'ing of hidden files
function __ls() {
if (( $# > 3 )); then
print "${argv[3]}:"
__ls_helper "${1}" "${2}" ${argv[3]}
for arg in ${argv[4,$#]}; do
print
print "${arg}:"
__ls_helper "${1}" "${2}" "${arg}"
done
else
__ls_helper "${1}" "${2}" "${3:-$PWD}"
fi
}
function __ls_helper() {
eval "args=(\"${3}\"/${2}(N))"
if (( ${#args} > 0 )); then
(cd "${3}" && eval "ls ${1} ${2}")
fi
}
# title shortcut {{{1
function __xtermicontitle {
print -nP "\e]0;${1}\a"
}
function __xtermicon {
print -nP "\e]1;${1}\a"
}
function __xtermtitle {
print -nP "\e]2;${1}\a"
}
function __screentitle {
print -nP "\ek${1}\e\\"
}
# git ps1 stuff {{{1
function __git_ps1 {
local g r b w i s u c p f
# quit early if no .git
g=$(git rev-parse --git-dir 2>/dev/null) || return
if [[ -f $g/rebase-merge/interactive ]]; then
r='|REBASE-i'
b=$(cat $g/rebase-merge/head-name)
elif [[ -d $g/rebase-merge ]]; then
r='|REBASE-m'
b=$(cat $g/rebase-merge/head-name)
else
if [[ -d $g/rebase-apply ]]; then
if [[ -f $g/rebase-apply/rebasing ]]; then
r='|REBASE'
elif [[ -f $g/rebase-apply/applying ]]; then
r='|AM'
else
r='|AM/REBASE'
fi
elif [[ -f $g/MERGE_HEAD ]]; then
r='|MERGING'
b=$(git symbolic-ref HEAD 2>/dev/null)
elif [[ -f $g/CHERRY_PICK_HEAD ]]; then
r='|CHERRY-PICKING'
b=$(git symbolic-ref HEAD 2>/dev/null)
else
[[ -f $g/BISECT_LOG ]] && r='|BISECTING'
# b=$(git symbolic-ref HEAD 2>/dev/null) || \
# b=$(git describe --exact-match HEAD 2>/dev/null) || \
# b=$(cut -c1-7 $g/HEAD)...
fi
b=$(git symbolic-ref HEAD 2>/dev/null) || {
b=$(
case ${GIT_PS1_DESCRIBE_STYLE} in
(contains)
git describe --contains HEAD ;;
(branch)
git describe --contains --all HEAD ;;
(describe)
git describe HEAD ;;
(* | default)
git describe --tags --exact-match HEAD ;;
esac 2>/dev/null) ||
b=$(cut -c1-7 $g/HEAD 2>/dev/null) ||
b='unknown'
b="(${b})"
}
fi
if [[ $(git rev-parse --is-inside-git-dir 2>/dev/null) == 'true' ]]; then
if [[ $(git rev-parse --is-bare-repository 2>/dev/null) == 'true' ]]; then
c='BARE:'
else
b='GIT_DIR!'
fi
elif [[ $(git rev-parse --is-inside-work-tree 2>/dev/null) == 'true' ]]; then
if [[ -n ${GIT_PS1_SHOWDIRTYSTATE} ]]; then
if [[ $(git config --bool bash.showDirtyState) != 'false' ]]; then
git diff --no-ext-diff --quiet --exit-code || w='*'
if git rev-parse --quiet --verify HEAD >/dev/null ; then
git diff-index --cached --quiet HEAD -- || i='+'
else
i='#'
fi
fi
fi
if [[ -n ${GIT_PS1_SHOWSTASHSTATE} ]]; then
git rev-parse --verify refs/stash >/dev/null 2>&1 && s='$'
fi
if [[ -n ${GIT_PS1_SHOWUNTRACKEDFILES} ]]; then
if [[ -n $(git ls-files --others --exclude-standard) ]]; then
u='%%' # doubled for literal % with printf
fi
fi
# if [[ -n ${GIT_PS1_SHOWUPSTREAM} ]]; then
# __git_ps1_show_upstream
# fi
fi
f="${w}${i}${s}${u}"
printf "${1:- (%s)}" "${c}${b##refs/heads/}${f:+ $f}${r}${p}"
}
# }}}1
# vim: fdm=marker