-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_settings.sh
More file actions
98 lines (82 loc) · 2.57 KB
/
bash_settings.sh
File metadata and controls
98 lines (82 loc) · 2.57 KB
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
# Generic "Host Independent" Bash Settings
source ~/dotfiles/bash_colors.sh
# Interesting little set of functions for git/svn info.
function parse_git_branch() {
local DIRTY STATUS
STATUS=$(git status --porcelain 2>/dev/null)
[ $? -eq 128 ] && return
[ -z "$(echo "$STATUS" | grep -e '^.M')" ] || DIRTY="*"
[ -z "$(echo "$STATUS" | grep -e '^[MDA]')" ] || DIRTY="${DIRTY}+"
[ -z "$(git stash list)" ]
echo "[$(git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* //')$DIRTY]"
}
function parse_svn_revision() {
local DIRTY REV=$(svn info 2>/dev/null | grep Revision | sed -e 's/Revision: //')
[ "$REV" ] || return
[ "$(svn st | grep -e '^ \?[M?] ')" ] && DIRTY='*'
echo "[r$REV$DIRTY]"
}
# Pretty sure this is broken (still)
#function parse_hg_branch() {
# local STATUS DIRTY=""
# STATUS=$(hg status 2>/dev/null)
# [[ `hg branch 2>/dev/null` ]] || return
# [ -z "$(echo "$STATUS" | grep -e '^[^?]')" ] || DIRTY="${DIRTY}+"
# echo "[$(hg branch 2>/dev/null | awk '{print $1}')$DIRTY]"
#}
function parse_vcs {
local STATUS
STATUS="$(parse_git_branch)$(parse_svn_revision)$(parse_hg_branch)"
if [ "$STATUS" ]; then
echo $STATUS
else
echo "[-]"
fi
}
# Check for an interactive session (What?)
[ -z "$PS1" ] && return
# Bash specifics
if [[ $SHELL == "/bin/bash" ]]; then
# Make bash check the window size after each command
shopt -s checkwinsize
# Bash Prompt
PS1_ES=0
PROMPT_COMMAND='PS1_ES=$?'
PS1_TIME="\[$Cyan\][\@]\[$Color_Off\]"
PS1_USER="\[$Red\]\u\[$Color_Off\]"
PS1_HOST="\[$Blue\]\h\[$Color_Off\]"
PS1_CWD="\[$Green\]\w\[$Color_Off\]"
PS1_VCS="\[$Purple\]\$(parse_vcs)"
PS1_END_COLOR='$(if [[ $PS1_ES -eq 0 ]]; then echo -ne "\[$Green\]"; else echo -ne "\[$Red\]"; fi)'
PS1_END="$PS1_END_COLOR\$\[$Color_Off\]"
PS1="$PS1_TIME $PS1_USER@$PS1_HOST:$PS1_CWD $PS1_VCS$PS1_END "
fi
# Useful Aliases
alias ls='ls --color=auto'
alias emacs='emacs -nw'
alias info='info --vi-keys'
alias pdb='python -m pdb'
alias pdb3='python3 -m pdb'
alias rm='rm -I'
export EDITOR="vim"
# If neovim is available, alias vim with that
if hash nvim ; then
alias vim="nvim"
export EDITOR="nvim"
fi
export VISUAL=$EDITOR # Stupid legacy variable for the same shit.
export PAGER="less"
# Add ~/bin to PATH if it exists
if [ -d ~/bin ] ; then
export PATH=$PATH":"$HOME"/bin"
fi
# Add Ruby gems to PATH if it exists
if [ -d ~/.gem ] ; then
export PATH=$PATH":"$HOME"/.gem/ruby/2.4.0/bin"
fi
# Add an alias to save the last command into a file.
alias getlast='fc -nl $((HISTCMD - 1))'
# Add local pip scripts to PATH if it exists
if [ -d ~/.local/bin ] ; then
export PATH=$PATH":"$HOME"/.local/bin"
fi