From 06d1242317f7159ccf3014f0a1480e7c56236ebb Mon Sep 17 00:00:00 2001 From: Mohammad Reza Karimi Date: Sun, 4 Jan 2026 21:28:36 -0500 Subject: add all sorts of things --- scripts/dot-local/bin/stowify | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 scripts/dot-local/bin/stowify (limited to 'scripts/dot-local/bin/stowify') diff --git a/scripts/dot-local/bin/stowify b/scripts/dot-local/bin/stowify new file mode 100755 index 0000000..fb51025 --- /dev/null +++ b/scripts/dot-local/bin/stowify @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +if [ $# -lt 2 ]; then + echo "Usage: $0 [source2 ...] " + return 1 +fi + +pkg="${@:$#}" +stowdir="$HOME/dotfiles" +sources=("${@:1:$#-1}") + +mkdir -p "$stowdir/$pkg" + +_stowify_convert_path() { + local rel_path="$1" + local IFS='/' + local parts out_parts part + + read -ra parts <<<"$rel_path" + for part in "${parts[@]}"; do + if [[ $part == .* ]]; then + out_parts+=("dot-${part#.}") + else + out_parts+=("$part") + fi + done + + local out="" + for part in "${out_parts[@]}"; do + if [ -z "$out" ]; then + out="$part" + else + out="$out/$part" + fi + done + printf '%s\n' "$out" +} + +for src in "${sources[@]}"; do + src="$(realpath -m "$src")" # expand to absolute path + + if [ ! -e "$src" ]; then + echo "Error: $src does not exist" + continue + fi + + if [[ $src == "$HOME"/* ]]; then + rel_path="${src#"$HOME"/}" + else + echo "Warning: $src is not under \$HOME — skipping" + continue + fi + + conv_rel_path="$(_stowify_convert_path "$rel_path")" || continue + + dest_path="$stowdir/$pkg/$conv_rel_path" + dest_dir="$(dirname "$dest_path")" + + echo "$dest_dir" + echo "$dest_path" + + mkdir -pv "$dest_dir" || { + echo "Failed to create $dest_dir" + continue + } + mv -v "$src" "$dest_path" || { + echo "Failed to move $src" + continue + } +done + +stow -d "$stowdir" -v --dotfiles "$pkg" -- cgit v1.2.3-71-gdd5e