all repos — nixfiles @ e31d0dbcfe860fc71e1f8917ed67c893297ae930

System and user configuration, managed by nix and home-manager

Update pure prompt

Alan Pearce
commit

e31d0dbcfe860fc71e1f8917ed67c893297ae930

parent

5a5b0c4a566792c0bd8f793c4a49a1f1467b1d96

1 file changed, 22 insertions(+), 3 deletions(-)

jump to
M zsh/functions/pure/prompt_pure_setupzsh/functions/pure/prompt_pure_setup
@@ -16,6 +16,21 @@ # %n => username
# %m => shortname host # %(?..) => prompt conditional - %(condition.true.false) + +# turns seconds into human readable time +# 165392 => 1d 21h 56m 32s +prompt_pure_human_time() { + local tmp=$1 + local days=$(( tmp / 60 / 60 / 24 )) + local hours=$(( tmp / 60 / 60 % 24 )) + local minutes=$(( tmp / 60 % 60 )) + local seconds=$(( tmp % 60 )) + (( $days > 0 )) && echo -n "${days}d " + (( $hours > 0 )) && echo -n "${hours}h " + (( $minutes > 0 )) && echo -n "${minutes}m " + echo "${seconds}s" +} + # fastest possible way to check if repo is dirty prompt_pure_git_dirty() { # check if we're in a git repo
@@ -31,7 +46,7 @@ prompt_pure_cmd_exec_time() {
local stop=$(date +%s) local start=${cmd_timestamp:-$stop} integer elapsed=$stop-$start - (($elapsed > ${PURE_CMD_MAX_EXEC_TIME:=5})) && echo ${elapsed}s + (($elapsed > ${PURE_CMD_MAX_EXEC_TIME:=5})) && prompt_pure_human_time $elapsed } prompt_pure_preexec() {
@@ -59,7 +74,7 @@ local prompt_pure_preprompt='\n%F{blue}%~%F{242}$vcs_info_msg_0_`prompt_pure_git_dirty` $prompt_pure_username%f %F{yellow}`prompt_pure_cmd_exec_time`%f'
print -P $prompt_pure_preprompt # check async if there is anything to pull - { + (( ${PURE_GIT_PULL:-1} )) && { # check if we're in a git repo command git rev-parse --is-inside-work-tree &>/dev/null && # check check if there is anything to pull
@@ -77,6 +92,10 @@ }
prompt_pure_setup() { + # prevent percentage showing up + # if output doesn't end with a newline + export PROMPT_EOL_MARK='' + prompt_opts=(cr subst percent) autoload -Uz add-zsh-hook
@@ -93,7 +112,7 @@ # show username@host if logged in through SSH
[[ "$SSH_CONNECTION" != '' ]] && prompt_pure_username='%n@%m ' # prompt turns red if the previous command didn't exit with 0 - PROMPT='%(?.%F{cyan}.%F{red})❯%f ' + PROMPT='%(?.%F{magenta}.%F{red})❯%f ' } prompt_pure_setup "$@"