5 # ~/.bashrc: executed by bash(1) for non-login shells.
6 # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
9 # Copied from .profile to do minor initialization for non-interactive non-login-shells
12 PATH="$HOME"/bin:"$HOME"/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
14 # Make `ssh host date` to display in 24-hour format
17 # If not running interactively, don't do anything
23 # Stop if non-interactive shell
24 [ -z "$PS1" ] && return
28 if [ "$HISTFILE" = "$HOME/.bash_history" ]; then
30 # This is the default value set by interactive bash
31 # when the global value was unset. Unset it here too.
35 # check the window size after each command and, if necessary,
36 # update the values of LINES and COLUMNS.
39 # If set, the pattern "**" used in a pathname expansion context will
40 # match all files and zero or more directories and subdirectories.
43 # append to the history file, don't overwrite it
46 [ "`type -t ls`" = alias ] && unalias ls
47 [ "`type -t ll`" = alias ] && unalias ll
50 functions() { typeset -f "$@"; }
53 if [ -z "$BASH_COMPLETION_COMPAT_DIR" ]; then
54 if [ -d /usr/share/bash-completion -a -r /usr/share/bash-completion/bash_completion ]; then
55 _BASH_COMPLETIONS_DIR=/usr/share/bash-completion/completions
56 . /usr/share/bash-completion/bash_completion
57 elif [ -r /etc/bash_completion ]; then
58 _BASH_COMPLETIONS_DIR=/etc/bash_completion.d
59 . /etc/bash_completion
60 elif [ -d /etc/bash_completion.d ]; then
61 _BASH_COMPLETIONS_DIR=/etc/bash_completion.d
62 for _compf in /etc/bash_completion.d/*; do
65 elif [ -d /usr/local/etc/bash_completion.d ]; then
66 _BASH_COMPLETIONS_DIR=/usr/local/etc/bash_completion.d
67 for _compf in /usr/local/etc/bash_completion.d/*; do
71 echo "Unknown OS type, cannot source bash_completion" >&2
76 [ -n "$_BASH_COMPLETIONS_DIR" -a -d "$_BASH_COMPLETIONS_DIR" -a -r "$_BASH_COMPLETIONS_DIR/$1" ] ||
77 complete -p $1 >/dev/null 2>&1
80 for cmd in builtin cgmem_nice command dbus-launch exec \
81 killall man nice nohup pidof pidOf KillAll pgrep pkill psg pswg \
82 run-hosts su sudo time whence whereis which xargs; do
83 ! has_completion $cmd && complete -o default -A command $cmd
86 for cmd in dig host mtr nslookup nc netcat nmap p ping ping6 \
87 ssh2 s2 socat telnet t tt \
88 tcptraceroute tcptraceroute6 tracert tracert6 traceroute traceroute6 \
89 whois wd wget wget-download wget-m wget-wrapper ww; do
90 ! has_completion $cmd && complete -A hostname $cmd
93 for cmd in distribute ftp lftp r rsync \
94 s scp ssh smbclient tcpdump tshark wireshark; do
95 ! has_completion $cmd && complete -o default -A hostname $cmd
98 for cmd in bg fg jobs; do
99 ! has_completion $cmd && complete -A job $cmd
102 complete -A job j wait
105 ! has_completion $cmd && complete -A function -A variable $cmd
108 if [ -d "$HOME"/.bash_completion.d ]; then
109 for _compf in "$HOME"/.bash_completion.d/*; do
114 delegate_completion() {
117 ! has_completion $prog && return
120 eval "_${prog}_completion_loader() {
121 _completion_loader $prog
122 if [ x"$DELEGATE_NOSPACE" = x1 ]; then
123 complete -o nospace -F _$prog $programs
125 complete -F _$prog $programs
127 unset _${prog}_completion_loader
130 complete -F _${prog}_completion_loader $programs
133 delegate_completion make m
134 delegate_completion ping p
135 delegate_completion python python2.7 python3.4 python3.5 python3.6 python3.7 python3.8 python3.9 python3.10 python3.11
136 DELEGATE_NOSPACE=1 delegate_completion rsync r rsync_cgmn rsync_cgmn_recode rsync_cgmn_recode2
137 delegate_completion ssh s
138 delegate_completion wget wget-m wget-wrapper ww
140 unset _BASH_COMPLETIONS_DIR has_completion delegate_completion
142 if [ -d "$HOME/lib/config" ]; then
143 complete -W "`cd \"$HOME/lib/config\" && echo *`" include
145 complete -W "`echo $BROWSER | sed 's/:/ /g'`" start-browser
147 if [ "`type -t short_curdir`" != function -a \
148 -r "$HOME"/admin/prog/bash_prompt ]; then
149 . "$HOME"/admin/prog/bash_prompt
152 if type -p pip >/dev/null 2>&1 || type -p pip3 >/dev/null 2>&1; then
153 _pip_completion_loader() {
154 eval "`pip completion --bash`"
155 complete -F _pip_completion pip pip2 pip2.7 pip3 pip3.4 pip3.5 pip3.6 pip3.7 pip3.8 pip3.9 pip3.10 pip3.11
156 unset _pip_completion_loader
159 complete -F _pip_completion_loader pip pip2 pip2.7 pip3 pip3.4 pip3.5 pip3.6 pip3.7 pip3.8 pip3.9 pip3.10 pip3.11
162 #if which pyenv >/dev/null 2>&1; then
163 # eval "`pyenv init -`"
164 # eval "`pyenv virtualenv-init -`"
167 . virtualenvwrapper_lazy.sh 2>/dev/null
169 if [ -n "$VIRTUAL_ENV" ] && ! type deactivate >/dev/null 2>&1; then
170 . "$VIRTUAL_ENV/bin/activate"
173 # Clean up python virtual environment on exit
174 # See https://virtualenvwrapper.readthedocs.io/en/latest/tips.html#clean-up-environments-on-exit
176 trap '[ "$VIRTUAL_ENV" ] && deactivate' EXIT
179 if test -x /usr/bin/git >/dev/null 2>&1; then
180 # chdir to a directory
182 if [ $# -ne 1 ]; then
183 echo "Usage: cdgitpath path_key" >&2
188 if [ -z "$path_key" ]; then
189 echo "Usage: cdgitpath path_key" >&2
193 path_url="`git config --get --path $path_key`"
194 if echo "$path_url" | grep -q '^file:/'; then
195 path_url="`echo \"$path_url\" | sed 's@^file:/\+@/@'`"
200 # chdir to a remote's directory (if the remote is on the local FS)
202 if [ $# -gt 1 ]; then
203 echo "Usage: cdremote [remote_name]" >&2
208 branch="`git rev-parse --abbrev-ref HEAD`"
209 remote="`git config --get branch.$branch.remote`"
214 if [ -n "$remote" ] && git config --get remote.$remote.url |
215 grep -q '^\(file:/\|/\|\.\./\)'; then # (file:/ or / or ../ at the beginning)
216 cdgitpath remote.$remote.url
221 echo "Cannot find directory for remote $1" >&2
222 echo "Usage: cdremote [remote_name]" >&2
226 _list_remotes '^\(file:/\|/\|\.\./\)' # (file:/ or / or ../ at the beginning)
227 if [ ${#GIT_REMOTES[*]} -eq 1 ]; then
228 remote=${GIT_REMOTES[0]}
230 cdgitpath remote.$remote.url
233 echo "Cannot find directory for any remote" >&2
234 echo "Usage: cdremote [remote_name]" >&2
239 # completion for aliases in global .gitconfig
241 # fixup rbi rbia rbiap rbip - do refs name completion
242 _git_fixup() { __gitcomp_nl "$(__git_refs)" ; }
243 _git_rbi() { __gitcomp_nl "$(__git_refs)" ; }
244 _git_rbia() { __gitcomp_nl "$(__git_refs)" ; }
245 _git_rbiap() { __gitcomp_nl "$(__git_refs)" ; }
246 _git_rbip() { __gitcomp_nl "$(__git_refs)" ; }
248 # push-to-all-remotes - do branch name completion
249 _git_push_to_all_remotes() { __gitcomp_nl "$(__git_heads)" ; }
251 _cdgitpath_complete() {
252 local cur="${COMP_WORDS[COMP_CWORD]}"
253 COMPREPLY=(`compgen -W "$(__git_config_get_set_variables)" -- "$cur"`)
260 complete -F _cdgitpath_complete cdgitpath git-open
262 # list remotes with URLs matching a regexp
264 if [ $# -ne 1 ]; then
265 echo "Usage: _list_remotes remote_regexp" >&2
268 declare -ag GIT_REMOTES=()
270 for remote in `git remote`; do
271 if git config --get remote.$remote.url | grep -q "$1"; then
272 GIT_REMOTES+=($remote)
277 # completion for cdremote and git-open-remote - list remotes with a pattern
278 _list_remotes_completion() {
279 local cur="${COMP_WORDS[COMP_CWORD]}"
281 COMPREPLY=(`compgen -W "${GIT_REMOTES[*]}" -- "$cur"`)
285 # completion for cdremote - list remotes with directories as URLs
286 _cdremote_complete() {
287 _list_remotes_completion '^\(file:/\|/\|\.\./\)' # (file:/ or / or ../ at the beginning)
288 if [ ${#COMPREPLY[*]} -eq 0 ]; then
289 _list_remotes_completion .
293 complete -F _cdremote_complete cdremote
295 # completion for git-open-remote - list remotes with http(s) URLs
297 _list_remotes_completion '^http\(s\)\?://'
298 if [ ${#COMPREPLY[*]} -eq 0 ]; then
299 _list_remotes_completion .
303 complete -F _git_open_remote git-open-remote
307 if [ "$SHLVL" -eq 1 -a "`type -t X`" = function ] && which startx >/dev/null 2>&1; then
308 # From https://stackoverflow.com/a/18839557
311 test -n "$(declare -f "$1")" || return
316 copy_function "$@" || return
320 rename_function X _non_bash_X
322 X() { history -a; _non_bash_X; history -r; }