X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=zsh%2Frc;h=5889186973ea19dde4a1a92375611f976c478526;hb=2253f9ef9bead0494d3fea83581007c7acd5a357;hp=a789428010b66f61180807fcf272c102f8a67df4;hpb=01837f58b576a29c8ac23058b97d0a71821258a6;p=config%2Fdotfiles.git diff --git a/zsh/rc b/zsh/rc index a789428..5889186 100644 --- a/zsh/rc +++ b/zsh/rc @@ -45,8 +45,10 @@ resolve_fg_to_resumed_job_name() { # MISCELLANEOUS SETTINGS -# Be paranoid, new files are readable/writable by me only. -umask 077 +# Be paranoid, new files are readable/writable by me only, but not as root. +if [[ $UID -ne 0 ]]; then + umask 077 +fi # Disable beeps. setopt nobeep @@ -360,33 +362,60 @@ prompt_precmd() { vcs_info_msg_0_= fi - local width width_left width_right - local top_left top_right - - # Display the current time in HEX in bright blue and vcs_info (if used) on - # the right in the top prompt. - top_right="$vcs_info_msg_0_($blue%B0x$(([##16] EPOCHSECONDS))%b$default)" - width_right=${#${(S%%)top_right//$~zero/}} - # Remove it if it would get too long. - if [[ $(( COLUMNS - 4 - 1 - width_right )) -lt 0 ]]; then - top_right= - width_right=0 + # Setup. Create variables holding the formatted content. + + # Current directory in yellow, truncated if necessary (WIDTH is replaced + # below). + local directory="${yellow}%WIDTH<..<%~%<<${default}" + + # Information about the VCS in this directory. + local vcs="${vcs_info_msg_0_}" + # Current time (seconds since epoch) in Hex in bright blue. + local seconds="${blue}%B0x$(([##16] EPOCHSECONDS))%b${default}" + + # User name (%n) in bright green. + local user="${green}%B%n%b${default}" + # Host name (%m) in bright green; underlined if running on a remote system + # through SSH. + local host="${green}%B%m%b${default}" + if [[ -n $SSH_CONNECTION ]]; then + host="%U${host}%u" fi - # Display current directory on the left in the top prompt. Truncate the - # directory if necessary. - width=$(( COLUMNS - 4 - 1 - width_right )) - top_left=".-$default%b($yellow%$width<..<%~%<<$default)%B$blue" + # Number of background processes in yellow. + local background="%(1j.${yellow}%j${default}.)" + # Exit code in bright red if not zero. + local exitcode="%(?..(${red}%B%?%b${default}%) )" + + # Prefix characters in first and second line. + local top_prefix="${blue}%B.-%b${default}" + local bottom_prefix="${blue}%B'%b${default}" + + # Combine them to create the prompt. + + local top_right="${vcs}(${seconds})" + + local width_top_prefix=${#${(S%%)top_prefix//$~zero/}} + local width_top_right=${#${(S%%)top_right//$~zero/}} + + # Calculate the maximum width of ${top_left}. -2 are the braces of + # ${top_left}, -1 is one separator from ${top_separator} (we want at least + # one between left and right parts). + local top_left_width_max=$(( + COLUMNS - $width_top_prefix - 2 - 1 - $width_top_right + )) + # Truncate directory if necessary. + local top_left="(${directory/WIDTH/${top_left_width_max}})" + local width_top_left=${#${(S%%)top_left//$~zero/}} # Calculate the width of the top prompt to fill the middle with "-". - width_left=${#${(S%%)top_left//$~zero/}} - width_right=${#${(S%%)top_right//$~zero/}} - width=$(( COLUMNS - width_left - width_right )) - - PROMPT="$blue%B$top_left${(l:$width::-:)}%b$default$top_right -$blue%B'%b$default\ -$green%B%n%b$default@$green%B%m%b$default %(1j.$yellow%j$default.)%# \ -%(?..($red%B%?%b$default%) )" + local width=$(( + COLUMNS - width_top_prefix - width_top_left - width_top_right + )) + local top_separator="%B${blue}${(l:${width}::-:)}%b${default}" + + PROMPT="${top_prefix}${top_left}${top_separator}${top_right} +${bottom_prefix}${user}@${host} ${background}%# ${exitcode}" } precmd_functions+=(prompt_precmd)