Ported the fish-style PWD function for bash/zsh prompt

pull/2/head
Bodaniel Jeanes 2010-06-27 01:37:43 +10:00
parent 3bad87fac8
commit 58769a6faa
2 changed files with 29 additions and 6 deletions

View File

@ -75,6 +75,31 @@ function extract() {
fi fi
} }
if [ `uname` = "Darwin" ]; then
function prompt_pwd() {
if [ "$PWD" != "$HOME" ]; then
printf "%s" `echo $PWD|sed -e 's|/private||' -e "s|^$HOME|~|" -e 's-/\(\.\{0,1\}[^/]\)\([^/]*\)-/\1-g'`
echo $PWD|sed -e 's-.*/\.\{0,1\}[^/]\([^/]*$\)-\1-'
else
echo '~'
fi
}
else # defined two for diff systems because Fish did (not entirely sure why)
function prompt_pwd() {
case "$PWD" in
$HOME)
echo '~'
;;
*)
printf "%s" `echo $PWD|sed -e "s|^$HOME|~|" -e 's-/\(\.\{0,1\}[^/]\)\([^/]*\)-/\1-g'`
echo $PWD|sed -n -e 's-.*/\.\{0,1\}.\([^/]*\)-\1-p'
;;
esac
}
fi
if [ $system_name = 'Darwin' ]; then if [ $system_name = 'Darwin' ]; then
function manpdf() { man -t $@ | open -f -a Preview; } function manpdf() { man -t $@ | open -f -a Preview; }
function osinfo() { function osinfo() {

View File

@ -1,17 +1,15 @@
function prompt_color() { function prompt_color() {
if [ "$(whoami)" = "root" ]; then if [ "$USER" = "root" ]; then
echo "red" echo "red"
else else
echo "green" echo "green"
fi fi
} }
# Prompts
ZSH_THEME_VCS_PROMPT_PREFIX="%{$fg[red]%}" ZSH_THEME_VCS_PROMPT_PREFIX="%{$fg[red]%}"
ZSH_THEME_VCS_PROMPT_SUFFIX="%{$reset_color%}" ZSH_THEME_VCS_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_VCS_PROMPT_FORMAT="${ZSH_THEME_VCS_PROMPT_PREFIX}%b:%h${ZSH_THEME_VCS_PROMPT_SUFFIX}" ZSH_THEME_VCS_PROMPT_FORMAT="${ZSH_THEME_VCS_PROMPT_PREFIX}%b:%h${ZSH_THEME_VCS_PROMPT_SUFFIX}"
# Prompts PS1='%{$fg[blue]%}$(prompt_pwd)%{$reset_color%} %{$fg[$(prompt_color)]%}♪%{$reset_color%} '
# PS1='%{$fg[green]%}%n@%m:%{$fg_bold[blue]%}%2~ %{$reset_color%}%(!.#.$) '
PS1='%~ %{$fg[$(prompt_color)]%}♪%{$reset_color%} '
RPS1='$(${VCPROMPT} -f ${ZSH_THEME_VCS_PROMPT_FORMAT})' RPS1='$(${VCPROMPT} -f ${ZSH_THEME_VCS_PROMPT_FORMAT})'