aboutsummaryrefslogtreecommitdiffstats
path: root/bash/.bashrc
blob: e211771e375164d7603f95d616d34e711dd0e53c (plain)
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# If not running interactively, don't do anything
[[ $- != *i* ]] && return

[ -f "/etc/bashrc" ] && source "/etc/bashrc"

# Default PS1
export PS1='[\d][\t]\u on \h\n\w $ '

# Additional local paths
export PATH="$PATH:/opt/homebrew/bin"
export PATH="$PATH:$HOME/.cargo/bin"
export PATH="$PATH:$HOME/.local/bin"
export PATH="$PATH:$HOME/.local/usr/bin"
export PATH="$PATH:$HOME/.local/usr/local/bin"

export C_INCLUDE_PATH="$C_INCLUDE_PATH:$HOME/.local/include"
export C_INCLUDE_PATH="$C_INCLUDE_PATH:$HOME/.local/usr/include"
export C_INCLUDE_PATH="$C_INCLUDE_PATH:$HOME/.local/usr/local/include"

export CPLUS_INCLUDE_PATH="$CPLUS_INCLUDE_PATH:$HOME/.local/include"
export CPLUS_INCLUDE_PATH="$CPLUS_INCLUDE_PATH:$HOME/.local/usr/include"
export CPLUS_INCLUDE_PATH="$CPLUS_INCLUDE_PATH:$HOME/.local/usr/local/include"

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/.local/lib"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/.local/usr/lib"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/.local/usr/local/lib"

export ANDROID_HOME="$HOME/Android/Sdk"
export PATH="$PATH:$ANDROID_HOME/platform-tools"

# Quit the shell like in vim
alias :q="exit"

# Keep OS compatibility
case "$(uname)" in
    Linux)
        alias ls="ls --color=auto"
        usr="/usr"
        ;;
    Darwin)

        alias flushdns="sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache"
        alias ls="ls -G"
        usr="/usr/local"
        ;;
    FreeBSD)
        alias ls="ls -G"
        usr="/usr/local"
        ;;

esac

# Colorfull manpages
man() {
    env LESS_TERMCAP_mb=$'\E[01;31m' \
    LESS_TERMCAP_md=$'\E[01;38;5;74m' \
    LESS_TERMCAP_me=$'\E[0m' \
    LESS_TERMCAP_se=$'\E[0m' \
    LESS_TERMCAP_so=$'\E[38;5;246m' \
    LESS_TERMCAP_ue=$'\E[0m' \
    LESS_TERMCAP_us=$'\E[04;38;5;146m' \
    man "$@"
}

# Helpfull functions
exists() {
    type $@ &> /dev/null
}

is_function() {
    function=$(type $@ 2> /dev/null | awk '/is a function/ { print "1" }')
    if [ -n "$function" ]; then
        return 0
    else
        return 1
    fi
}

is_alias() {
    alias=$(type $1 2> /dev/null | awk '/is aliased to/ { print "1" }')
    if [ -n "$alias" ]; then
        return 0
    else
        return 1
    fi
}

tunnel() {
    ssh -R ${1}:80:127.0.0.1:${2} serveo.net
}

# Set autocomplete for sudo
if exists complete && exists sudo; then
    complete -cf sudo
fi

# Jupiterbroadcasting live stream
if exists mpv; then
    alias jblive='mpv rtmp://videocdn-us.geocdn.scaleengine.net/jblive/live/jblive.stream'
elif exists vlc; then
    alias jblive='vlc rtmp://videocdn-us.geocdn.scaleengine.net/jblive/live/jblive.stream'
fi

# Set the default editor
if exists nvim; then
    export EDITOR="nvim"
elif exists vim; then
    export EDITOR="vim"
elif exists vi; then
    export EDITOR="vi"
fi

vim() {
    vim_bin=$(which $EDITOR)
    if [[ -z "$@" ]]; then
        $vim_bin
    elif [[ -d "$@" ]]; then
        dir=$(pwd)
        cd $@ && $vim_bin && cd $dir
    else
        $vim_bin $@
    fi
}

# Programming language specifics
if exists go; then
    export GOPATH="$HOME/programming/go"
    export PATH="$PATH:$GOPATH/bin"
fi

if exists gem; then
    export GEM_HOME="$(ruby -e 'print Gem.user_dir')"
    export PATH="$GEM_HOME/bin:$PATH"
