My goals are to:
- Do it automatically (without adding a line to my script every time I add or change the location of a config file)
- The files in the git repo folder should not be hidden, but the symlinks in my home directory should
- Existing files of the same name should be overwritten, but not directories. For example if I have
config/conf.txtin my dotfiles repo, it shouldn't overwrite the entire~/.configfolder, but simply add a link toconf.txtinside~/.config.
I think myMy current solution does these, but I'm sure it could probably be done better:
#!/usr/bin/env bash
# change this if dotfiles directory is moved or renamed
DOTFILES_DIR="$HOME/dotfiles"
echo -n Creating symlinks...
shopt -s extglob dotglob nocaseglob
# createCreate hidden symlinks, hard link them to the$HOME, filesrm old symlinks
for fdotfile in $DOTFILES_DIR/!(readme.*|$readme*|${0##*/}); do
cp -asf "$f" "$HOME/dotfileshidden="$DOTFILES_DIR/.${f##*dotfile##*/}"
done
# copy links into home directory, remove original links
for f in $DOTFILES_DIR/!(!(.*)|.git|.gitignore|*.swp|.|..); do #cp this-asf is"$dotfile" ugly"$hidden"
cp -alf "$f""$hidden" "$HOME"
rm -r "$f""$hidden"
done
echo done
I think I should be able to copy the files directly to the home directory, but I had some trouble getting that to work right if a destination folder already existed.
Edit: I was able to eliminate the second for loop. Much better. There may still be a better way, though.