-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
184 lines (160 loc) · 6.3 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
#!/bin/bash
#│-v-1 │ To-Do's
#└─────┴─────────
# (not actually settings, just settings todo's)
# For more todo’s, try /-ing “TODO”.
# TODO refactor bashprompt to function pieces, maybe.
#│-v-1 │ Set-up
#└─┬───┴─┬──────
#│-v-2 │ Other stuff
#└─────┴─────────────
# (Roughly) check whether .profile exists and doesn't contain the substring
# '.bashrc' (guessing that it attempts to source it).
#
# TODO: determine whether any distro actually has a ~/.profile that is not
# expected to source ~/.bashrc
if [[ -f ~/.profile ]] && [[ ! `cat ~/.profile` =~ '.bashrc' ]]; then
source /home/atimholt/.profile
fi
if [ -d "$HOME/.local/bin" ] ; then
export PATH="$HOME/.local/bin:$PATH"
fi
#│-v-2 │ X settings
#└─────┴────────────
if [[ `cat /proc/version` =~ "microsoft" ]]; then
# In WSL2
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
#export DISPLAY=:0
export LIBGL_ALWAYS_INDIRECT=1
else
# Real linux
export DISPLAY=:0
export LIBGL_ALWAYS_INDIRECT=0
fi
#│-v-2 │ Behavior
#└─┬───┴─┬────────
#│-v-3 │ Built-in Settings
#└─────┴───────────────────
# vi input mode for the command line
set -o vi
shopt -s dotglob
# default editors
if ! `which eselect &>/dev/null`; then
export EDITOR="nvim"
export VISUAL="nvim"
fi
#│-v-3 │ Tools
#└─┬───┴─┬─────
#│-v-4 │ Setup
#└─────┴───────
source ~/code/from_others/git-subrepo/.rc
#│-v-4 │ Settings
#└─────┴──────────
export MANWIDTH=80
#│-v-3 │ Aliases
#└─────┴─────────
## ls
alias l='ls -xF --color=auto --time-style=long-iso'
alias ll='ls -lhF --color=auto --time-style=long-iso'
alias la='ls -xAF --color=auto --time-style=long-iso'
alias lla='ls -lhAF --color=auto --time-style=long-iso'
alias glog="git log --all --graph --decorate --date=short-local --format='format:%Cblue%ad %h %Cred%d%Creset %s'"
## Mercurial
function hgdiff()
{
hg diff $1 | nvim - -R -M
}
function hghp()
{
hg help --verbose $1 | nvim - -R -M
}
#│-v-2 │ Appearance
#└─┬───┴─┬──────────
#│-v-3 │ Built-in Settings
#└─┬───┴─┬─────────────────
#│-v-4 │ Prompt Appearance
#└─────┴───────────────────
# text colors -v-
# Taken from (then fixed proper):
# http://www.reddit.com/r/commandline/comments/1do8cb/A/c9sdp29
TXTBLK='\[\e[0;30m\]' # Black - Regular
TXTRED='\[\e[0;31m\]' # Red
TXTGRN='\[\e[0;32m\]' # Green
TXTYLW='\[\e[0;33m\]' # Yellow
TXTBLU='\[\e[0;34m\]' # Blue
TXTPUR='\[\e[0;35m\]' # Purple
TXTCYN='\[\e[0;36m\]' # Cyan
TXTWHT='\[\e[0;37m\]' # White
BLDBLK='\[\e[1;30m\]' # Black - Bold
BLDRED='\[\e[1;31m\]' # Red
BLDGRN='\[\e[1;32m\]' # Green
BLDYLW='\[\e[1;33m\]' # Yellow
BLDBLU='\[\e[1;34m\]' # Blue
BLDPUR='\[\e[1;35m\]' # Purple
BLDCYN='\[\e[1;36m\]' # Cyan
BLDWHT='\[\e[1;37m\]' # White
TXTRST='\[\e[0m\]' # Text Reset
#-^-
terminal_is_new=1
function change_ps1
{ #-v-
local prev_exit=$?
local the_ps1=""
# “pre” prompt stuff.
if [ $terminal_is_new = 1 ] ; then
terminal_is_new=0
else
if [ $prev_exit = 0 ] ; then
the_ps1+="${TXTGRN}✓"
else
the_ps1+="${TXTRED}✗ (${prev_exit})"
fi
the_ps1+="${TXTRST}\n\n" # gap between associates this with previous
fi # command.
# basic info.
the_ps1+="${BLDGRN}\u${BLDBLU}@${BLDGRN}\H "
the_ps1+="${BLDBLU}\w"
# repo branch and status by color
# git code adapted from http://thepugautomatic.com/2008/12/git-dirty-prompt/
# TODO indicate whether is the head.
#-v-
current_branch="$(git branch --no-color 2> /dev/null | sed -e \
'/^[^*]/d' -e "s/* \(.*\)/\1/")"
if [ -n "${current_branch}" ] ; then
if [ -n "$(git status -s -u no 2> /dev/null)" ] ; then
the_ps1+="${TXTYLW}"
else
the_ps1+="${TXTGRN}"
fi
the_ps1+=" [git:${current_branch}]"
else # Only necessary if it’s not already another kind of repo.
current_branch="$(hg branch 2> /dev/null)"
if [ -n "${current_branch}" ] ; then
if [ -n "$(hg stat -q 2> /dev/null)" ] ; then
the_ps1+="${TXTYLW}"
else
the_ps1+="${TXTGRN}"
fi
the_ps1+=" [hg:${current_branch}]"
fi
fi
#-^-
# history number of current command.
the_ps1+="\n${TXTGRN}[${BLDBLU}!\!${TXTGRN}] 〉${TXTRST}"
export PS1=${the_ps1}
} #-^-
PROMPT_COMMAND=change_ps1
export PS2="${BLDBLU} … ${TXTGRN}〉${TXTRST}"
# Notes:
# ===-v-
#
# For detailed info on customizing the bash prompt, see:
# http://www.gilesorr.com/bashprompt/howto/
#
# For some good ideas, see:
# http://www.reddit.com/r/commandline/comments/1do8cb/alright_echo_your_ps1s_lets_see_your_colourful/
# http://www.reddit.com/r/programming/comments/697cu/bash_users_what_do_you_have_for_your_ps1/
#
# echo -n <value> will supress trailing newline
# -^-
# vim: set nowrap fmr=-v-,-^- fdm=marker cms=#%s et ts=2 sw=0 sts=-1 :