-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
276 lines (225 loc) · 8.11 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
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
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# Determine host and os info
os=$(uname -s)
host=$(uname -n | cut -d. -f1)
# OS Specific settings
case $os in
"Darwin")
export PATH="/opt/homebrew/bin:$PATH"
alias ls='ls -FG';
# Kindof does the same thing as lsub when it doesn't exist on OS X
alias lsusb='system_profiler SPUSBDataType'
# Show hidden files on OS X
alias showhidden='defaults write com.apple.finder AppleShowAllFiles YES && killall Finder'
alias hidehidden='defaults write com.apple.finder AppleShowAllFiles NO && killall Finder'
# Support for auto-completing brew. Also loads other auto-completions installed via brew.
if [ -f "$(brew --prefix)/etc/bash_completion" ]
then
# shellcheck source=/dev/null
. "$(brew --prefix)/etc/bash_completion"
fi
if type brew 2&>/dev/null; then
for completion_file in "$(brew --prefix)"/etc/bash_completion.d/*; do
# shellcheck source=/dev/null
source "$completion_file"
done
fi
if [ -f /usr/local/share/bash-completion/bash_completion ]; then
. /usr/local/share/bash-completion/bash_completion
fi
;;
"Linux")
alias ls='ls -F --color=auto'
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
# needed for podman/distrobox on steam deck
PATH=$HOME/.local/bin:$PATH
PATH=$HOME/.local/podman/bin:$PATH
;;
esac
# Brew autocompletion
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
# Include work specific aliases if it exists
if [[ -f ${HOME}/.dotfiles_work/bashrc_aliases ]]; then
# shellcheck source=/dev/null
. "${HOME}/.dotfiles_work/bashrc_aliases"
fi
# Include other work specific bashrc if it exists
if [[ -f ${HOME}/.dotfiles_work/bashrc ]]; then
# shellcheck source=/dev/null
. "${HOME}/.dotfiles_work/bashrc"
fi
# Bash settings
export PS1='\u@\h:\w [$?]\n\$ '
# append to the history file, don't overwrite it
shopt -s histappend
# set history size to unlimited
export HISTSIZE=
export HISTFILESIZE=
export HISTTIMEFORMAT="[%F %T] "
# force flush to history file after every command
export PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
# only set different bash history file when not using kyrat
if [ -z "${KYRAT_HOME}" ]; then
# set history file to a new location to prevent sessions that don't respect settings above from truncating
export HISTFILE=~/.bash_eternal_history
fi
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
shopt -s lithist
shopt -s cdspell # correct minor spelling mistakes in directory names for cd
# prevent me from doing stupid shit
export PIP_REQUIRE_VIRTUALENV=true
# complete sudo and man-pages
complete -cf sudo man
# get a nicer percentage in manpages
export MANPAGER='less -s -M +Gg'
# Vi Mode
set -o vi
# Support for gpg-agent. Used for ssh via gpg key (stored on yubikey)
if [ -f "${HOME}/.gpg-agent-info" ]; then
# shellcheck source=/dev/null
source "$HOME/.gpg-agent-info"
fi
# Custom scripts
PATH="${HOME}/bin:${PATH}"
# Rust/cargo
PATH="${HOME}/.cargo/bin:${PATH}"
# Go
PATH="${HOME}/go/bin:${PATH}"
# doom emacs
PATH="${PATH}:${HOME}/.emacs.d/bin"
# Put GNU versions of utilities further up in the path than older OSX versions
PATH="/usr/local/opt/coreutils/libexec/gnubin:${PATH}"
# Volta
export VOLTA_HOME="${HOME}/.volta"
PATH="${VOLTA_HOME}/bin:$PATH"
# Kyrat binary
PATH="$PATH:$HOME/.dotfiles/kyrat/bin"
PATH="$PATH:/usr/local/linkedin/bin:/export/content/linkedin/bin" # not sure why kyrat causes these not to added from /etc/profile
PATH="$PATH:${HOME}/.local/bin"
export PATH
# Display git status in prompt
GIT_PROMPT_START="${USER}@\h:\[\033[0;33m\]\w\[\033[0;0m\] _LAST_COMMAND_INDICATOR_ " # \u is somehow broken when calling new version of bash on linux
# export GIT_PROMPT_START
if [ -f "/usr/local/opt/bash-git-prompt/share/gitprompt.sh" ]; then
__GIT_PROMPT_DIR="/usr/local/opt/bash-git-prompt/share"
export __GIT_PROMPT_DIR
# shellcheck source=/dev/null
source "/usr/local/opt/bash-git-prompt/share/gitprompt.sh"
fi
#GIT_PROMPT_ONLY_IN_REPO=1
if [ -f "${HOME}/.bash-git-prompt/gitprompt.sh" ]; then
# shellcheck source=/dev/null
source "${HOME}/.bash-git-prompt/gitprompt.sh"
fi
export LS_COLORS="di=34"
# shellcheck source=/dev/null
[ -f "$HOME/.fzf.bash" ] && source "$HOME/.fzf.bash"
export FZF_DEFAULT_COMMAND='rg --files --no-ignore-messages --no-messages --hidden --no-ignore-vcs --ignore-file ~/.dotfiles/rgignore_fzf'
export FZF_ALT_C_COMMAND='rg --files --no-ignore-messages --no-messages --hidden --no-ignore-vcs --ignore-file ~/.dotfiles/rgignore_fzf'
export FZF_CTRL_T_COMMAND='rg --files --no-ignore-messages --no-messages --hidden --no-ignore-vcs --ignore-file ~/.dotfiles/rgignore_fzf'
export FZF_DEFAULT_OPTS="
--layout=reverse
--multi
--header='>:@ '
--pointer='->'
--prompt='$ '
--height 40%
--info=inline
--bind '?:toggle-preview'
--bind 'ctrl-a:select-all'
--bind 'ctrl-y:execute-silent(echo {+} | pbcopy)'
--bind 'ctrl-e:execute(echo {+} | xargs -o vim)'
"
_fzf_comprun() {
local command=$1
shift
case "$command" in
cd) fzf "$@" --preview 'tree -C {} | head -200' ;;
export|unset) fzf "$@" --preview "eval 'echo \$'{}" ;;
ssh) fzf "$@" --preview 'dig {}' ;;
vim) fzf "$@" --preview 'bat --style=numbers --color=always {} || cat {}' ;;
*) fzf "$@" ;;
esac
}
vws() { vim -c ":VWS /\c$1/" ~/vimwiki/index.wiki; }
# Aliases
alias db-update=~/.dotfiles/install
alias gl='git log --graph --oneline --all'
if type "nvim" &> /dev/null; then
alias vim='nvim'
alias vimdiff='nvim -d'
export EDITOR=nvim
export VISUAL=nvim
else
export EDITOR=vim
export VISUAL=vim
fi
if type "eza" &> /dev/null; then
export EXA_COLORS="xx=37"
alias l='eza -l -snew --color-scale all --color-scale-mode fixed -g --icons --git'
alias ll='eza -la --color-scale all --color-scale-mode fixed -g --icons --git'
alias lt='eza -l -snew --color-scale all --color-scale-mode fixed -g --icons --git --tree --level=2'
else
alias l='ls -lrht'
alias ll='ls -lrhta'
fi
if type "colordiff" &> /dev/null; then
alias diff='colordiff'
fi
alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'
alias dammit='sudo $(history -p \!\!)'
alias h=history
alias docker='sudo docker'
alias docker-compose='sudo docker-compose'
# alias sudo="sudo -E"
alias grep="grep --color=auto"
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias drm="docker rm"
alias dps="docker ps"
alias wiki='vim ~/vimwiki/index.wiki'
alias todo='vim ~/vimwiki/Todo.wiki'
alias diary='vim ~/vimwiki/diary/diary.wiki +VimwikiDiaryGenerateLinks +Calendar'
alias vimwiki2html='vim -R ~/vimwiki/index.wiki +VimwikiAll2HTML +q; open ~/vimwiki_html/index.html'
alias wikipull='cd ~/vimwiki/; git pull && git submodule update --remote --recursive --merge --init; cd -;'
alias wikipush='cd ~/vimwiki/personal/; git add . && git commit -m "alias commit: `date`" ; git push origin master; cd -; cd ~/vimwiki/; git add . && git commit -m "alias commit: `date`" && git push origin master; cd -;'
alias setlogintime='sudo lastlog -u $USER -S; sudo lastlog -u $USER'
alias ltmux="ssh -t deskr 'tmux -CC attach -d'"
# NixOS aliases
alias nixos-changelog='nix profile diff-closures --profile /nix/var/nix/profiles/system'
alias de="devenv"
# Functions
dirvimdiff ()
{
# Diff files between two directories in vimdiff, one at a time
# dirvimdiff dir1/ dir2/
for files in $(diff -rq $1 $2 | awk '/^Files .* differ.*$/ {print $2":"$4}');
do
nvim -d ${files%:*} ${files#*:};
done
}
# Enable direnv, if it's installed
if type "direnv" &> /dev/null; then
eval "$(direnv hook bash)"
fi