output asked headers in the order they were asked; avoid header name spoofing by...
[hband-tools.git] / user-tools / lnto
blob85539e4aa43a438971f6e9dbf3595cb2c0f6ca82
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 lnto - Convenience wrapper for ln(1). User enters link target paths relative to the current directory
10 =cut
12 EOF
15 set -e
16 set -o pipefail
18 type relpath >/dev/null
20 target_dir=''
21 declare -a opts=()
22 declare -a link_targets=()
24 add_link_target()
26 local file=$1
27 local filedir=`dirname "$file"`
28 local basename=`basename "$file"`
29 local relative_path=`relpath "$filedir" "$target_dir"`"$basename"
30 link_targets+=("$relative_path")
34 while [ $# != 0 ]
36 case "$1" in
37 --help|-h)
38 echo "Usage: $(basename "$0") [OPTIONS] <TARGET_DIR> [LINK_TARGET [LINK_TARGET [...]]]"
39 echo "Creates links (symlinks with -s) in TARGET_DIR which are pointing to LINK_TARGET."
40 echo "Unlike to ln(1), LINK_TARGET is relative to the current working directory, not to TARGET_DIR."
41 echo "OPTIONS are the same as for ln(1)."
42 exit
44 --) shift; break;;
45 -*) opts+=("$1");;
46 *) if [ -z "$target_dir" ]
47 then
48 target_dir=$1
49 else
50 add_link_target "$1"
51 fi;;
52 esac
53 shift
54 done
56 for file in "$@"
58 add_link_target "$file"
59 done
61 ln "${opts[@]}" -t "$target_dir" "${link_targets[@]}"