core-system-scripts

Scripts submodule for the core-system repository
git clone https://ccx.te2000.cz/git/core-system-scripts
Log | Files | Refs

commit cb70a8ffa4bad8f3752eb4b90cafa43b6011181d
parent 1e67ced4151fb14f852d449e97f318ceb0040179
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Wed, 27 Jul 2022 12:30:23 +0200

Move skel directory to scripts repository and make link-skel command.

Diffstat:
Acommand/link-skel | 13+++++++++++++
Askel/.config/zsh/.zshenv | 25+++++++++++++++++++++++++
Askel/.config/zsh/.zshrc | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 131 insertions(+), 0 deletions(-)

diff --git a/command/link-skel b/command/link-skel @@ -0,0 +1,13 @@ +#!/bin/zsh +main() { + local f l + (umask 077 && mkdir -p $HOME/.{config,cache,local/{share/zsh,state}}) || exit $? + for f in conf/skel/**/*(.D); do + l=$HOME/${f#conf/skel/} + [[ -e $l ]] && continue + mkdir -p $l:h || exit $? + s6-ln -s /current/$f $l || exit $? + done +} +typeset -f -t main +main "$@" diff --git a/skel/.config/zsh/.zshenv b/skel/.config/zsh/.zshenv @@ -0,0 +1,25 @@ +# nice PS4 with elapsed seconds (to two decimal places) and subshell indication +if zmodload zsh/system; then # to get actual pid + setopt PROMPT_SUBST + if [[ $TERM == (xterm|rxvt|screen|linux|console|Eterm|putty)* ]]; then + # first color is for main shell process, second is subshell + PS4_PID_COLORS=(cyan magenta) + PS4='+%B${SECONDS} %F{${PS4_PID_COLORS[1+($$ != ${sysparams[pid]})]}}%N%f:%F{yellow}%i%f>%b ' + else + PS4='+%B${SECONDS} ${sysparams[pid]} %N:%i>%b ' + fi + + # two digits after the decimal point + typeset -g -F 2 SECONDS + # typeset -F 2 SECONDS # do it twice, some bug I don't understand +fi + +if [[ -o login ]]; then + # Set default XDG directories so apps (and /etc/zsh/*) will make use of them + : ${XDG_DATA_HOME:=$HOME/.local/share} + : ${XDG_CONFIG_HOME:=$HOME/.config} + : ${XDG_STATE_HOME:=$HOME/.local/state} + : ${XDG_CACHE_HOME:=$HOME/.cache} + export XDG_DATA_HOME XDG_CONFIG_HOME XDG_STATE_HOME XDG_CACHE_HOME +fi +# vim: ft=zsh noet ts=4 sts=4 sw=4 diff --git a/skel/.config/zsh/.zshrc b/skel/.config/zsh/.zshrc @@ -0,0 +1,93 @@ +setopt extended_history inc_append_history hist_find_no_dups hist_expire_dups_first +HISTFILE=${XDG_DATA_HOME:-$HOME/.local/share}/zsh/history +HISTSIZE=2000 +SAVEHIST=1000 + +alias ll='ls -lh --full-time' +alias ns='netstat -ltup' + +setopt warn_create_global +prompt_hash_color_zshrc() { + local h c + # djbhash, simple string hash function to generate distinct numbers for similar strings + h=5381 + for c in ${(s::)1}; do + h=$(( ( (h << 5) + h + #c ) % 0xffffffff )) + done + + local -a color_list + # List of colors bright enough to be readable against dark background + if (($+FG_COLOR_NUMBERS)); then + color_list=( $=FG_COLOR_NUMBERS ) + elif [[ $terminfo[colors] == 256 ]]; then + color_list=( + 23 24 25 26 27 28 29 + 30 31 32 33 34 35 36 37 38 39 + 40 41 42 43 44 45 46 47 48 49 + 50 51 + 61 62 63 64 65 66 67 68 69 + 70 71 72 73 74 75 76 77 78 79 + 80 81 82 83 84 85 86 87 + 94 95 96 97 98 99 + 100 101 102 103 104 105 106 107 108 109 + 110 111 112 113 114 115 116 117 118 119 + 120 121 122 123 126 127 128 129 + 130 131 132 133 134 135 136 137 138 139 + 140 141 142 143 144 145 146 147 148 149 + 150 151 152 153 154 155 156 157 158 159 + 160 161 162 163 164 165 166 167 168 169 + 170 171 172 173 174 175 176 177 178 179 + 180 181 182 183 184 185 186 187 188 189 + 190 191 192 193 194 195 196 197 198 199 + 200 201 + ) + else + color_list=( 1 2 3 5 6 7 9 10 11 13 14 15 ) + fi + printf '%%F{%d}' $color_list[$h%$#color_list+1] +} + +(){ # prompt + local prompt_char prompt_color_host prompt_color_jobs prompt_color_errno prompt_color_dir prompt_color_user prompt_base + + if [[ ${LC_ALL:-${LC_MESSAGES:-$LANG}} == *.UTF-8 ]]; then + if (($UID)); then + prompt_char='▷' + else + prompt_char='▶' + fi + else + if (($UID)); then + prompt_char='%%' + else + prompt_char='#' + fi + fi + + prompt_color_host="%b%F{green}" + prompt_color_jobs="%b%F{cyan}" + prompt_color_errno="%B%F{yellow}" + prompt_color_dir="%B%F{yellow}" + + if [[ $terminfo[colors] == 256 ]]; then + autoload string_hash_color + prompt_color_host="%b$(prompt_hash_color_zshrc $HOST)" + prompt_color_errno="%b%F{214}" + prompt_color_dir="%b%F{214}" + fi + + prompt_color_user=$prompt_color_host + + if [[ $UID -eq 0 ]]; then + prompt_color_dir="%B%F{red}" + fi + + prompt_base="${prompt_color_user}%n${prompt_color_host}@%m%k ${prompt_color_dir}%1~" + PS1="%(?..${prompt_color_errno}<%?>)%(1j.${prompt_color_jobs}{%j}.)$prompt_base ${prompt_char}%b%f%k " + PS2="$prompt_base %_> %b%f%k" + PS3="$prompt_base ?# %b%f%k" +} +unset -f prompt_hash_color_zshrc + +autoload -Uz compinit +compinit