-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprompt
108 lines (93 loc) · 2.69 KB
/
prompt
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
# Modify prompt for source (SSH/screen/etc)
SSH_FLAG=0
SSH_IP=$(echo $SSH_CLIENT | awk '{ print $1 }')
if [ "$SSH_IP" ] ; then
SSH_FLAG=1
fi
SSH2_IP=$(echo $SSH2_CLIENT | awk '{ print $1 }')
if [ "$SSH2_IP" ] ; then
SSH_FLAG=1
fi
if [ "$SSH_FLAG" -eq 1 ] ; then
CONN="ssh"
elif [ -z "$SESS_SRC" ] ; then
CONN="lcl"
elif [ "$SESS_SRC" == "(:0.0)" -o "$SESS_SRC" == "" ] ; then
CONN="lcl"
else
CONN="tel"
fi
if [ "$CONN" == "lcl" ] ; then
CONN=
else
CONN="<$CONN> "
fi
if [ "$TERM" == "screen" ] ; then
SNAME=$(echo $STY | perl -pe 's/\d+\.//g')
if [ "$(echo $SNAME | perl -pe 's/(pts).*/$1/g')" = "pts" ] ; then
SNAME=screen
SNAME=" <$SNAME>"
fi
fi
BRANCH=
REPO=
GITINFO="\[\033"
if git rev-parse --abbrev-ref HEAD 1> /dev/null 2>&1 ; then
BRANCH=$(git rev-parse --abbrev-ref HEAD)
REPO="$(basename "$(git rev-parse --show-toplevel)")"
GITINFO="\[\033[01;35m\]$REPO\[\033[01;33m\] ($BRANCH) "
fi
LOC="\u@\h"
DIR="\[\033[01;34m\]\W"
if [ "$REPO" != "" ] ; then
DIR="$(pwd)"
#~ echo $DIR
DIR="$(echo "$REPO||$DIR" | perl -ne 'my ($a, $b) = split(/\|\|/, $_); $b =~ s/^.*$a\/?/\//; print $b;')"
#~ echo $DIR
fi
CON_COLOR="\[\033[01;31m\]"
LOC_COLOR="\[\033[01;32m\]"
PATH_COLOR="\[\033[01;34m\]"
PROMPT_COLOR="\[\033[01;32m\]"
PROMPT_CHAR="$"
if [[ ${EUID} == 0 ]]; then
CON_COLOR="\[\033[01;35m\]"
LOC_COLOR="\[\033[01;31m\]"
PATH_COLOR="\[\033[01;34m\]"
PROMPT_COLOR="\[\033[01;34m\]"
PROMPT_CHAR="#"
fi
if [[ -f ${HOME}/.bash_magic_dir ]]; then
source ${HOME}/.bash_magic_dir
fi
BASH_MAGIC_DIR=${BASH_MAGIC_DIR:-~/.bash.d}
BASH_MAGIC_DIR="${BASH_MAGIC_DIR/#\~/$HOME}"
BASHD_STAT_PARAMS=""
stat --version > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
BASHD_STAT_PARAMS="-c %Y"
else
BASHD_STAT_PARAMS="-f %m"
fi
for FILENAME in ${BASH_MAGIC_DIR}/* ; do
FILE="$(basename "${FILENAME}")"
FILEVAR="$(echo IMPORT_${FILE} | tr 'a-z' 'A-Z')"
FILELVL="$(echo LVL_${FILE} | tr 'a-z' 'A-Z')"
if [[ "${!FILELVL}" -ne "${SHLVL}" ]]; then
declare -x "${FILEVAR}=0"
declare -x "${FILELVL}=${SHLVL}"
fi
if [[ -f ${FILENAME} ]] ; then
if [[ ${FILENAME} -nt ${BASH_MAGIC_DIR}/archive/${FILE} ]]; then
echo "back up ${FILE}"
mkdir -p ${BASH_MAGIC_DIR}/archive
cp ${FILENAME} ${BASH_MAGIC_DIR}/archive/${FILE}
fi
if [[ "$(eval "stat ${BASHD_STAT_PARAMS} ${FILENAME}")" -gt "${!FILEVAR}" ]]; then
echo "source ${FILE}"
declare -x "${FILEVAR}=$(eval "stat ${BASHD_STAT_PARAMS} ${FILENAME}")"
source $FILENAME
fi
fi
done
export PROMPT_COMMAND="$(cat ${BASH_MAGIC_DIR}/.prompt_command | paste -sd ";" -)"