Commit bab72f5f authored by Marco van Hulten's avatar Marco van Hulten 🤔
Browse files

Make the manager simpler and correcter

The symlink manager is correct in use, using getopts for options, being
POSIX compatible (Bourne shell) and thus cross-platform and easy to use
(it does the right thing when no, or wrong, arguments are given).  Also
updated the documentation to reflect this.  However, I use arrays for
clarity, so one needs Bash (/bin/sh on OpenBSD won't work).

Resolves: #14 #7 #5 #1
parent 169fb71c
make-symlinks
Make for each file in INPUTDIR a symlink(7) to OUTPUTDIR/.
Make for each file in INPUTDIR a symlink(7) in OUTPUTDIR
SYNOPSIS
make-symlinks -i DIRIN -o DIROUT [-f] [-n]
make-symlinks [-i DIRIN] [-o DIROUT]
DESCRIPTION
This program will use ln(1) to make a symbolic link between files from one
directory to another.
By default DIRIN is the adjacent 'dotfiles' directory and DIROUT the user's
homedirectory. The files in DIRIN must not have leading dots as they will in
DIROUT. The target must either not exist or be a symlink. If it is a
directory, it will descend therein and does the same as on the root level,
except that it will not be prefixed with a dot and it will descend no further
into the directory structure.
OPTIONS
-i DIRIN Use files DIRIN/* (including dotfiles).
-o DIROUT Put symlinks in DIROUT/.
-a Always remove/overwrite destination files, even if they are not
symlinks.
-n Never remove/overwrite files, even not if they are symlinks.
EXAMPLE
Install dotfiles into homedirectory overwriting symlinks therein but no other
files:
Install the dotfiles from an alternative source into your homedirectory:
cd dotfiles+mgt/
bin/make-symlinks dotfiles ~
make-symlinks -i ~/my-dotfiles
#!/usr/bin/env bash
set -e
shopt -s failglob
# By default the 'dotfiles' directory lies adjacent to the 'bin' directory
dotfiles_dir="$(realpath ${1:-$(dirname $(realpath $0))/../dotfiles})"
if [ ! -d ${dotfiles_dir} ]; then
echo "ABORT: Directory ${dotfiles_dir} does not exist!"
dotfiles_dir="$(dirname $(dirname $(realpath $0)))/dotfiles"
install_dir="$HOME"
print_usage() {
echo "Usage: make-symlinks [-i DIRIN] [-o DIROUT]"
}
while getopts 'i:o:' flag; do
case "${flag}" in
i) dotfiles_dir="${OPTARG}" ;;
o) install_dir="${OPTARG}" ;;
*) print_usage
exit 1 ;;
esac
done
if [ ! -e ${dotfiles_dir} ]; then
echo "ABORT: ${dotfiles_dir} does not exist!"
exit 1
fi
# By default the target directory is the user's homedirectory
install_dir="${2:-$HOME}"
if [ ! -e ${install_dir} ]; then
echo "ABORT: ${install_dir} does not exist!"
exit 1
fi
if [ "${dotfiles_dir}" = "$(realpath ${install_dir})" ]; then
if [ "$(realpath ${dotfiles_dir})" = "$(realpath ${install_dir})" ]; then
echo "ABORT: The dotfiles directory is identical to installation directory!"
exit 1
fi
......
......@@ -3,9 +3,9 @@
.Os
.Sh SYMLINKS
.Nm make-symlinks
.Nd Make for each file in INPUTDIR a symlink(7) to OUTPUTDIR/.
.Nd Make for each file in INPUTDIR a symlink(7) to OUTPUTDIR
.Sh SYNOPSIS.Nm make-symlinks
.Op -i DIRIN -o DIROUT [-f] [-n]
.Op [-i DIRIN] [-o DIROUT]
.Ar
.Sh DESCRIPTION
This program will use ln(1) to make a symbolic link between files from one
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment