Squash merge omarchy-4 into master
This commit is contained in:
12 files changed
+876
-90
No files matched your search
@@ -1,62 +1,133 @@
|
||||
#!/bin/bash
|
||||
# Setup script for omarchy-nvim
|
||||
# This can be called from Omarchy setup scripts
|
||||
# Setup/refresh script for omarchy-nvim
|
||||
#
|
||||
# omarchy-nvim-setup: install missing config/data for the current user.
|
||||
# omarchy-nvim-refresh: back up existing config, reset cached data, and copy
|
||||
# the skel-seeded Omarchy Neovim defaults again.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SKEL_CONFIG_DIR="/etc/skel/.config/nvim"
|
||||
SKEL_DATA_DIR="/etc/skel/.local/share/nvim"
|
||||
PACKAGE_DIR="/usr/share/omarchy-nvim"
|
||||
CONFIG_SOURCE_DIR="$SKEL_CONFIG_DIR"
|
||||
DATA_SOURCE_DIR="$SKEL_DATA_DIR"
|
||||
CONFIG_DIR="${HOME}/.config/nvim"
|
||||
DATA_DIR="${HOME}/.local/share/nvim"
|
||||
STATE_DIR="${HOME}/.local/state/nvim"
|
||||
CACHE_DIR="${HOME}/.cache/nvim"
|
||||
|
||||
# Check if package is installed
|
||||
if [[ ! -d "$PACKAGE_DIR" ]]; then
|
||||
echo "Error: omarchy-nvim package not installed"
|
||||
command_name="$(basename "$0")"
|
||||
refresh=false
|
||||
|
||||
if [[ $command_name == "omarchy-nvim-refresh" ]]; then
|
||||
refresh=true
|
||||
fi
|
||||
|
||||
while (( $# > 0 )); do
|
||||
case "$1" in
|
||||
--force|--refresh)
|
||||
refresh=true
|
||||
;;
|
||||
-h|--help)
|
||||
cat <<'EOF'
|
||||
Usage: omarchy-nvim-setup [--force]
|
||||
omarchy-nvim-refresh
|
||||
|
||||
omarchy-nvim-setup installs Omarchy's skel-seeded Neovim config/data only when
|
||||
missing. omarchy-nvim-refresh backs up an existing config and overwrites it with
|
||||
the skel-seeded defaults.
|
||||
EOF
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Prefer /etc/skel so legacy setup/refresh uses the exact seed copied into new
|
||||
# users' homes. Fall back to the package share dir for older package layouts.
|
||||
if [[ ! -d "$CONFIG_SOURCE_DIR" || ! -d "$DATA_SOURCE_DIR" ]]; then
|
||||
CONFIG_SOURCE_DIR="$PACKAGE_DIR/config"
|
||||
DATA_SOURCE_DIR="$PACKAGE_DIR/data"
|
||||
fi
|
||||
|
||||
if [[ ! -d "$CONFIG_SOURCE_DIR" || ! -d "$DATA_SOURCE_DIR" ]]; then
|
||||
echo "Error: omarchy-nvim defaults not found; is omarchy-nvim installed?" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if nvim config already exists
|
||||
if [[ -d "$CONFIG_DIR" ]]; then
|
||||
if gum confirm "$(echo -e "Neovim configuration already exists at $CONFIG_DIR.\nThis will create a backup and overwrite it. Continue?")"; then
|
||||
# Backup existing config
|
||||
BACKUP_DIR="${CONFIG_DIR}.backup.$(date +%Y%m%d-%H%M%S)"
|
||||
echo "Backing up existing config to $BACKUP_DIR"
|
||||
mv "$CONFIG_DIR" "$BACKUP_DIR"
|
||||
else
|
||||
echo "Setup cancelled."
|
||||
exit 0
|
||||
backup_path() {
|
||||
local path="$1"
|
||||
local backup="${path}.backup.$(date +%Y%m%d-%H%M%S)"
|
||||
|
||||
if [[ -e $path || -L $path ]]; then
|
||||
echo "Backing up $path to $backup"
|
||||
mv "$path" "$backup"
|
||||
fi
|
||||
}
|
||||
|
||||
copy_tree() {
|
||||
local src="$1"
|
||||
local dest="$2"
|
||||
|
||||
mkdir -p "$(dirname "$dest")"
|
||||
cp -a "$src" "$dest"
|
||||
}
|
||||
|
||||
install_config() {
|
||||
if [[ -d "$CONFIG_DIR" && $refresh != true ]]; then
|
||||
echo "Neovim config already exists at $CONFIG_DIR; leaving it in place."
|
||||
return
|
||||
fi
|
||||
|
||||
backup_path "$CONFIG_DIR"
|
||||
copy_tree "$CONFIG_SOURCE_DIR" "$CONFIG_DIR"
|
||||
echo "Installed Neovim config to $CONFIG_DIR"
|
||||
}
|
||||
|
||||
install_data() {
|
||||
if [[ -d "$DATA_DIR" && $refresh != true ]]; then
|
||||
echo "Neovim data already exists at $DATA_DIR; leaving it in place."
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ $refresh == true ]]; then
|
||||
rm -rf "$DATA_DIR" "$CACHE_DIR" "$STATE_DIR"
|
||||
fi
|
||||
|
||||
copy_tree "$DATA_SOURCE_DIR" "$DATA_DIR"
|
||||
echo "Installed Neovim data to $DATA_DIR"
|
||||
}
|
||||
|
||||
install_config
|
||||
install_data
|
||||
|
||||
# Files copied into $HOME by the install user already have the right owner.
|
||||
# Only adjust ownership when this script is explicitly run as root.
|
||||
if (( EUID == 0 )); then
|
||||
target_user="${SUDO_USER:-${USER:-root}}"
|
||||
if [[ $target_user != "root" ]]; then
|
||||
chown -R "${target_user}:${target_user}" "$CONFIG_DIR" "$DATA_DIR"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Setting up Neovim configuration..."
|
||||
# Use a relative symlink so the same config works from /etc/skel and from any
|
||||
# user's home directory.
|
||||
mkdir -p "${CONFIG_DIR}/lua/plugins"
|
||||
ln -snf "../../../omarchy/current/theme/neovim.lua" "${CONFIG_DIR}/lua/plugins/theme.lua"
|
||||
|
||||
# Make sure everything is clear
|
||||
rm -rf $DATA_DIR $CACHE_DIR $STATE_DIR
|
||||
|
||||
# Create directories if needed
|
||||
mkdir -p "$(dirname "$CONFIG_DIR")"
|
||||
mkdir -p "$(dirname "$DATA_DIR")"
|
||||
|
||||
# Copy files (cache will be regenerated on first use)
|
||||
cp -r "$PACKAGE_DIR/config" "$CONFIG_DIR"
|
||||
cp -r "$PACKAGE_DIR/data" "$DATA_DIR"
|
||||
|
||||
# Ensure proper ownership of all nvim directories
|
||||
chown -R "${USER}:${USER}" "$CONFIG_DIR"
|
||||
chown -R "${USER}:${USER}" "$DATA_DIR"
|
||||
|
||||
# Create link for current theme
|
||||
ln -snf "${HOME}/.config/omarchy/current/theme/neovim.lua" "${CONFIG_DIR}/lua/plugins/theme.lua"
|
||||
|
||||
# Restore git working trees
|
||||
for dir in $DATA_DIR/lazy/*/; do
|
||||
if [ -d "$dir/.git" ]; then
|
||||
# Restore git working trees from the packaged lazy plugin cache.
|
||||
for dir in "$DATA_DIR"/lazy/*/; do
|
||||
if [[ -d "$dir/.git" ]]; then
|
||||
git --git-dir="$dir/.git" --work-tree="$dir" restore .
|
||||
fi
|
||||
done
|
||||
|
||||
# Set nvim.desktop as default so it takes priority in Nautilus
|
||||
# Set nvim.desktop as default so it takes priority in Nautilus.
|
||||
xdg-mime default nvim.desktop text/plain
|
||||
xdg-mime default nvim.desktop text/english
|
||||
xdg-mime default nvim.desktop text/x-makefile
|
||||
@@ -75,4 +146,8 @@ xdg-mime default nvim.desktop text/x-c++
|
||||
xdg-mime default nvim.desktop application/xml
|
||||
xdg-mime default nvim.desktop text/xml
|
||||
|
||||
echo "Neovim setup complete!"
|
||||
if [[ $refresh == true ]]; then
|
||||
echo "Neovim refresh complete!"
|
||||
else
|
||||
echo "Neovim setup complete!"
|
||||
fi
|
||||
Reference in new issue
Block a user