Permalink
Browse files

trimming the PWD on the prompt so that it stays on one line

  • Loading branch information...
1 parent 8f251ad commit 95c49a5293dbd9c4558dc5ba17c36fb9da47c204 Derek Wyatt committed May 15, 2012
Showing with 19 additions and 13 deletions.
  1. +19 −13 zsh_custom/themes/gnzh.zsh-theme
@@ -6,6 +6,18 @@ autoload -U colors zsh/terminfo # Used in the colour alias below
colors
setopt prompt_subst
+function limitStringToWidthByMidpoint
+{
+ local string="$1"
+ local width=$2
+ if (( ${#string} > $width )); then
+ local splitnum=$((width/2))
+ echo "$(echo $string | cut -c1-$splitnum) ... $(echo $string | cut -c$((${#string}-$splitnum))-)"
+ else
+ echo $string
+ fi
+}
+
# make some aliases for the colours: (coud use normal escap.seq's too)
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
eval PR_$color='%{$fg[${(L)color}]%}'
@@ -17,11 +29,11 @@ eval PR_BOLD="%{$terminfo[bold]%}"
if [[ $UID -ge 1000 ]]; then # normal user
eval PR_USER='${PR_GREEN}%n${PR_NO_COLOR}'
eval PR_USER_OP='${PR_GREEN}%#${PR_NO_COLOR}'
- local PR_PROMPT='$PR_NO_COLOR$PR_NO_COLOR'
+ local PR_PROMPT='$PR_NO_COLOR>$PR_NO_COLOR'
elif [[ $UID -eq 0 ]]; then # root
eval PR_USER='${PR_RED}%n${PR_NO_COLOR}'
eval PR_USER_OP='${PR_RED}%#${PR_NO_COLOR}'
- local PR_PROMPT='$PR_RED$PR_NO_COLOR'
+ local PR_PROMPT='$PR_RED>$PR_NO_COLOR'
fi
if [[ ${MY_SHELL_LEVEL:-0} -gt 1 ]]; then
local PR_PROMPT="$PR_PROMPT [$(($MY_SHELL_LEVEL-1))]"
@@ -36,20 +48,14 @@ fi
local return_code="%(?..%{$PR_RED%}%? ↵%{$PR_NO_COLOR%})"
-local user_host='${PR_USER}${PR_CYAN}@${PR_HOST}'
-local current_dir='%{$PR_BOLD$PR_BLUE%}%~%{$PR_NO_COLOR%}'
-local rvm_ruby=''
-if which rvm-prompt &> /dev/null; then
- rvm_ruby='%{$PR_RED%}‹$(rvm-prompt i v g s)›%{$PR_NO_COLOR%}'
-else
- if which rbenv &> /dev/null; then
- rvm_ruby='%{$PR_RED%}‹$(rbenv version | sed -e "s/ (set.*$//")›%{$PR_NO_COLOR%}'
- fi
-fi
local git_branch='$(git_prompt_info)%{$PR_NO_COLOR%}'
+local user_host='${PR_USER}${PR_CYAN}@${PR_HOST}'
+local prompty_stuff_so_far="$(git_prompt_info)$(print -P %n)$(print -P %m)"
+local len_so_far=$((${#prompty_stuff_so_far}+20))
+local current_dir='%{$PR_BOLD$PR_BLUE%}$(limitStringToWidthByMidpoint "$(print -P %~)" $((COLUMNS-$len_so_far)))%{$PR_NO_COLOR%}'
#PROMPT="${user_host} ${current_dir} ${rvm_ruby} ${git_branch}$PR_PROMPT "
-PROMPT="╭─${user_host} ${current_dir} ${rvm_ruby} ${git_branch}
+PROMPT="╭─${user_host} ${current_dir} ${git_branch}
╰─$PR_PROMPT "
RPS1="${return_code}"

0 comments on commit 95c49a5

Please sign in to comment.