]> git.phdru.name Git - dotfiles.git/blob - .bashrc
Feat(recode-filenames-recursive): Allow to omit parameters
[dotfiles.git] / .bashrc
1 #
2 # $HOME/.bashrc
3 #
4
5 # ~/.bashrc: executed by bash(1) for non-login shells.
6 # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
7 # for examples
8
9 # Copied from .profile to do minor initialization for non-interactive non-login-shells
10 umask 077
11
12 # Fix default PATH
13 if [ "$PATH" = "/usr/local/bin:/usr/bin:/bin:/usr/games" ]; then
14     PATH="$HOME"/bin:"$HOME"/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
15 fi
16
17 if [ -n "$DISPLAY" ]; then
18     PATH=$PATH:/usr/games
19 fi
20
21 # Make `ssh host date` to display in 24-hour format
22 LANG=C
23
24 # If not running interactively, don't do anything
25 case $- in
26     *i*) ;;
27       *) return ;;
28 esac
29
30 # Stop if non-interactive shell
31 [ -z "$PS1" ] && return
32
33 . "$HOME"/.shellrc
34
35 # This is the default value set by interactive bash
36 # when the global value was unset. Unset it here too.
37 if [ "$HISTFILE" = "$HOME/.bash_history" ]; then
38     history -r
39     unset HISTFILE
40 fi
41
42 # check the window size after each command and, if necessary,
43 # update the values of LINES and COLUMNS.
44 shopt -s checkwinsize
45
46 # If set, the pattern "**" used in a pathname expansion context will
47 # match all files and zero or more directories and subdirectories.
48 #shopt -s globstar
49
50 # append to the history file, don't overwrite it
51 shopt -s histappend
52
53 [ "`type -t ls`" = alias ] && unalias ls
54 [ "`type -t ll`" = alias ] && unalias ll
55
56 back() { cd - "$@"; }
57 functions() { typeset -f "$@"; }
58 j() { jobs; }
59
60 if [ -r "$HOME"/admin/prog/bash_prompt ]; then
61     . "$HOME"/admin/prog/bash_prompt
62     set_prompt
63     unset set_prompt
64 else
65     PS1="${debian_chroot:+($debian_chroot)}\u@\h:\W \$SHLVL\\$ "
66 fi
67
68 if [ -z "$BASH_COMPLETION_COMPAT_DIR" ]; then
69     if [ -d /usr/share/bash-completion -a -r /usr/share/bash-completion/bash_completion ]; then
70         _BASH_COMPLETIONS_DIR=/usr/share/bash-completion/completions
71         . /usr/share/bash-completion/bash_completion
72     elif [ -r /etc/bash_completion ]; then
73         _BASH_COMPLETIONS_DIR=/etc/bash_completion.d
74         . /etc/bash_completion
75     elif [ -d /etc/bash_completion.d ] &&
76             [ -n "`ls -A /etc/bash_completion.d`" ]; then
77         _BASH_COMPLETIONS_DIR=/etc/bash_completion.d
78         for _compf in /etc/bash_completion.d/*; do
79             . $_compf
80         done
81     elif [ -d /usr/local/etc/bash_completion.d ] &&
82             [ -n "`ls -A /usr/local/etc/bash_completion.d`" ]; then
83         _BASH_COMPLETIONS_DIR=/usr/local/etc/bash_completion.d
84         for _compf in /usr/local/etc/bash_completion.d/*; do
85             . $_compf
86         done
87     else
88         echo "Unknown OS type, cannot source bash_completion" >&2
89     fi
90 fi
91
92 has_completion() {
93     [ -n "$_BASH_COMPLETIONS_DIR" -a -d "$_BASH_COMPLETIONS_DIR" -a -r "$_BASH_COMPLETIONS_DIR/$1" ] ||
94     complete -p $1 >/dev/null 2>&1
95 }
96
97 for cmd in builtin cgmem_nice command dbus-launch exec \
98         killall man nice nohup pidof pidOf KillAll pgrep pkill psg pswg \
99         run-hosts su sudo time whence whereis which xargs; do
100     has_completion $cmd || complete -o default -A command $cmd
101 done
102
103 for cmd in dig host mtr nslookup nc netcat nmap p ping ping6 \
104         ssh2 s2 socat telnet t tt \
105         tcptraceroute tcptraceroute6 tracert tracert6 traceroute traceroute6 \
106         whois wd wget wget-download wget-m wget-wrapper ww; do
107     has_completion $cmd || complete -A hostname $cmd
108 done
109
110 for cmd in distribute ftp lftp r rsync \
111         s scp ssh smbclient tcpdump tshark wireshark; do
112     has_completion $cmd || complete -o default -A hostname $cmd
113 done
114
115 for cmd in bg fg jobs; do
116     has_completion $cmd || complete -A job $cmd
117 done
118
119 complete -A job j wait
120
121 for cmd in unset; do
122     has_completion $cmd || complete -A function -A variable $cmd
123 done
124
125 delegate_completion() {
126     local prog programs
127     prog=$1
128     has_completion $prog || return 0
129     shift
130     programs="$@"
131     eval "_${prog}_completion_loader() {
132         _completion_loader $prog
133         if [ x"$DELEGATE_NOSPACE" = x1 ]; then
134             complete -o nospace -F _$prog $programs
135         else
136             complete -F _$prog $programs
137         fi
138         unset _${prog}_completion_loader
139         return 124
140     }"
141     complete -F _${prog}_completion_loader $programs
142 }
143
144 delegate_completion make m
145 delegate_completion ping p
146 DELEGATE_NOSPACE=1 delegate_completion rsync r rsync_cgmn rsync_cgmn_recode rsync_cgmn_recode2
147 delegate_completion ssh s
148 delegate_completion wget wget-m wget-wrapper ww
149
150 if [ -d "$HOME"/.bash_completion.d ] &&
151         [ -n "`ls -A $HOME/.bash_completion.d`" ]; then
152     for _compf in "$HOME"/.bash_completion.d/*; do
153         . $_compf
154     done
155 fi
156
157 unset _BASH_COMPLETIONS_DIR has_completion delegate_completion
158
159 if [ -d "$HOME/lib/config" ]; then
160     complete -W "`cd \"$HOME/lib/config\" && echo *`" include
161 fi
162 complete -W "`echo $BROWSER | sed 's/:/ /g'`" start-browser
163
164
165 if [ -n "$VIRTUAL_ENV" ] && ! type deactivate >/dev/null 2>&1; then
166     . "$VIRTUAL_ENV/bin/activate"
167 fi
168
169 # Clean up python virtual environment on exit
170 # See https://virtualenvwrapper.readthedocs.io/en/latest/tips.html#clean-up-environments-on-exit
171
172 trap '[ "$VIRTUAL_ENV" ] && deactivate' EXIT
173
174 . virtualenvwrapper_lazy.sh 2>/dev/null
175
176
177 if test -d "$HOME"/.pyenv
178 then
179     PYENV_ROOT="$HOME"/.pyenv
180     export PYENV_ROOT
181     PATH="$PYENV_ROOT/bin:$PATH"
182     if which pyenv >/dev/null 2>&1; then
183 #        eval "`pyenv init --path`"
184         eval "`pyenv init -`"
185         eval "`pyenv virtualenv-init -`"
186     fi
187 fi
188
189
190 if test -x /usr/bin/screen >/dev/null 2>&1; then
191     screen_newwin() {
192         history -a
193         screen "$@"
194     }
195 fi
196
197 if [ "$SHLVL" -eq 1 -a "`type -t X`" = function ] && which startx >/dev/null 2>&1; then
198     # From https://stackoverflow.com/a/18839557
199
200     copy_function() {
201         test -n "$(declare -f "$1")" || return
202         eval "${_/$1/$2}"
203     }
204
205     rename_function() {
206         copy_function "$@" || return
207         unset -f "$1"
208     }
209
210     rename_function X _non_bash_X
211
212     X() { history -a; _non_bash_X; history -r; }
213 fi