123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #!/bin/bash
-
- . <(ffoom init)
- FFOO_INI_PATH="__FFOO_INI_PATH__"
-
- ffoo import core
- ffoo import ini
-
- 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() {
- iniread -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
|