-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.rccmn
117 lines (106 loc) · 3.09 KB
/
.rccmn
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
# create a history directory if it doesn't exit
#if [[ ! -d $HOME/.hist ]]; then
# mkdir -p $HOME/.hist
#fi
# deletes process history if the process is not active, these
# are assume exited bash sessions. note this is only valid
# for single system.
#function purge_hist {
# for i in $(comm -23 <(sort -n <(ls $HOME/.hist/history.* | sed "s#$HOME/.hist/history.##")) <(sort <(for i in $(ps -ex -o pid | sed 1d); do echo $# i ; done))); do echo "$HOME/.hist/history.$i"; done | xargs rm -f
#}
#function view_hist {
# strings -n 1 $0
#}
# Title Bar path will be truncated to this max length
SPATHLEN=40
# uses long/.../path
function shortpath_new_trunc {
pwd_length=$SPATHLEN
pwd_symbol="..."
newPWD="${1/#$HOME/~}"
if [ $(echo -n $newPWD | wc -c | tr -d " ") -gt $pwd_length ]; then
newPWD=$(echo -n $newPWD | awk -F '/' '{
print $1 "/" $2 "/.../" $(NF-1) "/" $(NF)}')
fi
echo ${newPWD}
}
# uses +long/path
function shortpath_bash {
typeset tpwd=$1
typeset more=
if [[ $tpwd = $HOME?\(/*\) ]]; then
tpwd=\~${tpwd#$HOME}
fi
if [[ $(echo -n $tpwd | wc -c | tr -d " ") -gt $SPATHLEN ]]; then
newPWD="$(echo -n $tpwd | sed -e "s/.*\(.\{$SPATHLEN\}\)/\1/")"
more=+
else
newPWD="$(echo -n $tpwd)"
fi
echo "$more$newPWD"
}
# for ksh88
# uses +long/path
function shortpath {
typeset tpwd=$1
typeset more=
# Replace leading $HOME with ~
if [[ $tpwd = "$HOME?(/*)" ]]; then
tpwd=\~${tpwd#$HOME}
fi
# Truncate if longer than SPATHLEN chars length
if (( ${#tpwd} > $SPATHLEN )); then
len=`echo $tpwd | wc -m`
start=$(expr $len - $SPATHLEN)
tpwd=`echo $tpwd | cut -c$start-$len`
more="+"
fi
printf "$more$tpwd\n"
}
# Construct a string to update GUI titlebar
function settitle {
_PWD=$(echo $PWD| sed "s;$HOME;~;") # strip home directory
# if an interactive session
if [[ -t 0 ]]; then
if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then
# replace spaces with percent sign for pathnames
# with spaces
SEARCH=' '
REPLACE='%20'
PWD_URL="file:${PWD//$SEARCH/$REPLACE}"
printf "\033]0;$SYS\007"
printf "\033]6;\007"
#printf "\033]7;$PWD_URL\007"
printf "\033]2;%s\007" "$SYS:$PWD"
elif [[ "$TERM" == *"xterm"* ]]; then
TMP_PWD=$(shortpath "$_PWD")
# clear out previous title bar
printf "\033]0;\007"
printf "\033]1;\007"
printf "\033]2;\007"
printf "\033]6;\007"
printf "\033]7;\007"
printf "\033]2;%s\007" "$SYS:$TMP_PWD"
fi
fi
}
# Set the prompt
function setprompt {
_PWD=$(echo $PWD| sed "s;$HOME;~;") # strip home directory
# Read only directories are Red.
if [[ ! -w "${PWD}" ]] ; then
CPWD="${Rc}${_PWD}${Nc}"
else
CPWD=$_PWD
fi
if [[ $TERM == "dumb" ]]; then
PS1="${HIST}[${SYS}:${CPWD}]$ "
PS2="> "
else
# ${LOGNAME} for login name
_PS1="${HIST}${Bc}[${Nc}${SYS}${Bc}:${Nc}${Wc}${CPWD}${Nc}${Bc}]${Nc}${Wc}${Nc}$ ${Nc}"
_PS2="${Bc}> ${Nc}"
PS1=$($ECHO $(settitle) >/dev/tty)$($ECHO ${_PS1})
PS2=$($ECHO ${_PS2})
fi
}