abra zsh config 2.0
This commit is contained in:
@@ -1 +0,0 @@
|
||||
../external/pure/async.zsh
|
499
.zprezto/modules/prompt/functions/async
Normal file
499
.zprezto/modules/prompt/functions/async
Normal file
@@ -0,0 +1,499 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
#
|
||||
# zsh-async
|
||||
#
|
||||
# version: 1.6.2
|
||||
# author: Mathias Fredriksson
|
||||
# url: https://github.com/mafredri/zsh-async
|
||||
#
|
||||
|
||||
typeset -g ASYNC_VERSION=1.6.2
|
||||
# Produce debug output from zsh-async when set to 1.
|
||||
typeset -g ASYNC_DEBUG=${ASYNC_DEBUG:-0}
|
||||
|
||||
# Wrapper for jobs executed by the async worker, gives output in parseable format with execution time
|
||||
_async_job() {
|
||||
# Disable xtrace as it would mangle the output.
|
||||
setopt localoptions noxtrace
|
||||
|
||||
# Store start time for job.
|
||||
float -F duration=$EPOCHREALTIME
|
||||
|
||||
# Run the command and capture both stdout (`eval`) and stderr (`cat`) in
|
||||
# separate subshells. When the command is complete, we grab write lock
|
||||
# (mutex token) and output everything except stderr inside the command
|
||||
# block, after the command block has completed, the stdin for `cat` is
|
||||
# closed, causing stderr to be appended with a $'\0' at the end to mark the
|
||||
# end of output from this job.
|
||||
local stdout stderr ret tok
|
||||
{
|
||||
stdout=$(eval "$@")
|
||||
ret=$?
|
||||
duration=$(( EPOCHREALTIME - duration )) # Calculate duration.
|
||||
|
||||
# Grab mutex lock, stalls until token is available.
|
||||
read -r -k 1 -p tok || exit 1
|
||||
|
||||
# Return output (<job_name> <return_code> <stdout> <duration> <stderr>).
|
||||
print -r -n - ${(q)1} $ret ${(q)stdout} $duration
|
||||
} 2> >(stderr=$(cat) && print -r -n - " "${(q)stderr}$'\0')
|
||||
|
||||
# Unlock mutex by inserting a token.
|
||||
print -n -p $tok
|
||||
}
|
||||
|
||||
# The background worker manages all tasks and runs them without interfering with other processes
|
||||
_async_worker() {
|
||||
# Reset all options to defaults inside async worker.
|
||||
emulate -R zsh
|
||||
|
||||
# Make sure monitor is unset to avoid printing the
|
||||
# pids of child processes.
|
||||
unsetopt monitor
|
||||
|
||||
# Redirect stderr to `/dev/null` in case unforseen errors produced by the
|
||||
# worker. For example: `fork failed: resource temporarily unavailable`.
|
||||
# Some older versions of zsh might also print malloc errors (know to happen
|
||||
# on at least zsh 5.0.2 and 5.0.8) likely due to kill signals.
|
||||
exec 2>/dev/null
|
||||
|
||||
# When a zpty is deleted (using -d) all the zpty instances created before
|
||||
# the one being deleted receive a SIGHUP, unless we catch it, the async
|
||||
# worker would simply exit (stop working) even though visible in the list
|
||||
# of zpty's (zpty -L).
|
||||
TRAPHUP() {
|
||||
return 0 # Return 0, indicating signal was handled.
|
||||
}
|
||||
|
||||
local -A storage
|
||||
local unique=0
|
||||
local notify_parent=0
|
||||
local parent_pid=0
|
||||
local coproc_pid=0
|
||||
local processing=0
|
||||
|
||||
local -a zsh_hooks zsh_hook_functions
|
||||
zsh_hooks=(chpwd periodic precmd preexec zshexit zshaddhistory)
|
||||
zsh_hook_functions=(${^zsh_hooks}_functions)
|
||||
unfunction $zsh_hooks &>/dev/null # Deactivate all zsh hooks inside the worker.
|
||||
unset $zsh_hook_functions # And hooks with registered functions.
|
||||
unset zsh_hooks zsh_hook_functions # Cleanup.
|
||||
|
||||
child_exit() {
|
||||
local -a pids
|
||||
pids=(${${(v)jobstates##*:*:}%\=*})
|
||||
|
||||
# If coproc (cat) is the only child running, we close it to avoid
|
||||
# leaving it running indefinitely and cluttering the process tree.
|
||||
if (( ! processing )) && [[ $#pids = 1 ]] && [[ $coproc_pid = $pids[1] ]]; then
|
||||
coproc :
|
||||
coproc_pid=0
|
||||
fi
|
||||
|
||||
# On older version of zsh (pre 5.2) we notify the parent through a
|
||||
# SIGWINCH signal because `zpty` did not return a file descriptor (fd)
|
||||
# prior to that.
|
||||
if (( notify_parent )); then
|
||||
# We use SIGWINCH for compatibility with older versions of zsh
|
||||
# (pre 5.1.1) where other signals (INFO, ALRM, USR1, etc.) could
|
||||
# cause a deadlock in the shell under certain circumstances.
|
||||
kill -WINCH $parent_pid
|
||||
fi
|
||||
}
|
||||
|
||||
# Register a SIGCHLD trap to handle the completion of child processes.
|
||||
trap child_exit CHLD
|
||||
|
||||
# Process option parameters passed to worker
|
||||
while getopts "np:u" opt; do
|
||||
case $opt in
|
||||
n) notify_parent=1;;
|
||||
p) parent_pid=$OPTARG;;
|
||||
u) unique=1;;
|
||||
esac
|
||||
done
|
||||
|
||||
killjobs() {
|
||||
local tok
|
||||
local -a pids
|
||||
pids=(${${(v)jobstates##*:*:}%\=*})
|
||||
|
||||
# No need to send SIGHUP if no jobs are running.
|
||||
(( $#pids == 0 )) && continue
|
||||
(( $#pids == 1 )) && [[ $coproc_pid = $pids[1] ]] && continue
|
||||
|
||||
# Grab lock to prevent half-written output in case a child
|
||||
# process is in the middle of writing to stdin during kill.
|
||||
(( coproc_pid )) && read -r -k 1 -p tok
|
||||
|
||||
kill -HUP -$$ # Send to entire process group.
|
||||
coproc : # Quit coproc.
|
||||
coproc_pid=0 # Reset pid.
|
||||
}
|
||||
|
||||
local request
|
||||
local -a cmd
|
||||
while :; do
|
||||
# Wait for jobs sent by async_job.
|
||||
read -r -d $'\0' request || {
|
||||
# Since we handle SIGHUP above (and thus do not know when `zpty -d`)
|
||||
# occurs, a failure to read probably indicates that stdin has
|
||||
# closed. This is why we propagate the signal to all children and
|
||||
# exit manually.
|
||||
kill -HUP -$$ # Send SIGHUP to all jobs.
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Check for non-job commands sent to worker
|
||||
case $request in
|
||||
_unset_trap) notify_parent=0; continue;;
|
||||
_killjobs) killjobs; continue;;
|
||||
esac
|
||||
|
||||
# Parse the request using shell parsing (z) to allow commands
|
||||
# to be parsed from single strings and multi-args alike.
|
||||
cmd=("${(z)request}")
|
||||
|
||||
# Name of the job (first argument).
|
||||
local job=$cmd[1]
|
||||
|
||||
# If worker should perform unique jobs
|
||||
if (( unique )); then
|
||||
# Check if a previous job is still running, if yes, let it finnish
|
||||
for pid in ${${(v)jobstates##*:*:}%\=*}; do
|
||||
if [[ ${storage[$job]} == $pid ]]; then
|
||||
continue 2
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Guard against closing coproc from trap before command has started.
|
||||
processing=1
|
||||
|
||||
# Because we close the coproc after the last job has completed, we must
|
||||
# recreate it when there are no other jobs running.
|
||||
if (( ! coproc_pid )); then
|
||||
# Use coproc as a mutex for synchronized output between children.
|
||||
coproc cat
|
||||
coproc_pid="$!"
|
||||
# Insert token into coproc
|
||||
print -n -p "t"
|
||||
fi
|
||||
|
||||
# Run job in background, completed jobs are printed to stdout.
|
||||
_async_job $cmd &
|
||||
# Store pid because zsh job manager is extremely unflexible (show jobname as non-unique '$job')...
|
||||
storage[$job]="$!"
|
||||
|
||||
processing=0 # Disable guard.
|
||||
done
|
||||
}
|
||||
|
||||
#
|
||||
# Get results from finnished jobs and pass it to the to callback function. This is the only way to reliably return the
|
||||
# job name, return code, output and execution time and with minimal effort.
|
||||
#
|
||||
# usage:
|
||||
# async_process_results <worker_name> <callback_function>
|
||||
#
|
||||
# callback_function is called with the following parameters:
|
||||
# $1 = job name, e.g. the function passed to async_job
|
||||
# $2 = return code
|
||||
# $3 = resulting stdout from execution
|
||||
# $4 = execution time, floating point e.g. 2.05 seconds
|
||||
# $5 = resulting stderr from execution
|
||||
# $6 = has next result in buffer (0 = buffer empty, 1 = yes)
|
||||
#
|
||||
async_process_results() {
|
||||
setopt localoptions unset noshwordsplit noksharrays noposixidentifiers noposixstrings
|
||||
|
||||
local worker=$1
|
||||
local callback=$2
|
||||
local caller=$3
|
||||
local -a items
|
||||
local null=$'\0' data
|
||||
integer -l len pos num_processed has_next
|
||||
|
||||
typeset -gA ASYNC_PROCESS_BUFFER
|
||||
|
||||
# Read output from zpty and parse it if available.
|
||||
while zpty -r -t $worker data 2>/dev/null; do
|
||||
ASYNC_PROCESS_BUFFER[$worker]+=$data
|
||||
len=${#ASYNC_PROCESS_BUFFER[$worker]}
|
||||
pos=${ASYNC_PROCESS_BUFFER[$worker][(i)$null]} # Get index of NULL-character (delimiter).
|
||||
|
||||
# Keep going until we find a NULL-character.
|
||||
if (( ! len )) || (( pos > len )); then
|
||||
continue
|
||||
fi
|
||||
|
||||
while (( pos <= len )); do
|
||||
# Take the content from the beginning, until the NULL-character and
|
||||
# perform shell parsing (z) and unquoting (Q) as an array (@).
|
||||
items=("${(@Q)${(z)ASYNC_PROCESS_BUFFER[$worker][1,$pos-1]}}")
|
||||
|
||||
# Remove the extracted items from the buffer.
|
||||
ASYNC_PROCESS_BUFFER[$worker]=${ASYNC_PROCESS_BUFFER[$worker][$pos+1,$len]}
|
||||
|
||||
len=${#ASYNC_PROCESS_BUFFER[$worker]}
|
||||
if (( len > 1 )); then
|
||||
pos=${ASYNC_PROCESS_BUFFER[$worker][(i)$null]} # Get index of NULL-character (delimiter).
|
||||
fi
|
||||
|
||||
has_next=$(( len != 0 ))
|
||||
if (( $#items == 5 )); then
|
||||
items+=($has_next)
|
||||
$callback "${(@)items}" # Send all parsed items to the callback.
|
||||
else
|
||||
# In case of corrupt data, invoke callback with *async* as job
|
||||
# name, non-zero exit status and an error message on stderr.
|
||||
$callback "async" 1 "" 0 "$0:$LINENO: error: bad format, got ${#items} items (${(q)items})" $has_next
|
||||
fi
|
||||
|
||||
(( num_processed++ ))
|
||||
done
|
||||
done
|
||||
|
||||
(( num_processed )) && return 0
|
||||
|
||||
# Avoid printing exit value when `setopt printexitvalue` is active.`
|
||||
[[ $caller = trap || $caller = watcher ]] && return 0
|
||||
|
||||
# No results were processed
|
||||
return 1
|
||||
}
|
||||
|
||||
# Watch worker for output
|
||||
_async_zle_watcher() {
|
||||
setopt localoptions noshwordsplit
|
||||
typeset -gA ASYNC_PTYS ASYNC_CALLBACKS
|
||||
local worker=$ASYNC_PTYS[$1]
|
||||
local callback=$ASYNC_CALLBACKS[$worker]
|
||||
|
||||
if [[ -n $callback ]]; then
|
||||
async_process_results $worker $callback watcher
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Start a new asynchronous job on specified worker, assumes the worker is running.
|
||||
#
|
||||
# usage:
|
||||
# async_job <worker_name> <my_function> [<function_params>]
|
||||
#
|
||||
async_job() {
|
||||
setopt localoptions noshwordsplit noksharrays noposixidentifiers noposixstrings
|
||||
|
||||
local worker=$1; shift
|
||||
|
||||
local -a cmd
|
||||
cmd=("$@")
|
||||
if (( $#cmd > 1 )); then
|
||||
cmd=(${(q)cmd}) # Quote special characters in multi argument commands.
|
||||
fi
|
||||
|
||||
# Quote the cmd in case RC_EXPAND_PARAM is set.
|
||||
zpty -w $worker "$cmd"$'\0'
|
||||
}
|
||||
|
||||
# This function traps notification signals and calls all registered callbacks
|
||||
_async_notify_trap() {
|
||||
setopt localoptions noshwordsplit
|
||||
|
||||
local k
|
||||
for k in ${(k)ASYNC_CALLBACKS}; do
|
||||
async_process_results $k ${ASYNC_CALLBACKS[$k]} trap
|
||||
done
|
||||
}
|
||||
|
||||
#
|
||||
# Register a callback for completed jobs. As soon as a job is finnished, async_process_results will be called with the
|
||||
# specified callback function. This requires that a worker is initialized with the -n (notify) option.
|
||||
#
|
||||
# usage:
|
||||
# async_register_callback <worker_name> <callback_function>
|
||||
#
|
||||
async_register_callback() {
|
||||
setopt localoptions noshwordsplit nolocaltraps
|
||||
|
||||
typeset -gA ASYNC_CALLBACKS
|
||||
local worker=$1; shift
|
||||
|
||||
ASYNC_CALLBACKS[$worker]="$*"
|
||||
|
||||
# Enable trap when the ZLE watcher is unavailable, allows
|
||||
# workers to notify (via -n) when a job is done.
|
||||
if [[ ! -o interactive ]] || [[ ! -o zle ]]; then
|
||||
trap '_async_notify_trap' WINCH
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Unregister the callback for a specific worker.
|
||||
#
|
||||
# usage:
|
||||
# async_unregister_callback <worker_name>
|
||||
#
|
||||
async_unregister_callback() {
|
||||
typeset -gA ASYNC_CALLBACKS
|
||||
|
||||
unset "ASYNC_CALLBACKS[$1]"
|
||||
}
|
||||
|
||||
#
|
||||
# Flush all current jobs running on a worker. This will terminate any and all running processes under the worker, use
|
||||
# with caution.
|
||||
#
|
||||
# usage:
|
||||
# async_flush_jobs <worker_name>
|
||||
#
|
||||
async_flush_jobs() {
|
||||
setopt localoptions noshwordsplit
|
||||
|
||||
local worker=$1; shift
|
||||
|
||||
# Check if the worker exists
|
||||
zpty -t $worker &>/dev/null || return 1
|
||||
|
||||
# Send kill command to worker
|
||||
async_job $worker "_killjobs"
|
||||
|
||||
# Clear the zpty buffer.
|
||||
local junk
|
||||
if zpty -r -t $worker junk '*'; then
|
||||
(( ASYNC_DEBUG )) && print -n "async_flush_jobs $worker: ${(V)junk}"
|
||||
while zpty -r -t $worker junk '*'; do
|
||||
(( ASYNC_DEBUG )) && print -n "${(V)junk}"
|
||||
done
|
||||
(( ASYNC_DEBUG )) && print
|
||||
fi
|
||||
|
||||
# Finally, clear the process buffer in case of partially parsed responses.
|
||||
typeset -gA ASYNC_PROCESS_BUFFER
|
||||
unset "ASYNC_PROCESS_BUFFER[$worker]"
|
||||
}
|
||||
|
||||
#
|
||||
# Start a new async worker with optional parameters, a worker can be told to only run unique tasks and to notify a
|
||||
# process when tasks are complete.
|
||||
#
|
||||
# usage:
|
||||
# async_start_worker <worker_name> [-u] [-n] [-p <pid>]
|
||||
#
|
||||
# opts:
|
||||
# -u unique (only unique job names can run)
|
||||
# -n notify through SIGWINCH signal
|
||||
# -p pid to notify (defaults to current pid)
|
||||
#
|
||||
async_start_worker() {
|
||||
setopt localoptions noshwordsplit
|
||||
|
||||
local worker=$1; shift
|
||||
zpty -t $worker &>/dev/null && return
|
||||
|
||||
typeset -gA ASYNC_PTYS
|
||||
typeset -h REPLY
|
||||
typeset has_xtrace=0
|
||||
|
||||
# Make sure async worker is started without xtrace
|
||||
# (the trace output interferes with the worker).
|
||||
[[ -o xtrace ]] && {
|
||||
has_xtrace=1
|
||||
unsetopt xtrace
|
||||
}
|
||||
|
||||
if (( ! ASYNC_ZPTY_RETURNS_FD )) && [[ -o interactive ]] && [[ -o zle ]]; then
|
||||
# When zpty doesn't return a file descriptor (on older versions of zsh)
|
||||
# we try to guess it anyway.
|
||||
integer -l zptyfd
|
||||
exec {zptyfd}>&1 # Open a new file descriptor (above 10).
|
||||
exec {zptyfd}>&- # Close it so it's free to be used by zpty.
|
||||
fi
|
||||
|
||||
zpty -b $worker _async_worker -p $$ $@ || {
|
||||
async_stop_worker $worker
|
||||
return 1
|
||||
}
|
||||
|
||||
# Re-enable it if it was enabled, for debugging.
|
||||
(( has_xtrace )) && setopt xtrace
|
||||
|
||||
if [[ $ZSH_VERSION < 5.0.8 ]]; then
|
||||
# For ZSH versions older than 5.0.8 we delay a bit to give
|
||||
# time for the worker to start before issuing commands,
|
||||
# otherwise it will not be ready to receive them.
|
||||
sleep 0.001
|
||||
fi
|
||||
|
||||
if [[ -o interactive ]] && [[ -o zle ]]; then
|
||||
if (( ! ASYNC_ZPTY_RETURNS_FD )); then
|
||||
REPLY=$zptyfd # Use the guessed value for the file desciptor.
|
||||
fi
|
||||
|
||||
ASYNC_PTYS[$REPLY]=$worker # Map the file desciptor to the worker.
|
||||
zle -F $REPLY _async_zle_watcher # Register the ZLE handler.
|
||||
|
||||
# Disable trap in favor of ZLE handler when notify is enabled (-n).
|
||||
async_job $worker _unset_trap
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Stop one or multiple workers that are running, all unfetched and incomplete work will be lost.
|
||||
#
|
||||
# usage:
|
||||
# async_stop_worker <worker_name_1> [<worker_name_2>]
|
||||
#
|
||||
async_stop_worker() {
|
||||
setopt localoptions noshwordsplit
|
||||
|
||||
local ret=0 worker k v
|
||||
for worker in $@; do
|
||||
# Find and unregister the zle handler for the worker
|
||||
for k v in ${(@kv)ASYNC_PTYS}; do
|
||||
if [[ $v == $worker ]]; then
|
||||
zle -F $k
|
||||
unset "ASYNC_PTYS[$k]"
|
||||
fi
|
||||
done
|
||||
async_unregister_callback $worker
|
||||
zpty -d $worker 2>/dev/null || ret=$?
|
||||
|
||||
# Clear any partial buffers.
|
||||
typeset -gA ASYNC_PROCESS_BUFFER
|
||||
unset "ASYNC_PROCESS_BUFFER[$worker]"
|
||||
done
|
||||
|
||||
return $ret
|
||||
}
|
||||
|
||||
#
|
||||
# Initialize the required modules for zsh-async. To be called before using the zsh-async library.
|
||||
#
|
||||
# usage:
|
||||
# async_init
|
||||
#
|
||||
async_init() {
|
||||
(( ASYNC_INIT_DONE )) && return
|
||||
typeset -g ASYNC_INIT_DONE=1
|
||||
|
||||
zmodload zsh/zpty
|
||||
zmodload zsh/datetime
|
||||
|
||||
# Check if zsh/zpty returns a file descriptor or not,
|
||||
# shell must also be interactive with zle enabled.
|
||||
typeset -g ASYNC_ZPTY_RETURNS_FD=0
|
||||
[[ -o interactive ]] && [[ -o zle ]] && {
|
||||
typeset -h REPLY
|
||||
zpty _async_test :
|
||||
(( REPLY )) && ASYNC_ZPTY_RETURNS_FD=1
|
||||
zpty -d _async_test
|
||||
}
|
||||
}
|
||||
|
||||
async() {
|
||||
async_init
|
||||
}
|
||||
|
||||
async "$@"
|
30
.zprezto/modules/prompt/functions/prompt-pwd
Normal file
30
.zprezto/modules/prompt/functions/prompt-pwd
Normal file
@@ -0,0 +1,30 @@
|
||||
#
|
||||
# Prompt setup function commonly used by prompt themes.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
# function prompt-pwd {
|
||||
|
||||
setopt localoptions extendedglob
|
||||
|
||||
local current_pwd="${PWD/#$HOME/~}"
|
||||
local ret_directory
|
||||
|
||||
if [[ "$current_pwd" == (#m)[/~] ]]; then
|
||||
ret_directory="$MATCH"
|
||||
unset MATCH
|
||||
elif zstyle -m ':prezto:module:prompt' pwd-length 'full'; then
|
||||
ret_directory=${PWD}
|
||||
elif zstyle -m ':prezto:module:prompt' pwd-length 'long'; then
|
||||
ret_directory=${current_pwd}
|
||||
else
|
||||
ret_directory="${${${${(@j:/:M)${(@s:/:)current_pwd}##.#?}:h}%/}//\%/%%}/${${current_pwd:t}//\%/%%}"
|
||||
fi
|
||||
|
||||
unset current_pwd
|
||||
|
||||
print "$ret_directory"
|
||||
|
||||
# }
|
@@ -1,89 +0,0 @@
|
||||
pmodload 'helper'
|
||||
|
||||
# %F{color}...%f -- foreground colors
|
||||
# %B...%b -- bold
|
||||
# %(x.a.b) -- if
|
||||
|
||||
# color chart: https://upload.wikimedia.org/wikipedia/en/1/15/Xterm_256color_chart.svg
|
||||
# COLOR_PWD='141'
|
||||
# COLOR_PWD_ROOT='201'
|
||||
# COLOR_PROMPT_STARTER='85'
|
||||
# COLOR_TIME='244'
|
||||
# COLOR_USERNAME='34'
|
||||
# COLOR_AT='244'
|
||||
# COLOR_HOSTNAME='162'
|
||||
|
||||
COLOR_PWD='cyan'
|
||||
COLOR_PWD_ROOT='red'
|
||||
COLOR_PROMPT_STARTER='green'
|
||||
COLOR_TIME='green'
|
||||
COLOR_USERNAME='blue'
|
||||
COLOR_AT=$COLOR_USERNAME
|
||||
COLOR_HOSTNAME=$COLOR_USERNAME
|
||||
|
||||
NEWLINE=$'\n'
|
||||
|
||||
function prompt_abra_precmd {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
|
||||
# Get Git repository information.
|
||||
if [[ -z $NOGIT ]] && (( $+functions[git-info] )); then
|
||||
git-info || true
|
||||
fi
|
||||
|
||||
PRE_LENGTH=$(($COLUMNS*2/3))
|
||||
|
||||
PRE='%$PRE_LENGTH<...<%~ %<<'
|
||||
PRE=$(print -P $PRE)
|
||||
PRE=$(print ${(l:$COLUMNS:)PRE})
|
||||
print -P '%(!.%F{$COLOR_PWD_ROOT}.%F{$COLOR_PWD})$PRE%f'
|
||||
}
|
||||
|
||||
function prompt_abra_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 precmd prompt_abra_precmd
|
||||
|
||||
# Set git-info parameters.
|
||||
zstyle ':prezto:module:git:info' verbose 'yes'
|
||||
zstyle ':prezto:module:git:info:action' format ':%%B%F{yellow}%s%f%%b'
|
||||
zstyle ':prezto:module:git:info:added' format ' %%B%F{green}✚%f%%b'
|
||||
zstyle ':prezto:module:git:info:ahead' format ' %%B%F{yellow}⬆%f%%b'
|
||||
zstyle ':prezto:module:git:info:behind' format ' %%B%F{yellow}⬇%f%%b'
|
||||
zstyle ':prezto:module:git:info:branch' format ':%F{green}%b%f'
|
||||
zstyle ':prezto:module:git:info:commit' format ':%F{green}%.7c%f'
|
||||
zstyle ':prezto:module:git:info:deleted' format ' %%B%F{red}✖%f%%b'
|
||||
zstyle ':prezto:module:git:info:modified' format ' %%B%F{blue}✱%f%%b'
|
||||
zstyle ':prezto:module:git:info:position' format ':%F{red}%p%f'
|
||||
zstyle ':prezto:module:git:info:renamed' format ' %%B%F{magenta}➜%f%%b'
|
||||
zstyle ':prezto:module:git:info:stashed' format ' %%B%F{cyan}✭%f%%b'
|
||||
zstyle ':prezto:module:git:info:unmerged' format ' %%B%F{yellow}═%f%%b'
|
||||
zstyle ':prezto:module:git:info:untracked' format ' %%B%F{white}◼%f%%b'
|
||||
zstyle ':prezto:module:git:info:keys' format \
|
||||
'prompt' '%b ' \
|
||||
'rprompt' '%A%B%S%a%d%m%r%U%u'
|
||||
|
||||
|
||||
|
||||
PROMPT=''
|
||||
PROMPT=$PROMPT'${git_info:+${(e)git_info[prompt]}}'
|
||||
PROMPT=$PROMPT'%(?.%F{$COLOR_PROMPT_STARTER}.%F{red})➤ %f'
|
||||
|
||||
RPROMPT=''
|
||||
RPROMPT=$RPROMPT'%(?::%F{red}%?%f )' # last command code if nonzero
|
||||
RPROMPT=$RPROMPT'%B%F{$COLOR_USERNAME}%n%f%b'
|
||||
RPROMPT=$RPROMPT'%B%F{$COLOR_AT}@%f%b'
|
||||
RPROMPT=$RPROMPT'%B%F{$COLOR_HOSTNAME}%2m%f%b'
|
||||
RPROMPT=$RPROMPT'${git_info[rprompt]} '
|
||||
RPROMPT=$RPROMPT'%F{$COLOR_TIME}%*%f'
|
||||
}
|
||||
|
||||
prompt_abra_setup "$@"
|
||||
|
1
.zprezto/modules/prompt/functions/prompt_abra_setup
Symbolic link
1
.zprezto/modules/prompt/functions/prompt_abra_setup
Symbolic link
@@ -0,0 +1 @@
|
||||
/Users/svxf/.zprezto/abra/prompt_abra_setup.zsh
|
@@ -1 +0,0 @@
|
||||
../external/agnoster/agnoster.zsh-theme
|
165
.zprezto/modules/prompt/functions/prompt_agnoster_setup
Normal file
165
.zprezto/modules/prompt/functions/prompt_agnoster_setup
Normal file
@@ -0,0 +1,165 @@
|
||||
# vim:ft=zsh ts=2 sw=2 sts=2
|
||||
#
|
||||
# agnoster's Theme - https://gist.github.com/3712874
|
||||
# A Powerline-inspired theme for ZSH
|
||||
#
|
||||
# # README
|
||||
#
|
||||
# In order for this theme to render correctly, you will need a
|
||||
# [Powerline-patched font](https://gist.github.com/1595572).
|
||||
#
|
||||
# In addition, I recommend the
|
||||
# [Solarized theme](https://github.com/altercation/solarized/) and, if you're
|
||||
# using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app -
|
||||
# it has significantly better color fidelity.
|
||||
#
|
||||
# # Goals
|
||||
#
|
||||
# The aim of this theme is to only show you *relevant* information. Like most
|
||||
# prompts, it will only show git information when in a git working directory.
|
||||
# However, it goes a step further: everything from the current user and
|
||||
# hostname to whether the last call exited with an error to whether background
|
||||
# jobs are running in this shell will all be displayed automatically when
|
||||
# appropriate.
|
||||
|
||||
### Segment drawing
|
||||
# A few utility functions to make it easy and re-usable to draw segmented prompts
|
||||
|
||||
CURRENT_BG='NONE'
|
||||
if [[ -z "$PRIMARY_FG" ]]; then
|
||||
PRIMARY_FG=black
|
||||
fi
|
||||
|
||||
# Characters
|
||||
SEGMENT_SEPARATOR="\ue0b0"
|
||||
PLUSMINUS="\u00b1"
|
||||
BRANCH="\ue0a0"
|
||||
DETACHED="\u27a6"
|
||||
CROSS="\u2718"
|
||||
LIGHTNING="\u26a1"
|
||||
GEAR="\u2699"
|
||||
|
||||
# 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
|
||||
print -n "%{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%}"
|
||||
else
|
||||
print -n "%{$bg%}%{$fg%}"
|
||||
fi
|
||||
CURRENT_BG=$1
|
||||
[[ -n $3 ]] && print -n $3
|
||||
}
|
||||
|
||||
# End the prompt, closing any open segments
|
||||
prompt_end() {
|
||||
if [[ -n $CURRENT_BG ]]; then
|
||||
print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
|
||||
else
|
||||
print -n "%{%k%}"
|
||||
fi
|
||||
print -n "%{%f%}"
|
||||
CURRENT_BG=''
|
||||
}
|
||||
|
||||
### 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() {
|
||||
local user=`whoami`
|
||||
|
||||
if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CONNECTION" ]]; then
|
||||
prompt_segment $PRIMARY_FG default " %(!.%{%F{yellow}%}.)$user@%m "
|
||||
fi
|
||||
}
|
||||
|
||||
# Git: branch/detached head, dirty status
|
||||
prompt_git() {
|
||||
local color ref
|
||||
is_dirty() {
|
||||
test -n "$(git status --porcelain --ignore-submodules)"
|
||||
}
|
||||
ref="$vcs_info_msg_0_"
|
||||
if [[ -n "$ref" ]]; then
|
||||
if is_dirty; then
|
||||
color=yellow
|
||||
ref="${ref} $PLUSMINUS"
|
||||
else
|
||||
color=green
|
||||
ref="${ref} "
|
||||
fi
|
||||
if [[ "${ref/.../}" == "$ref" ]]; then
|
||||
ref="$BRANCH $ref"
|
||||
else
|
||||
ref="$DETACHED ${ref/.../}"
|
||||
fi
|
||||
prompt_segment $color $PRIMARY_FG
|
||||
print -n " $ref"
|
||||
fi
|
||||
}
|
||||
|
||||
# Dir: current working directory
|
||||
prompt_dir() {
|
||||
prompt_segment blue $PRIMARY_FG ' %~ '
|
||||
}
|
||||
|
||||
# Status:
|
||||
# - was there an error
|
||||
# - am I root
|
||||
# - are there background jobs?
|
||||
prompt_status() {
|
||||
local symbols
|
||||
symbols=()
|
||||
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}$CROSS"
|
||||
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}$LIGHTNING"
|
||||
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}$GEAR"
|
||||
|
||||
[[ -n "$symbols" ]] && prompt_segment $PRIMARY_FG default " $symbols "
|
||||
}
|
||||
|
||||
# Display current virtual environment
|
||||
prompt_virtualenv() {
|
||||
if [[ -n $VIRTUAL_ENV ]]; then
|
||||
color=cyan
|
||||
prompt_segment $color $PRIMARY_FG
|
||||
print -Pn " $(basename $VIRTUAL_ENV) "
|
||||
fi
|
||||
}
|
||||
|
||||
## Main prompt
|
||||
prompt_agnoster_main() {
|
||||
RETVAL=$?
|
||||
CURRENT_BG='NONE'
|
||||
prompt_status
|
||||
prompt_context
|
||||
prompt_virtualenv
|
||||
prompt_dir
|
||||
prompt_git
|
||||
prompt_end
|
||||
}
|
||||
|
||||
prompt_agnoster_precmd() {
|
||||
vcs_info
|
||||
PROMPT='%{%f%b%k%}$(prompt_agnoster_main) '
|
||||
}
|
||||
|
||||
prompt_agnoster_setup() {
|
||||
autoload -Uz add-zsh-hook
|
||||
autoload -Uz vcs_info
|
||||
|
||||
prompt_opts=(cr subst percent)
|
||||
|
||||
add-zsh-hook precmd prompt_agnoster_precmd
|
||||
|
||||
zstyle ':vcs_info:*' enable git
|
||||
zstyle ':vcs_info:*' check-for-changes false
|
||||
zstyle ':vcs_info:git*' formats '%b'
|
||||
zstyle ':vcs_info:git*' actionformats '%b (%a)'
|
||||
}
|
||||
|
||||
prompt_agnoster_setup "$@"
|
@@ -76,7 +76,7 @@ function prompt_cloud_preview {
|
||||
function prompt_cloud_setup {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(cr percent subst)
|
||||
prompt_opts=(cr percent sp subst)
|
||||
|
||||
# Set the theme prefix to a cloud or to the user's given characters.
|
||||
if [[ -n "$1" ]]; then
|
||||
|
@@ -11,23 +11,12 @@
|
||||
# Load dependencies.
|
||||
pmodload 'helper'
|
||||
|
||||
function prompt_damoekri_pwd {
|
||||
local pwd="${PWD/#$HOME/~}"
|
||||
|
||||
if [[ "$pwd" == (#m)[/~] ]]; then
|
||||
_prompt_damoekri_pwd="$MATCH"
|
||||
unset MATCH
|
||||
else
|
||||
_prompt_damoekri_pwd="${${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}//\%/%%}/${${pwd:t}//\%/%%}"
|
||||
fi
|
||||
}
|
||||
|
||||
function prompt_damoekri_precmd {
|
||||
prompt_damoekri_precmd() {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
|
||||
# Format PWD.
|
||||
prompt_damoekri_pwd
|
||||
_prompt_damoekri_pwd=$(prompt-pwd)
|
||||
|
||||
# Get Git repository information.
|
||||
if (( $+functions[git-info] )); then
|
||||
@@ -43,7 +32,7 @@ function prompt_damoekri_precmd {
|
||||
function prompt_damoekri_setup {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(cr percent subst)
|
||||
prompt_opts=(cr percent sp subst)
|
||||
|
||||
# Load required functions.
|
||||
autoload -Uz add-zsh-hook
|
||||
|
@@ -38,7 +38,7 @@ function prompt_giddie_precmd {
|
||||
function prompt_giddie_setup {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(cr percent subst)
|
||||
prompt_opts=(cr percent sp subst)
|
||||
|
||||
# Load required functions.
|
||||
autoload -Uz vcs_info
|
||||
|
@@ -32,7 +32,7 @@ function prompt_kylewest_precmd {
|
||||
function prompt_kylewest_setup {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(cr percent subst)
|
||||
prompt_opts=(cr percent sp subst)
|
||||
|
||||
# Load required functions.
|
||||
autoload -Uz add-zsh-hook
|
||||
|
@@ -23,7 +23,7 @@ function prompt_minimal_precmd {
|
||||
function prompt_minimal_setup {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(cr percent subst)
|
||||
prompt_opts=(cr percent sp subst)
|
||||
|
||||
# Load required functions.
|
||||
autoload -Uz add-zsh-hook
|
||||
|
@@ -26,7 +26,7 @@ function prompt_nicoulaj_precmd {
|
||||
function prompt_nicoulaj_setup {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(cr percent subst)
|
||||
prompt_opts=(cr percent sp subst)
|
||||
|
||||
# Load required functions.
|
||||
autoload -Uz add-zsh-hook
|
||||
|
@@ -8,6 +8,7 @@
|
||||
# Isaac Wolkerstorfer <i@agnoster.net>
|
||||
# Jeff Sandberg <paradox460@gmail.com>
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
# Patrick Bos <egpbos@gmail.com>
|
||||
#
|
||||
# Screenshots:
|
||||
# http://i.imgur.com/0XIWX.png
|
||||
@@ -52,21 +53,14 @@ function prompt_paradox_build_prompt {
|
||||
prompt_paradox_start_segment green black '${(e)git_info[ref]}${(e)git_info[status]}'
|
||||
fi
|
||||
|
||||
if [[ -n "$python_info" ]]; then
|
||||
prompt_paradox_start_segment white black '${(e)python_info[virtualenv]}'
|
||||
fi
|
||||
|
||||
prompt_paradox_end_segment
|
||||
}
|
||||
|
||||
function prompt_paradox_pwd {
|
||||
local pwd="${PWD/#$HOME/~}"
|
||||
|
||||
if [[ "$pwd" == (#m)[/~] ]]; then
|
||||
_prompt_paradox_pwd="$MATCH"
|
||||
unset MATCH
|
||||
else
|
||||
_prompt_paradox_pwd="${${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}//\%/%%}/${${pwd:t}//\%/%%}"
|
||||
fi
|
||||
}
|
||||
|
||||
function prompt_paradox_print_elapsed_time {
|
||||
prompt_paradox_print_elapsed_time() {
|
||||
local end_time=$(( SECONDS - _prompt_paradox_start_time ))
|
||||
local hours minutes seconds remainder
|
||||
|
||||
@@ -90,13 +84,18 @@ function prompt_paradox_precmd {
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
|
||||
# Format PWD.
|
||||
prompt_paradox_pwd
|
||||
_prompt_paradox_pwd=$(prompt-pwd)
|
||||
|
||||
# Get Git repository information.
|
||||
if (( $+functions[git-info] )); then
|
||||
git-info
|
||||
fi
|
||||
|
||||
# Get Python environment information.
|
||||
if (( $+functions[python-info] )); then
|
||||
python-info
|
||||
fi
|
||||
|
||||
# Calculate and print the elapsed time.
|
||||
prompt_paradox_print_elapsed_time
|
||||
}
|
||||
@@ -108,7 +107,7 @@ function prompt_paradox_preexec {
|
||||
function prompt_paradox_setup {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(cr percent subst)
|
||||
prompt_opts=(cr percent sp subst)
|
||||
|
||||
# Load required functions.
|
||||
autoload -Uz add-zsh-hook
|
||||
@@ -143,6 +142,9 @@ function prompt_paradox_setup {
|
||||
'ref' '$(coalesce "%b" "%p" "%c")' \
|
||||
'status' '%s%D%A%B%S%a%d%m%r%U%u'
|
||||
|
||||
# %v - virtualenv name.
|
||||
zstyle ':prezto:module:python:info:virtualenv' format 'virtualenv:%v'
|
||||
|
||||
# Define prompts.
|
||||
PROMPT='
|
||||
${(e)$(prompt_paradox_build_prompt)}
|
||||
|
@@ -25,7 +25,7 @@ function prompt_peepcode_precmd {
|
||||
function prompt_peepcode_setup {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(cr percent subst)
|
||||
prompt_opts=(cr percent sp subst)
|
||||
|
||||
# Load required functions.
|
||||
autoload -Uz add-zsh-hook
|
||||
|
1912
.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup
Executable file
1912
.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup
Executable file
File diff suppressed because it is too large
Load Diff
@@ -1 +0,0 @@
|
||||
../external/powerline/prompt_powerline_setup
|
185
.zprezto/modules/prompt/functions/prompt_powerline_setup
Normal file
185
.zprezto/modules/prompt/functions/prompt_powerline_setup
Normal file
@@ -0,0 +1,185 @@
|
||||
#
|
||||
# A ZSH theme based on a combination of the skwp prezto theme and the robl ohmyzsh theme.
|
||||
# * RVM info shown on the right
|
||||
# * Git branch info on the left
|
||||
# * Single line prompt
|
||||
# * Time since last commit on the left
|
||||
# * Time in place of user@hostname
|
||||
#
|
||||
# Authors:
|
||||
# David Rice <me@davidjrice.co.uk>
|
||||
|
||||
ZSH_THEME_REP_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}"
|
||||
ZSH_THEME_REP_TIME_SINCE_COMMIT_MEDIUM="%{$fg[yellow]%}"
|
||||
ZSH_THEME_REP_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
|
||||
ZSH_THEME_REP_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
|
||||
|
||||
# returns the time since last git commit
|
||||
git_time_details()() {
|
||||
# only proceed if there is actually a git repository
|
||||
if $(git rev-parse --git-dir > /dev/null 2>&1); then
|
||||
# only proceed if there is actually a commit
|
||||
if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
|
||||
# get the last commit hash
|
||||
# lc_hash=$(git log --pretty=format:'%h' -1 2> /dev/null)
|
||||
# get the last commit time
|
||||
lc_time=$(git log --pretty=format:'%at' -1 2> /dev/null)
|
||||
|
||||
now=$(date +%s)
|
||||
seconds_since_last_commit=$((now-lc_time))
|
||||
lc_time_since=$(time_since_commit $seconds_since_last_commit)
|
||||
|
||||
echo "$lc_time_since"
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# returns the time by given seconds
|
||||
time_since_commit()() {
|
||||
seconds_since_last_commit=$(($1 + 0))
|
||||
|
||||
# totals
|
||||
MINUTES=$((seconds_since_last_commit / 60))
|
||||
HOURS=$((seconds_since_last_commit/3600))
|
||||
|
||||
# sub-hours and sub-minutes
|
||||
DAYS=$((seconds_since_last_commit / 86400))
|
||||
SUB_HOURS=$((HOURS % 24))
|
||||
SUB_MINUTES=$((MINUTES % 60))
|
||||
|
||||
if [ "$HOURS" -gt 24 ]; then
|
||||
echo "${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m"
|
||||
elif [ "$MINUTES" -gt 60 ]; then
|
||||
echo "${HOURS}h${SUB_MINUTES}m"
|
||||
else
|
||||
echo "${MINUTES}m"
|
||||
fi
|
||||
}
|
||||
|
||||
rvm_info_for_prompt() {
|
||||
if [[ -d ~/.rvm/ ]]; then
|
||||
local ruby_version=$(~/.rvm/bin/rvm-prompt)
|
||||
if [ -n "$ruby_version" ]; then
|
||||
echo "$ruby_version"
|
||||
fi
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_powerline_precmd() {
|
||||
# Check for untracked files or updated submodules since vcs_info doesn't.
|
||||
if [[ ! -z $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
|
||||
fmt_branch="%b%u%c${__PROMPT_SKWP_COLORS[4]}●%f"
|
||||
else
|
||||
fmt_branch="%b%u%c"
|
||||
fi
|
||||
zstyle ':vcs_info:*:prompt:*' formats "${fmt_branch}"
|
||||
|
||||
vcs_info 'prompt'
|
||||
RVM_PRECMD_INFO=$(rvm_info_for_prompt)
|
||||
|
||||
# zstyle ':prezto:module:ruby' rvm '%r'
|
||||
}
|
||||
|
||||
prompt_powerline_setup() {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(cr percent subst)
|
||||
|
||||
autoload -Uz add-zsh-hook
|
||||
autoload -Uz vcs_info
|
||||
|
||||
add-zsh-hook precmd prompt_powerline_precmd
|
||||
|
||||
# Use extended color pallete if available.
|
||||
if [[ $TERM = *256color* || $TERM = *rxvt* ]]; then
|
||||
__PROMPT_SKWP_COLORS=(
|
||||
"%F{81}" # turquoise
|
||||
"%F{166}" # orange
|
||||
"%F{135}" # purple
|
||||
"%F{161}" # hotpink
|
||||
"%F{118}" # limegreen
|
||||
)
|
||||
else
|
||||
__PROMPT_SKWP_COLORS=(
|
||||
"%F{cyan}"
|
||||
"%F{yellow}"
|
||||
"%F{magenta}"
|
||||
"%F{red}"
|
||||
"%F{green}"
|
||||
)
|
||||
fi
|
||||
|
||||
# Enable VCS systems you use.
|
||||
zstyle ':vcs_info:*' enable bzr git hg svn
|
||||
|
||||
# check-for-changes can be really slow.
|
||||
# You should disable it if you work with large repositories.
|
||||
zstyle ':vcs_info:*:prompt:*' check-for-changes true
|
||||
|
||||
# Formats:
|
||||
# %b - branchname
|
||||
# %u - unstagedstr (see below)
|
||||
# %c - stagedstr (see below)
|
||||
# %a - action (e.g. rebase-i)
|
||||
# %R - repository path
|
||||
# %S - path in the repository
|
||||
# %n - user
|
||||
# %m - machine hostname
|
||||
|
||||
# local fmt_branch="(${__PROMPT_SKWP_COLORS[1]}%b%f%u%c)"
|
||||
local fmt_branch="${__PROMPT_SKWP_COLORS[2]}%b%f%u%c"
|
||||
local fmt_action="${__PROMPT_SKWP_COLORS[5]}%a%f"
|
||||
local fmt_unstaged="${__PROMPT_SKWP_COLORS[2]}●%f"
|
||||
local fmt_staged="${__PROMPT_SKWP_COLORS[5]}●%f"
|
||||
|
||||
zstyle ':vcs_info:*:prompt:*' unstagedstr "${fmt_unstaged}"
|
||||
zstyle ':vcs_info:*:prompt:*' stagedstr "${fmt_staged}"
|
||||
zstyle ':vcs_info:*:prompt:*' actionformats "${fmt_branch}${fmt_action}"
|
||||
zstyle ':vcs_info:*:prompt:*' formats "${fmt_branch}"
|
||||
zstyle ':vcs_info:*:prompt:*' nvcsformats ""
|
||||
|
||||
# SPLIT RVM PROMPT INFO
|
||||
# TODO: should assign this to local variable? somehow doesn't work correctly.
|
||||
rvm_split=("${(s/@/)$(rvm_info_for_prompt)}")
|
||||
|
||||
# if [ "$POWERLINE_RIGHT_B" = "" ]; then
|
||||
# POWERLINE_RIGHT_B=%D{%H:%M:%S}
|
||||
local powerline_right_b=$rvm_split[1]
|
||||
# fi
|
||||
|
||||
# if [ "$POWERLINE_RIGHT_A" = "" ]; then
|
||||
local powerline_right_a=$rvm_split[2]
|
||||
# fi
|
||||
|
||||
# Setup powerline style colouring
|
||||
POWERLINE_COLOR_BG_GRAY=%K{240}
|
||||
POWERLINE_COLOR_BG_LIGHT_GRAY=%K{240}
|
||||
POWERLINE_COLOR_BG_WHITE=%K{255}
|
||||
|
||||
POWERLINE_COLOR_FG_GRAY=%F{240}
|
||||
POWERLINE_COLOR_FG_LIGHT_GRAY=%F{240}
|
||||
POWERLINE_COLOR_FG_WHITE=%F{255}
|
||||
|
||||
POWERLINE_SEPARATOR=$'\uE0B0'
|
||||
POWERLINE_R_SEPARATOR=$'\uE0B2'
|
||||
|
||||
POWERLINE_LEFT_A="%K{green}%F{white} %~ %k%f%F{green}%K{blue}"$POWERLINE_SEPARATOR
|
||||
POWERLINE_LEFT_B="%k%f%F{white}%K{blue} "'${vcs_info_msg_0_}'" %k%f%F{blue}%K{black}"$POWERLINE_SEPARATOR
|
||||
POWERLINE_LEFT_C=" %k%f%F{white}%K{black}"'$(git_time_details)'" %k%f%F{black}"$POWERLINE_SEPARATOR"%f "
|
||||
|
||||
PROMPT=$POWERLINE_LEFT_A$POWERLINE_LEFT_B$POWERLINE_LEFT_C
|
||||
# RPROMPT=$POWERLINE_COLOR_FG_WHITE$POWERLINE_R_SEPARATOR"%f$POWERLINE_COLOR_BG_WHITE $POWERLINE_COLOR_FG_GRAY$powerline_right_b "$POWERLINE_R_SEPARATOR"%f%k$POWERLINE_COLOR_BG_GRAY$POWERLINE_COLOR_FG_WHITE $powerline_right_a %f%k"
|
||||
# RPROMPT=$POWERLINE_COLOR_FG_WHITE$POWERLINE_R_SEPARATOR"%f$POWERLINE_COLOR_BG_WHITE $POWERLINE_COLOR_FG_GRAY"'$powerline_right_b'" "$POWERLINE_R_SEPARATOR"%f%k$POWERLINE_COLOR_BG_GRAY$POWERLINE_COLOR_FG_WHITE "'$powerline_right_a'" %f%k"
|
||||
RPROMPT=$POWERLINE_COLOR_FG_WHITE$POWERLINE_R_SEPARATOR"%f$POWERLINE_COLOR_BG_WHITE $POWERLINE_COLOR_FG_GRAY"'$(rvm_info_for_prompt)'" "
|
||||
}
|
||||
|
||||
prompt_powerline_setup "$@"
|
||||
|
||||
|
||||
|
@@ -1 +0,0 @@
|
||||
../external/pure/pure.zsh
|
486
.zprezto/modules/prompt/functions/prompt_pure_setup
Normal file
486
.zprezto/modules/prompt/functions/prompt_pure_setup
Normal file
@@ -0,0 +1,486 @@
|
||||
# Pure
|
||||
# by Sindre Sorhus
|
||||
# https://github.com/sindresorhus/pure
|
||||
# MIT License
|
||||
|
||||
# For my own and others sanity
|
||||
# git:
|
||||
# %b => current branch
|
||||
# %a => current action (rebase/merge)
|
||||
# prompt:
|
||||
# %F => color dict
|
||||
# %f => reset color
|
||||
# %~ => current path
|
||||
# %* => time
|
||||
# %n => username
|
||||
# %m => shortname host
|
||||
# %(?..) => prompt conditional - %(condition.true.false)
|
||||
# terminal codes:
|
||||
# \e7 => save cursor position
|
||||
# \e[2A => move cursor 2 lines up
|
||||
# \e[1G => go to position 1 in terminal
|
||||
# \e8 => restore cursor position
|
||||
# \e[K => clears everything after the cursor on the current line
|
||||
# \e[2K => clear everything on the current line
|
||||
|
||||
|
||||
# turns seconds into human readable time
|
||||
# 165392 => 1d 21h 56m 32s
|
||||
# https://github.com/sindresorhus/pretty-time-zsh
|
||||
prompt_pure_human_time_to_var() {
|
||||
local human total_seconds=$1 var=$2
|
||||
local days=$(( total_seconds / 60 / 60 / 24 ))
|
||||
local hours=$(( total_seconds / 60 / 60 % 24 ))
|
||||
local minutes=$(( total_seconds / 60 % 60 ))
|
||||
local seconds=$(( total_seconds % 60 ))
|
||||
(( days > 0 )) && human+="${days}d "
|
||||
(( hours > 0 )) && human+="${hours}h "
|
||||
(( minutes > 0 )) && human+="${minutes}m "
|
||||
human+="${seconds}s"
|
||||
|
||||
# store human readable time in variable as specified by caller
|
||||
typeset -g "${var}"="${human}"
|
||||
}
|
||||
|
||||
# stores (into prompt_pure_cmd_exec_time) the exec time of the last command if set threshold was exceeded
|
||||
prompt_pure_check_cmd_exec_time() {
|
||||
integer elapsed
|
||||
(( elapsed = EPOCHSECONDS - ${prompt_pure_cmd_timestamp:-$EPOCHSECONDS} ))
|
||||
typeset -g prompt_pure_cmd_exec_time=
|
||||
(( elapsed > ${PURE_CMD_MAX_EXEC_TIME:-5} )) && {
|
||||
prompt_pure_human_time_to_var $elapsed "prompt_pure_cmd_exec_time"
|
||||
}
|
||||
}
|
||||
|
||||
prompt_pure_set_title() {
|
||||
setopt localoptions noshwordsplit
|
||||
|
||||
# emacs terminal does not support settings the title
|
||||
(( ${+EMACS} )) && return
|
||||
|
||||
case $TTY in
|
||||
# Don't set title over serial console.
|
||||
/dev/ttyS[0-9]*) return;;
|
||||
esac
|
||||
|
||||
# tell the terminal we are setting the title
|
||||
print -n '\e]0;'
|
||||
# show hostname if connected through ssh
|
||||
[[ -n $SSH_CONNECTION ]] && print -Pn '(%m) '
|
||||
case $1 in
|
||||
expand-prompt)
|
||||
print -Pn $2;;
|
||||
ignore-escape)
|
||||
print -rn $2;;
|
||||
esac
|
||||
# end set title
|
||||
print -n '\a'
|
||||
}
|
||||
|
||||
prompt_pure_preexec() {
|
||||
if [[ -n $prompt_pure_git_fetch_pattern ]]; then
|
||||
# detect when git is performing pull/fetch (including git aliases).
|
||||
local -H MATCH MBEGIN MEND match mbegin mend
|
||||
if [[ $2 =~ (git|hub)\ (.*\ )?($prompt_pure_git_fetch_pattern)(\ .*)?$ ]]; then
|
||||
# we must flush the async jobs to cancel our git fetch in order
|
||||
# to avoid conflicts with the user issued pull / fetch.
|
||||
async_flush_jobs 'prompt_pure'
|
||||
fi
|
||||
fi
|
||||
|
||||
typeset -g prompt_pure_cmd_timestamp=$EPOCHSECONDS
|
||||
|
||||
# shows the current dir and executed command in the title while a process is active
|
||||
prompt_pure_set_title 'ignore-escape' "$PWD:t: $2"
|
||||
|
||||
# Disallow python virtualenv from updating the prompt, set it to 12 if
|
||||
# untouched by the user to indicate that Pure modified it. Here we use
|
||||
# magic number 12, same as in psvar.
|
||||
export VIRTUAL_ENV_DISABLE_PROMPT=${VIRTUAL_ENV_DISABLE_PROMPT:-12}
|
||||
}
|
||||
|
||||
# string length ignoring ansi escapes
|
||||
prompt_pure_string_length_to_var() {
|
||||
local str=$1 var=$2 length
|
||||
# perform expansion on str and check length
|
||||
length=$(( ${#${(S%%)str//(\%([KF1]|)\{*\}|\%[Bbkf])}} ))
|
||||
|
||||
# store string length in variable as specified by caller
|
||||
typeset -g "${var}"="${length}"
|
||||
}
|
||||
|
||||
prompt_pure_preprompt_render() {
|
||||
setopt localoptions noshwordsplit
|
||||
|
||||
# Set color for git branch/dirty status, change color if dirty checking has
|
||||
# been delayed.
|
||||
local git_color=242
|
||||
[[ -n ${prompt_pure_git_last_dirty_check_timestamp+x} ]] && git_color=red
|
||||
|
||||
# Initialize the preprompt array.
|
||||
local -a preprompt_parts
|
||||
|
||||
# Set the path.
|
||||
preprompt_parts+=('%F{blue}%~%f')
|
||||
|
||||
# Add git branch and dirty status info.
|
||||
typeset -gA prompt_pure_vcs_info
|
||||
if [[ -n $prompt_pure_vcs_info[branch] ]]; then
|
||||
preprompt_parts+=("%F{$git_color}"'${prompt_pure_vcs_info[branch]}${prompt_pure_git_dirty}%f')
|
||||
fi
|
||||
# Git pull/push arrows.
|
||||
if [[ -n $prompt_pure_git_arrows ]]; then
|
||||
preprompt_parts+=('%F{cyan}${prompt_pure_git_arrows}%f')
|
||||
fi
|
||||
|
||||
# Username and machine, if applicable.
|
||||
[[ -n $prompt_pure_username ]] && preprompt_parts+=('$prompt_pure_username')
|
||||
# Execution time.
|
||||
[[ -n $prompt_pure_cmd_exec_time ]] && preprompt_parts+=('%F{yellow}${prompt_pure_cmd_exec_time}%f')
|
||||
|
||||
local cleaned_ps1=$PROMPT
|
||||
local -H MATCH MBEGIN MEND
|
||||
if [[ $PROMPT = *$prompt_newline* ]]; then
|
||||
# When the prompt contains newlines, we keep everything before the first
|
||||
# and after the last newline, leaving us with everything except the
|
||||
# preprompt. This is needed because some software prefixes the prompt
|
||||
# (e.g. virtualenv).
|
||||
cleaned_ps1=${PROMPT%%${prompt_newline}*}${PROMPT##*${prompt_newline}}
|
||||
fi
|
||||
unset MATCH MBEGIN MEND
|
||||
|
||||
# Construct the new prompt with a clean preprompt.
|
||||
local -ah ps1
|
||||
ps1=(
|
||||
$prompt_newline # Initial newline, for spaciousness.
|
||||
${(j. .)preprompt_parts} # Join parts, space separated.
|
||||
$prompt_newline # Separate preprompt and prompt.
|
||||
$cleaned_ps1
|
||||
)
|
||||
|
||||
PROMPT="${(j..)ps1}"
|
||||
|
||||
# Expand the prompt for future comparision.
|
||||
local expanded_prompt
|
||||
expanded_prompt="${(S%%)PROMPT}"
|
||||
|
||||
if [[ $1 != precmd ]] && [[ $prompt_pure_last_prompt != $expanded_prompt ]]; then
|
||||
# Redraw the prompt.
|
||||
zle && zle .reset-prompt
|
||||
fi
|
||||
|
||||
typeset -g prompt_pure_last_prompt=$expanded_prompt
|
||||
}
|
||||
|
||||
prompt_pure_precmd() {
|
||||
# check exec time and store it in a variable
|
||||
prompt_pure_check_cmd_exec_time
|
||||
unset prompt_pure_cmd_timestamp
|
||||
|
||||
# shows the full path in the title
|
||||
prompt_pure_set_title 'expand-prompt' '%~'
|
||||
|
||||
# preform async git dirty check and fetch
|
||||
prompt_pure_async_tasks
|
||||
|
||||
# Check if we should display the virtual env, we use a sufficiently high
|
||||
# index of psvar (12) here to avoid collisions with user defined entries.
|
||||
psvar[12]=
|
||||
# When VIRTUAL_ENV_DISABLE_PROMPT is empty, it was unset by the user and
|
||||
# Pure should take back control.
|
||||
if [[ -n $VIRTUAL_ENV ]] && [[ -z $VIRTUAL_ENV_DISABLE_PROMPT || $VIRTUAL_ENV_DISABLE_PROMPT = 12 ]]; then
|
||||
psvar[12]="${VIRTUAL_ENV:t}"
|
||||
export VIRTUAL_ENV_DISABLE_PROMPT=12
|
||||
fi
|
||||
|
||||
# print the preprompt
|
||||
prompt_pure_preprompt_render "precmd"
|
||||
}
|
||||
|
||||
prompt_pure_async_git_aliases() {
|
||||
setopt localoptions noshwordsplit
|
||||
local dir=$1
|
||||
local -a gitalias pullalias
|
||||
|
||||
# we enter repo to get local aliases as well.
|
||||
builtin cd -q $dir
|
||||
|
||||
# list all aliases and split on newline.
|
||||
gitalias=(${(@f)"$(command git config --get-regexp "^alias\.")"})
|
||||
for line in $gitalias; do
|
||||
parts=(${(@)=line}) # split line on spaces
|
||||
aliasname=${parts[1]#alias.} # grab the name (alias.[name])
|
||||
shift parts # remove aliasname
|
||||
|
||||
# check alias for pull or fetch (must be exact match).
|
||||
if [[ $parts =~ ^(.*\ )?(pull|fetch)(\ .*)?$ ]]; then
|
||||
pullalias+=($aliasname)
|
||||
fi
|
||||
done
|
||||
|
||||
print -- ${(j:|:)pullalias} # join on pipe (for use in regex).
|
||||
}
|
||||
|
||||
prompt_pure_async_vcs_info() {
|
||||
setopt localoptions noshwordsplit
|
||||
builtin cd -q $1 2>/dev/null
|
||||
|
||||
# configure vcs_info inside async task, this frees up vcs_info
|
||||
# to be used or configured as the user pleases.
|
||||
zstyle ':vcs_info:*' enable git
|
||||
zstyle ':vcs_info:*' use-simple true
|
||||
# only export two msg variables from vcs_info
|
||||
zstyle ':vcs_info:*' max-exports 2
|
||||
# export branch (%b) and git toplevel (%R)
|
||||
zstyle ':vcs_info:git*' formats '%b' '%R'
|
||||
zstyle ':vcs_info:git*' actionformats '%b|%a' '%R'
|
||||
|
||||
vcs_info
|
||||
|
||||
local -A info
|
||||
info[top]=$vcs_info_msg_1_
|
||||
info[branch]=$vcs_info_msg_0_
|
||||
|
||||
print -r - ${(@kvq)info}
|
||||
}
|
||||
|
||||
# fastest possible way to check if repo is dirty
|
||||
prompt_pure_async_git_dirty() {
|
||||
setopt localoptions noshwordsplit
|
||||
local untracked_dirty=$1 dir=$2
|
||||
|
||||
# use cd -q to avoid side effects of changing directory, e.g. chpwd hooks
|
||||
builtin cd -q $dir
|
||||
|
||||
if [[ $untracked_dirty = 0 ]]; then
|
||||
command git diff --no-ext-diff --quiet --exit-code
|
||||
else
|
||||
test -z "$(command git status --porcelain --ignore-submodules -unormal)"
|
||||
fi
|
||||
|
||||
return $?
|
||||
}
|
||||
|
||||
prompt_pure_async_git_fetch() {
|
||||
setopt localoptions noshwordsplit
|
||||
# use cd -q to avoid side effects of changing directory, e.g. chpwd hooks
|
||||
builtin cd -q $1
|
||||
|
||||
# set GIT_TERMINAL_PROMPT=0 to disable auth prompting for git fetch (git 2.3+)
|
||||
export GIT_TERMINAL_PROMPT=0
|
||||
# set ssh BachMode to disable all interactive ssh password prompting
|
||||
export GIT_SSH_COMMAND=${GIT_SSH_COMMAND:-"ssh -o BatchMode=yes"}
|
||||
|
||||
command git -c gc.auto=0 fetch &>/dev/null || return 99
|
||||
|
||||
# check arrow status after a successful git fetch
|
||||
prompt_pure_async_git_arrows $1
|
||||
}
|
||||
|
||||
prompt_pure_async_git_arrows() {
|
||||
setopt localoptions noshwordsplit
|
||||
builtin cd -q $1
|
||||
command git rev-list --left-right --count HEAD...@'{u}'
|
||||
}
|
||||
|
||||
prompt_pure_async_tasks() {
|
||||
setopt localoptions noshwordsplit
|
||||
|
||||
# initialize async worker
|
||||
((!${prompt_pure_async_init:-0})) && {
|
||||
async_start_worker "prompt_pure" -u -n
|
||||
async_register_callback "prompt_pure" prompt_pure_async_callback
|
||||
typeset -g prompt_pure_async_init=1
|
||||
}
|
||||
|
||||
typeset -gA prompt_pure_vcs_info
|
||||
|
||||
local -H MATCH MBEGIN MEND
|
||||
if ! [[ $PWD = ${prompt_pure_vcs_info[pwd]}* ]]; then
|
||||
# stop any running async jobs
|
||||
async_flush_jobs "prompt_pure"
|
||||
|
||||
# reset git preprompt variables, switching working tree
|
||||
unset prompt_pure_git_dirty
|
||||
unset prompt_pure_git_last_dirty_check_timestamp
|
||||
unset prompt_pure_git_arrows
|
||||
unset prompt_pure_git_fetch_pattern
|
||||
prompt_pure_vcs_info[branch]=
|
||||
prompt_pure_vcs_info[top]=
|
||||
fi
|
||||
unset MATCH MBEGIN MEND
|
||||
|
||||
async_job "prompt_pure" prompt_pure_async_vcs_info $PWD
|
||||
|
||||
# # only perform tasks inside git working tree
|
||||
[[ -n $prompt_pure_vcs_info[top] ]] || return
|
||||
|
||||
prompt_pure_async_refresh
|
||||
}
|
||||
|
||||
prompt_pure_async_refresh() {
|
||||
setopt localoptions noshwordsplit
|
||||
|
||||
if [[ -z $prompt_pure_git_fetch_pattern ]]; then
|
||||
# we set the pattern here to avoid redoing the pattern check until the
|
||||
# working three has changed. pull and fetch are always valid patterns.
|
||||
typeset -g prompt_pure_git_fetch_pattern="pull|fetch"
|
||||
async_job "prompt_pure" prompt_pure_async_git_aliases $working_tree
|
||||
fi
|
||||
|
||||
async_job "prompt_pure" prompt_pure_async_git_arrows $PWD
|
||||
|
||||
# do not preform git fetch if it is disabled or working_tree == HOME
|
||||
if (( ${PURE_GIT_PULL:-1} )) && [[ $working_tree != $HOME ]]; then
|
||||
# tell worker to do a git fetch
|
||||
async_job "prompt_pure" prompt_pure_async_git_fetch $PWD
|
||||
fi
|
||||
|
||||
# if dirty checking is sufficiently fast, tell worker to check it again, or wait for timeout
|
||||
integer time_since_last_dirty_check=$(( EPOCHSECONDS - ${prompt_pure_git_last_dirty_check_timestamp:-0} ))
|
||||
if (( time_since_last_dirty_check > ${PURE_GIT_DELAY_DIRTY_CHECK:-1800} )); then
|
||||
unset prompt_pure_git_last_dirty_check_timestamp
|
||||
# check check if there is anything to pull
|
||||
async_job "prompt_pure" prompt_pure_async_git_dirty ${PURE_GIT_UNTRACKED_DIRTY:-1} $PWD
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_pure_check_git_arrows() {
|
||||
setopt localoptions noshwordsplit
|
||||
local arrows left=${1:-0} right=${2:-0}
|
||||
|
||||
(( right > 0 )) && arrows+=${PURE_GIT_DOWN_ARROW:-⇣}
|
||||
(( left > 0 )) && arrows+=${PURE_GIT_UP_ARROW:-⇡}
|
||||
|
||||
[[ -n $arrows ]] || return
|
||||
typeset -g REPLY=$arrows
|
||||
}
|
||||
|
||||
prompt_pure_async_callback() {
|
||||
setopt localoptions noshwordsplit
|
||||
local job=$1 code=$2 output=$3 exec_time=$4 next_pending=$6
|
||||
local do_render=0
|
||||
|
||||
case $job in
|
||||
prompt_pure_async_vcs_info)
|
||||
local -A info
|
||||
typeset -gA prompt_pure_vcs_info
|
||||
|
||||
# parse output (z) and unquote as array (Q@)
|
||||
info=("${(Q@)${(z)output}}")
|
||||
local -H MATCH MBEGIN MEND
|
||||
# check if git toplevel has changed
|
||||
if [[ $info[top] = $prompt_pure_vcs_info[top] ]]; then
|
||||
# if stored pwd is part of $PWD, $PWD is shorter and likelier
|
||||
# to be toplevel, so we update pwd
|
||||
if [[ $prompt_pure_vcs_info[pwd] = ${PWD}* ]]; then
|
||||
prompt_pure_vcs_info[pwd]=$PWD
|
||||
fi
|
||||
else
|
||||
# store $PWD to detect if we (maybe) left the git path
|
||||
prompt_pure_vcs_info[pwd]=$PWD
|
||||
fi
|
||||
unset MATCH MBEGIN MEND
|
||||
|
||||
# update has a git toplevel set which means we just entered a new
|
||||
# git directory, run the async refresh tasks
|
||||
[[ -n $info[top] ]] && [[ -z $prompt_pure_vcs_info[top] ]] && prompt_pure_async_refresh
|
||||
|
||||
# always update branch and toplevel
|
||||
prompt_pure_vcs_info[branch]=$info[branch]
|
||||
prompt_pure_vcs_info[top]=$info[top]
|
||||
|
||||
do_render=1
|
||||
;;
|
||||
prompt_pure_async_git_aliases)
|
||||
if [[ -n $output ]]; then
|
||||
# append custom git aliases to the predefined ones.
|
||||
prompt_pure_git_fetch_pattern+="|$output"
|
||||
fi
|
||||
;;
|
||||
prompt_pure_async_git_dirty)
|
||||
local prev_dirty=$prompt_pure_git_dirty
|
||||
if (( code == 0 )); then
|
||||
unset prompt_pure_git_dirty
|
||||
else
|
||||
typeset -g prompt_pure_git_dirty="*"
|
||||
fi
|
||||
|
||||
[[ $prev_dirty != $prompt_pure_git_dirty ]] && do_render=1
|
||||
|
||||
# When prompt_pure_git_last_dirty_check_timestamp is set, the git info is displayed in a different color.
|
||||
# To distinguish between a "fresh" and a "cached" result, the preprompt is rendered before setting this
|
||||
# variable. Thus, only upon next rendering of the preprompt will the result appear in a different color.
|
||||
(( $exec_time > 5 )) && prompt_pure_git_last_dirty_check_timestamp=$EPOCHSECONDS
|
||||
;;
|
||||
prompt_pure_async_git_fetch|prompt_pure_async_git_arrows)
|
||||
# prompt_pure_async_git_fetch executes prompt_pure_async_git_arrows
|
||||
# after a successful fetch.
|
||||
if (( code == 0 )); then
|
||||
local REPLY
|
||||
prompt_pure_check_git_arrows ${(ps:\t:)output}
|
||||
if [[ $prompt_pure_git_arrows != $REPLY ]]; then
|
||||
typeset -g prompt_pure_git_arrows=$REPLY
|
||||
do_render=1
|
||||
fi
|
||||
elif (( code != 99 )); then
|
||||
# Unless the exit code is 99, prompt_pure_async_git_arrows
|
||||
# failed with a non-zero exit status, meaning there is no
|
||||
# upstream configured.
|
||||
if [[ -n $prompt_pure_git_arrows ]]; then
|
||||
unset prompt_pure_git_arrows
|
||||
do_render=1
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if (( next_pending )); then
|
||||
(( do_render )) && typeset -g prompt_pure_async_render_requested=1
|
||||
return
|
||||
fi
|
||||
|
||||
[[ ${prompt_pure_async_render_requested:-$do_render} = 1 ]] && prompt_pure_preprompt_render
|
||||
unset prompt_pure_async_render_requested
|
||||
}
|
||||
|
||||
prompt_pure_setup() {
|
||||
# Prevent percentage showing up if output doesn't end with a newline.
|
||||
export PROMPT_EOL_MARK=''
|
||||
|
||||
prompt_opts=(subst percent)
|
||||
|
||||
# borrowed from promptinit, sets the prompt options in case pure was not
|
||||
# initialized via promptinit.
|
||||
setopt noprompt{bang,cr,percent,subst} "prompt${^prompt_opts[@]}"
|
||||
|
||||
if [[ -z $prompt_newline ]]; then
|
||||
# This variable needs to be set, usually set by promptinit.
|
||||
typeset -g prompt_newline=$'\n%{\r%}'
|
||||
fi
|
||||
|
||||
zmodload zsh/datetime
|
||||
zmodload zsh/zle
|
||||
zmodload zsh/parameter
|
||||
|
||||
autoload -Uz add-zsh-hook
|
||||
autoload -Uz vcs_info
|
||||
autoload -Uz async && async
|
||||
|
||||
add-zsh-hook precmd prompt_pure_precmd
|
||||
add-zsh-hook preexec prompt_pure_preexec
|
||||
|
||||
# show username@host if logged in through SSH
|
||||
[[ "$SSH_CONNECTION" != '' ]] && prompt_pure_username='%F{242}%n@%m%f'
|
||||
|
||||
# show username@host if root, with username in white
|
||||
[[ $UID -eq 0 ]] && prompt_pure_username='%F{white}%n%f%F{242}@%m%f'
|
||||
|
||||
# if a virtualenv is activated, display it in grey
|
||||
PROMPT='%(12V.%F{242}%12v%f .)'
|
||||
|
||||
# prompt turns red if the previous command didn't exit with 0
|
||||
PROMPT+='%(?.%F{magenta}.%F{red})${PURE_PROMPT_SYMBOL:-❯}%f '
|
||||
}
|
||||
|
||||
prompt_pure_setup "$@"
|
@@ -28,7 +28,7 @@ function prompt_skwp_precmd {
|
||||
function prompt_skwp_setup {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(cr percent subst)
|
||||
prompt_opts=(cr percent sp subst)
|
||||
|
||||
# Load required functions.
|
||||
autoload -Uz add-zsh-hook
|
||||
|
@@ -36,7 +36,7 @@ function prompt_smiley_precmd {
|
||||
|
||||
function prompt_smiley_setup {
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(percent subst)
|
||||
prompt_opts=(cr percent sp subst)
|
||||
|
||||
# Add hook for calling git-info before each command.
|
||||
add-zsh-hook precmd prompt_smiley_precmd
|
||||
|
@@ -32,44 +32,53 @@
|
||||
# Load dependencies.
|
||||
pmodload 'helper'
|
||||
|
||||
function prompt_sorin_pwd {
|
||||
local pwd="${PWD/#$HOME/~}"
|
||||
function prompt_sorin_async_callback {
|
||||
case $1 in
|
||||
prompt_sorin_async_git)
|
||||
# We can safely split on ':' because it isn't allowed in ref names.
|
||||
IFS=':' read _git_target _git_post_target <<<"$3"
|
||||
|
||||
if [[ "$pwd" == (#m)[/~] ]]; then
|
||||
_prompt_sorin_pwd="$MATCH"
|
||||
unset MATCH
|
||||
else
|
||||
_prompt_sorin_pwd="${${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}//\%/%%}/${${pwd:t}//\%/%%}"
|
||||
fi
|
||||
# The target actually contains 3 space separated possibilities, so we need to
|
||||
# make sure we grab the first one.
|
||||
_git_target=$(coalesce ${(@)${(z)_git_target}})
|
||||
|
||||
if [[ -z "$_git_target" ]]; then
|
||||
# No git target detected, flush the git fragment and redisplay the prompt.
|
||||
if [[ -n "$_prompt_sorin_git" ]]; then
|
||||
_prompt_sorin_git=''
|
||||
zle && zle reset-prompt
|
||||
fi
|
||||
else
|
||||
# Git target detected, update the git fragment and redisplay the prompt.
|
||||
_prompt_sorin_git="${_git_target}${_git_post_target}"
|
||||
zle && zle reset-prompt
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function prompt_sorin_git_info {
|
||||
if (( _prompt_sorin_precmd_async_pid > 0 )); then
|
||||
# Append Git status.
|
||||
if [[ -s "$_prompt_sorin_precmd_async_data" ]]; then
|
||||
alias typeset='typeset -g'
|
||||
source "$_prompt_sorin_precmd_async_data"
|
||||
RPROMPT+='${git_info:+${(e)git_info[status]}}'
|
||||
unalias typeset
|
||||
fi
|
||||
|
||||
# Reset PID.
|
||||
_prompt_sorin_precmd_async_pid=0
|
||||
|
||||
# Redisplay prompt.
|
||||
zle && zle reset-prompt
|
||||
fi
|
||||
}
|
||||
|
||||
function prompt_sorin_precmd_async {
|
||||
# Get Git repository information.
|
||||
function prompt_sorin_async_git {
|
||||
cd -q "$1"
|
||||
if (( $+functions[git-info] )); then
|
||||
git-info
|
||||
typeset -p git_info >! "$_prompt_sorin_precmd_async_data"
|
||||
print ${git_info[status]}
|
||||
fi
|
||||
}
|
||||
|
||||
function prompt_sorin_async_tasks {
|
||||
# Initialize async worker. This needs to be done here and not in
|
||||
# prompt_sorin_setup so the git formatting can be overridden by other prompts.
|
||||
if (( !${prompt_prezto_async_init:-0} )); then
|
||||
async_start_worker prompt_sorin -n
|
||||
async_register_callback prompt_sorin prompt_sorin_async_callback
|
||||
typeset -g prompt_prezto_async_init=1
|
||||
fi
|
||||
|
||||
# Signal completion to parent process.
|
||||
kill -WINCH $$
|
||||
# Kill the old process of slow commands if it is still running.
|
||||
async_flush_jobs prompt_sorin
|
||||
|
||||
# Compute slow commands in the background.
|
||||
async_job prompt_sorin prompt_sorin_async_git "$PWD"
|
||||
}
|
||||
|
||||
function prompt_sorin_precmd {
|
||||
@@ -77,31 +86,36 @@ function prompt_sorin_precmd {
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
|
||||
# Format PWD.
|
||||
prompt_sorin_pwd
|
||||
_prompt_sorin_pwd=$(prompt-pwd)
|
||||
|
||||
# Define prompts.
|
||||
RPROMPT='${editor_info[overwrite]}%(?:: %F{1}⏎%f)${VIM:+" %B%F{6}V%f%b"}'
|
||||
|
||||
# Kill the old process of slow commands if it is still running.
|
||||
if (( _prompt_sorin_precmd_async_pid > 0 )); then
|
||||
kill -KILL "$_prompt_sorin_precmd_async_pid" &>/dev/null
|
||||
# Handle updating git data. We also clear the git prompt data if we're in a
|
||||
# different git root now.
|
||||
if (( $+functions[git-dir] )); then
|
||||
local new_git_root="$(git-dir 2> /dev/null)"
|
||||
if [[ $new_git_root != $_sorin_cur_git_root ]]; then
|
||||
_prompt_sorin_git=''
|
||||
_sorin_cur_git_root=$new_git_root
|
||||
fi
|
||||
fi
|
||||
|
||||
# Compute slow commands in the background.
|
||||
trap prompt_sorin_git_info WINCH
|
||||
prompt_sorin_precmd_async &!
|
||||
_prompt_sorin_precmd_async_pid=$!
|
||||
# Run python info (this should be fast and not require any async)
|
||||
if (( $+functions[python-info] )); then
|
||||
python-info
|
||||
fi
|
||||
|
||||
prompt_sorin_async_tasks
|
||||
}
|
||||
|
||||
function prompt_sorin_setup {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(cr percent subst)
|
||||
prompt_opts=(cr percent sp subst)
|
||||
_prompt_sorin_precmd_async_pid=0
|
||||
_prompt_sorin_precmd_async_data="${TMPPREFIX}-prompt_sorin_data"
|
||||
_prompt_sorin_precmd_async_data=$(mktemp "${TMPDIR:-/tmp}/sorin-prompt-async-XXXXXXXXXX")
|
||||
|
||||
# Load required functions.
|
||||
autoload -Uz add-zsh-hook
|
||||
autoload -Uz async && async
|
||||
|
||||
# Add hook for calling git-info before each command.
|
||||
add-zsh-hook precmd prompt_sorin_precmd
|
||||
@@ -128,11 +142,28 @@ function prompt_sorin_setup {
|
||||
zstyle ':prezto:module:git:info:unmerged' format ' %%B%F{3}═%f%%b'
|
||||
zstyle ':prezto:module:git:info:untracked' format ' %%B%F{7}◼%f%%b'
|
||||
zstyle ':prezto:module:git:info:keys' format \
|
||||
'status' '$(coalesce "%b" "%p" "%c")%s%A%B%S%a%d%m%r%U%u'
|
||||
'status' '%b %p %c:%s%A%B%S%a%d%m%r%U%u'
|
||||
|
||||
# Set up non-zero return value display
|
||||
local show_return="✘ "
|
||||
# Default is to show the return value
|
||||
if zstyle -T ':prezto:module:prompt' show-return-val; then
|
||||
show_return+='%? '
|
||||
fi
|
||||
# Set python-info format
|
||||
zstyle ':prezto:module:python:info:virtualenv' format '%f%F{3}(%v)%F{7} '
|
||||
|
||||
# Get the async worker set up
|
||||
_sorin_cur_git_root=''
|
||||
|
||||
_prompt_sorin_git=''
|
||||
_prompt_sorin_pwd=''
|
||||
|
||||
# Define prompts.
|
||||
PROMPT='${SSH_TTY:+"%F{9}%n%f%F{7}@%f%F{3}%m%f "}%F{4}${_prompt_sorin_pwd}%(!. %B%F{1}#%f%b.)${editor_info[keymap]} '
|
||||
RPROMPT=''
|
||||
RPROMPT='$python_info[virtualenv]${editor_info[overwrite]}%(?:: %F{1}'
|
||||
RPROMPT+=${show_return}
|
||||
RPROMPT+='%f)${VIM:+" %B%F{6}V%f%b"}${_prompt_sorin_git}'
|
||||
SPROMPT='zsh: correct %F{1}%R%f to %F{2}%r%f [nyae]? '
|
||||
}
|
||||
|
||||
@@ -141,7 +172,7 @@ function prompt_sorin_preview {
|
||||
local +h RPROMPT=''
|
||||
local +h SPROMPT=''
|
||||
|
||||
editor-info 2>/dev/null
|
||||
editor-info 2> /dev/null
|
||||
prompt_preview_theme 'sorin'
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,7 @@ function prompt_steeef_precmd {
|
||||
function prompt_steeef_setup {
|
||||
setopt LOCAL_OPTIONS
|
||||
unsetopt XTRACE KSH_ARRAYS
|
||||
prompt_opts=(cr percent subst)
|
||||
prompt_opts=(cr percent sp subst)
|
||||
|
||||
# Load required functions.
|
||||
autoload -Uz add-zsh-hook
|
||||
|
Reference in New Issue
Block a user