-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash-config
140 lines (114 loc) · 3.13 KB
/
bash-config
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
# Based on AdamWhittingham/bash-config, kept only those I use, added some extra.
# Command Aliases
## ls aliases
alias ll='ls -alF'
# Homebrew aliases
alias bu='brew update && brew upgrade && brew cleanup'
## Ruby aliases
alias be='bundle exec'
alias rake='bundle exec rake'
## Git aliases
alias ga='git add'
alias gc='git commit'
alias gd='git diff'
alias gl='git_pretty_log'
alias gs='git status'
# Extra functions
function source_if_present(){
local file="$1"
[[ -f $file ]] && source "$file"
}
# Load Extra Things
# Run brew install bash-completion
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
# Git Log Niceness
_I_=' '
HASH="%C(green)%h%C(reset)"
AGE="%C(yellow)%ar%C(reset)"
AUTHOR="%C(bold blue)%an%C(reset)"
REFS="%C(bold red)%d%C(reset)"
COMMENT="%s"
FORMAT="$HASH$_I_$AGE$_I_$AUTHOR$_I_$REFS $COMMENT"
git_pretty_log() {
git log --graph --decorate --pretty="tformat:${FORMAT}" $* |
less -FXRS
}
function git_working_changed {
git diff --quiet 2> /dev/null
if [[ $? == 0 ]]; then return 1; else return 0; fi
}
function git_staging_changed {
git diff --cached --quiet 2> /dev/null
if [[ $? == 0 ]]; then return 1; else return 0; fi
}
function git_changed {
$(git_working_changed) || $(git_staging_changed)
}
# Bind extra keys
## Bind UpArrow and DownArrow to search to autocomplete the current command
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
# Force term type to stop all the stupidity in vim, tmux et. al. Not a good idea but fixes too many things not to do it for now.
export TERM=xterm-256color
# Set vim as default editor
export EDITOR=vim
# Get CLI file colors back in OS X
export CLICOLOR=1
# Colour Vars
bold="$(tput bold)"
reset="\001$(tput sgr0)\002"
blue="\001$bold$(tput setaf 4)\002"
cyan="\001$bold$(tput setaf 6)\002"
green="\001$bold$(tput setaf 2)\002"
purple="\001$bold$(tput setaf 5)\002"
red="\001$bold$(tput setaf 1)\002"
white="\001$bold$(tput setaf 7)\002"
yellow="\001$bold$(tput setaf 3)\002"
# Prompt Colour Functions
function user_colour {
local colour=$green
if [[ $(id -u) == 0 ]]; then
colour=$red
fi
echo $colour
}
git_prompt() {
if [ -n "$(__gitdir)" ]; then
echo -e "$(git_branch_colour)($(git_branch))"
fi
}
function git_seconds_since_commit {
now=`date +%s`
local last_commit=`git log --pretty=format:'%at' -1`
local seconds=$((now-last_commit))
echo $seconds
}
function seconds_to_minutes {
local secs="$1"
echo "$((${secs}/60))"
}
function git_mins_since_commit {
echo "$(seconds_to_minutes $(git_seconds_since_commit))"
}
function colour_for_minutes {
local minutes="$1"
local colour=$green
if [[ $minutes -gt 30 ]]; then colour=$red
elif [[ $minutes -gt 15 ]]; then colour=$yellow
fi
echo -e "$colour"
}
function git_branch_colour {
local colour=$blue
if $(git_changed) ; then
local minutes_since_commit="$(git_mins_since_commit)"
colour=$(colour_for_minutes $minutes_since_commit)
fi
echo -e $colour
}
function git_branch {
echo "$(__git_ps1 "%s")"
}
# Setup Prompt
export PS2="-> "
export PS1="$(user_colour)\u$reset@$yellow\h$reset:$purple\W$reset\$(git_prompt)$reset$PS2"