-
Notifications
You must be signed in to change notification settings - Fork 0
/
.util.zsh
114 lines (97 loc) · 2.35 KB
/
.util.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
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
autoload -Uz colors && colors
export PATH=~/bin:$PATH
function has() {
type "${1:?too few arguments}" &>/dev/null
}
# reload resets Completion function
function reload() {
local f
f=(~/.zsh/Completion/*(.))
unfunction $f:t 2>/dev/null
autoload -U $f:t
}
# is_login_shell returns true if current shell is first shell
function is_login_shell() {
[[ $SHLVL == 1 ]]
}
# is_git_repo returns true if cwd is in git repository
function is_git_repo() {
git rev-parse --is-inside-work-tree &>/dev/null
return $status
}
# is_screen_running returns true if GNU screen is running
function is_screen_running() {
[[ -n $STY ]]
}
# is_tmux_runnning returns true if tmux is running
function is_tmux_runnning() {
[[ -n $TMUX ]]
}
# is_screen_or_tmux_running returns true if GNU screen or tmux is running
function is_screen_or_tmux_running() {
is_screen_running || is_tmux_runnning
}
# shell_has_started_interactively returns true if the current shell is
# running from command line
function shell_has_started_interactively() {
[[ -n $PS1 ]]
}
# is_ssh_running returns true if the ssh deamon is available
function is_ssh_running() {
[[ -n $SSH_CLIENT ]]
}
# ostype returns the lowercase OS name
function ostype() {
echo ${(L):-$(uname)}
}
# os_detect export the PLATFORM variable as you see fit
function os_detect() {
export PLATFORM
case "$(ostype)" in
*'linux'*) PLATFORM='linux' ;;
*'darwin'*) PLATFORM='osx' ;;
*'bsd'*) PLATFORM='bsd' ;;
*) PLATFORM='unknown' ;;
esac
}
os_detect
# is_osx returns true if running OS is Macintosh
function is_osx() {
# os_detect
if [[ $PLATFORM == "osx" ]]; then
return 0
else
return 1
fi
}
alias is_mac=is_osx
# is_linux returns true if running OS is GNU/Linux
function is_linux() {
# os_detect
if [[ $PLATFORM == "linux" ]]; then
return 0
else
return 1
fi
}
# is_bsd returns true if running OS is FreeBSD
function is_bsd() {
# os_detect
if [[ $PLATFORM == "bsd" ]]; then
return 0
else
return 1
fi
}
# get_os returns OS name of the platform that is running
function get_os() {
local os
for os in osx linux bsd; do
if is_$os; then
echo $os
fi
done
}
function pp_paths() {
echo "$(tr ':' '\n' <<< \"$PATH\")"
}