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
29 # This is the default value set by interactive bash
30 # when the global value was unset. Unset it here too.
34 # check the window size after each command and, if necessary,
35 # update the values of LINES and COLUMNS.
38 # If set, the pattern "**" used in a pathname expansion context will
39 # match all files and zero or more directories and subdirectories.
42 # append to the history file, don't overwrite it
45 [ "`type -t ls`" = alias ] && unalias ls
46 [ "`type -t ll`" = alias ] && unalias ll
49 functions() { typeset -f "$@"; }
52 if [ -z "$BASH_COMPLETION_COMPAT_DIR" ]; then
53 if [ -d /usr/share/bash-completion -a -r /usr/share/bash-completion/bash_completion ]; then
54 _BASH_COMPLETIONS_DIR=/usr/share/bash-completion/completions
55 . /usr/share/bash-completion/bash_completion
56 elif [ -r /etc/bash_completion ]; then
57 _BASH_COMPLETIONS_DIR=/etc/bash_completion.d
58 . /etc/bash_completion
59 elif [ -d /etc/bash_completion.d ]; then
60 _BASH_COMPLETIONS_DIR=/etc/bash_completion.d
61 for _compf in /etc/bash_completion.d/*; do
64 elif [ -d /usr/local/etc/bash_completion.d ]; then
65 _BASH_COMPLETIONS_DIR=/usr/local/etc/bash_completion.d
66 for _compf in /usr/local/etc/bash_completion.d/*; do
70 echo "Unknown OS type, cannot source bash_completion" >&2
75 [ -n "$_BASH_COMPLETIONS_DIR" -a -d "$_BASH_COMPLETIONS_DIR" -a -r "$_BASH_COMPLETIONS_DIR/$1" ] ||
76 complete -p $1 >/dev/null 2>&1
79 for cmd in builtin cgmem_nice command dbus-launch exec \
80 killall man nice nohup pidof pidOf KillAll pgrep pkill psg pswg \
81 run-hosts su sudo time whence whereis which xargs; do
82 ! has_completion $cmd && complete -o default -A command $cmd
85 for cmd in dig host mtr nslookup nc netcat nmap p ping ping6 \
86 ssh2 s2 socat telnet t tt \
87 tcptraceroute tcptraceroute6 tracert tracert6 traceroute traceroute6 \
88 whois wd wget wget-download wget-m wget-wrapper ww; do
89 ! has_completion $cmd && complete -A hostname $cmd
92 for cmd in distribute ftp lftp r rsync \
93 s scp ssh smbclient tcpdump tshark wireshark; do
94 ! has_completion $cmd && complete -o default -A hostname $cmd
97 for cmd in bg fg jobs; do
98 ! has_completion $cmd && complete -A job $cmd
101 complete -A job j wait
104 ! has_completion $cmd && complete -A function -A variable $cmd
107 if [ -d "$HOME"/.bash_completion.d ]; then
108 for _compf in "$HOME"/.bash_completion.d/*; do
113 delegate_completion() {
116 ! has_completion $prog && return
119 eval "_${prog}_completion_loader() {
120 _completion_loader $prog
121 if [ x"$DELEGATE_NOSPACE" = x1 ]; then
122 complete -o nospace -F _$prog $programs
124 complete -F _$prog $programs
126 unset _${prog}_completion_loader
129 complete -F _${prog}_completion_loader $programs
132 delegate_completion make m
133 delegate_completion ping p
134 delegate_completion python python2.7 python3.4 python3.5 python3.6 python3.7 python3.8 python3.9 python3.10 python3.11
135 DELEGATE_NOSPACE=1 delegate_completion rsync r rsync_cgmn rsync_cgmn_recode rsync_cgmn_recode2
136 delegate_completion ssh s
137 delegate_completion wget wget-m wget-wrapper ww
139 unset _BASH_COMPLETIONS_DIR has_completion delegate_completion
141 if [ -d "$HOME/lib/config" ]; then
142 complete -W "`cd \"$HOME/lib/config\" && echo *`" include
144 complete -W "`echo $BROWSER | sed 's/:/ /g'`" start-browser
146 if [ "`type -t short_curdir`" != function -a \
147 -r "$HOME"/admin/prog/bash_prompt ]; then
148 . "$HOME"/admin/prog/bash_prompt
151 if type -p pip >/dev/null 2>&1 || type -p pip3 >/dev/null 2>&1; then
152 _pip_completion_loader() {
153 eval "`pip completion --bash`"
154 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
155 unset _pip_completion_loader
158 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
161 #if which pyenv >/dev/null 2>&1; then
162 # eval "`pyenv init -`"
163 # eval "`pyenv virtualenv-init -`"
166 . virtualenvwrapper_lazy.sh 2>/dev/null
168 if [ -n "$VIRTUAL_ENV" ] && ! type deactivate >/dev/null 2>&1; then
169 . "$VIRTUAL_ENV/bin/activate"
172 # Clean up python virtual environment on exit
173 # See https://virtualenvwrapper.readthedocs.io/en/latest/tips.html#clean-up-environments-on-exit
175 trap '[ "$VIRTUAL_ENV" ] && deactivate' EXIT
178 if test -x /usr/bin/git >/dev/null 2>&1; then
179 # chdir to a directory
181 if [ $# -ne 1 ]; then
182 echo "Usage: cdgitpath path_key" >&2
187 if [ -z "$path_key" ]; then
188 echo "Usage: cdgitpath path_key" >&2
192 path_url="`git config --get --path $path_key`"
193 if echo "$path_url" | grep -q '^file:/'; then
194 path_url="`echo \"$path_url\" | sed 's@^file:/\+@/@'`"
199 # chdir to a remote's directory (if the remote is on the local FS)
201 if [ $# -gt 1 ]; then
202 echo "Usage: cdremote [remote_name]" >&2
207 branch="`git rev-parse --abbrev-ref HEAD`"
208 remote="`git config --get branch.$branch.remote`"
213 if [ -n "$remote" ] && git config --get remote.$remote.url |
214 grep -q '^\(file:/\|/\|\.\./\)'; then # (file:/ or / or ../ at the beginning)
215 cdgitpath remote.$remote.url
220 echo "Cannot find directory for remote $1" >&2
221 echo "Usage: cdremote [remote_name]" >&2
225 _list_remotes '^\(file:/\|/\|\.\./\)' # (file:/ or / or ../ at the beginning)
226 if [ ${#GIT_REMOTES[*]} -eq 1 ]; then
227 remote=${GIT_REMOTES[0]}
229 cdgitpath remote.$remote.url
232 echo "Cannot find directory for any remote" >&2
233 echo "Usage: cdremote [remote_name]" >&2
238 # completion for aliases in global .gitconfig
240 # fixup rbi rbia rbiap rbip - do refs name completion
241 _git_fixup() { __gitcomp_nl "$(__git_refs)" ; }
242 _git_rbi() { __gitcomp_nl "$(__git_refs)" ; }
243 _git_rbia() { __gitcomp_nl "$(__git_refs)" ; }
244 _git_rbiap() { __gitcomp_nl "$(__git_refs)" ; }
245 _git_rbip() { __gitcomp_nl "$(__git_refs)" ; }
247 # push-to-all-remotes - do branch name completion
248 _git_push_to_all_remotes() { __gitcomp_nl "$(__git_heads)" ; }
250 _cdgitpath_complete() {
251 local cur="${COMP_WORDS[COMP_CWORD]}"
252 COMPREPLY=(`compgen -W "$(__git_config_get_set_variables)" -- "$cur"`)
259 complete -F _cdgitpath_complete cdgitpath git-open
261 # list remotes with URLs matching a regexp
263 if [ $# -ne 1 ]; then
264 echo "Usage: _list_remotes remote_regexp" >&2
267 declare -ag GIT_REMOTES=()
269 for remote in `git remote`; do
270 if git config --get remote.$remote.url | grep -q "$1"; then
271 GIT_REMOTES+=($remote)
276 # completion for cdremote and git-open-remote - list remotes with a pattern
277 _list_remotes_completion() {
278 local cur="${COMP_WORDS[COMP_CWORD]}"
280 COMPREPLY=(`compgen -W "${GIT_REMOTES[*]}" -- "$cur"`)
284 # completion for cdremote - list remotes with directories as URLs
285 _cdremote_complete() {
286 _list_remotes_completion '^\(file:/\|/\|\.\./\)' # (file:/ or / or ../ at the beginning)
287 if [ ${#COMPREPLY[*]} -eq 0 ]; then
288 _list_remotes_completion .
292 complete -F _cdremote_complete cdremote
294 # completion for git-open-remote - list remotes with http(s) URLs
296 _list_remotes_completion '^http\(s\)\?://'
297 if [ ${#COMPREPLY[*]} -eq 0 ]; then
298 _list_remotes_completion .
302 complete -F _git_open_remote git-open-remote
306 if [ "$SHLVL" -eq 1 -a "`type -t X`" = function ] && which startx >/dev/null 2>&1; then
307 # From https://stackoverflow.com/a/18839557
310 test -n "$(declare -f "$1")" || return
315 copy_function "$@" || return
319 rename_function X _non_bash_X
321 X() { history -a; _non_bash_X; history -r; }