#!/usr/bin/env bash # a helper symlink script since I always forget how to do this properly symlink() { local from to from="$1" to="$2" shift shift if [[ -z "$from" || -z "$to" ]]; then echo 'Usage: symlink [ln flags...]' echo 'Error: not enough arguments, provide file source "from" and destination "to" (including the link name in target directory)' 1>&2 return 1 fi # important! without full paths ln acts strange from="$(realpath "$from")" || return $? if [[ -e "$to" ]] && [[ "$*" != *"-f"* ]]; then echo "Error: $to already exists, specify -f flag to overwrite" 1>&2 return 1 fi echo "Linking $from -> $to" 1>&2 echo running: ln -s "$@" "$from" "$to" 1>&2 exec ln -s "$@" "$from" "$to" } symlink "$@" || exit $?