123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #!/bin/bash
-
- . $(ffoom path)
-
- ffoo import misc
- ffoo import pretty
-
- DEFAULT_TARGET=$HOME
- TRY_RELPATH=true
- FORCE=false
-
- PY_SCRIPT="
- import os.path
- import sys
- src, dst = sys.argv[1:]
- r = os.path.relpath(src, dst)
- a = os.path.abspath(src)
- if len(a) < len (r):
- print a
- else:
- print r
- "
-
- usage() {
- usage_is "[-f|--force] [-t|--target TARGET] SOURCE [NAME]"
- }
-
- link() {
- local src=$1
- local dst=$2
- debug -v src dst
- if $TRY_RELPATH;
- then
- src=$(python <(echo "$PY_SCRIPT") "$src" "$(dirname $dst)")
- fi
- think "linking $src to $dst"
- rm -f $dst
- ln -s $src $dst
- }
-
- load() {
- saturnin conf -p ln.dir.$1 | expand_tilde | debug_pipe out
- }
-
- while true; do case $1 in
- -f|--force) FORCE=true; shift ;;
- -t|--target) target=$2 shift 2 ;;
- "") usage ;;
- *) src=$1; name=$2; break ;;
- esac done
-
- test -z "$target" && target=$(load target)
- test -z "$prefix" && prefix=$(load prefix)
- test -z "$target" && target=$DEFAULT_TARGET
-
- case $prefix.$name in
- .) die "provide at least name or set prefix in ln.conf";;
- $prefix.) name=$prefix;;
- .$name) :;;
- *) name=$prefix.$name;;
- esac
-
- debug -v name target
-
- mkdir -p $target
- link $src $target/$name
|