diff --git a/.cache/zsh/.keep b/.cache/zsh/.keep new file mode 100644 index 0000000..e69de29 diff --git a/.cache/zsh/compcache/.keep b/.cache/zsh/compcache/.keep new file mode 100644 index 0000000..e69de29 diff --git a/.config/dotfiles/bin/.keep b/.config/dotfiles/bin/.keep new file mode 100644 index 0000000..e69de29 diff --git a/.config/dotfiles/gen-gitignore.sh b/.config/dotfiles/gen-gitignore.sh new file mode 100755 index 0000000..e39aa43 --- /dev/null +++ b/.config/dotfiles/gen-gitignore.sh @@ -0,0 +1,37 @@ +#!/bin/sh +set -f -e +set -o noglob errexit + +GIT_OPTIONAL_LOCKS=0 +export GIT_OPTIONAL_LOCKS + +path_gitignore='.config/dotfiles/gitignore' + +gen_gitignore() { + git rev-parse --git-dir >/dev/null 2>/dev/null + { + echo '*' + git ls-files | sed -E 's:^:!/:' + } > "$1" + exit 0 +} + +me=$(readlink -e "$0") +topdir=$(printf '%s' "${me}" | sed -E 's:/[^/]+/[^/]+/[^/]+$::') +cd "${topdir}" + +## end-point installation +dir=$(dirname "${me}")'/repo.git' +if [ -s "${dir}/packed-refs" ] ; then + GIT_DIR="${dir}" + GIT_WORK_TREE="${topdir}" + export GIT_DIR GIT_WORK_TREE + gen_gitignore "${GIT_WORK_TREE}/${path_gitignore}" || true +fi + +## development tree +if [ -s '.git/packed-refs' ] ; then + gen_gitignore "${path_gitignore}" || true +fi + +exit 1 diff --git a/.config/dotfiles/gitignore b/.config/dotfiles/gitignore new file mode 100644 index 0000000..01831a2 --- /dev/null +++ b/.config/dotfiles/gitignore @@ -0,0 +1,60 @@ +* +!/.cache/zsh/.keep +!/.cache/zsh/compcache/.keep +!/.config/dotfiles/bin/.keep +!/.config/dotfiles/gen-gitignore.sh +!/.config/dotfiles/gitignore +!/.config/dotfiles/install.sh +!/.config/zsh/alias.zsh +!/.config/zsh/alias/diff.zsh +!/.config/zsh/alias/directories.zsh +!/.config/zsh/alias/grep.zsh +!/.config/zsh/alias/history.zsh +!/.config/zsh/alias/idle.zsh +!/.config/zsh/alias/ls.zsh +!/.config/zsh/alias/sudo.zsh +!/.config/zsh/alias/telnet.zsh +!/.config/zsh/completion/.keep +!/.config/zsh/completion/buildah.zsh +!/.config/zsh/completion/podman.zsh +!/.config/zsh/env.zsh +!/.config/zsh/env/aux.zsh +!/.config/zsh/env/history.zsh +!/.config/zsh/env/ld.so.zsh +!/.config/zsh/env/pager.zsh +!/.config/zsh/env/quilt.zsh +!/.config/zsh/env/xdg.zsh +!/.config/zsh/lib.zsh +!/.config/zsh/lib/alternatives.zsh +!/.config/zsh/lib/cmdtime.zsh +!/.config/zsh/lib/completion.zsh +!/.config/zsh/lib/curl.zsh +!/.config/zsh/lib/enclave.zsh.wip +!/.config/zsh/lib/git.zsh +!/.config/zsh/lib/history.zsh +!/.config/zsh/lib/prompt.zsh +!/.config/zsh/lib/pswalk.zsh +!/.config/zsh/lib/selfservice.zsh +!/.config/zsh/lib/starship.zsh.sample +!/.config/zsh/lib/time.zsh +!/.config/zsh/local/.keep +!/.config/zsh/local/completion/.keep +!/.config/zsh/opt.zsh +!/.config/zsh/opt/chase.zsh +!/.config/zsh/opt/completion.zsh +!/.config/zsh/opt/directories.zsh +!/.config/zsh/opt/history.zsh +!/.config/zsh/opt/prompt.zsh +!/.config/zsh/rc.zsh +!/.config/zsh/rc/completion.zsh +!/.config/zsh/rc/keyboard.zsh +!/.config/zsh/rc/pager.zsh +!/.config/zsh/rc/prompt.zsh +!/.config/zsh/var/.keep +!/.gdbinit +!/.gitconfig +!/.screenrc +!/.selected_editor +!/.vimrc +!/.zshenv +!/.zshrc diff --git a/.config/dotfiles/install.sh b/.config/dotfiles/install.sh new file mode 100755 index 0000000..7383241 --- /dev/null +++ b/.config/dotfiles/install.sh @@ -0,0 +1,145 @@ +#!/bin/sh +set -f -e +set -o noglob errexit + +gh_repo='rockdrilla/dotfiles' +gh_br='main' + +f_gitignore='.config/dotfiles/gitignore' +u_gitignore="https://raw.githubusercontent.com/${gh_repo}/${gh_br}/${f_gitignore}" + +u_repo="https://github.com/${gh_repo}.git" +d_repo='.config/dotfiles/repo.git' + +u_tarball="https://github.com/${gh_repo}/archive/refs/heads/${gh_br}.tar.gz" + +main() { + ## dry run to test connectivity + curl -sSL "${u_gitignore}" >/dev/null + + umask 0077 + + if git_avail ; then + if [ -s "${HOME}/${d_repo}/packed-refs" ] ; then + dot_update + else + dot_install + fi + else + echo 'git is missing, proceed "raw" installation.' + dot_install_raw + fi + + echo 'installed.' +} + +git_avail() { + command git --version >/dev/null 2>/dev/null +} + +dot_install() { + git_env + mkdir -p "${GIT_DIR}" + git init -b ${gh_br} + git_config + git_update +} + +dot_update() { + git_env + git_config + git_update +} + +dot_install_raw() { + tf_tar=$(mktemp) + curl -sSL "${u_tarball}" > "${tf_tar}" + + td_tree=$(mktemp -d) + + if ! tar_try_extract "${tf_tar}" "${td_tree}" "${f_gitignore}" ; then + rm -rf "${tf_tar}" "${td_tree}" + exit 1 + fi + rm -f "${tf_tar}" + + tf_list=$(mktemp) + curl -sSL "${u_gitignore}" | \ + sed -En '/^!\/(.+)$/{s//\1/;p;}' > "${tf_list}" + + td_backup=$(mktemp -d) + while read f ; do + if [ -f "${HOME}/$f" ] ; then + if cmp_files "${td_tree}" "${HOME}" "$f" ; then + continue + fi + d=$(dirname "$f") + if [ -n "$d" ] ; then + mkdir -p "${td_backup}/$d" + fi + cat < "${HOME}/$f" > "${td_backup}/$f" + fi + done < "${tf_list}" + rm -f "${tf_list}" + + tar -C "${td_tree}" -cf . - | tar -C "${HOME}" -xf - + rm -rf "${td_tree}" + + n_bak=$(find "${td_backup}/" -mindepth 1 | wc -l) + if [ "${n_bak}" != 0 ] ; then + echo "backed-up files are here: ${td_backup}/" + ls -lghAG "${td_backup}/" + else + rmdir "${td_backup}" + fi +} + +git_env() { + GIT_DIR="${HOME}/${d_repo}" + GIT_WORK_TREE="${HOME}" + export GIT_DIR GIT_WORK_TREE +} + +git_config() { + ## remote + git remote add origin "${u_repo}" || \ + git remote set-url origin "${u_repo}" + git config remote.origin.fetch "+refs/heads/${gh_br}:refs/remotes/origin/${gh_br}" + git config remote.origin.tagopt '--no-tags' + git config "branch.${gh_br}.remote" origin + ## repo-specific + git config core.worktree "${GIT_WORK_TREE}" + git config core.excludesfile "${f_gitignore}" + ## generic + git config gc.auto 0 + git config pull.ff only + git config receive.denyNonFastForwards true +} + +git_update() { + git remote update -p + git pull +} + +tar_test() { + tar --wildcards -tf "$@" >/dev/null 2>/dev/null +} + +tar_try_extract() { + if tar_test "$1" "$3" ; then + tar -C "$2" -xf "$2" + return + fi + opt='--strip-components=1' + if tar_test "$1" ${opt} "*/$3" ; then + tar -C "$2" ${opt} -xf "$2" + return + fi + return 1 +} + +cmp_files() { + cmp -s "$1/$3" "$2/$3" >/dev/null 2>/dev/null +} + +main "$@" diff --git a/.config/zsh/alias.zsh b/.config/zsh/alias.zsh new file mode 100644 index 0000000..f2703ff --- /dev/null +++ b/.config/zsh/alias.zsh @@ -0,0 +1,5 @@ +#!/bin/zsh + +# alias which-command='whence -p ' +# alias which='whence -p ' +# alias zsh-which='whence -c ' diff --git a/.config/zsh/alias/diff.zsh b/.config/zsh/alias/diff.zsh new file mode 100644 index 0000000..9927f77 --- /dev/null +++ b/.config/zsh/alias/diff.zsh @@ -0,0 +1,3 @@ +#!/bin/zsh + +z-alt-set-static 'diff|. .' 'diff --color=auto|diff' diff --git a/.config/zsh/alias/directories.zsh b/.config/zsh/alias/directories.zsh new file mode 100644 index 0000000..3b62100 --- /dev/null +++ b/.config/zsh/alias/directories.zsh @@ -0,0 +1,16 @@ +#!/bin/zsh + +## alias -g ...='../..' +## alias -g ....='../../..' +## ... +for (( i=3 ; i < 10 ; i++ )) ; do + alias -g ${(l:i::.:)}='..'${(l:3*(i-2)::/..:)} +done ; unset i + +alias -- -='cd -' +alias 1='cd -' +## alias 2='cd -2' +## ... +for (( i=2 ; i < 10 ; i++ )) ; do + alias $i="cd -$i" +done ; unset i diff --git a/.config/zsh/alias/grep.zsh b/.config/zsh/alias/grep.zsh new file mode 100644 index 0000000..9fc9b11 --- /dev/null +++ b/.config/zsh/alias/grep.zsh @@ -0,0 +1,24 @@ +#!/bin/zsh + +z-alt-grep() { + local -a a + a=( ${(@s:|:)1} ) + [ ${#a} = 0 ] && a=( "$1" ) + local n=${#a} + [ -z "$1" ] && n=0 + case "$n" in + 0) : do nothing ;; + *) z-alt-set-static "grep|-q -e ' ' ${ZSHU[d_zdot]}/.zshenv" "$1" "GREP_OPTIONS='' " ;; + esac +} + +## TODO: add --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox} +GREP_GNU='--color=auto' + +z-alt-grep "grep ${GREP_GNU}|grep" + +unfunction z-alt-grep +unset GREP_GNU + +egrep() { grep -E "$@" ; } +fgrep() { grep -F "$@" ; } diff --git a/.config/zsh/alias/history.zsh b/.config/zsh/alias/history.zsh new file mode 100644 index 0000000..ebfe502 --- /dev/null +++ b/.config/zsh/alias/history.zsh @@ -0,0 +1,6 @@ +#!/bin/zsh + +fc() { builtin fc -i "$@" ; } + +# alias history='z-history ' +history() { builtin fc -il "$@" ; } diff --git a/.config/zsh/alias/idle.zsh b/.config/zsh/alias/idle.zsh new file mode 100644 index 0000000..1ef0f82 --- /dev/null +++ b/.config/zsh/alias/idle.zsh @@ -0,0 +1,9 @@ +#!/bin/zsh + +function { + local -a s + s+=( $(z-alt-find 'nice -n +40') ) + s+=( $(z-alt-find 'chrt -i 0' ) ) + s+=( $(z-alt-find 'ionice -c 3') ) + z-alt-set-static idle "$s|env" +} diff --git a/.config/zsh/alias/ls.zsh b/.config/zsh/alias/ls.zsh new file mode 100644 index 0000000..46d3b95 --- /dev/null +++ b/.config/zsh/alias/ls.zsh @@ -0,0 +1,53 @@ +#!/bin/zsh + +if [ -z "${LS_COLORS}" ] ; then + (( $+commands[dircolors] )) && eval "$(dircolors -b)" +fi + +case "${ZSHU[os_family]}" in +bsd|darwin) export LSCOLORS="Gxfxcxdxbxegedabagacad" ;; +esac + +__z_alt_ls() { + local -a a + a=( ${(@s:|:)1} ) + [ ${#a} = 0 ] && a=( "$1" ) + local n=${#a} + [ -z "$1" ] && n=0 + case "$n" in + 0) : do nothing ;; + *) z-alt-set-static 'ls|-d .' "$1" "LS_OPTIONS='' " ;; + # 1) z-alt-set-static 'ls|-d .' "$1" "LS_OPTIONS='' " ;; + # *) z-alt-set-dynamic 'ls|-d .' "$1" "LS_OPTIONS='' " ;; + esac +} + +LS_GNU='--color=tty --group-directories-first' + +case "${ZSHU[os_type]}" in +linux*) alt="ls ${LS_GNU}|ls" ;; +netbsd*) alt="gls ${LS_GNU}|ls" ;; +openbsd*) alt="gls ${LS_GNU}|colorls -G|ls" ;; +freebsd*) alt="gls ${LS_GNU}|ls -G|ls" ;; +darwin*) alt="gls ${LS_GNU}|ls -G|ls" ;; +*) alt="ls ${LS_GNU}|ls" ;; +esac + +__z_alt_ls "${alt}" + +unfunction __z_alt_ls +unset alt LS_GNU + +[ -n "${LS_COLORS}" ] && zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" + +case "${ZSHU[os_family]}" in +linux) alias l='ls -lhF ' ;; +bsd) alias l='ls -lhIF ' ;; +esac + +alias ll='ls -lAF ' + +case "${ZSHU[os_family]}" in +linux) alias lll='ls -lAn --full-time ' ;; +bsd) alias lll='ls -lAnT ' ;; +esac diff --git a/.config/zsh/alias/sudo.zsh b/.config/zsh/alias/sudo.zsh new file mode 100644 index 0000000..063f8e5 --- /dev/null +++ b/.config/zsh/alias/sudo.zsh @@ -0,0 +1,4 @@ +#!/bin/zsh + +alias sudo-i='sudo -i' +alias sudoi='sudo -i' diff --git a/.config/zsh/alias/telnet.zsh b/.config/zsh/alias/telnet.zsh new file mode 100644 index 0000000..a25fe59 --- /dev/null +++ b/.config/zsh/alias/telnet.zsh @@ -0,0 +1,6 @@ +#!/bin/zsh + +case "${ZSHU[os_type]}" in +linux-gnu) alias tl='telnet -K ' ;; +*bsd*) alias tl='telnet -K -N -y ' ;; +esac diff --git a/.config/zsh/completion/.keep b/.config/zsh/completion/.keep new file mode 100644 index 0000000..e69de29 diff --git a/.config/zsh/completion/buildah.zsh b/.config/zsh/completion/buildah.zsh new file mode 100644 index 0000000..01715a1 --- /dev/null +++ b/.config/zsh/completion/buildah.zsh @@ -0,0 +1,3 @@ +#!/bin/zsh + +__z_comp_bash buildah diff --git a/.config/zsh/completion/podman.zsh b/.config/zsh/completion/podman.zsh new file mode 100644 index 0000000..7a9f698 --- /dev/null +++ b/.config/zsh/completion/podman.zsh @@ -0,0 +1,3 @@ +#!/bin/zsh + +__z_comp_test podman && podman completion zsh | __z_comp_write podman diff --git a/.config/zsh/env.zsh b/.config/zsh/env.zsh new file mode 100644 index 0000000..682d1bb --- /dev/null +++ b/.config/zsh/env.zsh @@ -0,0 +1,86 @@ +#!/bin/zsh + +## sort-n-fill PATH +function { + local -a p=( $path ) + local -aU t npath games + + ## strip "games" first :) + t=( ${(@)p:#*games*} ) + games+=( ${(@)p:|t} ) + p=( $t ) + + ## process in-home part + t=( ${(@)p:#${HOME}/*} ) + npath+=( "${ZSHU[d_bin]}" "${HOME}/bin" ) + npath+=( ${(@)p:|t} ) + p=( $t ) + + ## process /usr/local/* + t=( ${(@)p:#/usr/local/*} ) + npath+=( /usr/local/sbin /usr/local/bin ) + npath+=( ${(@)p:|t} ) + p=( $t ) + + ## process /usr/* + t=( ${(@)p:#/usr/*} ) + npath+=( /usr/sbin /usr/bin ) + npath+=( ${(@)p:|t} ) + p=( $t ) + + ## now we're with /sbin and /bin... probably :) + npath+=( /sbin /bin ) + npath+=( $p ) + + ## finally... games! xD + npath+=( /usr/local/games /usr/games ) + npath+=( $games ) + + path=( $npath ) + hash -f +} + +unset GREP_OPTIONS +unset LS_OPTIONS + +unset LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES +unset LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION +export LANG=C.UTF8 +export LC_ALL=C.UTF-8 + +z-set-tmpdir() { + TMPDIR="$1" + TMP="$1" + TEMPDIR="$1" + TEMP="$1" + export TMPDIR TMP TEMPDIR TEMP +} +z-set-tmpdir "${TMPDIR:=/tmp}" + +ZSHU[uname]=$(uname -s 2>/dev/null) +ZSHU[uname]=${ZSHU[uname]:l} + +ZSHU[mach]=$(uname -m 2>/dev/null) +ZSHU[mach]=${ZSHU[mach]:l} +case "${ZSHU[mach]}" in +amd64) ZSHU[mach]=x86_64 ;; +arm64) ZSHU[mach]=aarch64 ;; +armv*) ZSHU[mach]=arm ;; +esac + +ZSHU[os_type]=${OSTYPE:l} + +ZSHU[os_family]=${ZSHU[uname]:l} +case "${ZSHU[os_family]}" in +*bsd) ZSHU[os_family]=bsd ;; +esac + +ZSHU[host_name]=${(%):-%m} +ZSHU[host_fqdn]=${(%):-%M} +ZSHU[host]=${ZSHU[host_name]} +function { + [ "${ZSHU[uname]}" = darwin ] || return + ZSHU[host]=$(scutil --get ComputerName 2>/dev/null) && return + ## last resort + ZSHU[host]=${ZSHU[host_name]} +} diff --git a/.config/zsh/env/aux.zsh b/.config/zsh/env/aux.zsh new file mode 100644 index 0000000..940c0cd --- /dev/null +++ b/.config/zsh/env/aux.zsh @@ -0,0 +1,6 @@ +#!/bin/zsh + +export NO_AT_BRIDGE=1 +export QT_ACCESSIBILITY=0 + +export MENUCONFIG_COLOR=blackbg diff --git a/.config/zsh/env/history.zsh b/.config/zsh/env/history.zsh new file mode 100644 index 0000000..7573ae4 --- /dev/null +++ b/.config/zsh/env/history.zsh @@ -0,0 +1,10 @@ +#!/bin/zsh + +## kinda unlimited history +HISTSIZE=10000000 +SAVEHIST=10000000 + +ZSHU[f_hist]="${ZSHU[d_var]}/history" +[ -f "${ZSHU[f_hist]}" ] || touch "${ZSHU[f_hist]}" + +HISTFILE="${ZSHU[f_hist]}" diff --git a/.config/zsh/env/ld.so.zsh b/.config/zsh/env/ld.so.zsh new file mode 100644 index 0000000..ab8d08c --- /dev/null +++ b/.config/zsh/env/ld.so.zsh @@ -0,0 +1,5 @@ +#!/bin/zsh + +typeset -T LD_LIBRARY_PATH ld_library_path +typeset -T LD_PRELOAD ld_preload +typeset -T LD_AUDIT ld_audit diff --git a/.config/zsh/env/pager.zsh b/.config/zsh/env/pager.zsh new file mode 100644 index 0000000..f7f2f40 --- /dev/null +++ b/.config/zsh/env/pager.zsh @@ -0,0 +1,3 @@ +#!/bin/zsh + +export LESS=RSF diff --git a/.config/zsh/env/quilt.zsh b/.config/zsh/env/quilt.zsh new file mode 100644 index 0000000..b617e9d --- /dev/null +++ b/.config/zsh/env/quilt.zsh @@ -0,0 +1,11 @@ +#!/bin/zsh + +QUILT_PATCHES="debian/patches" +QUILT_NO_DIFF_INDEX=1 +QUILT_NO_DIFF_TIMESTAMPS=1 +QUILT_PATCH_OPTS="--reject-format=unified" +QUILT_DIFF_ARGS="-p ab --no-timestamps --no-index --color=auto" +QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index" +QUILT_COLORS="diff_hdr=1;32:diff_add=1;34:diff_rem=1;31:diff_hunk=1;33:diff_ctx=35:diff_cctx=33" + +typeset -x -m 'QUILT*' diff --git a/.config/zsh/env/xdg.zsh b/.config/zsh/env/xdg.zsh new file mode 100644 index 0000000..44bdaf1 --- /dev/null +++ b/.config/zsh/env/xdg.zsh @@ -0,0 +1,13 @@ +#!/bin/zsh + +: ${XDG_CONFIG_HOME:=${HOME}/.config} +: ${XDG_CACHE_HOME:=${HOME}/.cache} +: ${XDG_DATA_HOME:=${HOME}/.local/share} +: ${XDG_RUNTIME_DIR:=${TMPDIR}} +: ${XDG_DATA_DIRS:=/usr/local/share:/usr/share} +: ${XDG_CONFIG_DIRS:=/etc/xdg} + +typeset -x -m 'XDG*' + +export -T XDG_DATA_DIRS xdg_data_dirs +export -T XDG_CONFIG_DIRS xdg_config_dirs diff --git a/.config/zsh/lib.zsh b/.config/zsh/lib.zsh new file mode 100644 index 0000000..1bf8d6b --- /dev/null +++ b/.config/zsh/lib.zsh @@ -0,0 +1,6 @@ +#!/bin/zsh + +disable which +which() { builtin whence -p "$@"; } +which-command() { builtin whence -p "$@"; } +zsh-which() { builtin whence -c "$@"; } diff --git a/.config/zsh/lib/alternatives.zsh b/.config/zsh/lib/alternatives.zsh new file mode 100644 index 0000000..51669bb --- /dev/null +++ b/.config/zsh/lib/alternatives.zsh @@ -0,0 +1,83 @@ +#!/bin/zsh + +## alternatives list is pipe-separated list of commands/binaries + +## find (first) candidate in alternatives +## $1 - alternatives list +## $2 - arguments to test command (USE WITH CAUTION!) +z-alt-find() { + local i c r t + local -a v a + + v=( ${(@s:|:)1} ) + [ ${#v} = 0 ] && v=( "$1" ) + for i ( $v ) ; do + a=( ${(@s: :)i} ) + + c=$(which "${a[1]}") + [ -z "$c" ] && continue + + # r=$(readlink -f "$c" 2>/dev/null) + # [ -z "$r" ] && continue + # a[1]="$r" + + if [ -n "$2" ] ; then + t="$a $2" + command ${(@s: :)t} /dev/null || continue + fi + + echo "${a[@]}" + return 0 + done + + return 127 +} + +## set function alias for alternative (one-time static resolve) +## $1 - function name +## $2 - alternatives list +## $3 - command wrapper +## $4 - function prologue +## $5 - function epilogue +z-alt-set-static() { + local n t a r + local -a s + n="$1" ; t='' + if [[ "$n" =~ '\|' ]] ; then + t=${n:${MBEGIN}} ; n=${n:0:${MBEGIN}-1} + fi + a=$(z-alt-find "$2" "$t") + if [ -n "$a" ] ; then + r=0 + [ -n "$4" ] && s+=( "$4 ;" ) + [ -n "$3" ] && s+=( "$3" ) + s+=( "command $a \"\$@\" || return 127" ) + [ -n "$5" ] && s+=( "; $5" ) + else + r=127 + s+=( 'return 127' ) + fi + eval "$n () { ${s[@]} ; } ; typeset -g $n" + return $r +} + +## set function alias for alternative (dynamic resolve) +## $1 - function name +## $2 - alternatives list +## $3 - command wrapper +## $4 - function prologue +## $5 - function epilogue +z-alt-set-dynamic() { + local n t + local -a s + n="$1" ; t='' + if [[ "$n" =~ '\|' ]] ; then + t=${n:${MBEGIN}} ; n=${n:0:${MBEGIN}-1} + fi + [ -n "$4" ] && s+=( "$4 ;" ) + s+=( 'local a=$(z-alt-find' "${(qq)2}" "${t:+' $t'} ) ;" ) + [ -n "$3" ] && s+=( "$3" ) + s+=( 'command ${(@s: :)a} "$@" || return 127' ) + [ -n "$5" ] && s+=( "; $5" ) + eval "$n () { ${s[@]} ; } ; typeset -g $n" +} diff --git a/.config/zsh/lib/cmdtime.zsh b/.config/zsh/lib/cmdtime.zsh new file mode 100644 index 0000000..258013c --- /dev/null +++ b/.config/zsh/lib/cmdtime.zsh @@ -0,0 +1,52 @@ +#!/bin/zsh + +zmodload -i zsh/datetime + +z-time() { + local a b elapsed result + a=${EPOCHREALTIME} + "$@" + result=$? + b=$(( ${EPOCHREALTIME} - a )) + elapsed=$(z-ts-to-human "$b" 6) + echo 1>&2 + echo "time took: ${elapsed}" 1>&2 + return ${result} +} + +if autoload -Uz add-zsh-hook ; then + +typeset -gA ZSHU_PS +ZSHU_PS[cmd_threshold]=3 + +__z_cmdtime_precmd() { + local t=${EPOCHREALTIME} + # local t=${(%):-%D{%s.%9.}} + + ZSHU_PS[elapsed]='' + (( ${+ZSHU_PS[cmd_ts]} )) || return + + t=$(( t - ${ZSHU_PS[cmd_ts]} )) + unset "ZSHU_PS[cmd_ts]" + + local x=$(( ${ZSHU_PS[cmd_threshold]} + 0 )) + [ "$x" = '0' ] && return + + x=$(( t - x )) + [ "${x:0:1}" = '-' ] && return + + local elapsed=$(z-ts-to-human "$t") + ZSHU_PS[elapsed]=" %f[%B%F{yellow}+${elapsed}%b%f] " +} + +__z_cmdtime_preexec() { + ZSHU_PS[cmd_ts]=${EPOCHREALTIME} + # ZSHU_PS[cmd_ts]=${(%):-%D{%s.%9.}} +} + +add-zsh-hook precmd __z_cmdtime_precmd +add-zsh-hook preexec __z_cmdtime_preexec + +else + echo "cmd time measurement is disabled due to missing hook support" 1>&2 +fi diff --git a/.config/zsh/lib/completion.zsh b/.config/zsh/lib/completion.zsh new file mode 100644 index 0000000..c196019 --- /dev/null +++ b/.config/zsh/lib/completion.zsh @@ -0,0 +1,69 @@ +#!/bin/zsh + +ZSHU[f_compdump]="${ZSHU[d_cache]}/compdump" +ZSHU[d_compcache]="${ZSHU[d_cache]}/compcache" +[ -d "${ZSHU[d_compcache]}" ] || mkdir -p "${ZSHU[d_compcache]}" + +fpath=( "${ZSHU[d_compcache]}" $fpath ) + +__z_compdump_print() { printf '#zshu %s %s\n' "$1" "${(P)1}" ; } + +__z_compdump_invalidate() { + command rm -f "${ZSHU[f_compdump]}" + find "${ZSHU[d_compcache]}/" -mindepth 1 -type f '!' -name '.keep' -delete + ZSHU[compdump_refresh]=1 +} + +__z_compdump_verify() { + unset "ZSHU[compdump_refresh]" + ZSHU[compdump_meta]='ZSH_VERSION ZSH_PATCHLEVEL FPATH PATH' + local i s + for i ( ${(s: :)ZSHU[compdump_meta]} ) ; do + s=$(__z_compdump_print "$i") + command grep -Fx -e "$s" "${ZSHU[f_compdump]}" &>/dev/null && continue + __z_compdump_invalidate + break + done +} + +__z_compdump_finalize() { + local i + if (( ${+ZSHU[compdump_refresh]} )) ; then + { + echo + for i ( ${(s: :)ZSHU[compdump_meta]} ) ; do + __z_compdump_print "$i" + done + } | tee -a "${ZSHU[f_compdump]}" &>/dev/null + unset "ZSHU[compdump_refresh]" + fi + unset "ZSHU[compdump_meta]" +} + +__z_comp_bash() { + (( ${+commands[$1]} )) || return 1 + (( ${+_comps[$1]} )) && return 2 + (( ${+ZSHU[compdump_bash]} )) || return 3 + (( ${+2} )) && return 0 + local f p + f=0 + for p ( /usr/share/bash-completion/completions ) ; do + [ -s "$p/$1" ] && f=1 && break + [ -s "$p/_$1" ] && f=1 && break + done + [ "$f" = 0 ] && return 1 + complete -C "$1" "$1" + return 0 +} + +__z_comp_test() { + (( ${+commands[$1]} )) || return 1 + (( ${+_comps[$1]} )) && return 2 + [ -s "${ZSHU[d_compcache]}/_$1" ] && return 3 + return 0 +} + +__z_comp_write() { + cat > "${ZSHU[d_compcache]}/_$1" + return 0 +} diff --git a/.config/zsh/lib/curl.zsh b/.config/zsh/lib/curl.zsh new file mode 100644 index 0000000..41cc0b2 --- /dev/null +++ b/.config/zsh/lib/curl.zsh @@ -0,0 +1,14 @@ +#!/bin/zsh + +__z_curl_headers() { + command curl -qsI "$@" 2>/dev/null +} +__z_curl_location() { + __z_curl_headers "$1" \ + | sed -En '/^[Ll]ocation: (.+)$/{s//\1/;p}' +} +__z_curl_response() { + __z_curl_headers -L "$1" \ + | sed -En '/^HTTP\/[0-9.]+ ([1-5][0-9]{2})( .+)?$/{s//\1/;p}' \ + | tail -n 1 +} diff --git a/.config/zsh/lib/enclave.zsh.wip b/.config/zsh/lib/enclave.zsh.wip new file mode 100644 index 0000000..ffe1542 --- /dev/null +++ b/.config/zsh/lib/enclave.zsh.wip @@ -0,0 +1,63 @@ +#!/bin/zsh + +if autoload -Uz add-zsh-hook ; then + +ZSHU[f_enclave]="${ZSHU[d_var]}/enclave" +[ -f "${ZSHU[f_enclave]}" ] || touch "${ZSHU[f_enclave]}" +[ -s "${ZSHU[f_enclave]}" ] && . "${ZSHU[f_enclave]}" + +## +test_enclave_enter() { echo "you are in $1 enclave" 1>&2 ; } +test_enclave_leave() { echo "you are left $1 enclave" 1>&2 ; } + +zstyle ":enclave:box1:path:${HOME}/prj/*" '' +zstyle ":enclave:box1:path:${HOME}/prj/_stale/*" exclude +zstyle ':enclave:box1:env:unset' 'var2' +zstyle ':enclave:box1:env:set' 'var1' 1 +zstyle ':enclave:box1:on_enter' test_enclave_enter +zstyle ':enclave:box1:on_leave' test_enclave_leave + +zstyle ":enclave:box2:path:${HOME}/doc/*" '' +zstyle ":enclave:box2:path:${HOME}/doc/work/*" exclude +zstyle ':enclave:box2:env:unset' 'var1' +zstyle ':enclave:box2:env:set' 'var2' 1 +zstyle ':enclave:box2:on_enter' test_enclave_enter +zstyle ':enclave:box2:on_leave' test_enclave_leave + +typeset -g var1=0 +typeset -g var2=0 +## + +__z_enclave_list() { + local -aU list=( $(zstyle -L ':enclave:*' \ + | sed -En "/^zstyle '?:enclave:([^:]+):.*\$/{s//\1/;p;}") ) + printf '%s' "${(j: :)list}" +} + +__z_chpwd_enclave() { + [ -z "${PWD}" ] && return + ## enclave changed? if no - do nothing + [ -z "${OLDPWD}" ] && return + [ "${PWD}" = "${OLDPWD}" ] && return + + local a + zstyle -s ":enclave:*:path:$PWD" '' a && \ + declare -p a + + ## call on_leave() + ## unset previously set + ## set previously set + + env > /tmp/env +} + +# zstyle -L ':enclave:*' +# echo + + + add-zsh-hook chpwd __z_chpwd_enclave + __z_chpwd_enclave + +else + echo "enclaves are disabled due to missing hook support" 1>&2 +fi diff --git a/.config/zsh/lib/git.zsh b/.config/zsh/lib/git.zsh new file mode 100644 index 0000000..38b5491 --- /dev/null +++ b/.config/zsh/lib/git.zsh @@ -0,0 +1,54 @@ +#!/bin/zsh + +## fancy and manageable PS1 for git +typeset -gA ZSHU_PS +ZSHU_PS[git]=0 + +_zshu_git_avail() { (( $+commands[git] )) ; } + +_zshu_git() { GIT_OPTIONAL_LOCKS=0 command git "$@"; } + +_zshu_git_is_repo() { _zshu_git rev-parse --git-dir &>/dev/null ; } + +zshu-git-test() { + [ "${ZSHU_PS[git]}" = '1' ] || return 1 + + _zshu_git_avail || return 2 + + _zshu_git_is_repo || return 3 + + return 0 +} + +_zshu_git_pwd() { + zshu-git-test || return + local p=${(%):-%~} + [[ "$p" =~ '/.+' ]] || return + local s pfx last + s=$(_zshu_git rev-parse --show-prefix) + s="${s%%/}" + if [ -n "$s" ] ; then + p=${p%%/$s} + last="${s:t}" + pfx="${s%${last}}" + pfx="${pfx%/}" + pfx="/${pfx}${pfx:+/}" + else + last="/" + fi + ZSHU_PS[pwd]="%F{magenta}$p%F{cyan}${pfx}%B${last}%f%b" +} + +zshu-git-enable() { ZSHU_PS[git]=1 ; } +zshu-git-disable() { ZSHU_PS[git]=0 ; } + +zshu-git-status() { + _zshu_git_avail + echo "Git binary: "${(%):-%(?..NOT )}"found in PATH" + [ "${ZSHU_PS[git]}" = 1 ] + echo "Git prompt: "${(%):-%(?.enabled.disabled)} + _zshu_git_is_repo + echo "Git repo: "${(%):-%(?..NOT )}"present" +} + +ZSHU[pwd_hook]="${ZSHU[pwd_hook]}${ZSHU[pwd_hook]:+ }_zshu_git_pwd" diff --git a/.config/zsh/lib/history.zsh b/.config/zsh/lib/history.zsh new file mode 100644 index 0000000..5cdcbc1 --- /dev/null +++ b/.config/zsh/lib/history.zsh @@ -0,0 +1,11 @@ +#!/bin/zsh + +z-history() { + local list + zparseopts -E l=list + if [[ -n "$list" ]]; then + builtin fc "$@" + else + [[ ${@[-1]-} = *[0-9]* ]] && builtin fc -il "$@" || builtin fc -il "$@" 1 + fi +} diff --git a/.config/zsh/lib/prompt.zsh b/.config/zsh/lib/prompt.zsh new file mode 100644 index 0000000..e8a7c72 --- /dev/null +++ b/.config/zsh/lib/prompt.zsh @@ -0,0 +1,44 @@ +#!/bin/zsh + +typeset -gA ZSHU_PM ZSHU_PS + +ZSHU_PM[rst]='%b%k%u%s%f' +ZSHU_PM[crlf]=$'\n' + +ZSHU_PM[status]='▪' +ZSHU_PS[lastcmd]="%B%(?.%F{green}.%F{red})${ZSHU_PM[status]}%f%b" + +ZSHU_PS[pwd_std]='%F{cyan}%B%~%f%b' + +ZSHU_PM[cmd_user]='%K{white}$' +ZSHU_PM[cmd_root]='%K{red}#' +ZSHU_PS[cmd]="%F{black}%(!.${ZSHU_PM[cmd_root]}.${ZSHU_PM[cmd_user]})${ZSHU_PM[rst]} " + +ZSHU_PM[user]='%(!.%F{red}.%F{green})%n%f' +ZSHU_PM[host]="%B%F{blue}${ZSHU[host]}%f%b" + +if autoload -Uz add-zsh-hook ; then + +__z_pwd() { + local p=${(%):-%~} + [[ "$p" =~ '/.+' ]] || return + local pfx="${p:h}" + pfx="${pfx%%/}" + local last="${p:t}" + ZSHU_PS[pwd]="%F{cyan}${pfx}/%B${last}%f%b" +} + +# ZSHU[pwd_hook]='' +__z_pwd_hook() { + unset "ZSHU_PS[pwd]" + for i ( ${(s: :)ZSHU[pwd_hook]} __z_pwd ) ; do + "$i" + (( ${+ZSHU_PS[pwd]} )) && return + done +} + +add-zsh-hook precmd __z_pwd_hook + +else + echo "shiny pwd's are disabled due to missing hook support" 1>&2 +fi diff --git a/.config/zsh/lib/pswalk.zsh b/.config/zsh/lib/pswalk.zsh new file mode 100644 index 0000000..8314b08 --- /dev/null +++ b/.config/zsh/lib/pswalk.zsh @@ -0,0 +1,42 @@ +#!/bin/zsh + +typeset -Uga ZSHU_PARENTS_PID +typeset -ga ZSHU_PARENTS_NAME + +function { + local i cmd + + i=$$ ; while : ; do + i=$(ps -o ppid= -p $i 2>/dev/null || : ) + i=${i//[^0-9]} + [[ "$i" =~ '^[1-9][0-9]*$' ]] || break + ZSHU_PARENTS_PID+=( $i ) + done + + for i ( ${ZSHU_PARENTS_PID} ) ; do + cmd=$(ps -o comm= -p $i 2>/dev/null || : ) + [ -n "${cmd}" ] && ZSHU_PARENTS_NAME+=( "${cmd##*/}" ) + done + + typeset -r ZSHU_PARENTS_PID + typeset -r ZSHU_PARENTS_NAME +} + +typeset -gA ZSHU_RUN + +z-run-test() { + local key i + key=$1 ; shift + v=0 + for i ( ${ZSHU_PARENTS_NAME} ) ; do + if (( ${+argv[(r)$i]} )) ; then + ZSHU_RUN[${key}]=1 + return + fi + done + ZSHU_RUN[${key}]=0 +} + +z-run-test gui konsole xterm x-terminal-emulator +z-run-test nested screen tmux +z-run-test elevated sudo su diff --git a/.config/zsh/lib/selfservice.zsh b/.config/zsh/lib/selfservice.zsh new file mode 100644 index 0000000..05a3b63 --- /dev/null +++ b/.config/zsh/lib/selfservice.zsh @@ -0,0 +1,14 @@ +#!/bin/zsh + +dotfiles-update() { + "${ZSHU[d_zdot]}/.config/dotfiles/install.sh" +} + +z-update() { + dotfiles-update +} + +z-reload() { + exec -a "${ZSH_ARGZERO}" "${ZSH_NAME}" "${argv[@]}" + echo "unable to reload (something went wrong), code $?" 1>&2 +} diff --git a/.config/zsh/lib/starship.zsh.sample b/.config/zsh/lib/starship.zsh.sample new file mode 100644 index 0000000..ebd66f1 --- /dev/null +++ b/.config/zsh/lib/starship.zsh.sample @@ -0,0 +1,205 @@ +#!/bin/zsh + +## inspired by 'https://starship.rs/install.sh' as of 2021-03-07 + +ZSHU[starship_baseurl]='https://github.com/starship/starship/releases' +## ZSHU[starship_target] is auto-detected +## ZSHU[starship_path] defaults to ZSHU[d_bin] which is in PATH already + +# export STARSHIP_CONFIG="$HOME/.config/starship.toml" +# export STARSHIP_CACHE="$HOME/.cache/starship" + +__z_starship_auto_path() { + echo "${ZSHU[starship_path]:-${ZSHU[d_bin]}}" +} + +__z_starship() { + local x=$(__z_starship_auto_path) + x="$x/starship" + [ -x "$x" ] || x=starship + [ -x "$x" ] || return 127 + "$x" "$@" +} + +__z_starship_test() { __z_starship -V &>/dev/null ; } + +## NB: supply TARGET environment variable to call +__z_starship_url_latest() { + printf '%s/latest/download/starship-%s.tar.gz' \ + "${ZSHU[starship_baseurl]}" "${TARGET}" +} + +## NB: supply TARGET environment variable to call +## $1 - version (semver like '0.50.0') +__z_starship_url_versioned() { + printf '%s/download/v%s/starship-%s.tar.gz' \ + "${ZSHU[starship_baseurl]}" "$1" "${TARGET}" +} + +## NB: install starship somewhere in PATH ;) +__z_starship_ver_installed() { + __z_starship -V 2>/dev/null \ + | sed -En '/^starship v?(\S.+)$/{s//\1/;p;}' +} + +## NB: supply TARGET environment variable to call +__z_starship_ver_latest() { + local x=$(__z_starship_url_latest) + local y=$(__z_curl_location "$x") + ## hackish strip, e.g.: + ## from: https://github.com/starship/starship/releases/download/v0.50.0/starship-x86_64-unknown-linux-musl.tar.gz + ## to: v0.50.0 + y=${y:h:t} + [ "${y:0:1}" = 'v' ] && y=${y:1} + echo "$y" +} + +__z_starship_detect_arch() { + local arch=${ZSHU[mach]} + case "${arch}" in + x86_64) [ "$(getconf LONG_BIT)" -eq 32 ] && arch=i686 ;; + aarch64) [ "$(getconf LONG_BIT)" -eq 32 ] && arch=arm ;; + esac + echo "${arch}" +} + +__z_starship_detect_platform() { + local platform=${ZSHU[uname]} + case "${ZSHU[uname]}" in + msys_nt*) platform=pc-windows-msvc ;; + cygwin_nt*) platform=pc-windows-msvc ;; + mingw*) platform=pc-windows-msvc ;; + linux) platform=unknown-linux-musl ;; ## static builds + darwin) platform=apple-darwin ;; + freebsd) platform=unknown-freebsd ;; + esac + echo "${platform}" +} + +## $1 - arch +## $2 - platform +__z_starship_detect_target() { + local target="$1-$2" + case "${target}" in + arm-unknown-linux-musl) target="${target}eabihf" ;; + esac + echo "${target}" +} + +__z_starship_auto_target() { + [ -n "${ZSHU[starship_target]}" ] && echo "${ZSHU[starship_target]}" && return + local arch=$(__z_starship_detect_arch) + local platform=$(__z_starship_detect_platform) + local target=$(__z_starship_detect_target "${arch}" "${platform}") + echo "${target}" +} + +__z_starship_install() { + local ver=${1:-latest} + local target url resp + target=$(__z_starship_auto_target) + if [ "${ver}" = 'latest' ] ; then + url=$(TARGET=${target} __z_starship_url_latest) + resp=$(__z_curl_response "${url}") + resp=${resp:-400} + [ ${resp} -ge 400 ] && return 1 + else + url=$(TARGET=${target} __z_starship_url_versioned "${ver}") + resp=$(__z_curl_response "${url}") + resp=${resp:-400} + if [ ${resp} -ge 400 ] ; then + ## last resort: try messing with version ;D + if [ "${ver:0:1}" = 'v' ] ; then + ver=${ver:1} + else + ver="v${ver}" + fi + url=$(TARGET=${target} __z_starship_url_versioned "${ver}") + resp=$(__z_curl_response "${url}") + resp=${resp:-400} + [ ${resp} -ge 400 ] && return 1 + fi + fi + + local t=$(mktemp -d) + local f="$t/starship.tar.gz" + command curl -sqL "${url}" > "$f" + command tar -C "$t" -xf "$f" starship &>/dev/null + if [ $? -ne 0 ] ; then + ## last resort + command tar -C "$t" --strip-components=1 --wildcards -xf "$f" '*/starship' &>/dev/null + if [ $? -ne 0 ] ; then + rm -rf "$t" + return 1 + fi + fi + local d=$(__z_starship_auto_path) + mv "$t/starship" "$d/" + local r=$? + if [ $r -eq 0 ] ; then + [ "${ver:0:1}" = 'v' ] && ver=${ver:1} + echo "starship: installed ${ver} version in $d/" 1>&2 + fi + rm -rf "$t" + return $r +} + +z-starship-target-available() { + local target url resp + target=$(__z_starship_auto_target) + url=$(TARGET=${target} __z_starship_url_latest) + resp=$(__z_curl_response "${url}") + resp=${resp:-400} + if [ ${resp} -lt 400 ] ; then + echo "starship: available for ${target}" 1>&2 + return 0 + else + echo "starship: NOT available for ${target}" 1>&2 + return 1 + fi +} + +z-starship-update-available() { + local target=$(__z_starship_auto_target) + local installed=$(__z_starship_ver_installed) + local latest=$(TARGET=${target} __z_starship_ver_latest) + if [ -z "${latest}" ] ; then + echo "starship: update is NOT available" 1>&2 + return 1 + fi + if [ -z "${installed}" ] ; then + echo "starship: NOT installed, install it 1st" 1>&2 + return 0 + fi + local tailver=$(printf '%s\n' "${installed}" "${latest}" | sort -Vu | tail -n 1) + if [ "${installed}" = "${tailver}" ] ; then + if [ "${installed}" = "${latest}" ] ; then + echo "starship: local version is up to date" 1>&2 + else + echo "starship: local version is newer! o_O" 1>&2 + fi + return 1 + else + echo "starship: update is available (${installed} -> ${latest})" 1>&2 + return 0 + fi +} + +z-starship-init() { + [ -n "${ZSHU[starship_init]}" ] && return + __z_starship_test || return + eval "$(__z_starship init zsh)" + ZSHU[starship_init]=1 +} + +z-starship-install() { + z-starship-target-available || return + __z_starship_install || \ + echo "starship: unable to install" 1>&2 +} + +z-starship-update() { + z-starship-update-available || return 0 + __z_starship_install || \ + echo "starship: unable to update" 1>&2 +} diff --git a/.config/zsh/lib/time.zsh b/.config/zsh/lib/time.zsh new file mode 100644 index 0000000..3c04859 --- /dev/null +++ b/.config/zsh/lib/time.zsh @@ -0,0 +1,42 @@ +#!/bin/zsh + +zmodload -i zsh/datetime +zmodload -i zsh/mathfunc + +z-ts-to-human() { + local t=$1 + local s=$(( int(t) )) + local ns=$(( int((t - s) * (10**9)) )) + t=$s + + local d=0 h=0 m=0 + if [ $t -ge 86400 ] ; then + d=$(( t / 86400 )) + t=$(( t % 86400 )) + fi + if [ $t -ge 3600 ] ; then + h=$(( t / 3600 )) + t=$(( t % 3600 )) + fi + if [ $t -ge 60 ] ; then + m=$(( t / 60 )) + t=$(( t % 60 )) + fi + + local f='%s.%6.' + f=$(strftime "$f" $t $ns) + + local x=3 + ## keep math in sync with format above + case "$2" in + 0) x=7 ;; + [1-5]) x=$(( 6 - $2 )) ;; + 6) x=0 ;; + esac + [ $x -gt 0 ] && f="${f:0:-$x}s" + + [ $s -ge 60 ] && f="${m}m:$f" + [ $s -ge 3600 ] && f="${h}h:$f" + [ $s -ge 86400 ] && f="${d}d:$f" + echo "$f" +} diff --git a/.config/zsh/local/.keep b/.config/zsh/local/.keep new file mode 100644 index 0000000..e69de29 diff --git a/.config/zsh/local/completion/.keep b/.config/zsh/local/completion/.keep new file mode 100644 index 0000000..e69de29 diff --git a/.config/zsh/opt.zsh b/.config/zsh/opt.zsh new file mode 100644 index 0000000..8b41feb --- /dev/null +++ b/.config/zsh/opt.zsh @@ -0,0 +1,13 @@ +#!/bin/zsh + +unsetopt err_exit +unsetopt err_return +unsetopt multios + +setopt bsd_echo +setopt interactive_comments +setopt long_list_jobs +setopt monitor +setopt prompt_subst +setopt zle +# setopt magic_equal_subst diff --git a/.config/zsh/opt/chase.zsh b/.config/zsh/opt/chase.zsh new file mode 100644 index 0000000..142e7d3 --- /dev/null +++ b/.config/zsh/opt/chase.zsh @@ -0,0 +1,5 @@ +#!/bin/zsh + +chase() { setopt chase_dots chase_links ; } +nochase() { unsetopt chase_dots chase_links ; } +nochase diff --git a/.config/zsh/opt/completion.zsh b/.config/zsh/opt/completion.zsh new file mode 100644 index 0000000..ee5ccd7 --- /dev/null +++ b/.config/zsh/opt/completion.zsh @@ -0,0 +1,8 @@ +#!/bin/zsh + +unsetopt flow_control +unsetopt menu_complete + +setopt always_to_end +setopt auto_menu +setopt complete_in_word diff --git a/.config/zsh/opt/directories.zsh b/.config/zsh/opt/directories.zsh new file mode 100644 index 0000000..0a9c3d7 --- /dev/null +++ b/.config/zsh/opt/directories.zsh @@ -0,0 +1,7 @@ +#!/bin/zsh + +setopt auto_cd +setopt auto_pushd +setopt cdable_vars +setopt pushd_ignore_dups +setopt pushd_minus diff --git a/.config/zsh/opt/history.zsh b/.config/zsh/opt/history.zsh new file mode 100644 index 0000000..df86c6d --- /dev/null +++ b/.config/zsh/opt/history.zsh @@ -0,0 +1,11 @@ +#!/bin/zsh + +setopt append_history +setopt extended_history +setopt hist_expire_dups_first +setopt hist_ignore_all_dups +setopt hist_ignore_dups +setopt hist_ignore_space +setopt hist_verify +setopt inc_append_history +setopt share_history diff --git a/.config/zsh/opt/prompt.zsh b/.config/zsh/opt/prompt.zsh new file mode 100644 index 0000000..dc7901f --- /dev/null +++ b/.config/zsh/opt/prompt.zsh @@ -0,0 +1,3 @@ +#!/bin/zsh + +setopt prompt_subst diff --git a/.config/zsh/rc.zsh b/.config/zsh/rc.zsh new file mode 100644 index 0000000..3876f2a --- /dev/null +++ b/.config/zsh/rc.zsh @@ -0,0 +1,22 @@ +#!/bin/zsh + +typeset -Ua zshu_modules +zshu_modules+=( + complete + complist + computil + langinfo + main + parameter + stat + terminfo + zle + zutil +) +for i ( ${zshu_modules} ) ; do + [[ "$i" != */* ]] && i="zsh/$i" + zmodload -i $i +done ; unset i +unset zshu_modules + +autoload -Uz +X colors && colors diff --git a/.config/zsh/rc/completion.zsh b/.config/zsh/rc/completion.zsh new file mode 100644 index 0000000..fe8fd58 --- /dev/null +++ b/.config/zsh/rc/completion.zsh @@ -0,0 +1,43 @@ +#!/bin/zsh + +__z_compdump_verify + +## :completion::::: + +zstyle ':completion::complete:*' use-cache 1 +zstyle ':completion::complete:*' cache-path "${ZSHU[d_compcache]}" + +bindkey -M menuselect '^o' accept-and-infer-next-history +zstyle ':completion:*' menu select + +zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*' + +zstyle ':completion:*' special-dirs true + +zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories + +zstyle ':completion:*:*:*:users' ignored-patterns adm amanda apache at avahi avahi-autoipd backup beaglidx bin bind cacti canna clamav colord daemon dbus distcache dnsmasq dovecot fax ftp games gdm gkrellmd gnats gopher hacluster haldaemon halt hplip hsqldb ident irc junkbust kdm ldap list lp mail mailman mailnull man messagebus mldonkey mysql nagios named netdump news nfsnobody nginx nobody nscd ntp ntpsec nut nx obsrun openvpn operator pcap polkitd postfix postgres privoxy proxy pulse pvm quagga radvd redsocks rpc rpcuser rpm rtkit saned sbuild sbws scard sddm shutdown speech-dispatcher squid sshd statd svn sync sys tcpdump tftp tss usbmux uucp uuidd vcsa wwwrun www-data x2gouser xfs '_*' 'systemd-*' 'debian-*' 'Debian-*' +zstyle '*' single-ignored show + +zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w" +zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' +zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' + +if autoload -Uz +X bashcompinit ; then + bashcompinit && ZSHU[compdump_bash]=1 +fi + +autoload -Uz +X compinit && \ +compinit -i -C -d "${ZSHU[f_compdump]}" + +function { + local i + for i ( ${ZSHU[d_conf]}/completion/*.zsh(N.r) ) ; do + source "$i" + done + for i ( ${ZSHU[d_conf]}/local/completion/*.zsh(N.r) ) ; do + source "$i" + done +} + +__z_compdump_finalize diff --git a/.config/zsh/rc/keyboard.zsh b/.config/zsh/rc/keyboard.zsh new file mode 100644 index 0000000..2d00811 --- /dev/null +++ b/.config/zsh/rc/keyboard.zsh @@ -0,0 +1,148 @@ +#!/bin/zsh + +typeset -Uga ZSHU_TERM_MISSING +typeset -A ZSHU_TI_KEYS +typeset -A ZSHU_FB_KEYS + +z-ti-test() { + local r i + r=0 + + for i ; do + [ -z "$i" ] && continue + if ! (( ${+terminfo[$i]} )) ; then + ZSHU_TERM_MISSING+=( "$1" ) + r=1 + fi + done + + return $r +} + +if z-ti-test smkx rmkx ; then + zle-line-init() { emulate -L zsh ; echoti smkx ; } + zle-line-finish() { emulate -L zsh ; echoti rmkx ; } + # zle-line-init() { echoti smkx ; } + # zle-line-finish() { echoti rmkx ; } + zle -N zle-line-init + zle -N zle-line-finish +fi + +## key [sequence] via terminfo +z-kseq-ti() { + [ -z "$1" ] && return + [ -z "$2" ] && return + z-ti-test "$2" && ZSHU_TI_KEYS[${terminfo[$2]}]=$1 +} + +## key [sequence] via fallback +z-kseq-fb() { + [ -z "$1" ] && return + [ -z "$2" ] && return + ZSHU_FB_KEYS[$2]=$1 +} + +z-kseq-ti Backspace kbs + +z-kseq-ti Home khome +z-kseq-ti End kend +z-kseq-ti Insert kich1 +z-kseq-ti Delete kdch1 + +z-kseq-ti Up kcuu1 +z-kseq-ti Down kcud1 +z-kseq-ti Left kcub1 +z-kseq-ti Right kcuf1 + +z-kseq-ti PageUp kpp +z-kseq-ti PageDown knp + +z-kseq-ti Shift-Tab kcbt + +z-kseq-fb Backspace '^?' +z-kseq-fb Home '^[[H' +z-kseq-fb End '^[[F' +z-kseq-fb Insert '^[[2~' +z-kseq-fb Delete '^[[3~' +z-kseq-fb Delete # '^[3;5~' + +z-kseq-fb Up '^[[A' +z-kseq-fb Down '^[[B' +z-kseq-fb Left '^[[D' +z-kseq-fb Right '^[[C' + +z-kseq-fb PageUp '^[[5~' +z-kseq-fb PageDown '^[[6~' + +z-kseq-fb Ctrl-Delete '^[[3;5~' +z-kseq-fb Ctrl-RightArrow '^[[1;5C' +z-kseq-fb Ctrl-LeftArrow '^[[1;5D' + +z-kseq-fb Esc-w '\ew' + +z-bind () { + local i sequence widget + local -a maps + + while [ "$1" != "--" ] ; do + maps+=( "$1" ) + shift + done + shift + + # sequence="$1" + widget="$2" + + local -Ua keys + keys+=( ${(k)ZSHU_TI_KEYS[(r)$1]} ) + keys+=( ${(k)ZSHU_FB_KEYS[(r)$1]} ) + + [ ${#keys} -eq 0 ] && return 1 + + case "${widget}" in + /*) + widget=${widget:1} + emulate zsh -c "autoload -RUz ${widget}" + zle -N "${widget}" + ;; + esac + + for i in "${maps[@]}" ; do + for k in "${keys[@]}" ; do + bindkey -M "$i" "$k" "${widget}" + done + done +} + +z-bind emacs -- Backspace backward-delete-char +z-bind viins -- Backspace vi-backward-delete-char +z-bind vicmd -- Backspace vi-backward-char +z-bind emacs -- Home beginning-of-line +z-bind viins vicmd -- Home vi-beginning-of-line +z-bind emacs -- End end-of-line +z-bind viins vicmd -- End vi-end-of-line +z-bind emacs viins -- Insert overwrite-mode +z-bind vicmd -- Insert vi-insert +z-bind emacs -- Delete delete-char +z-bind viins vicmd -- Delete vi-delete-char +z-bind emacs viins vicmd -- Up /up-line-or-beginning-search +z-bind emacs viins vicmd -- Down /down-line-or-beginning-search +z-bind emacs -- Left backward-char +z-bind viins vicmd -- Left vi-backward-char +z-bind emacs -- Right forward-char +z-bind viins vicmd -- Right vi-forward-char +z-bind emacs viins vicmd -- PageUp up-line-or-history +z-bind emacs viins vicmd -- PageDown down-line-or-history + +z-bind emacs viins vicmd -- Shift-Tab reverse-menu-complete + +z-bind emacs viins vicmd -- Ctrl-Delete kill-word +z-bind emacs -- Ctrl-RightArrow forward-word +z-bind viins vicmd -- Ctrl-RightArrow vi-forward-word +z-bind emacs -- Ctrl-LeftArrow backward-word +z-bind viins vicmd -- Ctrl-LeftArrow vi-backward-word + +z-bind emacs viins vicmd -- Esc-w kill-region + +## use emacs key bindings +bindkey -e diff --git a/.config/zsh/rc/pager.zsh b/.config/zsh/rc/pager.zsh new file mode 100644 index 0000000..d74ce26 --- /dev/null +++ b/.config/zsh/rc/pager.zsh @@ -0,0 +1,10 @@ +#!/bin/zsh + +PAGER=$(z-alt-find 'less|pager|more') +if [ -n "${PAGER}" ] ; then + export PAGER + READNULLCMD=$(which "${PAGER}" | xargs -r readlink -e) +else + unset READNULLCMD + unset NULLCMD +fi diff --git a/.config/zsh/rc/prompt.zsh b/.config/zsh/rc/prompt.zsh new file mode 100644 index 0000000..b0bdf1d --- /dev/null +++ b/.config/zsh/rc/prompt.zsh @@ -0,0 +1,84 @@ +#!/bin/zsh + +# z-starship-init + +## three-line prompt +function { + local -a line + + line+="${ZSHU_PM[rst]}" + line+="%B%F{black}┌[%b" + line+="%F{yellow}%D{%y.%m.%d} %B%D{%H:%M:%S}%f%b" + line+="%B%F{black}|%b" + line+="${ZSHU_PM[user]}%F{white}@${ZSHU_PM[host]}" + line+='${ZSHU_PS[elapsed]}' + line+='${ZSHU_PS[status_extra]}' + line+="${ZSHU_PM[rst]}" + + line+="${ZSHU_PM[crlf]}" + + line+="%B%F{black}┝%f%b " + line+='${ZSHU_PS[pwd]:-${ZSHU_PS[pwd_std]}}' + line+='${ZSHU_PS[pwd_extra]}' + line+="${ZSHU_PM[rst]}" + + line+="${ZSHU_PM[crlf]}" + + line+="%B%F{black}└[%f%b" + line+="${ZSHU_PS[lastcmd]}" + line+="%B%F{black}|%b%f" + line+="${ZSHU_PS[cmd]}" + + ZSHU_PS[ps1_3L]="${(j::)line}" +} + +## two-line prompt +function { + local -a line + local r + + line+="${ZSHU_PM[rst]}" + line+="%B%F{black}┌[%b" + line+="${ZSHU_PM[user]}%F{white}@${ZSHU_PM[host]}" + line+="%B%F{black}|%b" + line+='${ZSHU_PS[pwd]:-${ZSHU_PS[pwd_std]}}' + line+='${ZSHU_PS[pwd_extra]}' + line+='${ZSHU_PS[elapsed]}' + line+="${ZSHU_PM[rst]}" + + line+="${ZSHU_PM[crlf]}" + + line+="%B%F{black}└[%f%b" + line+="${ZSHU_PS[lastcmd]}" + line+="%B%F{black}|%b%f" + line+='${ZSHU_PS[status_extra]}' + line+="${ZSHU_PS[cmd]}" + + ZSHU_PS[ps1_2L]="${(j::)line}" +} + +## one-line prompt +function { + local -a line + + line+="${ZSHU_PM[rst]}" + line+="${ZSHU_PS[lastcmd]}" + line+="%B%F{black}|%b" + line+="${ZSHU_PM[user]}" + line+="%B%F{black}|%b" + line+='${ZSHU_PS[pwd]:-${ZSHU_PS[pwd_std]}}' + line+='${ZSHU_PS[pwd_extra]}' + line+='${ZSHU_PS[elapsed]}' + line+="%B%F{black}|%b" + line+="${ZSHU_PS[cmd]}" + + ZSHU_PS[ps1_1L]="${(j::)line}" +} + +ZSHU_PS[ps1_standard]=${ZSHU_PS[ps1_3L]} +ZSHU_PS[ps1_nested]=${ZSHU_PS[ps1_2L]} + +if [ "${ZSHU_RUN[nested]}" = 0 ] +then PS1=${ZSHU_PS[ps1_standard]} +else PS1=${ZSHU_PS[ps1_nested]} +fi diff --git a/.config/zsh/var/.keep b/.config/zsh/var/.keep new file mode 100644 index 0000000..e69de29 diff --git a/.gdbinit b/.gdbinit new file mode 100644 index 0000000..3f0793e --- /dev/null +++ b/.gdbinit @@ -0,0 +1,5 @@ +undisplay +display /i $pc +set disassembly-flavor intel +layout asm +layout regs diff --git a/.gitconfig b/.gitconfig new file mode 100644 index 0000000..c668154 --- /dev/null +++ b/.gitconfig @@ -0,0 +1,11 @@ +[credential] + helper = cache --timeout=86400 +[gc] + auto = 0 +[push] + default = simple + gpgSign = false +[commit] + gpgSign = false +[pack] + writeReverseIndex = true diff --git a/.screenrc b/.screenrc new file mode 100644 index 0000000..fcc94ce --- /dev/null +++ b/.screenrc @@ -0,0 +1,8 @@ +startup_message off +defutf8 on +utf8 on on +defscrollback 262144 +defflow off +deflogin off +#defshell -zsh +hardstatus alwaysfirstline "%{= ky}%y.%m.%d%{= kK}|%{= kY}%c:%s%{= kK}|%{= kB}%H%{= kK}|%{= kG}%S%{= kK}|%{= kM}#%w%{-}%= %{= kK}|%{= kr}%l%{= kG}" diff --git a/.selected_editor b/.selected_editor new file mode 100644 index 0000000..a0e916c --- /dev/null +++ b/.selected_editor @@ -0,0 +1 @@ +SELECTED_EDITOR="/usr/bin/vim.basic" diff --git a/.vimrc b/.vimrc new file mode 100644 index 0000000..642c6c5 --- /dev/null +++ b/.vimrc @@ -0,0 +1,3 @@ +:syntax on +:set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:< +:set nolist diff --git a/.zshenv b/.zshenv new file mode 100644 index 0000000..5673586 --- /dev/null +++ b/.zshenv @@ -0,0 +1,62 @@ +#!/bin/zsh + +if [[ -o interactive ]] ; then + + : "${ZDOTDIR:=${HOME}}" + + typeset -gA ZSHU + + ZSHU[t_begin]=${(%):-%D{%s.%6.}} + + ZSHU[d_zdot]="${ZDOTDIR}" + ZSHU[d_cache]="${ZDOTDIR}/.cache/zsh" + ZSHU[d_conf]="${ZDOTDIR}/.config/zsh" + + ZSHU[d_var]="${ZSHU[d_conf]}/var" + + ZSHU[d_bin]="${ZDOTDIR}/.config/dotfiles/bin/" + + for i ( d_zdot d_cache d_conf d_bin d_var ) ; do + d=${ZSHU[$i]} + [ -d "$d" ] || mkdir -p "$d" + done ; unset i d + + ## early escape + unsetopt GLOBAL_RCS + + ## safety measure: + ## redirect all following activity within ZDOTDIR to cache + ## (probably) these files are safe to remove + ZDOTDIR="${ZSHU[d_cache]}" + rm -f "${ZDOTDIR}/.zshrc" "${ZDOTDIR}/.zlogin" + + ## cleanup: start from scratch + for i ( a s f d ) ; do unhash -$i -m '*' ; done ; unset i + + ## set default umask + umask 0022 + + zshu_parts=( env opt lib rc alias local ) + + for n ( $zshu_parts ) ; do + f="${ZSHU[d_conf]}/$n.zsh" + [ -s "$f" ] && source "$f" + done ; unset n f + + for n ( $zshu_parts ) ; do + d="${ZSHU[d_conf]}/$n" + [ -d "$d" ] || continue + for i ( $d/*.zsh(N.r) ) ; do + source "$i" + done ; unset i + done ; unset n d + + unset zshu_parts + + ZSHU[t_end]=${(%):-%D{%s.%6.}} + + ZSHU[t_load]=$(( ZSHU[t_end] - ZSHU[t_begin] )) + ZSHU[t_load]=${ZSHU[t_load]:0:6} + + unset "ZSHU[t_begin]" "ZSHU[t_end]" +fi diff --git a/.zshrc b/.zshrc new file mode 100644 index 0000000..1a90fdb --- /dev/null +++ b/.zshrc @@ -0,0 +1,2 @@ +#!/bin/zsh +## this file is NOT used at all - job is already done by .zshenv