-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc.interactive
More file actions
219 lines (189 loc) · 5.35 KB
/
Copy pathbashrc.interactive
File metadata and controls
219 lines (189 loc) · 5.35 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
if [ -z "${TERM}" ] ||
[ "${TERM}" = "dumb" ]; then
eval `tset -s - | sed -e '1d'`
fi
if [ "${TERM}" = "screen" ] ||
[ "${TERM}" = "screen-w" ]; then
TERMTYPE=screen
elif [ "${TERM}" = "xterm-color" ] ||
[ "${TERM}" = "xterm-256color" ]; then
TERMTYPE=xterm
elif [ "${TERM}" = "emacs" ]; then
TERMTYPE=dumb
elif [ ! -z "${TERM}" ]; then
TERMTYPE="${TERM}"
else
TERMTYPE=dumb
fi
stty erase '^?' kill undef intr '^C' stop '^O' werase undef
if [ "${TERMTYPE}" != "dumb" ]; then
bind '"\e[5~":history-search-backward'
bind '"\e[6~":history-search-forward'
bind C-f:forward-word
bind C-b:backward-word
bind M-f:forward-char
bind M-b:backward-char
bind C-u:kill-whole-line
bind C-w:kill-region
# readline variables
bind "set show-all-if-ambiguous on"
bind "set page-completions off"
bind "set mark-symlinked-directories on"
fi
if [ ! -z "${DISPLAY}" ] &&
[ -z "${SSH_DISPLAY}" ]; then
SSH_DISPLAY="${DISPLAY}"
fi
export EDITOR=emacs
export BLOCKSIZE=K
export CVS_RSH=ssh
export RSYNC_RSH=ssh
if [ "${TERMTYPE}" = dumb ]; then
export PAGER="cat"
else
export PAGER="less -meiR"
fi
# set the prompt.
if [ ! -z "`type -t tput`" ]; then
t_bold_cmd="\[`tput bold`\]"
t_unbold_cmd="\[`tput sgr0`\]"
fi
if [ $UID -eq 0 ]; then
t_prompt_end='%'
else
t_prompt_end='»'
fi
export VIRTUAL_ENV_DISABLE_PROMPT=1
export NODE_VIRTUAL_ENV_DISABLE_PROMPT=1
function venv_prompt() {
if [ "${VIRTUAL_ENV##*/}" != "" ]; then
printf "$1" "${VIRTUAL_ENV##*/}"
fi
}
if [ "$TERMTYPE" = "xterm" ] ||
[ "$TERMTYPE" = "screen" ]; then
PS1="\[\e]0;[${HOST%.*}"'$(venv_prompt " (%s)")'"]:\w${t_prompt_end}\a\][${HOST%.*}"'$(venv_prompt " (%s)")'"]:${t_bold_cmd}\w${t_unbold_cmd}"'$(_dotfiles_scm_info ":%s")'"${t_prompt_end} "
else
PS1="[${HOST%.*}"'$(venv_prompt " (%s)")'"]:${t_bold_cmd}\w${t_unbold_cmd}${t_prompt_end} "
fi
function auto_env() {
local pwd="$(pwd)"
if [ ! -z "${AUTO_VIRTUAL_ENV_ROOT+x}" ]; then
case "${pwd}" in
${AUTO_VIRTUAL_ENV_ROOT}*)
;;
*)
deactivate
unset AUTO_VIRTUAL_ENV_ROOT
;;
esac
fi
if [ ! -z "${AUTOLOAD_ROOT+x}" ]; then
case "${pwd}" in
${AUTOLOAD_ROOT}*)
;;
*)
PYENV_PATH="$PYENV_PATH:$AUTOLOAD_ROOT/.pyenv-modules" module unload autoload
unset AUTOLOAD_ROOT
;;
esac
fi
while [ "$pwd" != "" ]; do
if [ -z "${AUTO_VIRTUAL_ENV_ROOT+x}" -a -e "${pwd}/.venv" ]; then
source ${pwd}/.venv/bin/activate
AUTO_VIRTUAL_ENV_ROOT="${pwd}"
fi
if [ -z "${AUTOLOAD_ROOT+x}" -a -e "${pwd}/.pyenv-modules/autoload.py" ]; then
AUTOLOAD_ROOT="${pwd}"
PYENV_PATH="$PYENV_PATH:$AUTOLOAD_ROOT/.pyenv-modules" module load autoload
fi
pwd="${pwd%/*}"
done
}
# merging history
if [[ ! -z "`type -t sqlite_history.py`" &&
( ! -L ~/.shell_history ||
-r ~/.shell_history ) ]]; then
function sqlite_history() {
local old_HISTTIMEFORMAT="${HISTTIMEFORMAT}"
HISTTIMEFORMAT='***** %s ***** '
local new_history_file=`history | sqlite_history.py`
HISTTIMEFORMAT="${old_HISTTIMEFORMAT}"
if [ ! -z "${new_history_file}" ]; then
history -c -r $new_history_file
rm -f $new_history_file
fi
}
PROMPT_COMMAND='auto_env; sqlite_history'
unset HISTFILE
else
PROMPT_COMMAND='auto_env; history -a; history -n'
fi
HISTCONTROL=erasedups:ignorespace
HISTFILESIZE=5000
HISTSIZE=1000
HISTTIMEFORMAT=' %F %T '
shopt -s histappend cmdhist lithist
if [ "$OSTYPE" = "Darwin" ]; then
shopt -s nocaseglob
bind "set completion-ignore-case on"
fi
set -o notify
set -o noclobber
IGNOREEOF=2
function watch() {
IFS=
sleeptime=1
while getopts ":s:" o; do
case "${o}" in
s)
sleeptime=${OPTARG}
;;
esac
done
shift $((OPTIND-1))
IFS=' '
while true; do
output=$(bash -c "$1")
clear
echo "${output}"
sleep $sleeptime
done
}
function repeat() {
local n=$1 # gets the number of times the succeeding command needs to be executed
shift # now $@ has the command that needs to be executed
while [ $(( n -= 1 )) -ge 0 ] #loop n times;
do
"$@" # execute the command; you can also add error handling here or parallelize the commands
done
}
function tmux () {
declare SAS
if [ ! -d ${HOME}/tmp ]; then
mkdir -p ${HOME}/tmp
fi
if [ "${TERMTYPE}" != "screen" ] && [ "${!SSH_AUTH_SOCK[@]}" ]; then
ln -sf ${SSH_AUTH_SOCK} ${HOME}/tmp/${USER}-agent-screen
SAS=${HOME}/tmp/${USER}-agent-screen
fi
SSH_AUTH_SOCK="${SAS}" command tmux $@
}
if [ "$OSTYPE" = "Darwin" ]; then
function alert() {
if [ $# -lt 1 ]; then
echo "Usage: alert <message> [<title>]"
return 1
fi
if [ $# -eq 1 ]; then
osascript -e 'display notification "'"${1}"'" with title "Alert"'
else
osascript -e 'display notification "'"${1}"'" with title "'"${2}"'"'
fi
}
fi
# clean up.
unset t_bold_cmd t_unbold_cmd
unset t_prompt_end
unset t_prompt_machname