fi

# Ezjail shortcuts
if exists ezjail-admin && exists sudo; then
    jl() {
        sudo ezjail-admin $1 $2\.tomvanderlee.com
    }
fi

# Showbanned ipadresses
if exists pfctl && exists sudo; then
    showbanned () {
        for table in "fail2ban" "permaban"; do
            banned=$(sudo pfctl -t $table -T show 2> /dev/null)

            if [ -z "$banned" ]; then
                nrBanned="0"
            else
                nrBanned=$(echo "$banned" | wc -l | awk '{ print $1 }')
            fi

            echo -e "$table ($nrBanned)\n$banned"
        done
    }
fi

# Always use pacaur even if it is not installed
if (exists pacman && ! exists pacaur) && exists sudo; then
    alias pacaur="sudo pacman"
fi

# Set the default pager
if exists less; then
    export PAGER="less"
fi

if exists virtualenv; then
    export VIRTUALENV_ALWAYS_COPY=1
fi

# Set the virtualenv parameters
if exists virtualenvwrapper.sh; then
    export WORKON_HOME=$HOME/.virtualenvs
    source $(which virtualenvwrapper.sh) 2> /dev/null
fi

# Start gnome-keyring-daemon
if exists gnome-keyring-daemon; then
    if [ -n "$DESKTOP_SESSION" ];then
        eval $(gnome-keyring-daemon --start 2> /dev/null)
        export SSH_AUTH_SOCK
    fi
fi

if exists sensible.bash; then
    source sensible.bash
fi

# Fancy bash prompt
if exists liquidprompt; then
    source $(which liquidprompt) 2> /dev/null
elif [ -f "/usr/share/liquidprompt/liquidprompt" ]; then
    source /usr/share/liquidprompt/liquidprompt 2> /dev/null
elif [ -f "/opt/homebrew/share/liquidprompt" ]; then
    source /opt/homebrew/share/liquidprompt 2> /dev/null
elif [ -f "/usr/local/share/liquidprompt" ]; then
    source /usr/local/share/liquidprompt 2> /dev/null
fi

# Fancy system info
if exists archey3; then
    archey3
elif exists screenfetch; then
    screenfetch
fi

if exists brew; then
    BASH_COMPLETION="$(brew --prefix)/etc/bash_completion"
    if [ -f "${BASH_COMPLETION}" ]; then
        source "${BASH_COMPLETION}"
    fi
fi

if exists lpass; then
    if exists complete; then
        _complete_lpass_accounts() {
            local search items item cmp newline

            newline='
            '

            cmp=${COMP_WORDS[COMP_CWORD]}
            search="$(sed 's/\\\ /___/g' <<< $cmp)"

            if [ -z "$search" ]; then
                return
            fi

            items=$(lpass ls --format "%an$newline%aN" | sed "s/\ /___/g")

            for item in $items; do
                if [[ $item =~ ^$search ]]; then
                    COMPREPLY+=( "$(sed 's/___/\\\ /g' <<< $item)" )
                fi
            done
        }

        complete -F _complete_lpass_accounts lpcp
    fi

    lps() {
        lpass ls --format "%aN" | grep $1
    }

    lpcp() {
        lpass show --password "$1" | pbcopy
        sleep 1
        lpass show --username "$1" | pbcopy
    }
fi

# heroku autocomplete setup
if exists heroku; then
    case "$(uname)" in
        Darwin)
            HEROKU_AC_BASH_SETUP_PATH=$HOME/Library/Caches/heroku/autocomplete/bash_setup
            ;;
    esac

    test -f $HEROKU_AC_BASH_SETUP_PATH \
        && source $HEROKU_AC_BASH_SETUP_PATH
fi

if exists pyenv; then
    eval "$(pyenv init -)"
    eval "$(pyenv virtualenv-init -)"
    export PATH="$PATH:$(pyenv root)/shims"
fi

if exists python3; then
    alias pyhttpd="python3 -m http.server"
fi

if exists yarnpkg; then
    alias yarn=yarnpkg
fi

if [ -s "/usr/local/opt/nvm/nvm.sh" ]; then
    export NVM_DIR="$HOME/.nvm"
    source "/usr/local/opt/nvm/nvm.sh"
fi

# vim: set ts=4 sw=4 tw=0 et :