Skip to content

Commit

Permalink
trimming the PWD on the prompt so that it stays on one line
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Wyatt committed May 15, 2012
1 parent 8f251ad commit 95c49a5
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions zsh_custom/themes/gnzh.zsh-theme
Expand Up @@ -6,6 +6,18 @@ autoload -U colors zsh/terminfo # Used in the colour alias below
colors colors
setopt prompt_subst 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) # make some aliases for the colours: (coud use normal escap.seq's too)
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
eval PR_$color='%{$fg[${(L)color}]%}' eval PR_$color='%{$fg[${(L)color}]%}'
Expand All @@ -17,11 +29,11 @@ eval PR_BOLD="%{$terminfo[bold]%}"
if [[ $UID -ge 1000 ]]; then # normal user if [[ $UID -ge 1000 ]]; then # normal user
eval PR_USER='${PR_GREEN}%n${PR_NO_COLOR}' eval PR_USER='${PR_GREEN}%n${PR_NO_COLOR}'
eval PR_USER_OP='${PR_GREEN}%#${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 elif [[ $UID -eq 0 ]]; then # root
eval PR_USER='${PR_RED}%n${PR_NO_COLOR}' eval PR_USER='${PR_RED}%n${PR_NO_COLOR}'
eval PR_USER_OP='${PR_RED}%#${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 fi
if [[ ${MY_SHELL_LEVEL:-0} -gt 1 ]]; then if [[ ${MY_SHELL_LEVEL:-0} -gt 1 ]]; then
local PR_PROMPT="$PR_PROMPT [$(($MY_SHELL_LEVEL-1))]" local PR_PROMPT="$PR_PROMPT [$(($MY_SHELL_LEVEL-1))]"
Expand All @@ -36,20 +48,14 @@ fi


local return_code="%(?..%{$PR_RED%}%? ↵%{$PR_NO_COLOR%})" 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 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}$PR_PROMPT "
PROMPT="╭─${user_host} ${current_dir} ${rvm_ruby} ${git_branch} PROMPT="╭─${user_host} ${current_dir} ${git_branch}
╰─$PR_PROMPT " ╰─$PR_PROMPT "
RPS1="${return_code}" RPS1="${return_code}"


Expand Down

0 comments on commit 95c49a5

Please sign in to comment.