aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/scripts/dotfiles.sh
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2023-08-06 23:01:08 +0200
committersrdusr <trevorgray@srdusr.com>2023-08-06 23:01:08 +0200
commit4dfe75ca5ed81a15db036a294fe2a36243413e19 (patch)
treebdd5acbec857240e352f04510e1260ab2c9994f3 /.local/bin/scripts/dotfiles.sh
parent7b13d618f5a90deb36367480ed4c70876fa41095 (diff)
parent692db3d7b9b80c1849b283738f6a2fe61ea0cdd2 (diff)
downloaddotfiles-4dfe75ca5ed81a15db036a294fe2a36243413e19.tar.gz
dotfiles-4dfe75ca5ed81a15db036a294fe2a36243413e19.zip
Merge commit '7f5e37f9dc4f834aecdc3f76652d79c0a1d842b0'
Diffstat (limited to '.local/bin/scripts/dotfiles.sh')
-rwxr-xr-x.local/bin/scripts/dotfiles.sh37
1 files changed, 37 insertions, 0 deletions
diff --git a/.local/bin/scripts/dotfiles.sh b/.local/bin/scripts/dotfiles.sh
new file mode 100755
index 0000000..b231367
--- /dev/null
+++ b/.local/bin/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)
+