diff --git a/zsh/plugins.zsh b/zsh/plugins.zsh index 1523b78..1b83534 100644 --- a/zsh/plugins.zsh +++ b/zsh/plugins.zsh @@ -47,43 +47,6 @@ plugin completions 'zsh-users/zsh-completions' # }}} -# spaceship prompt {{{ - - SPACESHIP_PROMPT_ADD_NEWLINE=false - - SPACESHIP_PROMPT_ORDER=( - user - host - dir - git - # hg - exec_time - # vi_mode - jobs - exit_code - line_sep - char - ) - - SPACESHIP_CHAR_SYMBOL="$ " - SPACESHIP_CHAR_SYMBOL_ROOT="# " - SPACESHIP_CHAR_SYMBOL_SECONDARY="> " - SPACESHIP_GIT_STATUS_DELETED="\u2718 " - SPACESHIP_HG_STATUS_DELETED="\u2718 " - SPACESHIP_EXIT_CODE_SYMBOL="\u2718 " - SPACESHIP_JOBS_SYMBOL="\u2726 " - - SPACESHIP_USER_SHOW=always - - SPACESHIP_DIR_TRUNC=0 - SPACESHIP_DIR_TRUNC_REPO=false - - SPACESHIP_EXIT_CODE_SHOW=true - - plugin spaceship-prompt 'denysdovhan/spaceship-prompt' - -# }}} - plugin fzf 'junegunn/fzf' build='./install --bin' \ after_load='plugin-cfg-path path prepend bin' \ after_load='plugin-cfg-path manpath prepend man' @@ -95,7 +58,5 @@ plugin ssh 'zpm-zsh/ssh' plugin base16-shell 'chriskempson/base16-shell' \ after_load='export BASE16_SHELL="$plugin_dir"' -autoload -Uz compinit && compinit -C - FAST_WORK_DIR="$ZSH_CACHE_DIR" plugin fast-syntax-highlighting 'zdharma/fast-syntax-highlighting' diff --git a/zsh/theme.zsh b/zsh/theme.zsh index 63996b6..0b519e1 100644 --- a/zsh/theme.zsh +++ b/zsh/theme.zsh @@ -7,4 +7,59 @@ configure_dircolors() { zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}" } +prompt_preexec_hook() { + typeset -g -i _PROMPT_EXEC_START_TIME + _PROMPT_EXEC_START_TIME="$(date +%s.%N)" +} + +prompt_precmd_hook() { + if [[ -v _PROMPT_EXEC_START_TIME ]]; then + local -F stop_time duration + stop_time="$(date +%s.%N)" + duration="$((stop_time - _PROMPT_EXEC_START_TIME))" + unset _PROMPT_EXEC_START_TIME + + if (( duration > 1 )); then + local -i t="$duration" d h m s + typeset -g _PROMPT_EXEC_TIME="" + d="$((t/60/60/24))" + h="$((t/60/60%24))" + m="$((t/60%60))" + s="$((t%60))" + (( d > 0 )) && _PROMPT_EXEC_TIME+="${d}d" + (( h > 0 )) && _PROMPT_EXEC_TIME+="${h}h" + (( m > 0 )) && _PROMPT_EXEC_TIME+="${m}m" + _PROMPT_EXEC_TIME+="${s}s" + else + unset _PROMPT_EXEC_TIME + fi + fi +} + +setup_prompt() { + setopt nopromptbang promptcr promptsp promptpercent promptsubst + + if [[ "$(date +%N)" != "N" ]]; then + preexec_functions+=(prompt_preexec_hook) + precmd_functions+=(prompt_precmd_hook) + else + echo "Please, install GNU coreutils to get command execution time in the prompt" + fi + + PROMPT='%F{8}┌─%f%B' + PROMPT+='%F{%(!.red.yellow)}%n%f' + PROMPT+=' at %F{${SSH_CONNECTION:+blue}${SSH_CONNECTION:-green}}%m%f' + PROMPT+=' in %F{cyan}%~%f' + PROMPT+=' ' + PROMPT+='${_PROMPT_EXEC_TIME:+" %F{yellow}$_PROMPT_EXEC_TIME%f"}' + PROMPT+='%(?.. %F{red}EXIT:%?%f)' + PROMPT+='%1(j. %F{blue}JOBS:%j%f.)' + PROMPT+=$'\n' + PROMPT+='%b%F{8}└─%f' + PROMPT+='%F{%(?.green.red)}%(!.#.\$)%f ' + + PROMPT2=' %_> ' +} + configure_dircolors +setup_prompt