From 3769cb3fa3bbac7aacaea31580564c699cb040a6 Mon Sep 17 00:00:00 2001 From: Jonas H Date: Fri, 27 Feb 2026 22:39:18 +0100 Subject: [PATCH] dot-add: support multiple files and directories --- dot-add | 60 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/dot-add b/dot-add index 2c5a374..811b224 100755 --- a/dot-add +++ b/dot-add @@ -1,50 +1,50 @@ #!/usr/bin/env bash -# dot-add: Move a config file into the dotfiles repo and stow it. +# dot-add: Move config files/dirs into the dotfiles repo and stow them. # -# Usage: dot-add +# Usage: dot-add [ ...] # -# Example: dot-add sway ~/.config/sway/config -# dot-add alacritty ~/.config/alacritty/alacritty.toml +# Examples: +# dot-add sway ~/.config/sway/config +# dot-add sway ~/.config/sway/ +# dot-add sway ~/.config/sway/* set -euo pipefail DOTFILES_DIR="$(cd "$(dirname "$0")" && pwd)" -if [[ $# -ne 2 ]]; then - echo "Usage: dot-add " - echo " package: name for the stow package (e.g. sway, alacritty)" - echo " file: path to the file (absolute or relative to HOME)" +if [[ $# -lt 2 ]]; then + echo "Usage: dot-add [ ...]" exit 1 fi PACKAGE="$1" -FILE="$(realpath "$2")" +shift -if [[ ! -e "$FILE" ]]; then - echo "Error: '$FILE' does not exist" - exit 1 -fi +add_one() { + local FILE + FILE="$(realpath "$1")" -if [[ ! "$FILE" == "$HOME/"* ]]; then - echo "Error: file must be under \$HOME ($HOME)" - exit 1 -fi + if [[ ! -e "$FILE" ]]; then + echo "Error: '$FILE' does not exist" >&2 + return 1 + fi -# Relative path from HOME (e.g. .config/sway/config) -REL="${FILE#$HOME/}" + if [[ ! "$FILE" == "$HOME/"* ]]; then + echo "Error: '$FILE' is not under \$HOME" >&2 + return 1 + fi -DEST_DIR="$DOTFILES_DIR/$PACKAGE/$(dirname "$REL")" -DEST="$DOTFILES_DIR/$PACKAGE/$REL" + local REL="${FILE#$HOME/}" + local DEST="$DOTFILES_DIR/$PACKAGE/$REL" -mkdir -p "$DEST_DIR" -mv "$FILE" "$DEST" -echo "Moved: $FILE -> $DEST" + mkdir -p "$(dirname "$DEST")" + mv "$FILE" "$DEST" + echo "Moved: $FILE -> $DEST" +} + +for PATH_ARG in "$@"; do + add_one "$PATH_ARG" +done -# Stow the package (restow if already stowed) stow --dir="$DOTFILES_DIR" --target="$HOME" --restow "$PACKAGE" echo "Stowed: $PACKAGE" -echo "" -echo "Next steps:" -echo " cd ~/dotfiles" -echo " git add $PACKAGE/$REL" -echo " git commit -m 'add $REL'"