-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathshellrc
129 lines (110 loc) · 3.51 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
config_dir="$HOME/.config/config_dir"
# Source a file if it exists.
function try_source {
[ -f "$1" ] && source "$1"
}
# Test if a command exists.
function test_command {
command -v "$1" > /dev/null
}
try_source "$config_dir/aliases"
# Set a color in the terminal palette.
# \param 1 The index in the pallete.
# \param 2 is a hexadecimal RGB color code.
function set_color {
if [ "$TERM" = "linux" ]; then
[ $1 -lt 16 ] && printf $'\e]P%X%s' "$1" "$2"
else
printf $'\e]4;%s;#%s\e\\' "$1" "$2"
fi
}
# Set terminal colors.
set_color 0 000000 # black
set_color 1 CC0000 # red
set_color 2 009900 # green
set_color 3 CC9900 # yellow
set_color 4 0066FF # blue
set_color 5 9933CC # magenta
set_color 6 009999 # cyan
set_color 7 CCCCCC # light grey
set_color 8 333333 # dark grey
set_color 9 FF3333 # bright red
set_color 10 33FF33 # bright green
set_color 11 FFFF33 # bright yellow
set_color 12 3399CC # bright blue
set_color 13 CC33FF # bright magenta
set_color 14 00FFFF # bright cyan
set_color 15 FFFFFF # white
# Set colors for 256
set_color 17 000033 # dark blue
set_color 22 003300 # dark green
set_color 52 330000 # dark red
set_color 53 330033 # dark magenta
# Disable ctrl-q and ctrl-s.
stty start undef stop undef
# Set up dircolors.
if test_command dircolors; then
test -r "$config_dir/dircolors" && eval "$(dircolors -b "$config_dir/dircolors")" || eval "$(dircolors -b)"
fi
# Set up additional colors for exa.
EXA_COLORS="uu=0:gu=0:un=33:gn=33"
EXA_COLORS="${EXA_COLORS}:lp=34;1"
EXA_COLORS="${EXA_COLORS}:ur=33:gr=33:tr=33"
EXA_COLORS="${EXA_COLORS}:uw=31:gw=31:tw=32"
EXA_COLORS="${EXA_COLORS}:ue=32:gx=32:tx=32"
EXA_COLORS="${EXA_COLORS}:ux=32;1"
# Highlight READMEs and license files.
EXA_COLORS="${EXA_COLORS}:README=33:README.*=33"
EXA_COLORS="${EXA_COLORS}:LICENSE=33:LICENSE.*=33"
EXA_COLORS="${EXA_COLORS}:COPYING=33:COPYING.*=33"
EXA_COLORS="${EXA_COLORS}:COPYING.LESSER=33:COPYING.LESSER.*=33"
# Build definition files.
EXA_COLORS="${EXA_COLORS}:Makefile=33;1"
EXA_COLORS="${EXA_COLORS}:Cargo.toml=33;1"
EXA_COLORS="${EXA_COLORS}:SConstruct=33;1"
EXA_COLORS="${EXA_COLORS}:CMakeLists.txt=33;1"
EXA_COLORS="${EXA_COLORS}:build.gradle=33;1"
EXA_COLORS="${EXA_COLORS}:Rakefile=33;1"
EXA_COLORS="${EXA_COLORS}:Gruntfile.js=33;1"
EXA_COLORS="${EXA_COLORS}:Gruntfile.coffee=33;1"
EXA_COLORS="${EXA_COLORS}:BUILD=33;1"
EXA_COLORS="${EXA_COLORS}:BUILD.bazel=33;1"
EXA_COLORS="${EXA_COLORS}:WORKSPACE=33;1"
EXA_COLORS="${EXA_COLORS}:build.xml=33;1"
EXA_COLORS="${EXA_COLORS}:package.xml=33;1"
export EXA_COLORS
# Enable viewing non-text files in less.
test_command lesspipe && eval "$(SHELL=/bin/sh lesspipe)"
# Create a directory and change to it.
function mkd {
if [ $# -gt 1 ]; then
echo "Usage: $0 [dir]" >&2
return 13
fi
if [ -z $1 ]; then
mkd "/tmp/$(date +%F-%H-%M-%S)"
else
mkdir -p "$1"
cd "$1"
fi
}
export TTY="$(tty)"
export TTY_HOST="$(who -m | awk '$NF ~ /\(.*\)/ { if ("/dev/" $2 == ENVIRON["TTY"]) { sub(/^\(/, "", $NF); sub(/\)$/, "", $NF); print $NF; exit 0; } }')"
export TTY_USER="$(ls -l "$TTY" 2>/dev/null | awk '{ print $3; exit 0; }')"
if [ -z "$TTY_USER" ]; then
export TTY_USER="$LOGNAME"
fi
if [ "$SHELLTTY" != "$TTY" ]; then
export SHELLTTY="$TTY"
export NESTEDSHELLS=0
elif [ "$SHELLPID" != "$$" ]; then
export NESTEDSHELLS=$(($NESTEDSHELLS + 1))
fi
export SHELLPID=$$
# Set up git prompt configuration.
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUPSTREAM=(auto verbose)
source "$config_dir/git-prompt.sh"
source "$HOME/.config/config_dir/git-prompt-path.sh"
try_source "$HOME/.shellrc.local"
# vi: ft=sh