Index: zshrc ================================================================== --- zshrc +++ zshrc @@ -3,11 +3,11 @@ export XDG_DATA_HOME="$HOME/.local/share" export EDITOR="vim" export VIMINIT="source $XDG_CONFIG_HOME/vim/vimrc" export PAGER="less" export LS_COLORS='di=34:ow=44;37:tw=44;37:st=44;37:ex=31:su=7;31:sg=7;31:ln=33:or=7;33:pi=32:do=32:bd=35:cd=35:so=32:*.bz2=36:*.dmg=36:*.gz=36:*.gpg=36:*.rar=36:*.tar=36:*.tbz2=36:*.tgz=36:*.xz=36:*.zip=36:*.orig=90:*~=90' -export SUDO_PROMPT=$(printf "\033[0;31m[\033[1;31msudo -> %%U\033[0;31m]\033[0m Password for \033[1m%%p@%%H\033[0m: ") +export SUDO_PROMPT="$(printf "\033[0;31m[\033[1;31msudo -> %%U\033[0;31m]\033[0m Password for \033[1m%%p@%%H\033[0m: ")" export GNUPGHOME="$XDG_DATA_HOME/gnupg" export CVS_RSH="ssh" LISTMAX=32768 WORDCHARS="*?[];!#~" local grep="" @@ -16,32 +16,38 @@ local ls_color="auto" local ls_on_cd="yes" local ls_on_init="no" local normal_user="js" -if [ "$COLORTERM" = "24bit" -o "$COLORTERM" = "truecolor" \ +autoload -U is-at-least + +if is-at-least 5.0.0 && [ "$COLORTERM" = "24bit" -o "$COLORTERM" = "truecolor" \ -o "$terminfo[colors]" = 16777216 ]; then local color_cwd="#209060" local color_host="#176945" local color_suffix="#29bc7d" local color_vcs="#43d696" local color_vcs_braces="#29bc7d" -elif [ "$terminfo[colors]" = 256 ]; then + local color_jobs="yellow" + local color_status="red" +elif is-at-least 5.0.0 && [ "$terminfo[colors]" = 256 ]; then local color_cwd="29" local color_host="23" local color_suffix="36" local color_vcs="78" local color_vcs_braces="36" + local color_jobs="yellow" + local color_status="red" else local color_cwd=2 local color_host=6 local color_suffix=2 local color_vcs=2 local color_vcs_braces=2 + local color_jobs=3 + local color_status=1 fi -local color_jobs="yellow" -local color_status="red" bindkey -v # history-incremental-search-backward is much more useful than # _history-complete-* bindkey "^R" history-incremental-search-backward @@ -114,25 +120,35 @@ __update_terminal_cwd() {} ;; esac set_prompt() { + if is-at-least 5.0.0; then + color() { printf "%%F{$1}" } + nocolor() { printf "%%f" } + else + color() { printf "%%{\033[3${1}m%%}" } + nocolor() { printf "%%{\033[0m%%}" } + fi + if [ -n "$1" ]; then - local branch="%F{$color_vcs_braces}(%F{$color_vcs}$1" - branch+="%F{$color_vcs_braces})" + local branch="$(color $color_vcs_braces)($(color $color_vcs)$1" + branch+="$(color $color_vcs_braces))" fi if [ "$(whoami)" != "$normal_user" ]; then local user="%n@" fi - PS1="%F{$color_host}$user%m %F{$color_cwd}%c$branch" - PS1+="%F{$color_suffix}%(!.#.>)%f " + PS1="$(color $color_host)$user%m $(color $color_cwd)%c$branch" + PS1+="$(color $color_suffix)%(!.#.>)$(nocolor) " PS2="%B>%b " - RPS1="%(1j.%F{$color_jobs}%B%j%b%f.)%(?..%(1j. .)" - RPS1+="%F{$color_status}%B%?%b%f)" - RPS2="%(1_.%F{black}%B(%_%)%b%f.)" + RPS1="%(1j.$(color $color_jobs)%B%j%b$(nocolor).)%(?..%(1j. .)" + RPS1+="$(color $color_status)%B%?%b$(nocolor))" + RPS2="%(1_.$(color black)%B(%_%)%b$(nocolor).)" + + unfunction color nocolor } set_prompt __precmd() { __update_terminal_cwd @@ -156,11 +172,11 @@ print -Pn "\e]0;$@\a" } unset_title() { precmd() { - print -Pn "\e]0;%c ยท %m\a" + print -Pn "\e]0;%m:%c\a" __precmd } } unset_title ;; @@ -220,11 +236,13 @@ __has_command vim && alias vi=vim __has_command gpg2 && alias gpg=gpg2 if [ "$(uname -s)" = "Darwin" ]; then - export MAKEFLAGS="-j$(($(sysctl -n machdep.cpu.thread_count) * 2))" + local thread_count="$(sysctl -n machdep.cpu.thread_count 2>/dev/null)" + test -z "$thread_count" && thread_count=1 + export MAKEFLAGS="-j$((thread_count * 2))" elif [ "$(uname -s)" = "NetBSD" ]; then export MAKEFLAGS="-j$(($(/sbin/sysctl -n hw.ncpu) * 2))" elif __has_command nproc; then export MAKEFLAGS="-j$(($(nproc) * 2))" fi