#!/bin/sh # symlinks or copies files into an automatically chosen target directory. always_copy=0 if test -n "$COLLECT_FILE_TARGET" then target="$COLLECT_FILE_TARGET" else target="$HOME/collected-$(date +%Y-%m-%d)" fi if test 0 -eq $# then echo "arguments: source_file ..." echo "COLLECT_FILE_TARGET: $target" exit fi while test $# -gt 0 do case "$1" in -c) always_copy=1 ;; --) shift break ;; -*) echo "Unknown option: $1" >&2 exit 1 ;; *) break ;; esac shift done mkdir -p "$target" target_device="$(stat -c %d "$target")" for a in "$@" do a="$(realpath "$a")" device="$(stat -c %d "$a")" if test 1 -eq $always_copy -o $target_device != $device then cp "$a" "$target" else ln -s "$a" "$target" fi done