prepare for symclone.

From now on, _src.posix will be the single source of truth.
And _home(.*) will symlink into it.
This commit is contained in:
Lockszmith (@VAST) 2025-02-20 23:34:24 -05:00
parent 5e26df3f9b
commit 44b03e8724
47 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,20 @@
#! /usr/bin/env bash
GH_PROJECT="${1}"
GH_DL_TAG="${2:-latest}"
GH_FILTER="${3:-deb}"
if [[ ! "$GH_FILTER" =~ '(' ]]; then
GH_FILTER="contains(\"${GH_FILTER}\")"
fi
SRC_URL=https://api.github.com/repos/${GH_PROJECT}/releases/${GH_DL_TAG}
DL_URL=$( \
curl -sL curl ${SRC_URL} \
| jq -r " \
.assets[] \
| select(.browser_download_url \
| ${GH_FILTER} ) \
| .browser_download_url \
")
[[ -n "$DL_URL" ]] \
&& printf "%s\n" $DL_URL \
|| return 1 2>/dev/null || exit 1

View file

@ -0,0 +1,38 @@
#! /usr/bin/env bash
# Helper function
is_sourced() {
if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file:*) return 0;; esac
else # Add additional POSIX-compatible shell names here, if needed.
case ${0##*/} in dash|-dash|bash|-bash|ksh|-ksh|sh|-sh) return 0;; esac
fi
return 1; # NOT sourced.
}
BASE_0=${BASE_0:-$0}
BASE_SHELL=$(basename "$SHELL")
if is_sourced; then
starship() {
if [[ ! -x "$HOME/bin/starship" ]]; then
curl -sS https://starship.rs/install.sh | FORCE=1 BIN_DIR="$HOME/bin" sh > /dev/null
fi
"$HOME/bin/starship" "${@}"
}
# shellcheck disable=SC1090
. <( starship init "$BASE_SHELL" ) 2> /dev/null
. <( starship completions ${BASE_SHELL} ) 2> /dev/null
elif [[ "$1" == '-' ]]; then
echo "BASE_0=${BASE_0}"
cat "${0}"
else
SCRIPT_NAME="$BASE_0"
printf '%s\n' \
"It seems $SCRIPT_NAME was invoked as a script. It should be sourced instead." \
'The easiest way is to call it like this:' \
" $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \
''
fi

View file

@ -0,0 +1,40 @@
#! /usr/bin/env bash
# Helper function
is_sourced() {
if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file:*) return 0;; esac
else # Add additional POSIX-compatible shell names here, if needed.
case ${0##*/} in dash|-dash|bash|-bash|ksh|-ksh|sh|-sh) return 0;; esac
fi
return 1; # NOT sourced.
}
BASE_0=${BASE_0:-$0}
BASE_SHELL=$(basename "$SHELL")
if is_sourced; then
webi() {
if [[ ! -x "${HOME}/.local/bin/webi" ]]; then
printf '%s\n' \
"webi isn't installed, install by running:" \
" curl -sS https://webi.sh/webi | sh"
return
fi
${HOME}/.local/bin/webi "${@}"
}
if is_cmd webi; then
webi
fi
elif [[ "$1" == '-' ]]; then
cat "${BASH_SOURCE[0]}"
else
SCRIPT_NAME="$BASE_0"
printf '%s\n' \
"It seems $SCRIPT_NAME was invoked as a script. It should be sourced instead." \
'The easiest way is to call it like this:' \
" $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \
''
fi

View file

