diff options
| author | srdusr <trevorgray@srdusr.com> | 2025-08-30 19:22:59 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2025-08-30 19:22:59 +0200 |
| commit | 19120d4f9761c67d99ed1ce3da6084b83f5a49c9 (patch) | |
| tree | f234cad1bdad88114a63c9702144da487024967a /linux/home/.scripts/dotfiles.sh | |
| parent | 5928998af5404ae2be84c6cecc10ebf84bd3f3ed (diff) | |
| download | dotfiles-19120d4f9761c67d99ed1ce3da6084b83f5a49c9.tar.gz dotfiles-19120d4f9761c67d99ed1ce3da6084b83f5a49c9.zip | |
Linux-specific dotfiles
Diffstat (limited to 'linux/home/.scripts/dotfiles.sh')
| -rwxr-xr-x | linux/home/.scripts/dotfiles.sh | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/linux/home/.scripts/dotfiles.sh b/linux/home/.scripts/dotfiles.sh new file mode 100755 index 0000000..b231367 --- /dev/null +++ b/linux/home/.scripts/dotfiles.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Set the bare dotfiles repo directory +dotfiles_dir="$HOME/.cfg" + +# Set the home directory +home_dir="$HOME" + +# Exclude the .cfg directory and any other files/directories you want to ignore +exclude_list=(".cfg") + +# Change to the home directory +cd "$home_dir" + +# Get a list of all dotfiles in the repository +files=$(find "$dotfiles_dir" -maxdepth 1 -type f -not -name ".*" -not -name "${exclude_list[*]}" -printf "%f\n") + +# Link each file to its corresponding location in $HOME +for file in $files; do + ln -sf "$dotfiles_dir/$file" "$home_dir/.$file" +done + +# Get a list of all dot directories in the repository +dirs=$(find "$dotfiles_dir" -maxdepth 1 -type d -not -path "$dotfiles_dir" -not -name ".*" -not -name "${exclude_list[*]}" -printf "%f\n") + +# Link each directory to its corresponding location in $HOME +for dir in $dirs; do + ln -sf "$dotfiles_dir/$dir" "$home_dir/.$dir" +done + +# Remove any symlinks that are no longer present in the repo +while IFS= read -r -d '' link; do + if [[ ! -e "$link" ]]; then + rm "$link" + fi +done < <(find "$home_dir" -maxdepth 1 -type l -name ".*" -not -name ".cfg" -print0) + |
