mirror of
https://github.com/Matir/skel.git
synced 2026-07-24 21:26:57 -07:00
Compare commits
4 Commits
9770514d6a
...
f4bb5108ab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4bb5108ab | ||
|
|
5eac8826da | ||
|
|
b1d625d3c5 | ||
|
|
5a7d9cf060 |
63
dotfiles/commonrc.sh
Normal file
63
dotfiles/commonrc.sh
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
|
||||||
|
# common functions for use in shell scripts
|
||||||
|
|
||||||
|
find_first() {
|
||||||
|
while [ "$#" -gt 0 ]; do
|
||||||
|
if test -e "${1}" ; then
|
||||||
|
echo "${1}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
have_command() {
|
||||||
|
command -v "$1" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper function: Returns 0 if the directory is in PATH, 1 otherwise
|
||||||
|
path_contains() {
|
||||||
|
case ":${PATH}:" in
|
||||||
|
*:"$1":*) return 0 ;;
|
||||||
|
*) return 1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Prepend a directory to PATH if it's not already there
|
||||||
|
path_prepend() {
|
||||||
|
if [ -d "$1" ] && ! path_contains "$1"; then
|
||||||
|
PATH="$1:${PATH}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Append a directory to PATH if it's not already there
|
||||||
|
path_append() {
|
||||||
|
if [ -d "$1" ] && ! path_contains "$1"; then
|
||||||
|
PATH="${PATH}:$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
source_first_existing() {
|
||||||
|
_sfe_script="$(find_first "$@")"
|
||||||
|
_sfe_status=$?
|
||||||
|
|
||||||
|
if [ "$_sfe_status" -eq 0 ]; then
|
||||||
|
. "$_sfe_script"
|
||||||
|
# Clean up our temporary variables before returning success
|
||||||
|
unset -v _sfe_script _sfe_status
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clean up our temporary variables before returning failure
|
||||||
|
unset -v _sfe_script _sfe_status
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
source_if_existing() {
|
||||||
|
if [ -f "$1" ]; then
|
||||||
|
. "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
@@ -59,6 +59,8 @@ DIRSTACKSIZE=16
|
|||||||
|
|
||||||
export OS="$(uname 2>/dev/null || echo "Unknown")"
|
export OS="$(uname 2>/dev/null || echo "Unknown")"
|
||||||
|
|
||||||
|
source ~/.commonrc.sh
|
||||||
|
|
||||||
# Set terminal title
|
# Set terminal title
|
||||||
case $TERM in
|
case $TERM in
|
||||||
# Only set the title for terminals that are likely to support it
|
# Only set the title for terminals that are likely to support it
|
||||||
@@ -163,31 +165,9 @@ bindkey '^r' history-incremental-search-backward
|
|||||||
# delete really deletes
|
# delete really deletes
|
||||||
bindkey "^[[3~" delete-char
|
bindkey "^[[3~" delete-char
|
||||||
|
|
||||||
source_if_existing() {
|
|
||||||
[[ -f "${1}" ]] && source "${1}"
|
|
||||||
}
|
|
||||||
|
|
||||||
source_first_existing() {
|
path_prepend "${HOME}/.npm-packages/bin"
|
||||||
while (($#)); do
|
path_prepend "${HOME}/.local/bin"
|
||||||
if test -e "${1}" ; then
|
|
||||||
source "${1}"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
have_command() {
|
|
||||||
command -v "${1}" &>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
if test -d ${HOME}/.local/bin ; then
|
|
||||||
export PATH="${HOME}/.local/bin:${PATH}"
|
|
||||||
fi
|
|
||||||
if test -d ${HOME}/.npm-packages/bin ; then
|
|
||||||
export PATH="${HOME}/.npm-packages/bin:${PATH}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Source extras and aliases if interactive
|
# Source extras and aliases if interactive
|
||||||
if [[ $- == *i* ]] ; then
|
if [[ $- == *i* ]] ; then
|
||||||
@@ -273,8 +253,7 @@ if [[ $- == *i* ]] ; then
|
|||||||
if command -v direnv >/dev/null 2>&1 ; then
|
if command -v direnv >/dev/null 2>&1 ; then
|
||||||
eval "$(direnv hook zsh)"
|
eval "$(direnv hook zsh)"
|
||||||
fi
|
fi
|
||||||
test -e "${HOME}/.iterm2_shell_integration.zsh" && \
|
source_if_existing "${HOME}/.iterm2_shell_integration.zsh"
|
||||||
source "${HOME}/.iterm2_shell_integration.zsh" || true
|
|
||||||
# mise, if installed
|
# mise, if installed
|
||||||
command -v mise >/dev/null 2>&1 && eval "$(mise activate zsh)"
|
command -v mise >/dev/null 2>&1 && eval "$(mise activate zsh)"
|
||||||
|
|
||||||
@@ -289,11 +268,11 @@ if [ -x /usr/bin/ack-grep ] ; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# I want these first always
|
# I want these first always
|
||||||
PATH="${HOME}/bin:${PATH}"
|
path_prepend "${HOME}/bin"
|
||||||
if [[ "$(uname)" == "Darwin" ]]; then
|
if [[ "$(uname)" == "Darwin" ]]; then
|
||||||
PATH="${HOME}/bin/macos:${PATH}"
|
path_prepend "${HOME}/bin/macos"
|
||||||
elif [[ "$(uname)" == "Linux" ]]; then
|
elif [[ "$(uname)" == "Linux" ]]; then
|
||||||
PATH="${HOME}/bin/linux:${PATH}"
|
path_prepend "${HOME}/bin/linux"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load any local settings
|
# Load any local settings
|
||||||
|
|||||||
@@ -8,25 +8,12 @@ function dumpenv {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if test -x "/sbin/starship" ; then
|
_STARSHIP_PATH="$(find_first "$(command -v starship)" /sbin/starship "${HOME}/tools/starship/starship" "${HOME}/.local/bin/starship" /usr/local/bin/starship)"
|
||||||
_STARSHIP_PATH="/sbin/starship"
|
if test -n "$_STARSHIP_PATH" ; then
|
||||||
function starship_prompt {
|
function starship_prompt {
|
||||||
eval "$(/sbin/starship init zsh)"
|
eval "$($_STARSHIP_PATH init zsh)"
|
||||||
}
|
|
||||||
elif test -x "${HOME}/tools/starship/starship" ; then
|
|
||||||
_STARSHIP_PATH="${HOME}/tools/starship/starship"
|
|
||||||
function starship_prompt {
|
|
||||||
eval "$($HOME/tools/starship/starship init zsh)"
|
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
if test -f ${HOME}/.zprompt ; then
|
|
||||||
if test "$(cat ${HOME}/.zprompt)" = "starship" ; then
|
|
||||||
if test -n "${_STARSHIP_PATH:-}" ; then
|
|
||||||
eval "$(${_STARSHIP_PATH} init zsh)"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
unset _STARSHIP_PATH
|
|
||||||
|
|
||||||
function hashall {
|
function hashall {
|
||||||
tee >(md5sum) | tee >(sha1sum) | sha256sum
|
tee >(md5sum) | tee >(sha1sum) | sha256sum
|
||||||
|
|||||||
95
install.sh
95
install.sh
@@ -7,14 +7,44 @@ set -o errexit
|
|||||||
set -o shwordsplit 2>/dev/null || true # Make zsh behave like bash
|
set -o shwordsplit 2>/dev/null || true # Make zsh behave like bash
|
||||||
|
|
||||||
HOME=${HOME:-$(cd ~ && pwd)}
|
HOME=${HOME:-$(cd ~ && pwd)}
|
||||||
|
LOCAL_BIN="${HOME}/.local/bin"
|
||||||
|
STARSHIP_INSTALL_HASH="52c64f14a558034ebeb1907ea9364e802b32474576fd3e68265f73bc33cc8fbb"
|
||||||
|
|
||||||
|
# 1. Get the raw script path (handles Bash vs Zsh)
|
||||||
|
TARGET="${BASH_SOURCE[0]}"
|
||||||
|
|
||||||
|
# 2. Loop to resolve symlinks completely
|
||||||
|
while [ -L "$TARGET" ]; do
|
||||||
|
DIR=$(cd -P "$(dirname -- "$TARGET")" &>/dev/null && pwd)
|
||||||
|
TARGET=$(readlink "$TARGET")
|
||||||
|
# If $TARGET is a relative symlink, resolve it relative to the symlink's directory
|
||||||
|
[[ $TARGET != /* ]] && TARGET="$DIR/$TARGET"
|
||||||
|
done
|
||||||
|
|
||||||
|
# 3. Get the final absolute directory
|
||||||
|
SCRIPT_DIR="$(cd -P "$(dirname -- "$TARGET")" &>/dev/null && pwd)"
|
||||||
|
|
||||||
have_command() {
|
have_command() {
|
||||||
command -v "${1}" >/dev/null 2>&1
|
command -v "${1}" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sudo_group() {
|
||||||
|
if [[ "$(id -u)" -eq 0 ]] ; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
have_command sudo && ( id -Gn | grep -q '\bsudo\b' )
|
||||||
|
}
|
||||||
|
|
||||||
|
maybe_sudo() {
|
||||||
|
if [[ "$(id -u)" -eq 0 ]] ; then
|
||||||
|
"$@"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if ! have_command sudo ; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
sudo "$@"
|
||||||
|
}
|
||||||
|
|
||||||
link_directory_contents() {
|
link_directory_contents() {
|
||||||
local SRCDIR="${1}"
|
local SRCDIR="${1}"
|
||||||
@@ -176,6 +206,41 @@ install_dotfiles() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_starship() {
|
||||||
|
if have_command starship ; then return 0 ; fi
|
||||||
|
if have_command apt-get && sudo_group ; then
|
||||||
|
if maybe_sudo apt-get install -qy starship ; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
echo "apt-get install starship failed, installing locally" >&2
|
||||||
|
fi
|
||||||
|
local tmpd
|
||||||
|
tmpd="$(mktemp -d tmp.starship.XXXXXX)"
|
||||||
|
local install_path="${tmpd}/install.sh"
|
||||||
|
if have_command curl ; then
|
||||||
|
curl -sSL --show-error -o "${install_path}" https://starship.rs/install.sh
|
||||||
|
elif have_command wget ; then
|
||||||
|
wget -q -O "${install_path}" --https-only https://starship.rs/install.sh
|
||||||
|
else
|
||||||
|
echo "No curl or wget available!!" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
local dl_hash
|
||||||
|
dl_hash="$(sha256sum "${install_path}" | awk '{print $1}')"
|
||||||
|
if [[ "$dl_hash" != "${STARSHIP_INSTALL_HASH}" ]] ; then
|
||||||
|
echo "Hash check failed!!" >&2
|
||||||
|
echo "Expected: ${STARSHIP_INSTALL_HASH}, got ${dl_hash} on ${install_path}" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if sudo_group ; then
|
||||||
|
if maybe_sudo sh "${install_path}" ; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
echo "root installation failed, falling back to user-local" >&2
|
||||||
|
fi
|
||||||
|
sh "${install_path}" -b "${LOCAL_BIN}"
|
||||||
|
}
|
||||||
|
|
||||||
install_main() {
|
install_main() {
|
||||||
if [[ -d "${BASEDIR}/.git" ]] && have_command git ; then
|
if [[ -d "${BASEDIR}/.git" ]] && have_command git ; then
|
||||||
if [[ -z "$(git -C "${BASEDIR}" status --porcelain)" ]]; then
|
if [[ -z "$(git -C "${BASEDIR}" status --porcelain)" ]]; then
|
||||||
@@ -185,6 +250,8 @@ install_main() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
[[ "$MINIMAL" = 1 ]] || {
|
[[ "$MINIMAL" = 1 ]] || {
|
||||||
|
mkdir -p "${LOCAL_BIN}"
|
||||||
|
install_starship
|
||||||
|
|
||||||
# Install vim-plug if not already present
|
# Install vim-plug if not already present
|
||||||
local VIM_PLUG_URL="https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
|
local VIM_PLUG_URL="https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
|
||||||
@@ -199,22 +266,22 @@ install_main() {
|
|||||||
else
|
else
|
||||||
echo "Error: curl not found. Cannot install vim-plug." >&2
|
echo "Error: curl not found. Cannot install vim-plug." >&2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install TPM (Tmux Plugin Manager) if not already present
|
# Install TPM (Tmux Plugin Manager) if not already present
|
||||||
local TPM_DIR="${HOME}/.tmux/plugins/tpm"
|
local TPM_DIR="${HOME}/.tmux/plugins/tpm"
|
||||||
local TPM_REPO="https://github.com/tmux-plugins/tpm"
|
local TPM_REPO="https://github.com/tmux-plugins/tpm"
|
||||||
|
|
||||||
if [[ ! -d "${TPM_DIR}" ]]; then
|
if [[ ! -d "${TPM_DIR}" ]]; then
|
||||||
verbose "Installing TPM (Tmux Plugin Manager)..."
|
verbose "Installing TPM (Tmux Plugin Manager)..."
|
||||||
if have_command git; then
|
if have_command git; then
|
||||||
git clone --depth 1 "${TPM_REPO}" "${TPM_DIR}"
|
git clone --depth 1 "${TPM_REPO}" "${TPM_DIR}"
|
||||||
else
|
else
|
||||||
echo "Error: git not found. Cannot install TPM." >&2
|
echo "Error: git not found. Cannot install TPM." >&2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# try to update dotfile overlays
|
# try to update dotfile overlays
|
||||||
if [[ -d "${BASEDIR}/dotfile_overlays" ]] ; then
|
if [[ -d "${BASEDIR}/dotfile_overlays" ]] ; then
|
||||||
for dotfiledir in "${BASEDIR}/dotfile_overlays/"* ; do
|
for dotfiledir in "${BASEDIR}/dotfile_overlays/"* ; do
|
||||||
if [[ -d "${dotfiledir}/.git" ]] ; then
|
if [[ -d "${dotfiledir}/.git" ]] ; then
|
||||||
@@ -243,7 +310,7 @@ read_saved_prefs
|
|||||||
|
|
||||||
# Defaults if not passed in or saved.
|
# Defaults if not passed in or saved.
|
||||||
# TODO: use flags instead of environment variables.
|
# TODO: use flags instead of environment variables.
|
||||||
: ${BASEDIR:=$HOME/.skel}
|
: ${BASEDIR:=${SCRIPT_DIR}}
|
||||||
: ${MINIMAL:=0}
|
: ${MINIMAL:=0}
|
||||||
: ${INSTALL_KEYS:=1}
|
: ${INSTALL_KEYS:=1}
|
||||||
: ${TRUST_ALL_KEYS:=0}
|
: ${TRUST_ALL_KEYS:=0}
|
||||||
|
|||||||
Reference in New Issue
Block a user