ln wrapper

This commit is contained in:
2026-08-08 18:06:50 +02:00
parent 7da0c922ad
commit 11f162c91a
2 changed files with 51 additions and 0 deletions
+1
View File
@@ -10,6 +10,7 @@ While created for my own use, they are shared here in case others find them usef
- **check**: Validates script dependencies and configuration - **check**: Validates script dependencies and configuration
- **e-ink**: Display handler for e-ink displays with image cycling support - **e-ink**: Display handler for e-ink displays with image cycling support
- **indeel**: File organization tool that watches a directory and sorts incoming files based on content hashes - **indeel**: File organization tool that watches a directory and sorts incoming files based on content hashes
- **lnw**: `ln` wrapper that always creates a symbolic link, auto-detects which argument is the existing target, and converts paths to absolute
- **mover**: Monitors a source directory and moves files with specified extensions to a destination directory - **mover**: Monitors a source directory and moves files with specified extensions to a destination directory
- **pushover**: Sends push notifications via Pushover API - **pushover**: Sends push notifications via Pushover API
- **stats**: HTTP server that provides system statistics (CPU, memory, disk usage, etc.) in JSON format - **stats**: HTTP server that provides system statistics (CPU, memory, disk usage, etc.) in JSON format
Executable
+50
View File
@@ -0,0 +1,50 @@
#!/bin/bash
# ln? pfft
# Ja het was waarschijnlijk minder moeite geweest om het te onthouden
# dan om dit scriptje te schrijven.
set -euo pipefail
usage() {
echo "Ook altijd geen idee hoe ln ook alweer werkt? Geen zorgen."
echo "Doe: $0 <file> <link>" >&2
echo " of: $0 <link> <file>" >&2
exit 1
}
if [ $# -ne 2 ]; then
usage
fi
a="$1"
b="$2"
a_exists=0
b_exists=0
if [ -e "$a" ]; then a_exists=1; fi
if [ -e "$b" ]; then b_exists=1; fi
if [ "$a_exists" -eq 1 ] && [ "$b_exists" -eq 1 ]; then
# is één van de twee al een link? Dan is het goed.
if { [ -L "$a" ] && [ "$(readlink "$a")" = "$(realpath "$b")" ]; } || \
{ [ -L "$b" ] && [ "$(readlink "$b")" = "$(realpath "$a")" ]; }; then
exit 0
fi
echo "[FOUT] deze bestaan al: $a, $b" >&2
exit 1
# Geen van beide bestaat
elif [ "$a_exists" -eq 0 ] && [ "$b_exists" -eq 0 ]; then
echo "[FOUT] allebei niet gevonden: $a, $b" >&2
exit 1
elif [ "$a_exists" -eq 1 ]; then
target="$a"
link="$b"
else
target="$b"
link="$a"
fi
target_abs="$(realpath "$target")"
link_abs="$(realpath -m "$link")"
ln -s "$target_abs" "$link_abs"