mirror of
				https://github.com/ItsDrike/dotfiles.git
				synced 2025-11-04 01:16:35 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			65 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
#!/bin/bash
 | 
						|
set -euo pipefail
 | 
						|
 | 
						|
dotdir="$HOME/dots"
 | 
						|
# the trailing slashes are important here!
 | 
						|
dothome="$dotdir/home/"
 | 
						|
dotroot="$dotdir/root/"
 | 
						|
 | 
						|
usage() {
 | 
						|
  echo "$0"
 | 
						|
  echo
 | 
						|
  echo "Usage: $0 [options] <file> <file...>
 | 
						|
 | 
						|
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="$(realpath "$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
 | 
						|
 | 
						|
for arg in "$@"; do
 | 
						|
  dotcopy "$arg"
 | 
						|
done
 |