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
13 if [ -n "$DISPLAY" ]; then
17 # Make `ssh host date` to display in 24-hour format
20 # If not running interactively, don't do anything
26 # Stop if non-interactive shell
27 [ -z "$PS1" ] && return
31 if [ "$HISTFILE" = "$HOME/.bash_history" ]; then
33 # This is the default value set by interactive bash
34 # when the global value was unset. Unset it here too.
38 # check the window size after each command and, if necessary,
39 # update the values of LINES and COLUMNS.
42 # If set, the pattern "**" used in a pathname expansion context will
43 # match all files and zero or more directories and subdirectories.
46 # append to the history file, don't overwrite it
49 [ "`type -t ls`" = alias ] && unalias ls
50 [ "`type -t ll`" = alias ] && unalias ll
53 functions() { typeset -f "$@"; }
56 if [ -r "$HOME"/admin/prog/bash_prompt ]; then
57 . "$HOME"/admin/prog/bash_prompt
61 PS1="${debian_chroot:+($debian_chroot)}\u@\h:\W \$SHLVL\\$ "
64 if [ -z "$BASH_COMPLETION_COMPAT_DIR" ]; then
65 if [ -d /usr/share/bash-completion -a -r /usr/share/bash-completion/bash_completion ]; then
66 _BASH_COMPLETIONS_DIR=/usr/share/bash-completion/completions
67 . /usr/share/bash-completion/bash_completion
68 elif [ -r /etc/bash_completion ]; then
69 _BASH_COMPLETIONS_DIR=/etc/bash_completion.d
70 . /etc/bash_completion
71 elif [ -d /etc/bash_completion.d ]; then
72 _BASH_COMPLETIONS_DIR=/etc/bash_completion.d
73 for _compf in /etc/bash_completion.d/*; do
76 elif [ -d /usr/local/etc/bash_completion.d ]; then
77 _BASH_COMPLETIONS_DIR=/usr/local/etc/bash_completion.d
78 for _compf in /usr/local/etc/bash_completion.d/*; do
82 echo "Unknown OS type, cannot source bash_completion" >&2
87 [ -n "$_BASH_COMPLETIONS_DIR" -a -d "$_BASH_COMPLETIONS_DIR" -a -r "$_BASH_COMPLETIONS_DIR/$1" ] ||
88 complete -p $1 >/dev/null 2>&1
91 for cmd in builtin cgmem_nice command dbus-launch exec \
92 killall man nice nohup pidof pidOf KillAll pgrep pkill psg pswg \
93 run-hosts su sudo time whence whereis which xargs; do
94 ! has_completion $cmd && complete -o default -A command $cmd
97 for cmd in dig host mtr nslookup nc netcat nmap p ping ping6 \
98 ssh2 s2 socat telnet t tt \
99 tcptraceroute tcptraceroute6 tracert tracert6 traceroute traceroute6 \
100 whois wd wget wget-download wget-m wget-wrapper ww; do
101 ! has_completion $cmd && complete -A hostname $cmd
104 for cmd in distribute ftp lftp r rsync \
105 s scp ssh smbclient tcpdump tshark wireshark; do
106 ! has_completion $cmd && complete -o default -A hostname $cmd
109 for cmd in bg fg jobs; do
110 ! has_completion $cmd && complete -A job $cmd
113 complete -A job j wait
116 ! has_completion $cmd && complete -A function -A variable $cmd
119 if [ -d "$HOME"/.bash_completion.d ]; then
120 for _compf in "$HOME"/.bash_completion.d/*; do
125 delegate_completion() {
128 ! has_completion $prog && return
131 eval "_${prog}_completion_loader() {
132 _completion_loader $prog
133 if [ x"$DELEGATE_NOSPACE" = x1 ]; then
134 complete -o nospace -F _$prog $programs
136 complete -F _$prog $programs
138 unset _${prog}_completion_loader
141 complete -F _${prog}_completion_loader $programs
144 delegate_completion make m
145 delegate_completion ping p
146 delegate_completion python python2.7 python3.4 python3.5 python3.6 python3.7 python3.8 python3.9 python3.10 python3.11 python3.12
147 DELEGATE_NOSPACE=1 delegate_completion rsync r rsync_cgmn rsync_cgmn_recode rsync_cgmn_recode2
148 delegate_completion ssh s
149 delegate_completion wget wget-m wget-wrapper ww
151 unset _BASH_COMPLETIONS_DIR has_completion delegate_completion
153 if [ -d "$HOME/lib/config" ]; then
154 complete -W "`cd \"$HOME/lib/config\" && echo *`" include
156 complete -W "`echo $BROWSER | sed 's/:/ /g'`" start-browser
158 if [ "`type -t short_curdir`" != function -a \
159 -r "$HOME"/admin/prog/bash_prompt ]; then
160 . "$HOME"/admin/prog/bash_prompt
163 if type -p pip >/dev/null 2>&1 || type -p pip3 >/dev/null 2>&1; then
164 _pip_completion_loader() {
165 eval "`pip completion --bash`"
166 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 pip3.12
167 unset _pip_completion_loader
170 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 pip3.12
173 if test -d "$HOME"/.pyenv
175 PYENV_ROOT="$HOME"/.pyenv
177 PATH="$PYENV_ROOT/bin:$PATH"
178 if which pyenv >/dev/null 2>&1; then
179 # eval "`pyenv init --path`"
180 eval "`pyenv init -`"
181 eval "`pyenv virtualenv-init -`"
186 . virtualenvwrapper_lazy.sh 2>/dev/null
188 if [ -n "$VIRTUAL_ENV" ] && ! type deactivate >/dev/null 2>&1; then
189 . "$VIRTUAL_ENV/bin/activate"
192 # Clean up python virtual environment on exit
193 # See https://virtualenvwrapper.readthedocs.io/en/latest/tips.html#clean-up-environments-on-exit
195 trap '[ "$VIRTUAL_ENV" ] && deactivate' EXIT
198 if test -x /usr/bin/git >/dev/null 2>&1; then
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 `cd_worktree`
240 _cd_worktree_comp() {
241 local cur="${COMP_WORDS[COMP_CWORD]}"
242 COMPREPLY=(`compgen -W "$(
243 git worktree list | awk '{s=$3; gsub("[\\\\[\\\\]]", "", s); print s}'
247 _cd_worktree_comp_loader() {
248 _completion_loader git
249 unset _cd_worktree_comp_loader
250 complete -F _cd_worktree_comp cd_worktree
254 complete -F _cd_worktree_comp_loader cd_worktree
256 # completion for aliases in global .gitconfig
258 # fixup rbi rbia rbiap rbip - do refs name completion
259 _git_fixup() { __gitcomp_nl "$(__git_refs)" ; }
260 _git_rbi() { __gitcomp_nl "$(__git_refs)" ; }
261 _git_rbia() { __gitcomp_nl "$(__git_refs)" ; }
262 _git_rbiap() { __gitcomp_nl "$(__git_refs)" ; }
263 _git_rbip() { __gitcomp_nl "$(__git_refs)" ; }
265 # push-to-all-remotes - do branch name completion
266 _git_push_to_all_remotes() { __gitcomp_nl "$(__git_heads)" ; }
268 _cdgitpath_complete() {
269 local cur="${COMP_WORDS[COMP_CWORD]}"
270 COMPREPLY=(`compgen -W "$(__git_config_get_set_variables)" -- "$cur"`)
277 complete -F _cdgitpath_complete cdgitpath git-open
279 # list remotes with URLs matching a regexp
281 if [ $# -ne 1 ]; then
282 echo "Usage: _list_remotes remote_regexp" >&2
285 declare -ag GIT_REMOTES=()
287 for remote in `git remote`; do
288 if git config --get remote.$remote.url | grep -q "$1"; then
289 GIT_REMOTES+=($remote)
294 # completion for cdremote and git-open-remote - list remotes with a pattern
295 _list_remotes_completion() {
296 local cur="${COMP_WORDS[COMP_CWORD]}"
298 COMPREPLY=(`compgen -W "${GIT_REMOTES[*]}" -- "$cur"`)
302 # completion for cdremote - list remotes with directories as URLs
303 _cdremote_complete() {
304 _list_remotes_completion '^\(file:/\|/\|\.\./\)' # (file:/ or / or ../ at the beginning)
305 if [ ${#COMPREPLY[*]} -eq 0 ]; then
306 _list_remotes_completion .
310 complete -F _cdremote_complete cdremote
312 # completion for git-open-remote - list remotes with http(s) URLs
314 _list_remotes_completion '^http\(s\)\?://'
315 if [ ${#COMPREPLY[*]} -eq 0 ]; then
316 _list_remotes_completion .
320 complete -F _git_open_remote git-open-remote
324 if [ "$SHLVL" -eq 1 -a "`type -t X`" = function ] && which startx >/dev/null 2>&1; then
325 # From https://stackoverflow.com/a/18839557
328 test -n "$(declare -f "$1")" || return
333 copy_function "$@" || return
337 rename_function X _non_bash_X
339 X() { history -a; _non_bash_X; history -r; }
342 if test -x /usr/bin/screen >/dev/null 2>&1; then