-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc
139 lines (124 loc) · 4.56 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
# environment
export PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin:/data/systems/bin:$PATH
# puppet path
export PATH=/opt/puppetlabs/bin:$PATH
# Editor
export EDITOR=/usr/bin/vim
# completion
source /etc/profile.d/bash_completion.sh
#colors
eval $(dircolors $HOME/.dotfiles/dircolors/dircolors.256dark)
#prompt
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
TITLEBAR='\[\e]0;\u@\h\a\]'
# Same thing.. but with octal ASCII escape chars
#TITLEBAR='\[\033]2;\u@\h\007\]'
# add git branch to prompt
git_branch() {
# -- Finds and outputs the current branch name by parsing the list of
# all branches
# -- Current branch is identified by an asterisk at the beginning
# -- If not in a Git repository, error message goes to /dev/null and
# no output is produced
git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
git_status() {
# Outputs a series of indicators based on the status of the
# working directory:
# + changes are staged and ready to commit
# ! unstaged changes are present
# ? untracked files are present
# S changes have been stashed
# P local commits need to be pushed to the remote
local status="$(git status --porcelain 2>/dev/null)"
local output=''
[[ -n $(egrep '^[MADRC]' <<<"$status") ]] && output="$output+"
[[ -n $(egrep '^.[MD]' <<<"$status") ]] && output="$output!"
[[ -n $(egrep '^\?\?' <<<"$status") ]] && output="$output?"
[[ -n $(git stash list) ]] && output="${output}S"
[[ -n $(git log --branches --not --remotes) ]] && output="${output}P"
[[ -n $output ]] && output="|$output" # separate from branch name
echo $output
}
git_color() {
# Receives output of git_status as argument; produces appropriate color
# code based on status of working directory:
# - White if everything is clean
# - Green if all changes are staged
# - Red if there are uncommitted changes with nothing staged
# - Yellow if there are both staged and unstaged changes
local staged=$([[ $1 =~ \+ ]] && echo yes)
local dirty=$([[ $1 =~ [!\?] ]] && echo yes)
if [[ -n $staged ]] && [[ -n $dirty ]]; then
echo -e '\033[1;33m' # bold yellow
elif [[ -n $staged ]]; then
echo -e '\033[1;32m' # bold green
elif [[ -n $dirty ]]; then
echo -e '\033[1;31m' # bold red
else
echo -e '\033[1;37m' # bold white
fi
}
git_prompt() {
# First, get the branch name...
local branch=$(git_branch)
# Empty output? Then we're not in a Git repository, so bypass the rest
# of the function, producing no output
if [[ -n $branch ]]; then
local state=$(git_status)
local color=$(git_color $state)
# Now output the actual code to insert the branch and status
echo -e "\x01$color\x02[$branch$state]\x01\033[00m\x02" # last bit resets color
fi
}
# Sample prompt declaration based off of the default Ubuntu 14.04.1 color
# prompt. Tweak as you see fit, or just stick "$(git_prompt)" into your
# favorite prompt.
# set prompt
if [ "$color_prompt" = yes ]; then
PS1="${TITLEBAR}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]>\$(git_prompt) "
else
PS1="${TITLEBAR}\u@\h:\W>\$(git_prompt)"
fi
unset color_prompt force_color_prompt
#aliases
alias cl='clear'
alias ls='ls --color=auto'
alias ll='ls -lah'
alias l.='ls -d .* --color=auto'
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias mkdir='mkdir -pv'
alias diff='colordiff'
alias mount='mount |column -t'
alias h='history'
alias j='jobs -l'
alias vi='vim -X'
alias rm='rm -I --preserve-root'
alias mv='mv -i'
alias cp='cp -i'
alias ln='ln -i'
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
alias root='sudo -i'
alias su='sudo -i'
alias wget='wget -c'
alias df='df -H'
alias du='du -ch'
alias rdp='xfreerdp -D -g 1920x1200 -d GAMEFORCE -u darf -x -b1 -z --ignore-certificate'
alias fixperm='find . -type f -print0 | xargs -0 chmod 644; find . -type d -print0 | xargs -0 chmod 755'