From 58769a6faa4d20ad254ca8586fa6c533315c9b75 Mon Sep 17 00:00:00 2001 From: Bodaniel Jeanes Date: Sun, 27 Jun 2010 01:37:43 +1000 Subject: [PATCH] Ported the fish-style PWD function for bash/zsh prompt --- bash/aliases | 25 +++++++++++++++++++++++++ zsh/theme | 10 ++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/bash/aliases b/bash/aliases index 03e8ec7..bf7f035 100644 --- a/bash/aliases +++ b/bash/aliases @@ -75,6 +75,31 @@ function extract() { 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 function manpdf() { man -t $@ | open -f -a Preview; } function osinfo() { diff --git a/zsh/theme b/zsh/theme index f197d3f..1f60f23 100644 --- a/zsh/theme +++ b/zsh/theme @@ -1,17 +1,15 @@ function prompt_color() { - if [ "$(whoami)" = "root" ]; then + if [ "$USER" = "root" ]; then echo "red" else echo "green" fi } +# Prompts ZSH_THEME_VCS_PROMPT_PREFIX="%{$fg[red]%}‹" ZSH_THEME_VCS_PROMPT_SUFFIX="›%{$reset_color%}" ZSH_THEME_VCS_PROMPT_FORMAT="${ZSH_THEME_VCS_PROMPT_PREFIX}%b:%h${ZSH_THEME_VCS_PROMPT_SUFFIX}" -# Prompts -# 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})' +PS1='%{$fg[blue]%}$(prompt_pwd)%{$reset_color%} %{$fg[$(prompt_color)]%}♪%{$reset_color%} ' +RPS1='$(${VCPROMPT} -f ${ZSH_THEME_VCS_PROMPT_FORMAT})' \ No newline at end of file