diff --git a/.stowrc b/.stowrc new file mode 100644 index 0000000..ee23bfa --- /dev/null +++ b/.stowrc @@ -0,0 +1 @@ +--target=~ diff --git a/README.md b/README.md index abf8137..6a5e53e 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,15 @@ The dotfiles use `GNU stow` to link themselves in the home directory. You can clone this repository anywhere (though I have mine in `~/.dotfiles` as it seemed most logical for me). Once in the repository directory, when you then run `./install.sh` it will install many of the packages I use (though they are probably slightly out-of-date) and link the dotfiles into the home directory. -Since it is based on `stow`, it will not overwrite anything already in the home directory. -If you do not want to install any packages but only link the dotfiles run `./_bootstrap/autostow.sh -s`, once again from the main repository directory. +Since it is based on `stow`, it will not overwrite anything already in the home directory (though you can force it to if you really want, using `stow --override='.*'` -- I do not recommend this). + +If you do not want to install any packages, but only link the dotfiles run `stow -S */` from the main repository directory. + +After all files are linked and you open a new shell session, the `dotlink` alias will allow you to re-link all dotfiles from anywhere on the system.[^1] + +[^1]: This alias only works when the dotfiles are cloned into `~/.dotfiles` mirroring my setup. + This is due to a hard-coded cd into this directory. + If your dotfiles lie in another directory and you want to use the dotlink alias, simply change the corresponding line in `_bootstrap/.config/sh/alias.d/dotlink.sh`] Both automatic installation paths are presumably somewhat brittle. In any case, I would suggest to manually look through the files for things you want instead of copying and activating everything. Dotfiles are too personal to be standardized like that. diff --git a/_assets/.stow-local-ignore b/_assets/.stow-local-ignore new file mode 100644 index 0000000..96787ae --- /dev/null +++ b/_assets/.stow-local-ignore @@ -0,0 +1 @@ +^/.* # everything diff --git a/_bootstrap/.config/sh/alias.d/dotlink.sh b/_bootstrap/.config/sh/alias.d/dotlink.sh new file mode 100644 index 0000000..6fc74c5 --- /dev/null +++ b/_bootstrap/.config/sh/alias.d/dotlink.sh @@ -0,0 +1,13 @@ +# relink all stowed files from anywhere +# grepping is to remove meaningless stderr lines until this bug is fixed: +# https://github.com/aspiers/stow/issues/65 +# +# redirection is a neat way to filter stderr msgs by redirecting stderr +# to stdout in a subshell, grepping in it, and redirecting back to stderr: +# https://stackoverflow.com/a/15936384 +# +# to customize this to your own needs, change the `push folder` to the +# location of your dotfiles (stow) repository +alias dotlink="pushd ~/.dotfiles;\ + stow -R */ 2> >(grep -v 'Absolute/relative mismatch between Stow dir' 1>&2) ;\ + popd" diff --git a/_bootstrap/.stow-local-ignore b/_bootstrap/.stow-local-ignore new file mode 100644 index 0000000..1bf0cf2 --- /dev/null +++ b/_bootstrap/.stow-local-ignore @@ -0,0 +1,4 @@ +# TODO find a more generic way to express 'ignore any non-folder files' + +^/install_packages.sh +^/packages.csv diff --git a/_bootstrap/autostow.sh b/_bootstrap/autostow.sh deleted file mode 100755 index 25638b1..0000000 --- a/_bootstrap/autostow.sh +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env bash -# -# autostow.sh -# -# Stow automatic symlinking script -# -# Invokes stow for every folder within this repository, and that's it. - -ignore="${AUTOSTOW_IGNORED_DIRS}" - -main() { - case "$1" in - -s | --stow) - have_stow - stow_dirs - exit 0 - ;; - -d | --delete) - have_stow - unstow_dirs - exit 0 - ;; - -n | --dry-run) - have_stow - dryrun - exit 0 - ;; - -v | --version) - printf "System bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.2.1\n" - ;; - -h | --help | *) - usage - exit 0 - ;; - esac - shift -} - -stow_dirs() { - printf "Creating dotfile symlinks .................................................\n" - for d in */; do - - if is_ignored "$d"; then - printf "ignoring %s\n" "$d" - continue - fi - - printf "stowing %s\n" "$d" - stow -S -t ~ "$d" - done - printf "Done creating symlinks ....................................................\n" -} - -unstow_dirs() { - printf "Removing dotfile symlinks .................................................\n" - for d in */; do - - if is_ignored "$d"; then - printf "ignoring %s\n" "$d" - continue - fi - - printf "unstowing %s\n" "$d" - stow -D -t ~ "$d" - done - printf "Done removing symlinks ....................................................\n" -} - -dryrun() { - printf "Printing processed directories ............................................\n" - for d in */; do - - if is_ignored "$d"; then - printf "ignoring %s\n" "$d" - continue - fi - - printf "processing %s\n" "$d" - done - printf "Done printing directories .................................................\n" -} - -is_ignored() { - IFS=":" - for ign in $ignore; do - # it is either passed in through our environment variable - if [ "$ign" = "$1" ] || [ "$ign/" = "$1" ]; then - return 0 - fi - done - # or it starts with a _ which is ignored by default (that's the regex). - # (using herestring to avoid cat>grep) - if grep -q -e '^_[[:alnum:]]\{1,\}' <<<"$1"; then return 0; fi - return 1 -} - -have_stow() { - if ! type stow >/dev/null 2>&1; then - printf "GNU stow needs to be installed for this script to function. Please install stow through your package manager.\n" - exit 1 - fi -} - -usage() { - printf "%s\n" \ - "" \ - " autostow.sh - Automatically stow your dotfiles." \ - " Uses GNU stow to set up automatic links to any dotfiles in subdirectories of this directory." \ - "" \ - " Usage: stow.sh -dhsn" \ - "" \ - " Options:" \ - "" \ - " -h | --help Print out this help." \ - "" \ - " -s | --stow Install dotfiles, by symlinking any directory found next to stow.sh using GNU stow." \ - "" \ - " -d | --delete Remove dotfiles, by unlinking any directory found next to stow.sh using GNU stow." \ - "" \ - " -n | --dry-run Do not invoke any operation but print out directories affected, simulating a dry-run." \ - "" \ - " Note, by default any directory starting with an underscore _directoryname will be ignored." \ - " Additional folders to ignore can be set through the environment variable AUTOSTOW_IGNORED_DIRS " \ - " using a colon-separated string: AUTOSTOW_IGNORED_DIRS=\"directories:to:ignore\" " \ - "" \ - "" -} - -main "$@" diff --git a/install.sh b/install.sh index f8b3b0d..406c651 100755 --- a/install.sh +++ b/install.sh @@ -6,7 +6,7 @@ # # Will first install yay, then all my used packages (read from bootstrap/packages.csv) # -# Will symlink all my dotfiles into their correct places using autostow.sh +# Finally, symlinks all dotfiles into their correct locations using stow bootstrap_dir="${BOOTSTRAP_DIRECTORY:-./_bootstrap}" @@ -60,7 +60,7 @@ install() { unset BOOTSTRAP_PACKAGES echo "=================== BEGINNING DOTFILE MANAGEMENT ==========================" - "$bootstrap_dir"/autostow.sh -s + stow -R ./*/ echo "====================== INSTALLATION FINISHED =============================="