-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathshellrc
129 lines (110 loc) · 3.22 KB
/
shellrc
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
# Shared by both bash and zsh
if [[ -z "$_THIS_DIR" ]]; then
echo "Error: don't source this file directly, source '_bashrc' or '_zshrc'"
return
fi
source $_THIS_DIR/shell/find_sources
source $_THIS_DIR/shell/trash_rm
# Only show my processes
alias mytop='top -u $(id -u -n)'
# Dequarantine files downloaded from the Internet
if [[ $(uname) == "Darwin" ]]; then
alias dequarantine='xattr -r -d com.apple.quarantine'
allowapp() {
if [[ "$#" -eq 0 ]]; then
echo "Usage: $0 <path/to/app>"
return 1
fi
codesign --sign - --force --deep $@ && xattr -d com.apple.quarantine $@
}
fi
# Grep options
_GREP_OPTIONS="--color --exclude-dir=.svn --exclude-dir=.git"
alias grep="grep $_GREP_OPTIONS"
alias egrep="egrep $_GREP_OPTIONS"
alias fgrep="fgrep $_GREP_OPTIONS"
alias rot13="tr 'A-Za-z' 'N-ZA-Mn-za-m'"
if [[ $(uname) == "Darwin" ]]; then
export CLICOLOR=1
alias ls="ls -G"
else
alias ls="ls --color --time-style='+%F %T'"
fi
# The `pinstall` aliaa -- package install
make_install_alias() {
local sudo
if which sudo &> /dev/null; then
sudo='sudo '
fi
if which yum &> /dev/null; then
alias pinstall="${sudo}yum install"
elif which brew &> /dev/null; then
alias pinstall="brew install"
elif which apt &> /dev/null; then
alias pinstall="${sudo}apt install"
elif which apt-get &> /dev/null; then
alias pinstall="${sudo}apt-get install"
fi
}
make_install_alias
alias ll='ls -l'
alias la='ls -a'
# Fix `tail -f` problem for WSL
if [[ -n "$IS_WSL" || -n "$WSL_DISTRO_NAME" ]]; then
alias tail='tail ---disable-inotify'
fi
export EDITOR=vim
export FIGNORE=svn
export NINJA_STATUS='[%es:%p %o/s %f/%r/%t] '
export PATH=$PATH:$HOME/.local/bin
export PATH=$PATH:$_THIS_DIR/bin
export PATH=$PATH:$HOME/go/bin
export PYTHONDONTWRITEBYTECODE=1
# Set the best locale
function _set_locale() {
local all
local l
all=$(locale -a 2>/dev/null)
for l in "zh_CN.UTF-8" "zh_CN.utf8" "en_US.UTF-8" "C.UTF-8"; do
if [[ "$all" == *"$l"* ]]; then
export LC_ALL="$l"
return
fi
done
echo "Warning: Can't set correct locale" > /dev/stderr
}
_set_locale
# Git branch in prompt.
parse_git_branch() {
LC_ALL=C git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# Make dir and change to it immediately
mkcd() {
mkdir $@ && cd "${@: -1}"
}
# Prohibit the use of vim in the vscode terminal
_no_vim_in_vscode() {
echo "Don't use vim in vscode terminal, [cmd+click] the filename to edit in in vscode." > /dev/stderr
# Check this variable again to allow change the behavior dynamically
if [ "$ALLOW_VIM_IN_VSCODE" != "1" ]; then
local answer
echo -n "Open it in vscode (y/N)? "
read answer
if [ "$answer" = "y" ]; then
code "$@"
return
fi
fi
\vim "$@"
}
if [ "$ALLOW_VIM_IN_VSCODE" != "1" -a "$TERM_PROGRAM" = "vscode" ]; then
alias vim=_no_vim_in_vscode
alias vi=vim
fi
# Use vscode as git editor in vscode terminal
if [ "$TERM_PROGRAM" = "vscode" ]; then
export EDITOR="code --wait"
fi
# Shell history optimization
# ignoreboth=ignoreboth:ignoredups
export HISTCONTROL=ignoreboth