forked from jumper149/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
82 lines (75 loc) · 2.26 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
#!/usr/bin/env bash
# if not running interactively, don't do anything
[[ $- != *i* ]] && return
source "${HOME}/.profile"
source "${HOME}/.posixrc"
# don't clutter home directory
HISTFILE="${XDG_DATA_HOME}/bash/bash_history"
mkdir -p "$(dirname "${HISTFILE}")"
# auto completion
source "/usr/share/git/completion/git-completion.bash"
__git_complete dotgit __git_main
__git_complete safegit __git_main
# shell prompt
source "/usr/share/git/completion/git-prompt.sh"
__red_ps="$(tput setaf 1)"
__green_ps="$(tput setaf 2)"
__orange_ps="$(tput setaf 3)"
__blue_ps="$(tput setaf 4)"
__purple_ps="$(tput setaf 5)"
__yellow_ps="$(tput setaf 11)"
__bold_ps="$(tput bold)"
__normal_ps="$(tput sgr0)"
function __exit_ps1() {
local EXIT="${?}"
local EXIT_COLOR=""
if [ "${EXIT}" = 0 ]; then
EXIT_COLOR="${__green_ps}"
else
EXIT_COLOR="${__red_ps}"
fi
printf '\001%s\002' "${EXIT_COLOR}"
return "${EXIT}"
}
function __hostname_ps1() {
local EXIT="${?}"
if [ -n "${SSH_CONNECTION}" ]; then
printf "\001%s\002@\001%s\002%s" "${__normal_ps}" "${__purple_ps}" "${1}"
fi
return "${EXIT}"
}
PS1='\001${__normal_ps}\002[$(__exit_ps1)\u$(__hostname_ps1 \h) \001${__blue_ps}\002\W$(__git_ps1 " \001${__normal_ps}\002@\001${__orange_ps}\002%s")\001${__normal_ps}\002]\001${__bold_ps}\002\$\001${__normal_ps}\002 '
function __whitespace_ps2() {
local EXIT="${?}"
local EXTRA_SPACE="3"
local USERNAME="${1}"
local HOSTNAME=""
if [ -n "${SSH_CONNECTION}" ]; then
HOSTNAME="@${2}"
fi
local DIRECTORY="${3}"
if [ "${DIRECTORY}" = "${HOME}" ]; then
DIRECTORY="~"
fi
local GIT_BRANCH
GIT_BRANCH="$(__git_ps1 " @%s")"
local LENGTH="$(( EXTRA_SPACE + ${#USERNAME} + ${#HOSTNAME} + ${#DIRECTORY} + ${#GIT_BRANCH} ))"
printf '%*s' "${LENGTH}" ""
return "${EXIT}"
}
PS2='$(__whitespace_ps2 \u \h \W)\001${__yellow_ps}${__bold_ps}\002|\001${__normal_ps}\002 '
# vim input
set -o vi
if [ "${TERM}" = "linux" ]; then
__graphical_session="$(decide "Xmonad" "i3" "TTY")"
case $__graphical_session in
"TTY")
;;
"i3")
startx ~/.xinitrc "i3" && exit
;;
"Xmonad")
startx ~/.xinitrc "xmonad" && exit
;;
esac
fi