3
\$\begingroup\$

I took the agnoster theme and re-wrote it to this:

CURRENT_FG='NONE'

# I don't know if this is important or not...
() {
   local LC_ALL="" LC_CTYPE="en_US.UTF-8"
}

# Begin a segment
# Takes two arguments, background and foreground.
prompt_segment() {
  echo -n "%{%K{$1}%}%{%F{$2}%} "
  CURRENT_FG=$2
  echo -n ${@:3}
}

# End the prompt, closing any open segments
prompt_end() {
  echo -n "%{%k%F{$CURRENT_FG}%}"
  echo -n "\$%{%f%}"
  CURRENT_FG=''
}

### Prompt components
# Each component will draw itself, and hide itself if no information needs to be shown

# Context: user@hostname (who am I and where am I)
prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    prompt_segment black default "%(!.%{%F{yellow}%}.)$USER@%m"
  fi
}

# Git: branch/detached head, dirty status
prompt_git() {
  (( $+commands[git] )) || return
  local PL_BRANCH_CHAR
  () {
    local LC_ALL="" LC_CTYPE="en_US.UTF-8"
    PL_BRANCH_CHAR=$'\ue0a0' # 
  }
  local ref

  if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
    ref='refs/heads/master' # $(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git rev-parse --short HEAD 2> /dev/null)"
    if command git status --porcelain 2> /dev/null | read -k1 -u0; then
      prompt_segment default yellow
    else
      prompt_segment default green
    fi

    setopt promptsubst
    # these are too slow
    #autoload -Uz vcs_info

    # these were too slow
    #zstyle ':vcs_info:*' enable git
    #zstyle ':vcs_info:*' get-revision true
    #zstyle ':vcs_info:*' check-for-changes true
    #zstyle ':vcs_info:*' stagedstr '†'
    #zstyle ':vcs_info:*' unstagedstr '*'
    #zstyle ':vcs_info:*' formats '%u%c'
    #zstyle ':vcs_info:*' actionformats '%u%c'
    #vcs_info
    echo -n "${ref/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }"
  fi
}

# Dir: current working directory
prompt_dir() {
  prompt_segment default cyan $(echo -n "${PWD/#$HOME/~}" | awk -F '/' '{ if (length($0) > 14) { if (NF > 4) print $1 "/" $2 "/.../" $(NF-1) "/" $NF; else if (NF > 3) print $1 "/" $2 "/.../" $NF; else if (NF > 2) print $1 "/.../" $NF; else print $0;} else print $0;}')
  #prompt_segment default cyan $(echo -n "${PWD/#$HOME/~}")
}

# Virtualenv: current working virtualenv
prompt_virtualenv() {
  local virtualenv_path="$VIRTUAL_ENV"
  if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
    prompt_segment blue black "(`basename $virtualenv_path`)"
  fi
}

# Status:
# - was there an error
# - am I root
# - are there background jobs?
prompt_status() {
  ( [[ $(jobs -l | wc -l) -gt 0 ]] ) && prompt_segment blue black "◷"
}

## Main prompt
build_prompt() {
  RETVAL=$?
  prompt_status
  prompt_virtualenv
  prompt_context
  prompt_dir
  prompt_git
  prompt_end
}

PROMPT='%{%f%b%k%}$(build_prompt) '

How can I speed up this theme to make it as fast as possible?

I'd like to be able to hold down the enter key without gaps between lines and weird lag.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.