forked from randy3k/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bashrc
More file actions
120 lines (107 loc) · 3.52 KB
/
Copy path.bashrc
File metadata and controls
120 lines (107 loc) · 3.52 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# interactive shell only
[[ ! $- == *i* ]] && return
# aliases
[[ -e ~/.aliases ]] && . ~/.aliases
# enable i-search
stty -ixon -ixoff
# keybinds
# substring search
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind '"\e[1;9D": backward-word'
bind '"\e[1;9C": forward-word'
bind '"\e[1;3D": backward-word'
bind '"\e[1;3C": forward-word'
# ignore ctrl-d
IGNOREEOF=1
# bash completion
bind "set completion-ignore-case on"
bind "set show-all-if-ambiguous on"
bind "set colored-stats on"
bind "set colored-completion-prefix on"
bind TAB:menu-complete
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
if [[ -f /usr/local/opt/git/share/git-core/contrib/completion/git-completion.bash ]]; then
source /usr/local/opt/git/share/git-core/contrib/completion/git-completion.bash
fi
if [[ -f /opt/local/etc/bash_completion.d/git-completion.bash ]]; then
source /opt/local/etc/bash_completion.d/git-completion.bash
fi
if [[ $BASH_VERSION > 4.2 ]]; then
[[ -f /usr/local/etc/bash_completion.d/R ]] && source /usr/local/etc/bash_completion.d/R
fi
[[ -f /usr/local/etc/bash_completion.d/tmux ]] && source /usr/local/etc/bash_completion.d/tmux
# color
if [ "$(uname)" == "Darwin" ]; then
export CLICOLOR=1
export LSCOLORS=exfxcxdxbxegedabagacad
else
export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43:*.rpm=90'
fi
# prompt
function git-branch-name {
echo `git symbolic-ref HEAD --short 2> /dev/null || (git branch | sed -n 's/\* (*\([^)]*\))*/\1/p')`
}
function git-dirty {
[[ `wc -l <<< "$1" ` -eq 1 ]] || echo "*"
}
function git-unpushed {
if [[ "$1" =~ ("behind "([[:digit:]]*)) ]]
then
echo -n "-${BASH_REMATCH[2]}"
fi
if [[ "$1" =~ ("ahead "([[:digit:]]*)) ]]
then
echo -n "+${BASH_REMATCH[2]}"
fi
}
function gitcolor {
st=$(git status -b --porcelain 2>/dev/null)
[[ $? -eq 0 ]] || return
if [[ $(git-dirty "$st") == "*" ]];
then
echo -e "\033[31m"
elif [[ $(git-unpushed "$st") != "" ]];
then
echo -e "\033[33m"
else
echo -e "\033[32m"
fi
}
function gitify {
st=$(git status -b --porcelain 2>/dev/null)
[[ $? -eq 0 ]] || return
dirty=$(git-dirty "$st")
unpushed=$(git-unpushed "$st")
echo -e " ($(git-branch-name)$dirty$unpushed)"
}
PS1="\[\033[33m\](\h)\[\033[00m\]-\W\[\$(gitcolor)\]\$(gitify)\[\033[00m\]\$ "
if [ "$(uname)" == "Darwin" ] && [ "$TERM" = "xterm-256color" ] && [ -z "$INSIDE_EMACS" ]; then
update_terminal_cwd() {
local url_path=''
{
local i ch hexch LC_CTYPE=C LC_ALL=
for ((i = 0; i < ${#PWD}; ++i)); do
ch="${PWD:i:1}"
if [[ "$ch" =~ [/._~A-Za-z0-9-] ]]; then
url_path+="$ch"
else
printf -v hexch "%02X" "'$ch"
# printf treats values greater than 127 as
# negative and pads with "FF", so truncate.
url_path+="%${hexch: -2:2}"
fi
done
}
printf '\e]0;\a'
printf '\e]1;%s\a' `basename $PWD`
printf '\e]7;%s\a' "file://$HOSTNAME$url_path"
}
PROMPT_COMMAND="update_terminal_cwd${PROMPT_COMMAND:+; $PROMPT_COMMAND}"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ] && [ "$TERM" == "xterm-256color" ]; then
PROMPT_COMMAND='reset_terminal_title'
function reset_terminal_title {
printf "\033]0;%s\007" "${HOSTNAME%%.*}"
printf '\033]7;\007'
}
fi