-
Notifications
You must be signed in to change notification settings - Fork 3
/
.bashrc
207 lines (197 loc) · 6.51 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
# shellcheck disable=SC2148
# /etc/skel/.bashrc
# This bashrc file is created by Chawye Hsu, licensed under the MIT license.
#------------------------------------------------------------------------------#
# Support Platforms:
# Windows: Git-Bash/MSYS2/MinGW
# macOS: Bash
# Linux: Bash
#------------------------------------------------------------------------------#
# Test for an interactive shell.
[[ $- != *i* ]] && return
#-----------------------#
# Environment Variables #
#-----------------------#
export LANG=en_US.UTF-8
export TZ=UTC-8
# default editor
export EDITOR=nano
# Always display git dirty state
export GIT_PS1_SHOWDIRTYSTATE=1
# Enable Node.js (chalk) color
export FORCE_COLOR=1
# Xterm colors
[ "$TERM" == "xterm" ] && export TERM=xterm-256color
# XDG environment variables
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_STATE_HOME="$HOME/.local/state"
# XDG compliance
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/npm/npmrc"
# PATH updates - Add `~/.local/bin`:
_localbin="$HOME/.local/bin"
if [[ -d "$_localbin" && ":$PATH:" != *":$_localbin:"* ]]; then
export PATH="$_localbin:$PATH"
fi
# PATH updates -
case "$OSTYPE" in
darwin*)
# NOTES: macOS's default PATH (definition in `/etc/paths`):
# "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
#
# A `/Library/Apple/usr/bin` path will be added when the
# Xcode command line tools is installed.
# PATH updates - Add super bin directory installed by Homebrew:
if [[ -d "/usr/local/sbin" && ":$PATH:" != *":/usr/local/sbin:"* ]]; then
export PATH="/usr/local/sbin:$PATH"
fi
# bash-completion:
_bashcomp="/usr/local/etc/bash_completion"
# shellcheck disable=SC1090
[ -f "$_bashcomp" ] && source "$_bashcomp"
# Ruby rbenv:
[ -x "$(command -v rbenv)" ] && eval "$(rbenv init -)"
;;
linux*)
# PATH updates - Add linuxbrew:
_linuxbrew1="/home/linuxbrew/.linuxbrew/bin/brew" # sudo
[[ -f $_linuxbrew1 ]] && eval "$($_linuxbrew1 shellenv)"
_linuxbrew2="$HOME/.linuxbrew/bin/brew" # non sudo
[[ -f $_linuxbrew2 ]] && eval "$($_linuxbrew2 shellenv)"
# Add git-prompt (Arch Linux):
_gitprompt="/usr/share/git/completion/git-prompt.sh"
# shellcheck disable=SC1090
[ -f "$_gitprompt" ] && source "$_gitprompt"
esac
#--------------------#
# ls and dircolors #
#--------------------#
# LS_COLORS generated by [vivid](https://github.com/sharkdp/vivid)
if [ -x "$(command -v vivid)" ]; then
# shellcheck disable=SC2155
export LS_COLORS="$(vivid -m 8-bit generate snazzy)"
fi
# Uniform `ls` command on all platforms
case "$OSTYPE" in
darwin*)
if [ -x "$(command -v gls)" ]; then
alias ls='gls -F --group-directories-first --color' # GNU ls
else
alias ls="ls -F -G" # BSD/macOS ls
fi
;;
linux*|msys*)
# Too many unconcerned files and directories in Windows $HOME, ignore them.
ignoreList=("_viminfo" "navdb.csv" "NTUSER*" "ntuser*" "Local Settings*" \
"Application Data*" "My Documents*" "NetHood*" "PrintHood*" "Recent*" \
"SendTo*" "Templates*" "Cookies*" "3D Objects" "Thumbs.db" "Start Menu" \
"desktop.ini" "Saved Games" "Creative Cloud Files")
for item in "${ignoreList[@]}"; do
lsIgnore+="'$item',"
done
# shellcheck disable=SC2139
alias ls="ls -F --group-directories-first --color --ignore={$lsIgnore}"
;;
esac
alias l="ls"
alias la="ls -A"
alias ll="ls -lh"
alias lla="ls -lhA"
#---------------#
# Unify Aliases #
#---------------#
alias c="clear"
alias :q="exit"
alias ..="cd .."
alias ...="cd ../.."
alias myip="curl -s https://api.ip.sb/ip"
alias cls="clear"
case "$OSTYPE" in
darwin*)
alias here="open ."
;;
msys*)
# winpty fixes
alias ipconfig="winpty ipconfig"
alias nslookup="winpty nslookup"
alias ping="winpty ping"
# Emulate ifconfig on Windows MSYS
alias ifconfig="ipconfig"
alias open="explorer"
alias here="open ."
;;
esac
#-------------------------------------#
# ssh-agent on Git-Bash/MSYS2/MinGW #
#-------------------------------------#
# ref: https://help.github.com/articles/working-with-ssh-key-passphrases/
if [ "$OSTYPE" == "msys" ] && [ -x "$(command -v ssh)" ]; then
# ensure .ssh directory exists
[ ! -d "$HOME/.ssh" ] && mkdir -p "$HOME/.ssh" >| /dev/null
# test ssh is Win32-OpenSSH or not
if [[ ! "$(ssh -V 2>&1)" == *"Windows"* ]]; then
# we use $USERPROFILE instead of $HOME to locate SSH ENV,
# so we can share ssh env between Git-Bash and MSYS2,
# but be aware of that Win32-OpenSSH does not use SSH ENV
agentenv="$HOME/.ssh/agent.env"
# load ssh env
# shellcheck disable=SC1090
[ -f "$agentenv" ] && source "$agentenv" >| /dev/null
# agentstatus:
# 0=agent running w/ key;
# 1=agent w/o key;
# 2=agent not running.
agentstatus=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ "$agentstatus" -eq 2 ]; then
# shellcheck disable=SC1090
(umask 077; ssh-agent >| "$agentenv") && source "$agentenv" >| /dev/null
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ "$agentstatus" -eq 1 ]; then
ssh-add
fi
unset agentenv
else
ssh-agent >| /dev/null
ssh-add
fi
fi
#-------------------------------------#
# Program-languages specific settings #
#-------------------------------------#
# conda initialize
[ -x "$(command -v conda)" ] && eval "$(conda 'shell.bash' 'hook')"
#----------------------------#
# The Chawye's styled prompt #
#----------------------------#
function styled_prompt() {
# Color table
local RESET="\[\033[0m\]"
local BLACK="\[\033[0;30m\]"
local RED="\[\033[0;31m\]"
local GREEN="\[\033[0;32m\]"
local YELLOW="\[\033[0;33m\]"
local BLUE="\[\033[0;34m\]"
local MAGENTA="\[\033[0;35m\]"
local CYAN="\[\033[0;36m\]"
local WHITE="\[\033[0;37m\]"
# Terminal title
local TERMTITLE="\[\e]0; \w\a\]"
# Special system environment detection: WSL, MSYS2/MinGW
if [[ "$(uname -r)" == *"icrosoft"* ]]; then
DIST="$MAGENTA(WSL)$RESET"
elif [ -n "$MSYSTEM" ]; then
DIST="$MAGENTA($MSYSTEM)$RESET"
else
DIST=""
fi
# git-prompt
[ "$(type -t __git_ps1)" = 'function' ] && GITPS1="\$(__git_ps1 ' (%s)')"
# PS1 command substitution issue with newline:
# https://stackoverflow.com/questions/33220492/
# https://stackoverflow.com/questions/21517281/
# __git_ps1 not update issue:
# https://askubuntu.com/questions/896445/#comment2153553_1163371
PS1="$TERMTITLE$GREEN\h$DIST $YELLOW\W$CYAN$GITPS1$RESET"$'\n\$ '
}
styled_prompt