-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path.bashrc
172 lines (147 loc) · 4.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
# shellcheck disable=SC1090,SC1091,SC2039
##########################
# Early Initialization #
##########################
# Setup some environment variables before the interactivity check. This is the
# only place where you can place startup commands that will be picked up by
# non-interactive SSH sessions.
#
# https://www.gnu.org/software/bash/manual/bash.html#Invoked-by-remote-shell-daemon
if [[ -f ~/.nix-profile/etc/profile.d/hm-session-vars.sh ]]; then
source ~/.nix-profile/etc/profile.d/hm-session-vars.sh
fi
export EDITOR="nvim"
export LANG="en_US.UTF-8"
export LESS="iFMR"
export PAGER="less"
export SYSTEMD_LESS="iFRSMK"
export GOPATH=~/Documents/src/go
# whether to make use of powerline fonts
if [[ -n "$DISPLAY$WAYLAND_DISPLAY$SSH_CONNECTION$SSH_TTY" ]]; then
export USE_POWERLINE=1
else
export USE_POWERLINE=0
fi
# skip the rest for non-interactive sessions
case $- in
*i*) ;;
*) return ;;
esac
###########################
# Environment Variables #
###########################
GPG_TTY="$(tty)"
printf -v PATH "%s:" \
~/.local/bin \
"$PATH" \
~/.config/emacs/bin
PATH="${PATH%%:}"
export GPG_TTY
export PATH
command -v direnv >/dev/null 2>&1 && eval "$(direnv hook bash)"
###########################
# Aliases and Functions #
###########################
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias ls='ls -F --color=auto'
alias ll='ls -lh'
alias la='ls -lAh'
alias ssh-fa='ssh-agent ssh -o AddKeysToAgent=confirm -o ForwardAgent=yes'
#############
# History #
#############
HISTCONTROL=ignoreboth
HISTSIZE=1000
HISTFILESIZE=2000
shopt -s cmdhist
shopt -s lithist
shopt -s histappend
######################
# Terminal Support #
######################
__dot::urlencode() {
# Use LC_CTYPE=C to process text byte-by-byte.
local LC_CTYPE=C LC_ALL='' raw_url="$1" safe
while [[ -n "$raw_url" ]]; do
safe="${raw_url%%[!a-zA-Z0-9/:_\.\-\!\'\(\)~]*}"
printf "%s" "$safe"
raw_url="${raw_url#"$safe"}"
if [[ -n "$raw_url" ]]; then
printf "%%%02X" "'$raw_url"
raw_url="${raw_url#?}"
fi
done
}
__dot::report_cwd() {
printf "\e]7;file://%s%s\a" "${HOSTNAME:-}" "$(__dot::urlencode "$PWD")"
}
# deal with missing line feeds from previous command
__dot::print_missing_lf() {
# XXX: This might not sit well with misbehaving terminals. It also messes
# up output on window resize, but I decided to just live with it for now
# because only a few applications fail to output a trailing newline.
# FWIW zsh also exhibits this behavior.
#
# Reference:
# https://www.vidarholen.net/contents/blog/?p=878
# https://unix.stackexchange.com/questions/60459
printf "\\e[7m\$\\e[0m%$((COLUMNS - 1))s\\r\\e[K"
}
case "$TERM" in
xterm*)
PROMPT_COMMAND="__dot::print_missing_lf;__dot::report_cwd;$PROMPT_COMMAND"
;;
screen*|tmux*)
PROMPT_COMMAND="__dot::print_missing_lf;$PROMPT_COMMAND"
;;
esac
if [[ -n "$INSIDE_EMACS" ]]; then
export EDITOR='emacsclient'
fi
##########
# Misc #
##########
set -o noclobber
shopt -s checkjobs
shopt -s checkwinsize
shopt -s globstar
stty -ixoff -ixon # disable flow control
if ! shopt -oq posix; then
if [[ -f /usr/share/bash-completion/bash_completion ]]; then
source /usr/share/bash-completion/bash_completion
elif [[ -f /etc/bash_completion ]]; then
source /etc/bash_completion
fi
fi
###########
# Theme #
###########
if [[ $TERM == "dumb" ]]; then
PS1='\u@\h:\w\$ '
return
fi
unset LS_COLORS # clear distro defaults
__prompt_dashboard_lite() {
local exitcode="$?" # must come first
PS1='\[\e]0;\w\a\]' # set terminal title
if (( EUID == 0 || UID == 0 || EUID != UID )); then
PS1+='\[\e[1;31m\]\u\[\e[0m\] in '
fi
PS1+='\[\e[1;34m\]\w\[\e[0m\]'
if [[ -n "$SSH_CONNECTION" ]]; then
PS1+=' at \[\e[1;33m\]\h\[\e[0m\]'
fi
PS1+=' using \[\e[1;32m\]bash\[\e[0m\]'
if [[ -n "$IN_NIX_SHELL" ]]; then
PS1+=' via \[\e[1;36m\]'"${name:-nix-shell}"'\[\e[0m\]'
fi
if (( exitcode == 0 )); then
PS1+='\n\[\e[1;32m\]\$\[\e[0m\] '
else
PS1+='\n\[\e[1;31m\]\$\[\e[0m\] '
fi
}
# must come last
PROMPT_COMMAND="__prompt_dashboard_lite;$PROMPT_COMMAND"