-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_bashrc
138 lines (116 loc) · 4.2 KB
/
dot_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
# If not running interactively, don't do anything
# vim: set ft=bash:
case $- in
*i*) ;;
*) return;;
esac
# Change default shell, if we're running distrobox
if [ -f "/run/host/etc/hostname" ] && [ -f "/etc/bbsh" ] && shopt -q login_shell ; then
read -p "Bash shell started as login shell inside bbsh. Will change to zsh." -t 1 -N 1 -s
echo ""
echo '[ -d "${HOME}/.local/bin" ] && export PATH="${HOME}/.local/bin:${PATH}"' | sudo tee /etc/profile.d/bin_path.sh >/dev/null
source /etc/profile.d/bin_path.sh
chsh -s /bin/zsh
exec /bin/zsh -l
fi
# Check if Path needs to be augmented with ~/.local/bin
if [[ -d "${HOME}/.local/bin" ]] ; then
if ! [[ "${PATH}" =~ "${HOME}/.local/bin" ]] ; then
export PATH="${HOME}/.local/bin:${PATH}"
fi
fi
# Set vi/vim keybindings
set -o vi
bind '"\e."':yank-last-arg
HISTCONTROL=ignoreboth
HISTSIZE=1000
HISTFILESIZE=2000
shopt -s histappend
shopt -s checkwinsize
shopt -s globstar
### Display error exit codes
EC() { echo -e '\e[1;33m'code $?'\e[m\n'; }
trap EC ERR
### check the window size after each command and, if necessary,
shopt -s checkwinsize
### Search History
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
### Set Word Forward/Backward as [ctrl][left]/[ctrl][right]
bind '"\e[1;5C": forward-word'
bind '"\e[1;5D": backward-word'
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
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
function command_not_found_handle {
# check because c-n-f could've been removed in the meantime
if [ -x /usr/lib/command-not-found ]; then
/usr/lib/command-not-found -- "$1"
return $?
elif [ -x /usr/share/command-not-found/command-not-found ]; then
/usr/share/command-not-found/command-not-found -- "$1"
return $?
else
printf "%s: command not found\n" "$1" >&2
return 127
fi
}
fi
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
if [ -n "${SUDO_USER}" ] ; then
sudo_state='\033[97;1;101mS\033[m'
else
sudo_state=''
fi
if [ "$(id -u)" -eq 0 ] ; then
user_state='\033[91;100;1m\u\033[0m' # Root Colour (uid = 0)
elif [ "$(id -u)" -lt 1000 ] ; then
user_state='\033[92;100;1m\u\033[0m' # System Account Colour (0 < uid < 1000)
else
user_state='\033[92;100;1m\u\033[0m' # Normal User Colour
fi
if [ -f "/run/host/etc/hostname" ] ; then # when this file exists, distrobox is used
host_state="\033[97;1;44m$(cat /run/host/etc/hostname)\033[0m"
phost_state='\033[0m📦'
else
host_state="\033[97;44m\h\033[0m"
phost_state=''
fi
PS1="${phost_state}${sudo_state}${user_state}@${host_state} [\033[01;34m\]\w\[\033[00m]\$ "
unset phost_state sudo_state user_state host_state
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
if [ -f /run/.containerenv ] ; then
if grep -q '^\s*name\s*=\s*"debian"' /run/.containerenv ; then
alias tf='az account set --subscription "$(basename ${PWD})" && terraform'
alias nvim='distrobox-host-exec distrobox enter bbsh -a "--env NVIM_APPNAME=nvim-bbsh" -- nvim'
alias nv='distrobox-host-exec distrobox enter bbsh -a "--env NVIM_APPNAME=nvim-bbsh" -- nvim'
alias nvimdiff='distrobox-host-exec distrobox enter bbsh -a "--env NVIM_APPNAME=nvim-bbsh" -- nvim -d'
alias nvdiff='distrobox-host-exec distrobox enter bbsh -a "--env NVIM_APPNAME=nvim-bbsh" -- nvim -d'
cd "${HOME}/Projects.umcu"
fi
fi