Skip to content

Instantly share code, notes, and snippets.

@wishfoundry
Created October 8, 2013 20:54
Show Gist options
  • Select an option

  • Save wishfoundry/6891492 to your computer and use it in GitHub Desktop.

Select an option

Save wishfoundry/6891492 to your computer and use it in GitHub Desktop.

Revisions

  1. wishfoundry created this gist Oct 8, 2013.
    138 changes: 138 additions & 0 deletions my_prezto_theme
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,138 @@
    # Load dependencies.
    pmodload 'helper'

    CURRENT_BG='NONE'
    SEGMENT_SEPARATOR='⮀'


    # Begin a segment
    # Takes two arguments, background and foreground. Both can be omitted,
    # rendering default background/foreground.
    prompt_segment() {
    local bg fg
    [[ -n $1 ]] && bg="%K{$1}" || bg="%k"
    [[ -n $2 ]] && fg="%F{$2}" || fg="%f"
    if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
    echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
    else
    echo -n "%{$bg%}%{$fg%} "
    fi
    CURRENT_BG=$1
    [[ -n $3 ]] && print -Pn $3
    }

    # End the prompt, closing any open segments
    prompt_end() {
    if [[ -n $CURRENT_BG ]]; then
    echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
    else
    echo -n "%{%k%}"
    fi
    echo -n "%{%f%}"
    CURRENT_BG=''
    }

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

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

    #%{%F{blue}%}%n%{%F{red}%}@%{%F{green}%}%M
    function build_prompt {
    prompt_segment black default '%(1?;%{%F{red}%}✘ ;)%(!;%{%F{yellow}%}⚡ ;)%(1j;%{%F{cyan}%}%j⚙ ;)'
    prompt_segment blue black '${_prompt_sorin_pwd}' #'%2~'
    if $git_status; then
    prompt_segment green black '${(e)git_info[prompt]}${git_info[status]}'
    fi
    prompt_end
    }

    start_time=$SECONDS
    function prompt_paradox_preexec {
    start_time=$SECONDS
    }

    function calc_elapsed_time {
    if [[ $timer_result -ge 3600 ]]; then
    let "timer_hours = $timer_result / 3600"
    let "remainder = $timer_result % 3600"
    let "timer_minutes = $remainder / 60"
    let "timer_seconds = $remainder % 60"
    print -P "%B%F{red}>>> elapsed time ${timer_hours}h${timer_minutes}m${timer_seconds}s%b"
    elif [[ $timer_result -ge 60 ]]; then
    let "timer_minutes = $timer_result / 60"
    let "timer_seconds = $timer_result % 60"
    print -P "%B%F{yellow}>>> elapsed time ${timer_minutes}m${timer_seconds}s%b"
    elif [[ $timer_result -gt 10 ]]; then
    print -P "%B%F{green}>>> elapsed time ${timer_result}s%b"
    fi
    }

    function prompt_paradox_precmd {
    setopt LOCAL_OPTIONS
    unsetopt XTRACE KSH_ARRAYS

    # Format PWD.
    prompt_sorin_pwd

    # Get Git repository information.
    if (( $+functions[git-info] )); then
    git_status=git-info
    fi
    timer_result=$(($SECONDS-$start_time))
    if [[ $timer_result -gt 10 ]]; then
    calc_elapsed_time
    fi
    start_time=$SECONDS
    }

    function prompt_paradox_setup {
    setopt LOCAL_OPTIONS
    unsetopt XTRACE KSH_ARRAYS
    prompt_opts=(cr percent subst)

    # Load required functions.
    autoload -Uz add-zsh-hook

    # Add hook for calling git-info before each command.
    add-zsh-hook preexec prompt_paradox_preexec
    add-zsh-hook precmd prompt_paradox_precmd

    zstyle ':prezto:module:editor:info:completing' format '%B%F{red}...%f%b'
    zstyle ':prezto:module:editor:info:keymap:primary' format '%B%F{blue}❯%f%b'
    zstyle ':prezto:module:editor:info:keymap:primary:overwrite' format '%F{red}♺%f'
    zstyle ':prezto:module:editor:info:keymap:alternate' format '%B%F{red}❮%f%b'
    zstyle ':prezto:module:git:info:action' format '! %s'
    zstyle ':prezto:module:git:info:added' format '✚'
    zstyle ':prezto:module:git:info:ahead' format '⬆'
    zstyle ':prezto:module:git:info:behind' format '⬇'
    zstyle ':prezto:module:git:info:branch' format '⭠ %b'
    zstyle ':prezto:module:git:info:commit' format '➦ %.7c'
    zstyle ':prezto:module:git:info:deleted' format '✖'
    zstyle ':prezto:module:git:info:modified' format '✱'
    zstyle ':prezto:module:git:info:position' format '%p'
    zstyle ':prezto:module:git:info:renamed' format '➙'
    zstyle ':prezto:module:git:info:stashed' format 's'
    zstyle ':prezto:module:git:info:unmerged' format '═'
    zstyle ':prezto:module:git:info:untracked' format '?'
    zstyle ':prezto:module:git:info:keys' format \
    'prompt' '$(coalesce "%b" "%p" "%c")%s' \
    'status' ' %A%B%S%a%d%m%r%U%u'

    # Define prompts.
    # PROMPT='
    # %{%f%b%k%}$(build_prompt)
    PROMPT='
    %{%f%b%k%}$(build_prompt)
    ${editor_info[keymap]} '
    RPROMPT='[%D{%L:%M:%S %p}]'
    SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
    }

    prompt_paradox_setup "$@"