diff options
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 109 |
1 files changed, 62 insertions, 47 deletions
@@ -114,7 +114,7 @@ Copy and paste the following snippet to any profile/startup file ie. `~/.bashrc` ```bash # Dotfiles Management System if [[ -d "$HOME/.cfg" && -d "$HOME/.cfg/refs" ]]; then - # Core git wrapper with repository as work-tree + # Core git wrapper - .cfg is bare repo, work-tree points to .cfg itself _config() { git --git-dir="$HOME/.cfg" --work-tree="$HOME/.cfg" "$@" } @@ -163,7 +163,9 @@ if [[ -d "$HOME/.cfg" && -d "$HOME/.cfg/refs" ]]; then fi case "$repo_path" in - # Common configs → OS-specific config dirs + common/scripts/*) + echo "$HOME/.scripts/${repo_path#common/scripts/}" + ;; common/config/*) case "$CFG_OS" in linux) @@ -174,6 +176,7 @@ if [[ -d "$HOME/.cfg" && -d "$HOME/.cfg/refs" ]]; then echo "$HOME/Library/Application Support/${repo_path#common/config/}" ;; windows) + # Windows Bash (Git Bash, MSYS, WSL) respects LOCALAPPDATA echo "$LOCALAPPDATA\\${repo_path#common/config/}" ;; *) @@ -181,32 +184,18 @@ if [[ -d "$HOME/.cfg" && -d "$HOME/.cfg/refs" ]]; then ;; esac ;; - - # Common assets → stay in repo - common/assets/*) + common/assets/*|profile/*|README.md) echo "$HOME/.cfg/$repo_path" ;; - - # Other common files (dotfiles like .bashrc, .gitconfig, etc.) → $HOME common/*) - echo "$HOME/${repo_path#common/}" + echo "$HOME/.cfg/$repo_path" ;; - - # OS-specific home */home/*) echo "$HOME/${repo_path#*/home/}" ;; - - # Profile configs and README → stay in repo - profile/*|README.md) + *) echo "$HOME/.cfg/$repo_path" ;; - - # Default fallback - *) - echo "$HOME/.cfg/$repo_path" - ;; - esac } @@ -232,6 +221,7 @@ if [[ -d "$HOME/.cfg" && -d "$HOME/.cfg/refs" ]]; then config() { local cmd="$1"; shift local target_dir="" + # Parse optional --target flag for add if [[ "$cmd" == "add" ]]; then while [[ "$1" == --* ]]; do @@ -251,7 +241,29 @@ if [[ -d "$HOME/.cfg" && -d "$HOME/.cfg/refs" ]]; then case "$cmd" in add) local file_path - for file_path in "$@"; do + local git_opts=() + local files=() + + # Parse arguments + while [[ $# -gt 0 ]]; do + case "$1" in + --target|-t) + target_dir="$2" + shift 2 + ;; + -*) # Any other flags are git flags + git_opts+=("$1") + shift + ;; + *) # Anything else is a file + files+=("$1") + shift + ;; + esac + done + + # Process each file + for file_path in "${files[@]}"; do local repo_path if [[ -n "$target_dir" ]]; then local rel_path @@ -269,11 +281,13 @@ if [[ -d "$HOME/.cfg" && -d "$HOME/.cfg/refs" ]]; then mkdir -p "$(dirname "$full_repo_path")" cp -a "$file_path" "$full_repo_path" - git --git-dir="$HOME/.cfg" --work-tree="$HOME/.cfg" add "$repo_path" + # Only git flags + repo_path go to git + _config add "${git_opts[@]}" "$repo_path" echo "Added: $file_path -> $repo_path" done ;; + rm) local rm_opts="" local file_path_list=() @@ -299,11 +313,13 @@ if [[ -d "$HOME/.cfg" && -d "$HOME/.cfg/refs" ]]; then echo "Removed: $file_path" done ;; + sync) local direction="${1:-to-repo}"; shift _config ls-files | while read -r repo_file; do local sys_file="$(_sys_path "$repo_file")" local full_repo_path="$HOME/.cfg/$repo_file" + if [[ "$direction" == "to-repo" ]]; then if [[ -e "$sys_file" && -n "$(diff "$full_repo_path" "$sys_file" 2>/dev/null || echo "diff")" ]]; then cp -a "$sys_file" "$full_repo_path" @@ -324,18 +340,36 @@ if [[ -d "$HOME/.cfg" && -d "$HOME/.cfg/refs" ]]; then fi done ;; + status) + # Check for missing files and auto-sync existing ones local auto_synced=() + local missing_files=() + while read -r repo_file; do local sys_file="$(_sys_path "$repo_file")" local full_repo_path="$HOME/.cfg/$repo_file" - if [[ -e "$sys_file" && -e "$full_repo_path" ]]; then + + if [[ ! -e "$full_repo_path" ]]; then + missing_files+=("$repo_file") + elif [[ -e "$sys_file" ]]; then if ! diff -q "$full_repo_path" "$sys_file" >/dev/null 2>&1; then cp -fa "$sys_file" "$full_repo_path" auto_synced+=("$repo_file") fi fi done < <(_config ls-files) + + # Report missing files + if [[ ${#missing_files[@]} -gt 0 ]]; then + echo "=== Missing Files (consider removing from git) ===" + for repo_file in "${missing_files[@]}"; do + echo "missing: $repo_file" + done + echo + fi + + # Report auto-synced files if [[ ${#auto_synced[@]} -gt 0 ]]; then echo "=== Auto-synced Files ===" for repo_file in "${auto_synced[@]}"; do @@ -343,13 +377,15 @@ if [[ -d "$HOME/.cfg" && -d "$HOME/.cfg/refs" ]]; then done echo fi + _config status - echo ;; - deploy) + + deploy|checkout) + echo "Deploying dotfiles from .cfg..." _config ls-files | while read -r repo_file; do local full_repo_path="$HOME/.cfg/$repo_file" - local sys_file="$(_sys_path "$repo_file")" # destination only + local sys_file="$(_sys_path "$repo_file")" # Only continue if the source exists if [[ -e "$full_repo_path" && -n "$sys_file" ]]; then @@ -369,29 +405,7 @@ if [[ -d "$HOME/.cfg" && -d "$HOME/.cfg/refs" ]]; then fi done ;; - checkout) - echo "Checking out dotfiles from .cfg..." - _config ls-files | while read -r repo_file; do - local full_repo_path="$HOME/.cfg/$repo_file" - local sys_file="$(_sys_path "$repo_file")" - - if [[ -e "$full_repo_path" && -n "$sys_file" ]]; then - local dest_dir - dest_dir="$(dirname "$sys_file")" - # Create destination if it doesn't exist - if [[ "$sys_file" == /* && "$sys_file" != "$HOME/"* ]]; then - _sudo_prompt mkdir -p "$dest_dir" - _sudo_prompt cp -a "$full_repo_path" "$sys_file" - else - mkdir -p "$dest_dir" - cp -a "$full_repo_path" "$sys_file" - fi - - echo "Checked out: $repo_file -> $sys_file" - fi - done - ;; backup) local timestamp=$(date +%Y%m%d%H%M%S) local backup_dir="$HOME/.dotfiles_backup/$timestamp" @@ -407,6 +421,7 @@ if [[ -d "$HOME/.cfg" && -d "$HOME/.cfg/refs" ]]; then done echo "Backup complete. To restore, copy files from $backup_dir to their original locations." ;; + *) _config "$cmd" "$@" ;; |
