commit f5a8b82b914ca696bbe41453827929bc772f3332 Author: ccx <ccx@te2000.cz> Date: Sat, 16 Mar 2024 23:42:03 +0000 Import ZSH configuration as autoloaded functions Diffstat:
A | zsh-functions/alias_setup_gdb | | | 1 | + |
A | zsh-functions/alias_setup_ls | | | 1 | + |
A | zsh-functions/alias_setup_netstat | | | 1 | + |
A | zsh-functions/ccx_prompt_hash_color | | | 40 | ++++++++++++++++++++++++++++++++++++++++ |
A | zsh-functions/djbhash | | | 8 | ++++++++ |
A | zsh-functions/prompt_ccx_setup | | | 42 | ++++++++++++++++++++++++++++++++++++++++++ |
A | zsh-functions/site_zshenv_10_PS4 | | | 15 | +++++++++++++++ |
A | zsh-functions/site_zshrc_30_prompt | | | 4 | ++++ |
A | zsh-functions/site_zshrc_40_completion | | | 24 | ++++++++++++++++++++++++ |
A | zsh-functions/site_zshrc_50_history | | | 84 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | zsh-functions/site_zshrc_60_misc | | | 24 | ++++++++++++++++++++++++ |
A | zsh-functions/site_zshrc_70_keymap | | | 6 | ++++++ |
A | zsh-functions/site_zshrc_80_aliases | | | 9 | +++++++++ |
A | zsh-functions/site_zshrc_85_aliasinit | | | 21 | +++++++++++++++++++++ |
A | zsh-functions/string_hash_color | | | 14 | ++++++++++++++ |
A | zsh-functions/zsh-newuser-install | | | 0 |
16 files changed, 294 insertions(+), 0 deletions(-)
diff --git a/zsh-functions/alias_setup_gdb b/zsh-functions/alias_setup_gdb @@ -0,0 +1 @@ +alias gdbrun="gdb --ex run --args" diff --git a/zsh-functions/alias_setup_ls b/zsh-functions/alias_setup_ls @@ -0,0 +1 @@ +alias ll="ls -lh --full-time" diff --git a/zsh-functions/alias_setup_netstat b/zsh-functions/alias_setup_netstat @@ -0,0 +1 @@ +alias ns="netstat -ltup" diff --git a/zsh-functions/ccx_prompt_hash_color b/zsh-functions/ccx_prompt_hash_color @@ -0,0 +1,40 @@ +#!zsh +# vim: ft=zsh et sts=4 ts=4 sw=4 + +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] diff --git a/zsh-functions/djbhash b/zsh-functions/djbhash @@ -0,0 +1,8 @@ +#!zsh +# vim: ft=zsh et sts=4 ts=4 sw=4 +local h c +h=5381 +for c in ${(s::)1}; do + h=$(( ( (h << 5) + h + #c ) % 0xffffffff )) +done +printf ${2:-%d} $h diff --git a/zsh-functions/prompt_ccx_setup b/zsh-functions/prompt_ccx_setup @@ -0,0 +1,42 @@ +#!zsh +# vim: ft=zsh et sts=4 ts=4 sw=4 + +autoload -Uz ccx_prompt_hash_color +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$(ccx_prompt_hash_color $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" diff --git a/zsh-functions/site_zshenv_10_PS4 b/zsh-functions/site_zshenv_10_PS4 @@ -0,0 +1,15 @@ +# nice PS4 with ellapsed seconds (to two decimal places) +zmodload zsh/system # to get actual pid +zmodload zsh/terminfo # to get terminal color capability +setopt PROMPT_SUBST +if (($terminfo[colors] >= 8)); then + # first color is for main shell process, second is subshell + typeset -g -a PS4_PID_COLORS + 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 + +typeset -g -F 2 SECONDS # two digits after the decimal point +# vim: ft=zsh noet ts=4 sts=4 sw=4 diff --git a/zsh-functions/site_zshrc_30_prompt b/zsh-functions/site_zshrc_30_prompt @@ -0,0 +1,4 @@ +#!zsh +# vim: ft=zsh et sts=4 ts=4 sw=4 +autoload -Uz prompt_ccx_setup +prompt_ccx_setup diff --git a/zsh-functions/site_zshrc_40_completion b/zsh-functions/site_zshrc_40_completion @@ -0,0 +1,24 @@ +autoload -Uz compinit +compinit + +zstyle ':completion:*' use-cache on +zstyle ':completion:*' cache-path ~/.zsh/cache + +############################ +# dircolors for completion # +############################ + +if (($+commands[dircolors])); then + if [[ -e "${HOME}/.dircolors" ]]; then + eval $(dircolors -b "${HOME}/.dircolors") + elif [[ -e /etc/DIR_COLORS ]]; then + eval $(dircolors -b /etc/DIR_COLORS) + else + eval $(dircolors -b) + fi +fi + +[[ -n "$LS_COLORS" ]] && \ + zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} + +# vim: ft=zsh diff --git a/zsh-functions/site_zshrc_50_history b/zsh-functions/site_zshrc_50_history @@ -0,0 +1,84 @@ +#!zsh +# vim: ft=zsh et sts=4 ts=4 sw=4 +HISTFILE=${XDG_DATA_HOME:-$HOME/.local/share}/zsh/history +HISTSIZE=9999 +SAVEHIST=6000 + +if ! [[ -d ${HISTFILE:h} ]]; then + printf '%s\n' >&2 \ + "warning: cannot write to history file ${(qqq)HISTFILE}: directory does not exist" +fi + +# +++ history options +++ + +### when exiting, append history entries to $HISTFILE, rather +### than replacing the old file; this is the default +#setopt append_history + +### alias for append_history +#setopt hist_append + +### enable '!' history expansion +setopt bang_hist + +### alias for bang_hist +#setopt hist_expand + +### additional info in $HISTFILE +setopt no_extended_history + +### add '|' to output redirections in the history. +setopt no_hist_allow_clobber + +### beep? beep yourself!eleven!! +setopt no_hist_beep + +### don't add entered command to history, if it's a dup of the previous event. +setopt hist_ignore_dups + +### if the commandline starts with a whitespace, don't add it to history +setopt hist_ignore_space + +### dont add 'history' command (fc -l) to the history +setopt hist_no_store + +### remove unneeded blanks from commands in history +setopt no_hist_reduce_blanks + +### bullet-proof history-expansion +setopt no_hist_verify + +### don't add functions to history +setopt no_hist_no_functions + +### alias for no_hist_no_functions +#setopt log + +### if the internal history needs to be trimmed, throw away dups first +setopt no_hist_expire_dups_first + +### when using history don't find dups, even if they are not contiguous. +setopt hist_find_no_dups + +### if the entered command is a dup, remove the old one from history. +setopt hist_ignore_all_dups + +### don't write dups to $HISTFILE +setopt hist_save_no_dups + +### append every single command to $HISTFILE immediately after hitting +### ENTER. +setopt inc_append_history + +### always import new commands from $HISTFILE (see 'inc_append_history') +setopt no_share_history + +### when saving history: DATA => $HISTFILE.new; mv $HISTFILE.new $HISTFILE +### you normally don't unset this one. +setopt hist_save_by_copy + +### history substitutions (:s, :&) performed with patterns instead of +### strings +setopt no_hist_subst_pattern + +# vim: ft=zsh et sts=4 ts=4 sw=4 diff --git a/zsh-functions/site_zshrc_60_misc b/zsh-functions/site_zshrc_60_misc @@ -0,0 +1,24 @@ +#!zsh +# vim: ft=zsh et sts=4 ts=4 sw=4 + +DIRSTACKSIZE=30 + +### If the execution of a command takes longer than +### REPORTTIME (in seconds), time statistics are printed +REPORTTIME=4 + +NULLCMD="cat" + +if (($+commands[bat])); then + readnullcmd() { + local in=/proc/self/fd/0 + if [[ -f $in:A ]]; then + bat $in:A + else + bat + fi + } + READNULLCMD=readnullcmd +else + READNULLCMD=${PAGER:-more} +fi diff --git a/zsh-functions/site_zshrc_70_keymap b/zsh-functions/site_zshrc_70_keymap @@ -0,0 +1,6 @@ +#!zsh +# vim: ft=zsh et sts=4 ts=4 sw=4 + +# Force emacs-style keymap (for now) +# As default vim keymap isn't all that great +bindkey -e diff --git a/zsh-functions/site_zshrc_80_aliases b/zsh-functions/site_zshrc_80_aliases @@ -0,0 +1,9 @@ +mkcd() { + mkdir $* && cd ${argv[-1]} +} + +# function for enabling xtrace for single line +trace() { "$@" } +functions -t trace +alias trace='trace ' +compdef _precommand trace diff --git a/zsh-functions/site_zshrc_85_aliasinit b/zsh-functions/site_zshrc_85_aliasinit @@ -0,0 +1,21 @@ +emulate -L zsh +setopt extendedglob +local ppath='' name func +local -a match mbegin mend alias_functions +for func in $^fpath/alias_setup_*(N) +do + if [[ $func = */alias_setup_(#b)(*) ]] + then + name="$match[1]" + if [[ -r "$func" ]] && (($+commands[$name])) + then + alias_functions+=$func:t + autoload -Uz $func:t + fi + else + print "Eh? Mismatch between glob patterns in aliasinit." + fi +done +for func in ${(o)alias_functions}; do + $func +done diff --git a/zsh-functions/string_hash_color b/zsh-functions/string_hash_color @@ -0,0 +1,14 @@ +#!zsh +# vim: ft=zsh et sts=4 ts=4 sw=4 +local h +local -a color_list +autoload -Uz djbhash +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 +h=$(djbhash ${1:-$HOST}) +printf ${2:-%d} $color_list[$h%$#color_list+1] diff --git a/zsh-functions/zsh-newuser-install b/zsh-functions/zsh-newuser-install