Skip to content

Commit

Permalink
Update zsh theme
Browse files Browse the repository at this point in the history
  • Loading branch information
trongrg committed Sep 26, 2019
1 parent b4c7107 commit 68977ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 53 deletions.
67 changes: 14 additions & 53 deletions modules/prompt/functions/prompt_trongrg_setup
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#!/usr/bin/env zsh
#
# A theme based on trongrg2 theme
# A theme based on trongrg theme
# * RVM/Rbenv info shown on the right
# * Git branch info on the left
# * Single line prompt
#
# Authors:
# Trong Tran trongrg2@gmail.com
# Trong Tran trongrg@gmail.com

pmodload 'helper'

function prompt_trongrg2_pwd {
function prompt_trongrg_pwd {
local pwd="${PWD/#$HOME/~}"

if [[ "$pwd" == (#m)[/~] ]]; then
_prompt_trongrg2_pwd="$MATCH"
_prompt_trongrg_pwd="$MATCH"
unset MATCH
else
_prompt_trongrg2_pwd="${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}/${pwd:t}"
_prompt_trongrg_pwd="${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}/${pwd:t}"
fi
}

function prompt_trongrg2_precmd {
function prompt_trongrg_precmd {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS

Expand All @@ -30,56 +30,21 @@ function prompt_trongrg2_precmd {
git-info
fi

# Get ruby information
if (( $+functions[ruby-info] )); then
ruby-info
fi

# Format PWD.
prompt_trongrg2_pwd
prompt_trongrg_pwd

local prompt_line_1
prompt_trongrg2_setup_prompt
prompt_trongrg_setup_prompt

PROMPT="$prompt_line_1$prompt_new_line$prompt_chars "
SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
}

prompt_trongrg2_setup_prompt () {
local prompt_line_1a_width=${#${(S%%)prompt_line_1a//(\%([KF1]|)\{*\}|\%[Bbkf])}}
local prompt_line_1b_width=${#${(S%%)prompt_line_1b//(\%([KF1]|)\{*\}|\%[Bbkf])}}
local git_info_width=${#${(S%%)git_info[prompt]//(\%([KF1]|)\{*\}|\%[Bbkf])}}

local prompt_padding_size=$(( COLUMNS
- prompt_line_1a_width
- prompt_line_1b_width
- git_info_width
- 1 ))

# Try to fit in long path and user@host.
if (( prompt_padding_size > 0 )); then
local prompt_padding
eval "prompt_padding=\${(l:${prompt_padding_size}:: :)_empty_zz}"
prompt_line_1="$prompt_line_1a$git_info$prompt_padding$prompt_line_1b"
return
fi

prompt_padding_size=$(( COLUMNS - prompt_line_1a_width ))

# Didn't fit; try to fit in just long path.
if (( prompt_padding_size > 0 )); then
local prompt_padding
eval "prompt_padding=\${(l:${prompt_padding_size}:: :)_empty_zz}"
prompt_line_1="$prompt_line_1a$git_info$prompt_padding"
return
fi

# Still didn't fit; truncate
local prompt_pwd_size=$(( COLUMNS - 5 ))
prompt_line_1="$prompt_gfx_tbox$prompt_l_paren%B%F{$prompt_adam2_color2}%$prompt_pwd_size<...<%~%<<$prompt_r_paren%b%F{$prompt_adam2_color1} "
prompt_trongrg_setup_prompt () {
prompt_line_1="$prompt_line_1a$git_info"
}

function prompt_trongrg2_setup {
function prompt_trongrg_setup {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
prompt_opts=(cr percent subst)
Expand Down Expand Up @@ -122,17 +87,13 @@ function prompt_trongrg2_setup {
zstyle ':prezto:module:git:info:untracked' format "${__GIT_COLORS[8]} ✭%f"
zstyle ':prezto:module:git:info:renamed' format "${__GIT_COLORS[5]} ➜%f"

# ruby info (rvm, rbenv)
zstyle ':prezto:module:ruby:info:version' format '[%v]'

prompt_user_host="${__PROMPT_COLORS[3]}%n%f@${__PROMPT_COLORS[2]}%m%f"
prompt_pwd="${__PROMPT_COLORS[5]}"'$_prompt_trongrg2_pwd'"%f"
prompt_pwd="${__PROMPT_COLORS[5]}"'$_prompt_trongrg_pwd'"%f"

prompt_line_1a="$prompt_user_host $prompt_pwd "
prompt_line_1b='%F{blue}$ruby_info[version]%f'
prompt_chars=" %B${__PROMPT_COLORS[2]}${__PROMPT_COLORS[1]}${__PROMPT_COLORS[5]}❯%f%b"

add-zsh-hook precmd prompt_trongrg2_precmd
add-zsh-hook precmd prompt_trongrg_precmd
}

prompt_trongrg2_setup "$@"
prompt_trongrg_setup "$@"
1 change: 1 addition & 0 deletions runcoms/zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
fi

# Customize to your needs...
for config_file ($HOME/.yadr/zsh/*.zsh) source $config_file

0 comments on commit 68977ba

Please sign in to comment.