git://git.iain.cx/iain
/
profile.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Unexpand ~ in short prompt.
[profile.git]
/
.profile.d
/
ps1.bashrc
diff --git
a/.profile.d/ps1.bashrc
b/.profile.d/ps1.bashrc
index
0283611
..
7bd93b7
100644
(file)
--- a/
.profile.d/ps1.bashrc
+++ b/
.profile.d/ps1.bashrc
@@
-200,14
+200,28
@@
function __ps1_colon() {
}
function __ps1_short() {
}
function __ps1_short() {
+ local pwd=${PWD/#$HOME/\~}
local dirtrim=${PROMPT_DIRTRIM//[^0-9]/}
local dirtrim=${PROMPT_DIRTRIM//[^0-9]/}
+
+ if [ "${dirtrim:0:1}" = "0" ]; then
+ echo "$pwd"
+ return $1
+ fi
+
dirtrim=${dirtrim##0}
if [ -z "$dirtrim" ]; then
dirtrim=${dirtrim##0}
if [ -z "$dirtrim" ]; then
- echo "$PWD"
- return $1
+ local prompt="$USER$HOSTNAME$pwd"
+ local width=$(((COLUMNS*2)/3))
+ if [ ${#prompt} -le ${width:-53} ]; then
+ echo "$pwd"
+ return $1
+ else
+ dirtrim=1
+ fi
fi
fi
- local dirname=${PWD##*/}
- local basename=${PWD%/$dirname}
+
+ local dirname=${pwd##*/}
+ local basename=${pwd%/$dirname}
local reversed=
local component
for component in ${basename//\// }; do
local reversed=
local component
for component in ${basename//\// }; do
@@
-216,14
+230,16
@@
function __ps1_short() {
local n=1
local short=
for component in $reversed; do
local n=1
local short=
for component in $reversed; do
+ [ $n = 1 -a "$PWD" = "$pwd" ] || short="/$short"
if [ $n -ge $dirtrim ]; then
if [ $n -ge $dirtrim ]; then
- short="
/
${component:0:1}$short"
+ short="${component:0:1}$short"
else
else
- short="
/
$component$short"
+ short="$component$short"
fi
n=$((n+1))
done
fi
n=$((n+1))
done
- echo "$short/$dirname"
+
+ echo "$short$dirname"
return $1
}
return $1
}