-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc_dfp
128 lines (99 loc) · 4.25 KB
/
.bashrc_dfp
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
## reviewing for help: https://sanctum.geek.nz/arabesque/bash-prompts/
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=20000
# don't add noise to the history file
HISTIGNORE='l:ls:bg:fg:pwd:history'
HISTTIMEFORMAT='%F %T '
# append to the history file, don't overwrite it
shopt -s histappend
# pack multiline commands into single history entry
shopt -s cmdhist
# attempt to complete @hostnames
shopt -s hostcomplete
# add command to history immediately
PROMPT_COMMAND='history -a'
# check the window size after each command and, if necessary, update the values of LINES and COLUMNS.
shopt -s checkwinsize
#
alias l='ls -al'
alias lsd='ls -ld */'
#
alias vim="vim -u ~/dfp-dotfiles/.vimrc"
alias vi="vim -u ~/dfp-dotfiles/.vimrc"
# string parts to help with colorizing the bash prompt
cgr="\[\e[2m\]";
cy="\[\e[38;5;226m\]"
cend="\[\e[0m\]";
# prompt, get an intuitive time string
function prompt_time {
timestring=$(date +%I:%M)
echo $timestring
}
# put the git branch on the prompt
function prompt_gitbranch {
gitbranch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')
echo $gitbranch
}
# indicate the depth of the path
function prompt_pathdepth {
foo=$(pwd)
arr=($(echo $foo | tr "/" " "))
echo ${#arr[@]}
}
# colorize hostname
function colorizehostname {
# you can add chars to the empty prefix to tweak the color
hostnamestring="zzzz"$(hostname)
let sum=0
lettervalues=($(echo $hostnamestring | grep -o .))
# sum up ordinal values of letters in hostname
for lv in "${lettervalues[@]}"
do
let sum=$sum+7\*$(printf '%d' "'$lv")
#echo "sum:"$sum
done
# convert sum to color index, try to avoid bad colors
colorindex=$(($sum % 72))
colorindex=$(($colorindex + 160))
# emit color code and hostname
echo "\[\e[38;5;"$colorindex"m\]"$(hostname)
}
export PS1="$cgr\$(prompt_time)$cend \u@$(colorizehostname)$cend $cgr/\$(prompt_pathdepth)/$cend\W $cy\$(prompt_gitbranch)$cend$ "
# tell less to: (i) ignore case in searches (j) center the target line in window
# (M) use verbose prompt (r) parse color codes as colors
export LESS=-ij.5Mr
# Add an "alert" alias for long running commands. Use like: sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# make directories in ls 'orange' instead of 'dark blue' which is impossible to read on a black background
LS_COLORS=$LS_COLORS:'di=0;33:' ; export LS_COLORS
################################################################################################
### git aliases
### ... probably all this stuff should be in ~/.gitconfig ?
###
# show what was done in specfic commit (diff between commit and previous commit)
function diffcommit {
git diff $1~ $1
}
alias gitdiffcommit=diffcommit
# show the git history of a project:
alias githist="git log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all"
#gitlog = git log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
#gitlogn = git log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
#gitlogs = git log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
#gitlogr = git log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative
#gitlist = git ls-files
#gitunstage = git reset --
#accept-ours = "!f() { git checkout --ours -- \"${@:-.}\"; git add -u \"${@:-.}\"; }; f"
#accept-theirs = "!f() { git checkout --theirs -- \"${@:-.}\"; git add -u \"${@:-.}\"; }; f"