12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/bin/bash
-
- . <(ffoom init)
-
- ffoo import core
-
- 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() {
- local u
- u="[-d|--debug] [-f|--force] [-v|--verbose]"
- u="$u [-t|--target TARGET] SOURCE [NAME]"
- usage_is "$u"
- }
-
- 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-ini -p ln.dir.$1 | expand_tilde | debug_pipe out
- }
-
- while true; do case $1 in
- -d|--debug) FFOO_DEBUG=true; shift ;;
- -f|--force) FORCE=true; shift ;;
- -v|--verbose) FFOO_VERBOSE=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.ini";;
- $prefix.) name=$prefix;;
- .$name) :;;
- *) name=$prefix.$name;;
- esac
-
- debug -v name target
-
- mkdir -p $target
- link $src $target/$name
|