-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
231 lines (199 loc) · 8.9 KB
/
.bashrc
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
# Thomas Jansson
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
elif [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
# Load bash completion
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
# Export some options
if [ -z "$PS1" ]; then
#echo This shell is not interactive
:
else
#echo This shell is interactive
bind 'set show-all-if-ambiguous on' # Set tab-autocompletion to show options if not clear
bind 'set completion-ignore-case on' # Ignores the case in the above
fi
# Terminal languages
if [[ "$(uname)" == "Linux" ]]; then
export LANGUAGE="en_US:en"
export LC_ALL="en_DK.UTF-8"
export LANG="en_DK.UTF-8"
elif [[ "$(uname)" == "Darwin" ]]; then
export LC_CTYPE="UTF-8"
export LC_TERMINAL="iTerm2"
fi
set -C # The noclobber option prevents you from overwriting existing files with the > operator.
shopt -s dirspell # attempts spelling correction on directory names during word completion if the directory name initially supplied does not exist.
shopt -s cdspell # automatically corrects small typos in directory names
shopt -s histappend # istory list is appended to the file named by the value of the HISTFILE variable when the shell exits, rather than overwriting the file.
shopt -s histreedit # If set, and Readline is being used, a user is given the opportunity to re-edit a failed history substitution.
shopt -s histverify # If set, and Readline is being used, the results of history substitution are not immediately passed to the shell parser. Instead, the resulting line is loaded into the Readline editing buffer, allowing further modification.
shopt -s globstar # If set, the pattern ** used in a pathname expansion context will match all files and zero or more directories and subdirectories
shopt -s nocaseglob # The nocaseglob option is similar to the dotglob option, except nocaseglob causes differences in upper- and lowercase letters in file names and directories to be ignored in name expansions.
shopt -s checkwinsize # Check the window size after each command, and update LINES and COLUMNS if the size has changed.
export HISTFILESIZE=5000 # the bash history should save 3000 commands
export HISTCONTROL=ignoredups #don't put duplicate lines in the history.
export HISTIGNORE="&:ls:cd:bg:fg:ll" # ignore these commands in history
# Make sure we are using the ibus for X11 input
export GTK_IM_MODULE="ibus"
export QT_IM_MODULE="ibus"
export QT4_IM_MODULE="ibus"
export XMODIFIERS="@im=ibus"
# Shell and prompt configuration
export GS_OPTIONS="-sPAPERSIZE=a4"
export FIGNORE=".svn:.git" # $FIGNORE is just a colon-separated list of suffixes to ignore when doing tab completion.
export PROMPT_DIRTRIM=2
ulimit -S -c 0 # Don't want coredumps.
unset MAILCHECK # Don't want my shell to warn me of incoming mail.
export PATH=$PATH:/usr/sbin/:/sbin/:~/bin/
# Set up simple markdown based notes. Inspired by https://github.com/hachibu/note.sh and inplemented using:
# * Syncthing on laptop: http://ubuntuhandbook.org/index.php/2020/11/install-syncthing-gtk-ubuntu-20-10/
# * Syncthing on server: https://docs.syncthing.net/users/autostart.html#linux using system level systemd
# Monitor on server: sudo systemctl status [email protected]
# Manage: firefox https://127.0.0.1:8384/ (use special user and pw)
# export NOTE_DIR=$HOME/Documents/syncthing/notes
# alias takenote="vim $NOTE_DIR/$(date +'%Y-%m-%d-'$HOSTNAME ).md"
# function takenotegrep() { grep -i -n --color='auto' "${1}" "$NOTE_DIR"/*.md; }
# Use vim for manpages:
export MANPAGER="vim -M +MANPAGER -"
# Try to load git __git_ps1 if possible
if [ -f /usr/lib/git-core/git-sh-prompt ]; then # LINUNX
source /usr/lib/git-core/git-sh-prompt
elif [ -f /Library/Developer/CommandLineTools/usr/share/git-core/git-prompt.sh ]; then # MAC OS
source /Library/Developer/CommandLineTools/usr/share/git-core/git-prompt.sh
fi
# Set up the prompt with GIT niceness if available
if [ "$TERM" != "dumb" ]; then
export TERM=xterm-256color
if hash __git_ps1 &> /dev/null; then
# Show the git branch if possible
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWCOLORHINTS=1
GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWSTASHSTATE=true
# With timestamp
PS1="\[\033[01;33m\][\A]\[\033[01;32m\]\u@\[\033[01;33m\]\h\\[\033[32m\]\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\] \[\033[01;35m\]\$(__git_ps1 '(%s)')\[\033[00m\]$ "
# Without timestamp
#PS1="\[\033[01;32m\]\u@\[\033[01;33m\]\h\\[\033[32m\] \[\033[01;34m\]\w\[\033[00m\] \[\033[01;35m\]\$(__git_ps1 '(%s)')\[\033[00m\]$ "
else
# With timestamp
PS1="\[\033[01;33m\][\A]\[\033[01;32m\]\u@\[\033[01;33m\]\h\\[\033[32m\]\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\] $ "
# Without timestamp
#PS1="\[\033[01;32m\]\u@\[\033[01;33m\]\h\\[\033[32m\] \[\033[01;34m\]\w\[\033[00m\] \[\033[00m\]$ "
fi
# Hack to support Mac not having dircolors
if dircolors 1> /dev/null 2>&1; then
eval "`dircolors -b`"
alias ls='ls --color=auto --hide=*~' # Hide the annoying tmp files from emacs users.
else
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
fi
fi
# Check if ripgrep is installed
if command -v rg > /dev/null 2>&1; then
# If ripgrep is installed, alias grep to use ripgrep
alias grep='rg --color=auto'
else
# If ripgrep is not installed, use the default grep
alias grep='grep --color=auto'
fi
# User specific aliases and functions
alias pwgen="pwgen 12"
alias ccat="pygmentize -g" # Color highlighting cat function, requires pygmentize python program
alias mv="mv -i"
alias cp="cp -i"
alias rm="rm -i"
alias bc="bc -l"
alias ll="ls -lrth"
alias llz="ls -lrSh"
alias tgrep='grep -i -n --exclude-dir=".git" --exclude="*.pyc" --color=auto'
alias pylab="echo 'Remember bpython'; ipython --pylab"
alias did="vim +'normal Go' +'r!date' ~/did.txt" # https://theptrk.com/2018/07/11/did-txt-file/
if [ $HOSTNAME == "Thomas-MBP.local" ]; then # MAC
alias df='df -hIl'
. $HOMEBREW_PREFIX/etc/profile.d/z.sh # Tracks most-used directories to make cd smarter
else
alias df='df -hT -x squashfs -x tmpfs -x devtmpfs -x fuse' # Avoid all the fake devices
fi
alias black='black --line-length 120'
# https://stackoverflow.com/questions/17983068/delete-local-git-branches-after-deleting-them-on-the-remote-repo
alias gitpurge_deleted_branched=" git fetch --all -p; git branch -vv | grep ': gone]' | awk '{ print \$2 }' | xargs -n 1 git branch -d"
alias gitpurge_deleted_branched_dry="git fetch --all -p; git branch -vv | grep ': gone]'"
# Johnny decimal function
cjdfunction() {
pushd ~/**/${1}*
}
export cjdfunction
alias cjd='cjdfunction' # Or any other alias you prefer.
###########
# VIM setup
###########
export PYTHONBREAKPOINT="pudb.set_trace"
export EDITOR=vim
export SVN_EDITOR=vim
export GIT_EDITOR=vim
export VISUAL=vim
alias vim="vim -p -X" # Open multiple files in tabs and avoid X
# If vim have been build then use this instead
if [ -d "$HOME/.vimbuild/vim/runtime" ]; then
export VIMRUNTIME="$HOME/.vimbuild/vim/runtime"
alias vim="$HOME/.vimbuild/vim/src/vim -p"
fi
#####################
# Host specific setup
#####################
if [ $HOSTNAME == "pascal" ]; then
alias sshdyn="ssh -X 192.168.0.160"
elif [ $HOSTNAME == "VirtualBox" ]; then
alias sshdyn="ssh -X 192.168.0.160"
else
# Removed X as it was needed and slowed something down (vim)
# alias sshdyn="ssh -o ServerAliveInterval=60 [email protected] -XC -p 443" # port 443 avoids firewalls
alias sshdyn="ssh -o ServerAliveInterval=60 [email protected] -C -p 22" # port 443 avoids firewalls
fi
################
# Connected Cars
################
# Load external aliases if it exists that should not be part of a public GH repo
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# MAC - Add Visual Studio Code (code)
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
# if [ $HOSTNAME == "x1" ]; then
if [ -f ~/code/docker-python/.connections ]; then
# export REGION='EU1'
source ~/code/docker-python/.connections
source ~/code/data-quality/python_module_autocomplete.sh
fi
# If possible try to load conda aliases
if [ -f ~/code/connectedcars/docker-python/.conda_aliases ]; then
source ~/code/connectedcars/docker-python/.conda_aliases
fi
if [ -f ~/code/docker-python/.conda_aliases ]; then
source ~/code/docker-python/.conda_aliases
fi
##############
# CONDA python
##############
if [ $HOSTNAME == "curie" ]; then
source ~/miniconda3/etc/profile.d/conda.sh
conda activate base
else
source ~/miniconda3/etc/profile.d/conda.sh
conda activate prod
fi
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion