-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.common.ksh
More file actions
150 lines (128 loc) · 3.13 KB
/
base.common.ksh
File metadata and controls
150 lines (128 loc) · 3.13 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/ksh
#
# Copyright (c) 2001-2025 Matthew Pearson <matthewpearson@gmail.com>.
#
# These scripts are free. There is no warranty; your mileage may vary.
# Visit http://creativecommons.org/licenses/by-nc-sa/4.0/ for more details.
#
# shell commands executed each time a bash or ksh shell starts
#
[ -f "$HOME/.profile" ] && . "$HOME/.profile"
CDPATH=".:${HOME}:__G_WORKSPACE__"
unset MAILCHECK
if [ -d "$HOME/.autoenv" ]
then
. "$HOME/.autoenv/activate.sh"
else
alias autoenv_init=
fi
# internal variable used by update_title and redo
if [ "$BASH" ]
then
_shell=bash # some bashes id themselves as /bin/sh
else
_shell="$(basename "$SHELL")"
fi
is_remote_tty()
{
wholine="$(who -m --lookup 2>/dev/null)"
[ "$?" -eq 0 ] || wholine="$(who -m)"
[ ! "$wholine" ] || \
[ "$(echo "$wholine" | cut -sd\( -f 2 | \
sed -e 's/[:0.)]//g' -e 's/unix//')" ] && echo 1 || echo
}
# see https://gist.github.com/bamanzi/5875262
git_repo_name()
{
top_dir="$(git rev-parse --git-dir 2>/dev/null)"
if [ "$top_dir" = .git ]
then
basename "$PWD"
elif [ "$top_dir" ]
then
dirname "$top_dir" | xargs basename
fi
}
if [[ "$TTY" != *console ]] &&
[ "$TERM" ] && [ -f "$HOME/.dircolors" ] && \
[ "$(grep -c "[^-a-z]$TERM$" "$HOME/.dircolors")" -eq 1 ]
then
#
# other ways of setting the terminal title:
# ^[ is an ansi escape (^Q-esc); ^G is a bell (^Q-^G)
#
# printf '\e]2;%s\a' # bash only
# printf '\033]2;%s\033' # darwin only
# printf ']2;%s'" # SunOS only
#
set_terminal_title()
{
printf '\033]2;%s\007' "$*" # works on most systems
}
set_tab_title()
{
printf '\033]1;%s\007' "$*" # works on iterm2
}
update_titles()
{
_ppath=$(dirs +0 | sed -e 's|\([^/]\)$|\1/|' \
-e 's|.\{1,\}\(\(/[^/]*\)\{6,6\}\)$|...\1|')
if [ ! "$(is_remote_tty)" ]
then
_host="localhost"
elif [ "$THOST" ] && [ "$THOST" != "$HOST" ]
then
_host="$THOST"
else
_host="$HOST"
fi
if [ "$USER" != __G_USER__ ] || [ "$USER" = admin ]
then
_string="$USER@$_host"
else
_string="$_host"
fi
_string="$_string $_ppath"
[ "$WSNAME" ] && [ "$WSNAME" != "None" ] && _string="$_string — $WSNAME"
tab2='['"$(git_repo_name)"']'
[ "$tab2" = '[]' ] && tab2="$(basename "$(dirs +0)")"
set_tab_title "$_host" "$tab2"
set_terminal_title "$(printf '%s\n' "$_string")"
unset _host _ppath _string
}
else
set_terminal_title() { :; }
set_tab_title() { :; }
update_titles() { :; }
fi
update_titles
redo()
{
deactivate 2>/dev/null
hash -r
# shellcheck disable=SC2269
PATH="$PATH"
_ENV_PROFILED='' . "${HOME}/.${_shell}rc"
autoenv_init
# there are lots of reasons to not call xrdb
if [ "$USER" != root ] && [ -r "$XENVIRONMENT" ] && [ "$DISPLAY" ]
then
xrdb -remove
xrdb -load "$XENVIRONMENT"
fi
}
if [ -f "${HOME}/opt/stderred/build/libstderred.dylib" ]
then
if [ ! "$DYLD_INSERT_LIBRARIES" ]
then
export DYLD_INSERT_LIBRARIES="${HOME}/opt/stderred/build/libstderred.dylib${DYLD_INSERT_LIBRARIES:+:$DYLD_INSERT_LIBRARIES}"
fi
fi
if [ -f "${HOME}/opt/stderred/build/libstderred.so" ]
then
if [ ! "$LD_PRELOAD" ]
then
export LD_PRELOAD="${HOME}/opt/stderred/build/libstderred.so${LD_PRELOAD:+:$LD_PRELOAD}"
fi
fi
#EOF __TAGGED__