Initial dotfiles setup with dot-add helper
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Stow metadata
|
||||||
|
.stow-local-ignore
|
||||||
50
dot-add
Executable file
50
dot-add
Executable file
@@ -0,0 +1,50 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# dot-add: Move a config file into the dotfiles repo and stow it.
|
||||||
|
#
|
||||||
|
# Usage: dot-add <package-name> <file-path>
|
||||||
|
#
|
||||||
|
# Example: dot-add sway ~/.config/sway/config
|
||||||
|
# dot-add alacritty ~/.config/alacritty/alacritty.toml
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
DOTFILES_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
|
||||||
|
if [[ $# -ne 2 ]]; then
|
||||||
|
echo "Usage: dot-add <package> <file>"
|
||||||
|
echo " package: name for the stow package (e.g. sway, alacritty)"
|
||||||
|
echo " file: path to the file (absolute or relative to HOME)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
PACKAGE="$1"
|
||||||
|
FILE="$(realpath "$2")"
|
||||||
|
|
||||||
|
if [[ ! -e "$FILE" ]]; then
|
||||||
|
echo "Error: '$FILE' does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! "$FILE" == "$HOME/"* ]]; then
|
||||||
|
echo "Error: file must be under \$HOME ($HOME)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Relative path from HOME (e.g. .config/sway/config)
|
||||||
|
REL="${FILE#$HOME/}"
|
||||||
|
|
||||||
|
DEST_DIR="$DOTFILES_DIR/$PACKAGE/$(dirname "$REL")"
|
||||||
|
DEST="$DOTFILES_DIR/$PACKAGE/$REL"
|
||||||
|
|
||||||
|
mkdir -p "$DEST_DIR"
|
||||||
|
mv "$FILE" "$DEST"
|
||||||
|
echo "Moved: $FILE -> $DEST"
|
||||||
|
|
||||||
|
# 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'"
|
||||||
Reference in New Issue
Block a user