aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2026-12-02 18:49:11 -0800
committerEugene Triguba <hello@eugenetriguba.com>2026-12-02 18:49:11 -0800
commitb9ad60df754e13ae25f36890ef09de0e28ef9041 (patch)
treeb93d61cfbcda709c806d92098a8bcd9e26e24a42
parentUpdate .profile/.kshrc split (diff)
downloaddotfiles-b9ad60df754e13ae25f36890ef09de0e28ef9041.zip
Add link script
Diffstat (limited to '')
-rw-r--r--.link-ignore9
-rwxr-xr-xlink.sh63
2 files changed, 72 insertions, 0 deletions
diff --git a/.link-ignore b/.link-ignore
new file mode 100644
index 0000000..f590d4e
--- /dev/null
+++ b/.link-ignore
@@ -0,0 +1,9 @@
+.git
+.gitignore
+.link-ignore
+LICENSE
+link.sh
+macos
+README.md
+scripts
+*.swp
diff --git a/link.sh b/link.sh
new file mode 100755
index 0000000..a1b2ec4
--- /dev/null
+++ b/link.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+set -o errexit
+set -o nounset
+
+SCRIPT_DIR="$(realpath "$(dirname "$0")")"
+IGNORE_FILE="$SCRIPT_DIR/.link-ignore"
+
+DRY_RUN=''
+
+main() {
+ parse_args "$@"
+
+ for f in $SCRIPT_DIR/* $SCRIPT_DIR/.[!.]*; do
+ [ -e "$f" ] || continue
+ filename=${f##*/}
+ if is_ignored "$filename"; then
+ continue
+ fi
+ if [ -n "$DRY_RUN" ]; then
+ echo "Would link: $f to $HOME/$filename"
+ else
+ ln -sf "$f" "$HOME/$filename"
+ fi
+ done
+}
+
+parse_args() {
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --help|-h)
+ usage
+ exit 0
+ ;;
+ --dry-run)
+ DRY_RUN=1
+ shift
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+ done
+}
+
+usage() {
+ echo "Usage: $0 [--dry-run]"
+}
+
+is_ignored() {
+ [ -f "$IGNORE_FILE" ] || return 1
+ while IFS= read -r pattern || [ -n "$pattern" ]; do
+ case $pattern in
+ ''|'#'*) continue ;; # Skip blank lines and comments
+ esac
+ case $1 in
+ $pattern) return 0 ;; # Unquoted so we can treat it as a glob
+ esac
+ done < "$IGNORE_FILE"
+ return 1
+}
+
+main "$@"