-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.sh_rc
executable file
·176 lines (155 loc) · 3.72 KB
/
.sh_rc
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
#!/not/executable/bash
# commands that must be run on each new shell
# generally, this is aliases, shell settings, functions
# if your command only needs to be run once per *terminal* use ~/.sh_env
# don't put duplicate lines in the history. See bash(1) for more options
HISTCONTROL=erasedups
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=64000
HISTFILESIZE=512000
SAVEHIST=$HISTFILESIZE
HISTTIMEFORMAT='[%F %a %p %I:%M%z]'
# aliases and functions {
alias time="/usr/bin/time -ao /dev/tty"
alias tmux-env='eval "$(tmux show-env -s)"'
alias crterm='export TERM=xterm-256color; . ~/.bashrc'
reset() {
## http://askubuntu.com/a/123296/23034
tput rmcup
command reset
}
login() {
. "$HOME/.profile"
if [ "$ZSH_VERSION" ]; then
. "$HOME/.zshrc"
fi
}
silent(){
"$@" >/dev/null 2>&1
}
noisy(){
echo "+$*" >&2
"$@"
}
# enable color support of ls and also add handy aliases
if has dircolors; then
if test -r ~/.dircolors; then
eval "$(dircolors -b ~/.dircolors)"
else
eval "$(dircolors -b)"
fi
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
fi
# busybox grep doesn't have --color=auto :(
if echo | grep --color=auto -q '' 2>/dev/null; then
alias grep='grep --color=auto'
alias fgrep='grep -F --color=auto'
alias egrep='grep -E --color=auto'
fi
alias diffstat='diffstat -C'
alias diff='diff --minimal --unified'
alias info='info --vi-keys'
alias ip='ip --color'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias ..='noisy cd ..'
alias ...='noisy cd ../..'
alias ....='noisy cd ../../..'
alias .....='noisy cd ../../../..'
alias ......='noisy cd ../../../../..'
alias .......='noisy cd ../../../../../..'
## Add an "alert" alias for long running commands. Use like so:
## sleep 10; alert
#alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -re '\''s/^\s*[0-9]+\s*//;s/[;&|]+\s*alert$//'\'')"'
# http://superuser.com/a/599156/50425
title() {
echo -n "]0;$*"
}
alert() {
command alert "${*:-It"'"s done!}" " (status: $?)"
}
mkdir -p "$XDG_RUNTIME_DIR/tmux-env"
tmux_env() {
if ! [ "$TMUX" ]; then
return 0
fi
local var=$XDG_RUNTIME_DIR/tmux-env
local old=$var/old.$$
local new=$var/new
tmux show-env -s > "$new"
if test -e "$old" && cmp -s "$old" "$new"; then
:
else
mv "$new" "$old"
. "$old"
fi
}
# } aliases and functions
if [[ "$COLORTERM" ]]; then
# set a fancy prompt
ansi_color() {
# terminfo will decide whether TERM is color capable
tput setaf "$@"
}
RESET="$(tput sgr0)"
else
ansi_color() { :; }
RESET=""
fi
RED="$(ansi_color 1)"
GREEN="$(ansi_color 2)"
YELLOW="$(ansi_color 3)"
BLUE="$(ansi_color 4)"
PURPLE="$(ansi_color 5)"
TEAL="$(ansi_color 6)"
PROMPT_DIRTRIM=3
if [ "${BASH:-}" ]; then
PSLESC='\['
PSRESC='\]'
PSUSER='\u'
PSHOST='\h'
PS1PWD='\w'
PSDATE='\D{'"$HISTTIMEFORMAT"'}'
elif [ "$ZSH_VERSION" ]; then
PSLESC='%{'
PSRESC='%}'
PSUSER='%n'
PSHOST='%M'
PS1PWD='%~'
PSDATE='%D{'"$HISTTIMEFORMAT"'}'
else # dash, busybox, or similar
PSLESC=''
PSRESC=''
PS1PWD='$PWD'
PSUSER='$USER'
PSHOST='$(hostname -s)'
PSDATE='$(date +"$HISTTIMEFORMAT")'
fi
if [ "$(id -u)" -eq 0 ]; then
PS1END='#'
else
PS1END='$'
fi
esc() {
echo -n "$PSLESC$1$PSRESC"
}
PS1="$(esc "$YELLOW")$PS1PWD
"\
"$(esc "$PURPLE")$PSDATE "\
"$(esc "$BLUE")$PSUSER"\
"$(esc "$RESET")@"\
"$(esc "$GREEN")$PSHOST "\
"$(esc "$RED")$PS1END"\
"$(esc "$RESET") "
unset esc
export PS1
# extra shell settings for work
. "$HOME/.sh_lib/functions.d/trysource.sh"
trysource ~/private-dotfiles/.sh_rc
. "$HOME/.sh_advanced_rc"
echo "==> $HOME/TODO.md <=="
cat "$HOME/TODO.md"