@ -0,0 +1,79 @@
#! /usr/bin/env bash
# Helper function
is_sourced() {
if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file:*) return 0;; esac
else # Add additional POSIX-compatible shell names here, if needed.
case ${0##*/} in dash|-dash|bash|-bash|ksh|-ksh|sh|-sh) return 0;; esac
fi
return 1; # NOT sourced.
}
BASE_0=${BASE_0:-$0}
BASE_SHELL=$(basename "$SHELL")
if is_sourced; then
zellij-cleanup() {
env which zellij > /dev/null && env which zellij | grep -E "^$HOME" | ${SUDO:-} xargs -tr rm
[[ -d "$HOME/.cache/zellij" ]] && echo "$HOME/.cache/zellij" | ${SUDO:-} xargs -tr rm -fR
find /tmp -maxdepth 1 -mindepth 1 -type d -name 'zellij*' -print0 | ${SUDO:-} xargs -r0t rm -fR
if [[ -d "$HOME/.cache/zellij" ]]; then
printf 'Zellij cleanup failed to remove the cache directory, you might still have a zellij session active.\n'
else
printf 'Zellij has been cleaned up, you can now reinstall it.\n'
unset zellij-cleanup
fi
}
refresh-zellij() {
${SET:-:} -x
if [ -z "$(env which zellij)" ] && ! [ -x ~/.local/bin/zellij ]; then
if [[ ! -r /tmp/zellij/bootstrap/zellij ]]; then
printf "Grabbing zellij from the web!\n"
bash <(curl -sL zellij.dev/launch) "--help" > /dev/null 2>&1 || true
fi
if [[ -r /tmp/zellij/bootstrap/zellij ]]; then
mv /tmp/zellij/bootstrap/zellij ~/.local/bin/zellij
rm -fR /tmp/zellij
fi
fi
refresh-zellij() { :; }
}
zellij() {
refresh-zellij
if [[ $# -eq 0 ]]; then
env zellij attach -c $USER@$(hostname)
else
env zellij "${@}"
fi
}
zellij-completion() {
if [[ "${BASE_SHELL}" == "zsh" ]]; then
type _zellij > /dev/null \
|| . <( env zellij setup --generate-completion zsh | sed -Ee 's/^(_(zellij) ).*/compdef \1\2/' )
else
. <( env zellij setup --generate-completion "$BASE_SHELL" )
fi
}
${SET:-:} -x
if [[ -n "$(env which zellij)" ]]; then
zellij-completion
fi
${SET:-:} -x
# Was needed when zsh would load
# . <( zellij setup --generate-completion "$BASE_SHELL" | sed -ne '/^function/,$p' )
if [[ -z "$ZELLIJ_SESSION_NAME" ]]; then
zellij attach -c $USER@$(hostname)
fi
elif [[ "$1" == '-' ]]; then
cat "${BASH_SOURCE[0]}"
else
SCRIPT_NAME="$BASE_0"
printf '%s\n' \
"It seems $SCRIPT_NAME was invoked as a script. It should be sourced instead." \
'The easiest way is to call it like this:' \
" $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \
''
fi

View file

@ -0,0 +1,123 @@
#! /usr/bin/env bash
# shellcheck disable=SC2034,SC1090
# SC2034 variables appear unsued. export if used externally
# - uneeded, as this checked whether script is sourced
# SC1090 Can't follow non-constant source
# Use basename instead of ${0:##*/} to be POSIX compliant
# Some shells return -<name> in $0 when sourced, ${0#-} drops that initial dash
BASE_0=${BASE_0:-$(basename -- "${0#-}")}
SCRIPT_DIR=${SCRIPT_DIR:-"$( cd -- "$( dirname -- "$0" )" &> /dev/null && pwd )"}
BASE_SHELL=$(basename "$SHELL")
# Helper function
is_sourced() {
DBG_="$(
printf '\n\t\t%-12s%s' '$0:' "$0" BASE_0: "$BASE_0" BASE_SHELL: "$BASE_SHELL"
)"
if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file:*) return 0;; esac
else
case "$(basename -- "${0}")" in $BASE_SHELL|-$BASE_SHELL) return 0;; esac
fi
return 1; # NOT sourced.
}
if [[ "$1" == '-' ]]; then
printf 'BASE_0="%s"\nSCRIPT_DIR=%s\n' "${BASE_0}" "${SCRIPT_DIR}"
cat "${BASH_SOURCE[0]}"
elif is_sourced; then
# This part is sourced, and might run in a non-bash shell
DBG_="Is Sourced"
USER_HOME=$HOME
[[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")"
[[ -n "$KUBECONFIG" && -r "$KUBECONFIG" ]] || unset KUBECONFIG
[[ ! -r "$HOME/.kube/config" ]] \
|| export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}"
if [[ -z "$KUBECONFIG" && -z "$FIX_KUBECTL_RECALL" ]]; then
(unset kubectl 2>/dev/null) || (unalias kubectl 2>/dev/null) || true
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
fi
(unset kubectl-fix 2> /dev/null) || true
DBG_="Check if k3s exists, but kubectl isn't available"
if (type 'k3s' >/dev/null 2>&1) && ! (type 'kubectl' >/dev/null 2>&1); then
DBG_="Define kubectl"
if [[ -r "${KUBECONFIG}" ]]; then
kubectl() { k3s kubectl "${@}"; }
elif [[ -n "${KUBECONFIG}" && -e "${KUBECONFIG}" ]]; then
eval "
kubectl-fix() {
mkdir \"$HOME/.kube\" -p
if [[ -e \"\${KUBECONFIG}\" && ! -r \"$HOME/.kube/config\" ]]; then
sudo install --mod 600 --owner \"$USER\" \"\${KUBECONFIG}\" \"$HOME/.kube/config\"
unset KUBECONFIG
fi
FIX_KUBECTL_RECALL=1 . \"${SCRIPT_DIR}/${BASE_0}\"
}"
printf '%s\n' \
"KUBECONFIG[${KUBECONFIG}] exsits, but is unreadable." \
'Run kubectl-fix (which will invoke sudo) to fix'
fi
fi
if (type 'kubectl' >/dev/null 2>&1); then
. <( kubectl completion "${BASE_SHELL}" )
if (type 'kubectl-cnpg' >/dev/null 2>&1 ); then
. <( kubectl cnpg completion "${BASE_SHELL}" )
fi
if ! (type 'kubectl-cnpg' >/dev/null 2>&1) || [[ -n "$UPGRADE" ]]; then
DL_VER=1.22.0
GH_URL=https://github.com/cloudnative-pg/cloudnative-pg
DL_FILE="kubectl-cnpg_${DL_VER}_linux_x86_64.deb"
URL=${GH_URL}/releases/download/v${DL_VER}/${DL_FILE}
printf '%s\n' \
'To download and install cnpg kubectl plugin, run:' \
" curl -sSLO ${URL}" \
" sudo dpkg -i $DL_FILE"
fi
if ! (type 'kubetui' >/dev/null 2>&1) || [[ -n "$UPGRADE" ]]; then
DL_VER=1.5.0
GH_URL=https://github.com/sarub0b0/kubetui
DL_FILE=kubetui-x86_64-unknown-linux-musl-rustls
URL=${GH_URL}/releases/download/v${DL_VER}/${DL_FILE}
printf '%s\n' \
'To download and install kubetui, run:' \
" curl -sSL ${URL} > ~/bin/kubetui" \
" chmod +x ~/bin/kubetui"
fi
if ! (type 'k9s' >/dev/null 2>&1) || [[ -n "$UPGRADE" ]]; then
printf '%s\n' \
'To download and install k9s, run:' \
" curl -sS https://webinstall.dev/k9s | bash"
fi
if (type 'k3s' >/dev/null 2>&1 ); then
. <( k3s completion "${SHELL##*/}" )
fi
if (type 'helm' >/dev/null 2>&1); then
. <( helm completion "${SHELL##*/}" 2>/dev/null )
fi
kg() {
kubectl get "${NS:+--namespace=}${NS:---all-namespaces}" "${@:-pods}" | { sed -u 1q; sort; }
}
fi
else
SCRIPT_NAME="$BASE_0"
printf '%s\n' \
"It seems $SCRIPT_NAME was invoked as a script. It should be sourced instead." \
'The easiest way is to call it like this:' \
" $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \
''
fi

View file

@ -0,0 +1,32 @@
#! /usr/bin/env bash
set -e
BASE_0=${BASE_0:-$0}
BASE_SHELL=$(basename "$SHELL")
#! /usr/bin/env bash
_update-atuin() { (
set -e
local LatestURL="$(
get-github-release.sh \
atuinsh/atuin \
latest atuin-x86_64-unknown-linux-musl.tar.gz \
| grep -E 'tar\.gz$'
)"
local dlPath="$(mktemp --directory --suffix atuin)"
local appPath="$HOME/.local/bin"
printf 'Downloading from %s... ' "${LatestURL#*/download/}"
curl -sLO --output-dir "$dlPath" "$LatestURL" && printf 'Done'
printf '\n'
( cd "$dlPath"; curl -sL "$LatestURL.sha256" | sha256sum --check )
( cd "$appPath"; tar zxf "$dlPath"/*.tar.gz --strip-components=1 --no-anchored 'atuin' )
rm -R "$dlPath"
printf '%s\n' \
'atuin binary installed, please restart you shell'
); }
_update-atuin "${@}"

View file

@ -0,0 +1,57 @@
#! /usr/bin/env bash
set -e
BASE_0=${BASE_0:-$0}
BASE_SHELL=$(basename "$SHELL")
_update-nvim() {
local LatestURL="$(get-github-release.sh \
neovim/neovim latest appimage \
| grep appimage\$
)"
local appDir="${HOME}/.local/bin"
if [ "$USER" = "root" ]; then
appDir="${HOME}/usr-local-bin"
while umount --types overlay /usr/local/bin 2>/dev/null; do
:
done
mkdir -pm 755 "$appDir" \
&& mount -t overlay overlay -o "lowerdir=$appDir:/usr/local/bin" /usr/local/bin
update-alternatives --remove vim.tiny /usr/bin/vim.tiny
fi
local appPath="${appDir}/nvim.AppImage"
rm "${appDir}/"{nvim.AppImage,nvim,vi,vim,vim.tiny,vimdiff} 2>/dev/null || true
printf 'Downloading from %s... ' "${LatestURL#*/download/}"
curl -sLo "$appPath" "$LatestURL" && printf 'Done'
printf '\n'
chmod +x "$appPath"
ln -rs "$appPath" "${appDir}/nvim"
ln -rs "$appPath" "${appDir}/vi"
ln -rs "$appPath" "${appDir}/vim"
ln -rs "$appPath" "${appDir}/vim.tiny"
ln -rs "$appPath" "${appDir}/vimdiff"
if [ "$USER" = "root" ]; then
update-alternatives --install /usr/bin/editor editor "$appPath" 110
update-alternatives --install /usr/bin/edit edit "$appPath" 110
update-alternatives --install /usr/bin/ex ex "$appPath" 110
update-alternatives --install /usr/bin/vi vi "$appPath" 110
update-alternatives --install /usr/bin/view view "$appPath" 110
update-alternatives --install /usr/bin/vim vim "$appPath" 110
update-alternatives --install /usr/bin/vimdiff vimdiff "$appPath" 110
update-alternatives --set editor "$appPath"
update-alternatives --set edit "$appPath"
update-alternatives --set ex "$appPath"
update-alternatives --set vi "$appPath"
update-alternatives --set view "$appPath"
update-alternatives --set vim "$appPath"
update-alternatives --set vimdiff "$appPath"
fi
}
_update-nvim "${@}"

View file

@ -0,0 +1 @@
nvim.AppImage

View file

@ -0,0 +1 @@
nvim

View file

@ -0,0 +1 @@
nvim

View file

@ -0,0 +1 @@
nvim

View file

@ -0,0 +1 @@
nvim