feat(zsh): move configuration to zsh/
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
.cache
|
zsh/.cache
|
||||||
|
|||||||
+79
-52
@@ -9,7 +9,7 @@ SCRIPT_NAME="$(basename -- "$SCRIPT_FILE")"
|
|||||||
SCRIPT_DIR="$(dirname -- "$SCRIPT_FILE")"
|
SCRIPT_DIR="$(dirname -- "$SCRIPT_FILE")"
|
||||||
|
|
||||||
SOURCE_DIR="$SCRIPT_DIR"
|
SOURCE_DIR="$SCRIPT_DIR"
|
||||||
TARGET_DIR="$HOME"
|
DEST_DIR="$HOME"
|
||||||
|
|
||||||
PRINT_HELP=false
|
PRINT_HELP=false
|
||||||
REMOVE_EXISTING=false
|
REMOVE_EXISTING=false
|
||||||
@@ -39,8 +39,6 @@ SYMLINKS=(
|
|||||||
".Xresources"
|
".Xresources"
|
||||||
".xinitrc"
|
".xinitrc"
|
||||||
".xinit-scripts"
|
".xinit-scripts"
|
||||||
".zshrc"
|
|
||||||
".p10k.zsh"
|
|
||||||
".gtkrc-2.0"
|
".gtkrc-2.0"
|
||||||
".config/tmux"
|
".config/tmux"
|
||||||
".config/alacritty"
|
".config/alacritty"
|
||||||
@@ -57,6 +55,9 @@ SYMLINKS=(
|
|||||||
".local/share/fonts"
|
".local/share/fonts"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
typeset -A SYMLINK_MAP
|
||||||
|
SYMLINK_MAP[zsh/rc]=".zshrc"
|
||||||
|
|
||||||
error() {
|
error() {
|
||||||
msg="$1"
|
msg="$1"
|
||||||
ERROR=true
|
ERROR=true
|
||||||
@@ -71,62 +72,88 @@ check_packages_installed() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
create_symlinks() {
|
remove_symlink() {
|
||||||
|
local link src
|
||||||
|
link="${DEST_DIR}/$1"
|
||||||
|
|
||||||
|
if test -s "$link"; then
|
||||||
|
src="$(readlink -f -- "$link")"
|
||||||
|
echo "Removing symlink: $link -> $src"
|
||||||
|
rm "$link"
|
||||||
|
elif test -e "$link"; then
|
||||||
|
error "object to be removed is not a symlink:"
|
||||||
|
error "${link}: $(stat -c '%F' -- "$link")"
|
||||||
|
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_all_symlinks() {
|
||||||
for link in "${SYMLINKS[@]}"; do
|
for link in "${SYMLINKS[@]}"; do
|
||||||
SOURCE_PATH="${SOURCE_DIR}/$link"
|
remove_symlink "$link"
|
||||||
|
done
|
||||||
|
|
||||||
# Check source exists
|
for src dst in ${(kv)SYMLINK_MAP}; do
|
||||||
if ! test -e "$SOURCE_PATH"; then
|
remove_symlink "$dst"
|
||||||
error "the following source path does not exist:"
|
|
||||||
error "$SOURCE_PATH"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
TARGET_LINK="${TARGET_DIR}/$link"
|
|
||||||
TARGET_LINK_PARENT="$(dirname -- "$TARGET_LINK")"
|
|
||||||
|
|
||||||
# Create parent dirs if necessary
|
|
||||||
if ! test -d "$TARGET_LINK_PARENT"; then
|
|
||||||
echo "Creating $TARGET_LINK_PARENT"
|
|
||||||
mkdir -p "$TARGET_LINK_PARENT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if already exists as a symlink
|
|
||||||
if test -s "$TARGET_LINK"; then
|
|
||||||
if ! $IGNORE_EXISTING; then
|
|
||||||
error "target link already exists:"
|
|
||||||
error "$TARGET_LINK"
|
|
||||||
fi
|
|
||||||
continue
|
|
||||||
elif test -e "$TARGET_LINK"; then
|
|
||||||
error "target path already exists and is not a symlink:"
|
|
||||||
error "$TARGET_LINK"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create link
|
|
||||||
echo "Linking $SOURCE_PATH -> $TARGET_LINK"
|
|
||||||
ln -s "$SOURCE_PATH" "$TARGET_LINK"
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_existing() {
|
create_symlink() {
|
||||||
for link in "${SYMLINKS[@]}"; do
|
local src dst dst_parent
|
||||||
TARGET_LINK="${TARGET_DIR}/$link"
|
|
||||||
TARGET_LINK_PARENT="$(dirname -- "$TARGET_LINK")"
|
|
||||||
|
|
||||||
if test -s "$TARGET_LINK"; then\
|
if test -z "$1"; then
|
||||||
echo "Removing symlink $TARGET_LINK"
|
error "missing src argument:"
|
||||||
rm "$TARGET_LINK"
|
error "$0 $1 $2"
|
||||||
elif test -e "$TARGET_LINK"; then
|
return
|
||||||
error "target path already exists and is not a symlink:"
|
|
||||||
error "$TARGET_LINK"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test -z "$2"; then
|
||||||
|
error "missing dst argument:"
|
||||||
|
error "$0 $1 $2"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
src="${SCRIPT_DIR}/$1"
|
||||||
|
dst="${DEST_DIR}/$2"
|
||||||
|
dst_parent="$(dirname -- "$dst")"
|
||||||
|
|
||||||
|
if ! test -e "$src"; then
|
||||||
|
error "the following source path does not exist:"
|
||||||
|
error "$src"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! test -d "$dst_parent"; then
|
||||||
|
echo "Creating $dst_parent"
|
||||||
|
mkdir -p "$dst_parent"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -s "$dst"; then
|
||||||
|
if $IGNORE_EXISTING; then
|
||||||
|
remove_symlink "$2"
|
||||||
|
else
|
||||||
|
error "path already exists:"
|
||||||
|
error "$dst"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
elif test -e "$dst"; then
|
||||||
|
error "path already exists and is not a symlink:"
|
||||||
|
error "${dst}: $(stat -c '%F' -- "$dst")"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Creating link: $dst -> $src"
|
||||||
|
ln -s "$src" "$dst"
|
||||||
|
}
|
||||||
|
|
||||||
|
create_all_symlinks() {
|
||||||
|
for link in "${SYMLINKS[@]}"; do
|
||||||
|
create_symlink "$link" "$link"
|
||||||
done
|
done
|
||||||
|
|
||||||
if $ERROR; then
|
for src dst in ${(kv)SYMLINK_MAP}; do
|
||||||
exit 1
|
create_symlink "$src" "$dst"
|
||||||
fi
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
check_terminfo() {
|
check_terminfo() {
|
||||||
@@ -174,11 +201,11 @@ done
|
|||||||
if $PRINT_HELP; then
|
if $PRINT_HELP; then
|
||||||
print_help
|
print_help
|
||||||
elif $REMOVE_EXISTING; then
|
elif $REMOVE_EXISTING; then
|
||||||
remove_existing
|
remove_all_symlinks
|
||||||
else
|
else
|
||||||
check_terminfo
|
check_terminfo
|
||||||
check_packages_installed
|
check_packages_installed
|
||||||
create_symlinks
|
create_all_symlinks
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $ERROR; then
|
if $ERROR; then
|
||||||
|
|||||||
+6
-4
@@ -1,3 +1,4 @@
|
|||||||
|
# vim: set ft=zsh:
|
||||||
|
|
||||||
_here="$(dirname -- "$(readlink -f -- "${HOME}/.zshrc")")"
|
_here="$(dirname -- "$(readlink -f -- "${HOME}/.zshrc")")"
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ setopt INC_APPEND_HISTORY_TIME
|
|||||||
# Ref: https://zsh.sourceforge.io/Doc/Release/Parameters.html
|
# Ref: https://zsh.sourceforge.io/Doc/Release/Parameters.html
|
||||||
|
|
||||||
path=("${HOME}/.local/bin" "${path[@]}")
|
path=("${HOME}/.local/bin" "${path[@]}")
|
||||||
fpath=("${_here}/.zsh_functions" "${fpath[@]}")
|
fpath=("${_here}/functions" "${fpath[@]}")
|
||||||
export PATH
|
export PATH
|
||||||
export MAIL="/var/spool/mail/$USER"
|
export MAIL="/var/spool/mail/$USER"
|
||||||
export MAILCHECK=60
|
export MAILCHECK=60
|
||||||
@@ -54,8 +55,8 @@ if [[ ! -d "${_here}/.cache" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
_antidote="${_here}/.cache/.antidote"
|
_antidote="${_here}/.cache/.antidote"
|
||||||
_plugins="${_here}/.zsh_plugins.txt"
|
_plugins="${_here}/plugins"
|
||||||
_plugins_cache="${_here}/.cache/.zsh_plugins.zsh"
|
_plugins_cache="${_here}/.cache/plugins.zsh"
|
||||||
|
|
||||||
if [[ ! -d "$_antidote" ]]; then
|
if [[ ! -d "$_antidote" ]]; then
|
||||||
git clone --depth=1 https://github.com/mattmc3/antidote.git "$_antidote"
|
git clone --depth=1 https://github.com/mattmc3/antidote.git "$_antidote"
|
||||||
@@ -72,7 +73,7 @@ if [[ ! "${_plugins_cache}" -nt "${_plugins}" ]]; then
|
|||||||
antidote bundle <"${_plugins}" >"${_plugins_cache}"
|
antidote bundle <"${_plugins}" >"${_plugins_cache}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# shellcheck source=.cache/.zsh_plugins.zsh
|
# shellcheck source=zsh/.cache/plugins.zsh
|
||||||
source "${_plugins_cache}"
|
source "${_plugins_cache}"
|
||||||
|
|
||||||
unset _antidote _plugins _plugins_cache
|
unset _antidote _plugins _plugins_cache
|
||||||
@@ -132,6 +133,7 @@ function ssh_with_title() {
|
|||||||
###########
|
###########
|
||||||
# Aliases #
|
# Aliases #
|
||||||
###########
|
###########
|
||||||
|
# TODO: alias for safe rm and ask for replacing during mv/cp
|
||||||
|
|
||||||
alias ln='ln -fi'
|
alias ln='ln -fi'
|
||||||
alias rm='rm -I'
|
alias rm='rm -I'
|
||||||
Reference in New Issue
Block a user