zsh: update
PS: zprof rocks!
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
#!/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 data>
|
||||
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
|
||||
## </test data>
|
||||
|
||||
__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
|
@@ -29,12 +29,12 @@ z-git-test() {
|
||||
}
|
||||
|
||||
__z_git_pwd() {
|
||||
local x
|
||||
|
||||
unset 'ZSHU_PS[git_ref]' 'ZSHU_PS[git_changes]' 'ZSHU_PS[git_tag]' 'ZSHU_GIT[path_root]' 'ZSHU_GIT[path_mid]' 'ZSHU_GIT[path_last]' 'ZSHU_GIT[commit]' 'ZSHU_GIT[detached]' 'ZSHU_GIT[ref]' 'ZSHU_GIT[remote]' 'ZSHU_GIT[tag]' 'ZSHU_GIT[ref_behind]' 'ZSHU_GIT[ref_ahead]' 'ZSHU_GIT[ref_changes]'
|
||||
|
||||
unset 'ZSHU_PS[git_ref]' 'ZSHU_PS[git_changes]' 'ZSHU_PS[git_tag]'
|
||||
ZSHU_GIT=()
|
||||
z-git-test || return
|
||||
|
||||
|
||||
local x
|
||||
x=$(__z_git rev-parse --short HEAD 2>/dev/null)
|
||||
[ -n "$x" ] || return
|
||||
ZSHU_GIT[commit]=$x
|
||||
|
@@ -4,25 +4,20 @@ typeset -Uga ZSHU_PARENTS_PID
|
||||
typeset -ga ZSHU_PARENTS_NAME
|
||||
|
||||
function {
|
||||
local i c
|
||||
local i c g
|
||||
|
||||
i=$$ ; while : ; do
|
||||
i=$(ps -o ppid= -p $i 2>/dev/null) || :
|
||||
i=${i//[^0-9]}
|
||||
[[ "$i" =~ '^[1-9][0-9]*$' ]] || break
|
||||
i=${PPID}
|
||||
while : ; do
|
||||
[ -n "$i" ] || break
|
||||
## don't deal with PID1
|
||||
[ "$i" = 1 ] && continue
|
||||
[ "$i" = 1 ] && break
|
||||
|
||||
ZSHU_PARENTS_PID+=( $i )
|
||||
read -r i c g <<< $(ps -o 'ppid=,comm=' -p "$i" 2>/dev/null)
|
||||
[ -n "$c" ] && ZSHU_PARENTS_NAME+=( "${c:t}" )
|
||||
done
|
||||
|
||||
for i ( ${ZSHU_PARENTS_PID} ) ; do
|
||||
c=$(ps -o comm= -p $i 2>/dev/null) || :
|
||||
[ -n "$c" ] || continue
|
||||
ZSHU_PARENTS_NAME+=( "${c:t}" )
|
||||
done
|
||||
|
||||
typeset -r ZSHU_PARENTS_PID
|
||||
typeset -r ZSHU_PARENTS_NAME
|
||||
typeset -r ZSHU_PARENTS_PID ZSHU_PARENTS_NAME
|
||||
}
|
||||
|
||||
typeset -gA ZSHU_RUN
|
||||
|
@@ -1,15 +1,17 @@
|
||||
#!/bin/zsh
|
||||
|
||||
say_my_name() {
|
||||
set -a
|
||||
GIT_COMMITTER_NAME="$1"
|
||||
GIT_AUTHOR_NAME="$1"
|
||||
DEBFULLNAME="$1"
|
||||
export GIT_COMMITTER_NAME GIT_AUTHOR_NAME DEBFULLNAME
|
||||
set +a
|
||||
}
|
||||
|
||||
say_my_email() {
|
||||
set -a
|
||||
GIT_COMMITTER_EMAIL="$1"
|
||||
GIT_AUTHOR_EMAIL="$1"
|
||||
DEBEMAIL="$1"
|
||||
export GIT_COMMITTER_EMAIL GIT_AUTHOR_EMAIL DEBEMAIL
|
||||
set +a
|
||||
}
|
||||
|
@@ -1,16 +1,31 @@
|
||||
#!/bin/zsh
|
||||
|
||||
dotfiles-update() {
|
||||
"${ZSHU[d_zdot]}/.config/dotfiles/install.sh"
|
||||
"${ZSHU[d_dotfiles]}/install.sh" "$@"
|
||||
}
|
||||
|
||||
dotfiles-git() { (
|
||||
cd "${ZSHU[d_zdot]}/"
|
||||
export GIT_DIR="${ZSHU[d_zdot]}/.config/dotfiles/repo.git"
|
||||
export GIT_WORK_TREE="${ZSHU[d_zdot]}"
|
||||
set -a
|
||||
GIT_DIR="${ZSHU[d_dotfiles]}/repo.git"
|
||||
GIT_WORK_TREE="${ZSHU[d_zdot]}"
|
||||
set +a
|
||||
zsh -i
|
||||
) }
|
||||
|
||||
dotfiles-gen-gitignore() {
|
||||
local x='.config/dotfiles/gen-gitignore.sh'
|
||||
[ -x "$x" ] || {
|
||||
echo "${x:t} is somewhere else" >&2
|
||||
return 1
|
||||
}
|
||||
if [ -d .config/dotfiles/repo.git ] ; then
|
||||
echo "NOT going to change dotfiles installation" >&2
|
||||
return 1
|
||||
fi
|
||||
"$x" "$@"
|
||||
}
|
||||
|
||||
z-zwc-gen() {
|
||||
local i
|
||||
for i ( "${ZSHU[d_conf]}"/**/*.zsh(N.r) ) ; do
|
||||
|
@@ -1,205 +0,0 @@
|
||||
#!/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
|
||||
}
|
Reference in New Issue
Block a user