mirror of
https://github.com/sebaschi/dotfiles.git
synced 2025-12-30 02:28:26 +01:00
Move old scripts into resources; They have no active use currently but good to keep for reference
This commit is contained in:
268
resources/dot-install
Executable file
268
resources/dot-install
Executable file
@@ -0,0 +1,268 @@
|
||||
#!/bin/sh
|
||||
# dot-install: Create symlinks for dotfiles configurations
|
||||
|
||||
set -e
|
||||
|
||||
DOTFILES_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
CONFIG_DIR="${HOME}/.config"
|
||||
|
||||
# Print usage info
|
||||
usage() {
|
||||
echo "Usage: dot-install [PACKAGE...] [all]"
|
||||
echo
|
||||
echo "Available packages:"
|
||||
echo " bash - Bash configuration files (all)"
|
||||
echo " bash:aliases - Bash aliases only"
|
||||
echo " bash:completion - Bash completion only"
|
||||
echo " bash:env - Bash environment only"
|
||||
echo " bash:functions - Bash functions only"
|
||||
echo " bash:fedora - Fedora specific bash aliases"
|
||||
echo " borg - Borg backup profiles"
|
||||
echo " fish - Fish shell configuration"
|
||||
echo " ghostty - Ghostty terminal configuration"
|
||||
echo " git - Git configuration"
|
||||
echo " nvim - Neovim configuration"
|
||||
echo " rsync - Rsync filter rules"
|
||||
echo " starship - Starship prompt configuration"
|
||||
echo " tmux - Tmux configuration"
|
||||
echo " vim - Vim configuration"
|
||||
echo " zellij - Zellij terminal multiplexer configuration"
|
||||
echo " zsh - Zsh configuration"
|
||||
echo " all - Install all packages"
|
||||
echo
|
||||
echo "Example: dot-install bash:aliases git nvim"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Create parent directories if they don't exist
|
||||
ensure_dir() {
|
||||
if [ ! -d "$1" ]; then
|
||||
mkdir -p "$1"
|
||||
echo "Created directory: $1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Create a symlink and handle existing files
|
||||
link_file() {
|
||||
local src="$1"
|
||||
local dest="$2"
|
||||
|
||||
# Check if destination already exists
|
||||
if [ -e "$dest" ]; then
|
||||
if [ -L "$dest" ]; then
|
||||
# If it's already a symlink, check if it points to our file
|
||||
if [ "$(readlink "$dest")" = "$src" ]; then
|
||||
echo "Link already exists: $dest -> $src"
|
||||
return 0
|
||||
else
|
||||
echo "Removing existing link: $dest"
|
||||
rm "$dest"
|
||||
fi
|
||||
else
|
||||
# If it's a regular file or directory
|
||||
echo "Backing up existing file: $dest -> ${dest}.bak"
|
||||
mv "$dest" "${dest}.bak"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create the symlink
|
||||
ln -s "$src" "$dest"
|
||||
echo "Created link: $dest -> $src"
|
||||
}
|
||||
|
||||
# Add source command to bashrc if needed
|
||||
add_source_to_bashrc() {
|
||||
local file="$1"
|
||||
local config_path="$CONFIG_DIR/bash/$file"
|
||||
|
||||
if [ -f "$HOME/.bashrc" ]; then
|
||||
if ! grep -q "source \$HOME/.config/bash/$file" "$HOME/.bashrc"; then
|
||||
echo "Adding source command for $file to .bashrc"
|
||||
echo "[ -f \$HOME/.config/bash/$file ] && source \$HOME/.config/bash/$file" >> "$HOME/.bashrc"
|
||||
fi
|
||||
else
|
||||
echo "Warning: $HOME/.bashrc does not exist. You'll need to manually source $file."
|
||||
fi
|
||||
}
|
||||
|
||||
install_bash_aliases() {
|
||||
echo "Installing bash aliases..."
|
||||
|
||||
ensure_dir "$CONFIG_DIR/bash"
|
||||
link_file "$DOTFILES_DIR/bash/bash_aliases" "$CONFIG_DIR/bash/bash_aliases"
|
||||
add_source_to_bashrc "bash_aliases"
|
||||
}
|
||||
|
||||
install_bash_completion() {
|
||||
echo "Installing bash completion..."
|
||||
|
||||
ensure_dir "$CONFIG_DIR/bash"
|
||||
link_file "$DOTFILES_DIR/bash/bash_completion" "$CONFIG_DIR/bash/bash_completion"
|
||||
add_source_to_bashrc "bash_completion"
|
||||
}
|
||||
|
||||
install_bash_env() {
|
||||
echo "Installing bash environment..."
|
||||
|
||||
ensure_dir "$CONFIG_DIR/bash"
|
||||
link_file "$DOTFILES_DIR/bash/bash_env" "$CONFIG_DIR/bash/bash_env"
|
||||
add_source_to_bashrc "bash_env"
|
||||
}
|
||||
|
||||
install_bash_functions() {
|
||||
echo "Installing bash functions..."
|
||||
|
||||
ensure_dir "$CONFIG_DIR/bash"
|
||||
link_file "$DOTFILES_DIR/bash/bash_functions" "$CONFIG_DIR/bash/bash_functions"
|
||||
add_source_to_bashrc "bash_functions"
|
||||
}
|
||||
|
||||
install_bash_fedora() {
|
||||
echo "Installing fedora aliases..."
|
||||
|
||||
ensure_dir "$CONFIG_DIR/bash"
|
||||
link_file "$DOTFILES_DIR/bash/fedora_aliases" "$CONFIG_DIR/bash/fedora_aliases"
|
||||
add_source_to_bashrc "fedora_aliases"
|
||||
}
|
||||
|
||||
install_bash() {
|
||||
echo "Installing all bash configuration..."
|
||||
|
||||
install_bash_aliases
|
||||
install_bash_completion
|
||||
install_bash_env
|
||||
install_bash_functions
|
||||
install_bash_fedora
|
||||
|
||||
# Create a .bash_dir symlink in home directory for compatibility
|
||||
link_file "$CONFIG_DIR/bash" "$HOME/.bash_dir"
|
||||
}
|
||||
|
||||
install_borg() {
|
||||
echo "Installing borg backup profiles..."
|
||||
|
||||
ensure_dir "$CONFIG_DIR/borg"
|
||||
link_file "$DOTFILES_DIR/borg-backup-profiles" "$CONFIG_DIR/borg"
|
||||
}
|
||||
|
||||
install_fish() {
|
||||
echo "Installing fish configuration..."
|
||||
|
||||
ensure_dir "$CONFIG_DIR"
|
||||
link_file "$DOTFILES_DIR/fish" "$CONFIG_DIR/fish"
|
||||
}
|
||||
|
||||
install_ghostty() {
|
||||
echo "Installing ghostty configuration..."
|
||||
|
||||
ensure_dir "$CONFIG_DIR"
|
||||
link_file "$DOTFILES_DIR/ghostty" "$CONFIG_DIR/ghostty"
|
||||
}
|
||||
|
||||
install_git() {
|
||||
echo "Installing git configuration..."
|
||||
|
||||
link_file "$DOTFILES_DIR/git/gitconfig" "$HOME/.gitconfig"
|
||||
}
|
||||
|
||||
install_nvim() {
|
||||
echo "Installing neovim configuration..."
|
||||
|
||||
ensure_dir "$CONFIG_DIR"
|
||||
link_file "$DOTFILES_DIR/nvim" "$CONFIG_DIR/nvim"
|
||||
}
|
||||
|
||||
install_rsync() {
|
||||
echo "Installing rsync filter rules..."
|
||||
|
||||
link_file "$DOTFILES_DIR/sync-filter-fedora/dot-rsync-filter-home" "$HOME/.rsync-filter-home"
|
||||
}
|
||||
|
||||
install_starship() {
|
||||
echo "Installing starship configuration..."
|
||||
|
||||
ensure_dir "$CONFIG_DIR"
|
||||
link_file "$DOTFILES_DIR/dot-config/starship.toml" "$CONFIG_DIR/starship.toml"
|
||||
}
|
||||
|
||||
install_tmux() {
|
||||
echo "Installing tmux configuration..."
|
||||
|
||||
link_file "$DOTFILES_DIR/tmux/tmux.conf" "$HOME/.tmux.conf"
|
||||
}
|
||||
|
||||
install_vim() {
|
||||
echo "Installing vim configuration..."
|
||||
|
||||
link_file "$DOTFILES_DIR/vim/vimrc" "$HOME/.vimrc"
|
||||
|
||||
ensure_dir "$HOME/.vim"
|
||||
link_file "$DOTFILES_DIR/vim/initvim" "$HOME/.vim/init.vim"
|
||||
}
|
||||
|
||||
install_zellij() {
|
||||
echo "Installing zellij configuration..."
|
||||
|
||||
ensure_dir "$CONFIG_DIR/zellij"
|
||||
link_file "$DOTFILES_DIR/dot-config/zellij.kdl" "$CONFIG_DIR/zellij/config.kdl"
|
||||
}
|
||||
|
||||
install_zsh() {
|
||||
echo "Installing zsh configuration..."
|
||||
|
||||
link_file "$DOTFILES_DIR/zsh/zshrc" "$HOME/.zshrc"
|
||||
}
|
||||
|
||||
# Install vimconfig as config for neovim
|
||||
install_vim_neovim() {
|
||||
echo "Installing init.vim as config for *neovim*"
|
||||
|
||||
ensure_dir "$CONFIG_DIR/nvim"
|
||||
link_file "$DOTFILES_DIR/vim/initvim" "$CONFIG_DIR/nvim/init.vim"
|
||||
}
|
||||
|
||||
install_all() {
|
||||
install_bash
|
||||
install_borg
|
||||
install_fish
|
||||
install_ghostty
|
||||
install_git
|
||||
install_nvim
|
||||
install_rsync
|
||||
install_starship
|
||||
install_tmux
|
||||
install_vim
|
||||
install_zellij
|
||||
install_zsh
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
bash) install_bash ;;
|
||||
bash:aliases) install_bash_aliases ;;
|
||||
bash:completion) install_bash_completion ;;
|
||||
bash:env) install_bash_env ;;
|
||||
bash:functions) install_bash_functions ;;
|
||||
bash:fedora) install_bash_fedora ;;
|
||||
borg) install_borg ;;
|
||||
fish) install_fish ;;
|
||||
ghostty) install_ghostty ;;
|
||||
git) install_git ;;
|
||||
nvim) install_nvim ;;
|
||||
vimnvim) install_vim_neovim ;;
|
||||
rsync) install_rsync ;;
|
||||
starship) install_starship ;;
|
||||
tmux) install_tmux ;;
|
||||
vim) install_vim ;;
|
||||
zellij) install_zellij ;;
|
||||
zsh) install_zsh ;;
|
||||
all) install_all ;;
|
||||
*) echo "Unknown package: $arg"; usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "Installation complete!"
|
||||
354
resources/dot-install.py
Executable file
354
resources/dot-install.py
Executable file
@@ -0,0 +1,354 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
dot-install: Create symlinks for dotfiles configurations
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import click
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
# Global variables
|
||||
DOTFILES_DIR = Path(__file__).resolve().parent
|
||||
CONFIG_DIR = Path(os.environ.get('XDG_CONFIG_HOME', '')) if os.environ.get('XDG_CONFIG_HOME') else Path.home() / ".config"
|
||||
|
||||
|
||||
# Config registry to hold all configurations
|
||||
CONFIG_REGISTRY = {}
|
||||
|
||||
|
||||
def register_config(name, src_paths, dest_paths, post_actions=None, description=None):
|
||||
"""Register a configuration in the central registry"""
|
||||
if not isinstance(src_paths, list):
|
||||
src_paths = [src_paths]
|
||||
if not isinstance(dest_paths, list):
|
||||
dest_paths = [dest_paths]
|
||||
|
||||
CONFIG_REGISTRY[name] = {
|
||||
'src_paths': src_paths,
|
||||
'dest_paths': dest_paths,
|
||||
'post_actions': post_actions or [],
|
||||
'description': description or f"Install {name} configuration"
|
||||
}
|
||||
|
||||
|
||||
# Helper functions
|
||||
def ensure_dir(directory):
|
||||
"""Create directory if it doesn't exist"""
|
||||
if not directory.exists():
|
||||
directory.mkdir(parents=True)
|
||||
click.echo(f"Created directory: {directory}")
|
||||
|
||||
|
||||
def link_file(src, dest):
|
||||
"""Create a symlink and handle existing files"""
|
||||
# Check if destination already exists
|
||||
if dest.exists():
|
||||
if dest.is_symlink():
|
||||
# If it's already a symlink, check if it points to our file
|
||||
if dest.resolve() == src.resolve():
|
||||
click.echo(f"Link already exists: {dest} -> {src}")
|
||||
return
|
||||
else:
|
||||
click.echo(f"Removing existing link: {dest}")
|
||||
dest.unlink()
|
||||
else:
|
||||
# If it's a regular file or directory
|
||||
backup = Path(f"{dest}.bak")
|
||||
click.echo(f"Backing up existing file: {dest} -> {backup}")
|
||||
shutil.move(dest, backup)
|
||||
|
||||
# Create the symlink
|
||||
dest.symlink_to(src)
|
||||
click.echo(f"Created link: {dest} -> {src}")
|
||||
|
||||
|
||||
def add_source_to_bashrc(file):
|
||||
"""Add source command to bashrc if needed"""
|
||||
bashrc = Path.home() / ".bashrc"
|
||||
config_path = f"$HOME/.config/bash/{file}"
|
||||
|
||||
if bashrc.exists():
|
||||
with open(bashrc, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
if f"source {config_path}" not in content:
|
||||
click.echo(f"Adding source command for {file} to .bashrc")
|
||||
with open(bashrc, 'a') as f:
|
||||
f.write(f"\n[ -f {config_path} ] && source {config_path}\n")
|
||||
else:
|
||||
click.echo(f"Warning: {bashrc} does not exist. You'll need to manually source {file}.")
|
||||
|
||||
|
||||
def install_config(name):
|
||||
"""Install a configuration from the registry"""
|
||||
if name not in CONFIG_REGISTRY:
|
||||
click.echo(f"Unknown configuration: {name}")
|
||||
return
|
||||
|
||||
cfg = CONFIG_REGISTRY[name]
|
||||
click.echo(f"Installing {name} configuration...")
|
||||
|
||||
# Ensure directories exist for all destination paths
|
||||
for dest in cfg['dest_paths']:
|
||||
ensure_dir(dest.parent)
|
||||
|
||||
# Create symlinks
|
||||
for src, dest in zip(cfg['src_paths'], cfg['dest_paths']):
|
||||
link_file(src, dest)
|
||||
|
||||
# Run any post-installation actions
|
||||
for action in cfg['post_actions']:
|
||||
action()
|
||||
|
||||
|
||||
# Register bash components
|
||||
def register_bash_configs():
|
||||
# Bash aliases
|
||||
register_config(
|
||||
'bash:aliases',
|
||||
DOTFILES_DIR / "bash" / "bash_aliases",
|
||||
CONFIG_DIR / "bash" / "bash_aliases",
|
||||
[lambda: add_source_to_bashrc("bash_aliases")],
|
||||
"Install bash aliases"
|
||||
)
|
||||
|
||||
# Bash completion
|
||||
register_config(
|
||||
'bash:completion',
|
||||
DOTFILES_DIR / "bash" / "bash_completion",
|
||||
CONFIG_DIR / "bash" / "bash_completion",
|
||||
[lambda: add_source_to_bashrc("bash_completion")],
|
||||
"Install bash completion"
|
||||
)
|
||||
|
||||
# Bash environment
|
||||
register_config(
|
||||
'bash:env',
|
||||
DOTFILES_DIR / "bash" / "bash_env",
|
||||
CONFIG_DIR / "bash" / "bash_env",
|
||||
[lambda: add_source_to_bashrc("bash_env")],
|
||||
"Install bash environment"
|
||||
)
|
||||
|
||||
# Bash functions
|
||||
register_config(
|
||||
'bash:functions',
|
||||
DOTFILES_DIR / "bash" / "bash_functions",
|
||||
CONFIG_DIR / "bash" / "bash_functions",
|
||||
[lambda: add_source_to_bashrc("bash_functions")],
|
||||
"Install bash functions"
|
||||
)
|
||||
|
||||
# Fedora aliases
|
||||
register_config(
|
||||
'bash:fedora',
|
||||
DOTFILES_DIR / "bash" / "fedora_aliases",
|
||||
CONFIG_DIR / "bash" / "fedora_aliases",
|
||||
[lambda: add_source_to_bashrc("fedora_aliases")],
|
||||
"Install fedora aliases"
|
||||
)
|
||||
|
||||
# Full bash (meta-configuration)
|
||||
register_config(
|
||||
'bash',
|
||||
[], # No direct files, will call each component
|
||||
[], # No direct destinations
|
||||
[
|
||||
lambda: install_config('bash:aliases'),
|
||||
lambda: install_config('bash:completion'),
|
||||
lambda: install_config('bash:env'),
|
||||
lambda: install_config('bash:functions'),
|
||||
lambda: install_config('bash:fedora'),
|
||||
lambda: link_file(CONFIG_DIR / "bash", Path.home() / ".bash_dir")
|
||||
],
|
||||
"Install all bash configuration"
|
||||
)
|
||||
|
||||
|
||||
# Register all other configurations
|
||||
def register_all_configs():
|
||||
register_bash_configs()
|
||||
|
||||
# Borg backup profiles
|
||||
register_config(
|
||||
'borg',
|
||||
DOTFILES_DIR / "borg-backup-profiles",
|
||||
CONFIG_DIR / "borg",
|
||||
description="Install borg backup profiles"
|
||||
)
|
||||
|
||||
# Fish shell
|
||||
register_config(
|
||||
'fish',
|
||||
DOTFILES_DIR / "fish",
|
||||
CONFIG_DIR / "fish",
|
||||
description="Install fish shell configuration"
|
||||
)
|
||||
|
||||
# Ghostty terminal
|
||||
register_config(
|
||||
'ghostty',
|
||||
DOTFILES_DIR / "ghostty",
|
||||
CONFIG_DIR / "ghostty",
|
||||
description="Install ghostty terminal configuration"
|
||||
)
|
||||
|
||||
# Git
|
||||
register_config(
|
||||
'git',
|
||||
DOTFILES_DIR / "git" / "gitconfig",
|
||||
Path.home() / ".gitconfig",
|
||||
description="Install git configuration"
|
||||
)
|
||||
|
||||
# Neovim
|
||||
register_config(
|
||||
'nvim',
|
||||
DOTFILES_DIR / "nvim",
|
||||
CONFIG_DIR / "nvim",
|
||||
description="Install neovim configuration"
|
||||
)
|
||||
|
||||
# Rsync filter rules
|
||||
register_config(
|
||||
'rsync',
|
||||
DOTFILES_DIR / "sync-filter-fedora" / "dot-rsync-filter-home",
|
||||
Path.home() / ".rsync-filter-home",
|
||||
description="Install rsync filter rules"
|
||||
)
|
||||
|
||||
# Starship prompt
|
||||
register_config(
|
||||
'starship',
|
||||
DOTFILES_DIR / "dot-config" / "starship.toml",
|
||||
CONFIG_DIR / "starship.toml",
|
||||
description="Install starship prompt configuration"
|
||||
)
|
||||
|
||||
# Tmux
|
||||
register_config(
|
||||
'tmux',
|
||||
DOTFILES_DIR / "tmux" / "tmux.conf",
|
||||
Path.home() / ".tmux.conf",
|
||||
description="Install tmux configuration"
|
||||
)
|
||||
|
||||
# Vim
|
||||
register_config(
|
||||
'vim',
|
||||
[
|
||||
DOTFILES_DIR / "vim" / "vimrc",
|
||||
DOTFILES_DIR / "vim" / "initvim"
|
||||
],
|
||||
[
|
||||
Path.home() / ".vimrc",
|
||||
Path.home() / ".vim" / "init.vim"
|
||||
],
|
||||
description="Install vim configuration"
|
||||
)
|
||||
|
||||
# Vim config as neovim config
|
||||
register_config(
|
||||
'vimnvim',
|
||||
DOTFILES_DIR / "vim" / "initvim",
|
||||
CONFIG_DIR / "nvim" / "init.vim",
|
||||
description="Install vim config as config for neovim"
|
||||
)
|
||||
|
||||
# Zellij
|
||||
register_config(
|
||||
'zellij',
|
||||
DOTFILES_DIR / "dot-config" / "zellij.kdl",
|
||||
CONFIG_DIR / "zellij" / "config.kdl",
|
||||
description="Install zellij configuration"
|
||||
)
|
||||
|
||||
# Zsh
|
||||
register_config(
|
||||
'zsh',
|
||||
DOTFILES_DIR / "zsh" / "zshrc",
|
||||
Path.home() / ".zshrc",
|
||||
description="Install zsh configuration"
|
||||
)
|
||||
|
||||
# All (meta-configuration)
|
||||
all_configs = [
|
||||
'bash', 'borg', 'fish', 'ghostty', 'git', 'nvim',
|
||||
'rsync', 'starship', 'tmux', 'vim', 'zellij', 'zsh'
|
||||
]
|
||||
|
||||
register_config(
|
||||
'all',
|
||||
[],
|
||||
[],
|
||||
[lambda cfg=cfg: install_config(cfg) for cfg in all_configs],
|
||||
"Install all configurations"
|
||||
)
|
||||
|
||||
|
||||
# Register all configurations
|
||||
register_all_configs()
|
||||
|
||||
|
||||
# Main CLI command group
|
||||
@click.group(invoke_without_command=True)
|
||||
@click.pass_context
|
||||
def cli(ctx):
|
||||
"""Create symlinks for dotfiles configurations"""
|
||||
# If no subcommand is provided, show help
|
||||
if ctx.invoked_subcommand is None:
|
||||
click.echo(ctx.get_help())
|
||||
|
||||
|
||||
# Dynamically create commands for each configuration
|
||||
for name, cfg in CONFIG_REGISTRY.items():
|
||||
# Skip bash sub-commands to handle them specially
|
||||
if ':' in name:
|
||||
continue
|
||||
|
||||
# Create a command function dynamically
|
||||
def make_command(name=name):
|
||||
@cli.command(name=name)
|
||||
def cmd():
|
||||
install_config(name)
|
||||
cmd.__doc__ = cfg['description']
|
||||
return cmd
|
||||
|
||||
# Add the command to the CLI
|
||||
make_command()
|
||||
|
||||
|
||||
# Create bash command group
|
||||
@cli.group()
|
||||
def bash():
|
||||
"""Bash configuration files"""
|
||||
pass
|
||||
|
||||
|
||||
# Create bash subcommands
|
||||
for name, cfg in CONFIG_REGISTRY.items():
|
||||
if name.startswith('bash:'):
|
||||
sub_name = name.split(':')[1]
|
||||
|
||||
def make_subcommand(name=name, sub_name=sub_name):
|
||||
@bash.command(name=sub_name)
|
||||
def cmd():
|
||||
install_config(name)
|
||||
cmd.__doc__ = cfg['description']
|
||||
return cmd
|
||||
|
||||
make_subcommand()
|
||||
|
||||
|
||||
# Add bash "all" command
|
||||
@bash.command('all')
|
||||
def bash_all():
|
||||
"""Install all bash configurations"""
|
||||
install_config('bash')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
||||
145
resources/test-dot-install
Executable file
145
resources/test-dot-install
Executable file
@@ -0,0 +1,145 @@
|
||||
#!/bin/sh
|
||||
# test-dot-install: Test the dot-install script in an isolated environment
|
||||
|
||||
set -e
|
||||
|
||||
# Create temporary test environment
|
||||
TEST_HOME=$(mktemp -d)
|
||||
TEST_CONFIG="$TEST_HOME/.config"
|
||||
ORIGINAL_HOME=$HOME
|
||||
DOTFILES_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
SCRIPT="$DOTFILES_DIR/dot-install"
|
||||
|
||||
# Ensure cleanup of test environment
|
||||
cleanup() {
|
||||
HOME=$ORIGINAL_HOME
|
||||
rm -rf "$TEST_HOME"
|
||||
echo "Cleaned up test environment"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Color output
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Helper functions
|
||||
assert() {
|
||||
if [ "$1" = "$2" ]; then
|
||||
printf "${GREEN}✓ PASS:${NC} $3\n"
|
||||
else
|
||||
printf "${RED}✗ FAIL:${NC} $3 (Expected '$2', got '$1')\n"
|
||||
FAILED=1
|
||||
fi
|
||||
}
|
||||
|
||||
assert_file_exists() {
|
||||
if [ -e "$1" ]; then
|
||||
printf "${GREEN}✓ PASS:${NC} File exists: $1\n"
|
||||
else
|
||||
printf "${RED}✗ FAIL:${NC} File does not exist: $1\n"
|
||||
FAILED=1
|
||||
fi
|
||||
}
|
||||
|
||||
assert_symlink() {
|
||||
if [ -L "$1" ]; then
|
||||
local target=$(readlink "$1")
|
||||
if [ "$target" = "$2" ]; then
|
||||
printf "${GREEN}✓ PASS:${NC} Symlink correct: $1 -> $2\n"
|
||||
else
|
||||
printf "${RED}✗ FAIL:${NC} Symlink target mismatch for $1. Expected: $2, Got: $target\n"
|
||||
FAILED=1
|
||||
fi
|
||||
else
|
||||
printf "${RED}✗ FAIL:${NC} Not a symlink: $1\n"
|
||||
FAILED=1
|
||||
fi
|
||||
}
|
||||
|
||||
# Start testing
|
||||
echo "Starting dot-install tests in isolated environment: $TEST_HOME"
|
||||
FAILED=0
|
||||
HOME="$TEST_HOME"
|
||||
mkdir -p "$TEST_CONFIG"
|
||||
|
||||
# Create a mock .bashrc for testing source additions
|
||||
echo "# Mock .bashrc file" > "$TEST_HOME/.bashrc"
|
||||
|
||||
# Test 1: Install bash aliases only
|
||||
echo "\nTest 1: Installing bash:aliases only"
|
||||
"$SCRIPT" bash:aliases
|
||||
|
||||
assert_file_exists "$TEST_CONFIG/bash"
|
||||
assert_file_exists "$TEST_CONFIG/bash/bash_aliases"
|
||||
assert_symlink "$TEST_CONFIG/bash/bash_aliases" "$DOTFILES_DIR/bash/bash_aliases"
|
||||
|
||||
# Check .bashrc was updated
|
||||
grep -q "source \$HOME/.config/bash/bash_aliases" "$TEST_HOME/.bashrc"
|
||||
if [ $? -eq 0 ]; then
|
||||
printf "${GREEN}✓ PASS:${NC} .bashrc correctly updated for bash_aliases\n"
|
||||
else
|
||||
printf "${RED}✗ FAIL:${NC} .bashrc not updated for bash_aliases\n"
|
||||
FAILED=1
|
||||
fi
|
||||
|
||||
# Test 2: Install full bash
|
||||
echo "\nTest 2: Installing full bash package"
|
||||
"$SCRIPT" bash
|
||||
|
||||
assert_file_exists "$TEST_CONFIG/bash/bash_aliases"
|
||||
assert_file_exists "$TEST_CONFIG/bash/bash_completion"
|
||||
assert_file_exists "$TEST_CONFIG/bash/bash_env"
|
||||
assert_file_exists "$TEST_CONFIG/bash/bash_functions"
|
||||
assert_file_exists "$TEST_CONFIG/bash/fedora_aliases"
|
||||
assert_symlink "$HOME/.bash_dir" "$TEST_CONFIG/bash"
|
||||
|
||||
# Test 3: Install nvim
|
||||
echo "\nTest 3: Installing nvim package"
|
||||
"$SCRIPT" nvim
|
||||
|
||||
assert_symlink "$TEST_CONFIG/nvim" "$DOTFILES_DIR/nvim"
|
||||
|
||||
# Test 4: Install git
|
||||
echo "\nTest 4: Installing git package"
|
||||
"$SCRIPT" git
|
||||
|
||||
assert_symlink "$TEST_HOME/.gitconfig" "$DOTFILES_DIR/git/gitconfig"
|
||||
|
||||
# Test 5: Install starship
|
||||
echo "\nTest 5: Installing starship package"
|
||||
"$SCRIPT" starship
|
||||
|
||||
assert_symlink "$TEST_CONFIG/starship.toml" "$DOTFILES_DIR/dot-config/starship.toml"
|
||||
|
||||
# Test 6: Install zellij
|
||||
echo "\nTest 6: Installing zellij package"
|
||||
"$SCRIPT" zellij
|
||||
|
||||
assert_file_exists "$TEST_CONFIG/zellij"
|
||||
assert_symlink "$TEST_CONFIG/zellij/config.kdl" "$DOTFILES_DIR/dot-config/zellij.kdl"
|
||||
|
||||
# Test 7: Test idempotence (installing twice)
|
||||
echo "\nTest 7: Testing idempotence (installing twice)"
|
||||
# Redirect output to suppress it during the second run
|
||||
"$SCRIPT" git > /dev/null
|
||||
|
||||
assert_symlink "$TEST_HOME/.gitconfig" "$DOTFILES_DIR/git/gitconfig"
|
||||
|
||||
# Test 8: Test backup functionality
|
||||
echo "\nTest 8: Testing backup functionality"
|
||||
echo "test content" > "$TEST_HOME/.tmux.conf"
|
||||
"$SCRIPT" tmux
|
||||
|
||||
assert_file_exists "$TEST_HOME/.tmux.conf.bak"
|
||||
assert_symlink "$TEST_HOME/.tmux.conf" "$DOTFILES_DIR/tmux/tmux.conf"
|
||||
|
||||
# Report results
|
||||
echo "\nTest Summary:"
|
||||
if [ $FAILED -eq 0 ]; then
|
||||
printf "${GREEN}All tests passed!${NC}\n"
|
||||
exit 0
|
||||
else
|
||||
printf "${RED}$FAILED tests failed!${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user