From b29dfb9af63eced376ee9368809f5148216fc08c Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sat, 17 Feb 2024 23:11:38 +0100 Subject: [PATCH] Rewrite dot-put script --- home/.local/bin/scripts/cli/dot-put | 61 ++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/home/.local/bin/scripts/cli/dot-put b/home/.local/bin/scripts/cli/dot-put index a60725d..b5b35ad 100755 --- a/home/.local/bin/scripts/cli/dot-put +++ b/home/.local/bin/scripts/cli/dot-put @@ -4,12 +4,61 @@ set -euo pipefail dotdir="$HOME/dots" dothome="$dotdir/home" dotroot="$dotdir/root" -syspath="$(realpath "$1")" -if [[ "$syspath" == "$HOME"* ]]; then - dotpath="${syspath/#$HOME/$dothome}" -else - dotpath="$dotroot$syspath" +usage() { + echo "$0" + echo + echo "Usage: $0 [options] + +Options: + -h, --help Print this usage message. +Positional arguments: + file Path to be copied to dotfiles. + +Details: + A script to quickly copy specified files to dotfile directory. +" +} + +dotcopy() { + syspath="$1" + + if [[ "$syspath" == "$HOME"* ]]; then + dotpath="${syspath/#$HOME/$dothome}" + else + dotpath="$dotroot$syspath" + fi + + # Ensure the destination directory exists + mkdir -p "$(dirname "$dotpath")" + + cp -vi "$syspath" "$dotpath" +} + +getopt=$(getopt \ + --longoptions=help \ + --options=h \ + -- "$@") || exit 1 +eval set -- "${getopt}" + +while [ $# -gt 0 ]; do + case "$1" in + -h | --help) + usage + exit 0 + ;; + --) + shift 1 + break + ;; + esac +done + +if [ $# -eq 0 ]; then + echo "No paths specified" >&2 + exit 1 fi -cp -vi "$syspath" "$dotpath" +for arg in "$@"; do + dotcopy "$arg" +done