123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #!/bin/bash
-
- . <(ffoom init)
- FFOO_INIPATH="__FFOO_INIPATH__"
-
- 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 [-i|--intermediate] [-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 ln.ini | expand_tilde | debug_pipe out
- }
-
- while true;
- do
- case $1 in
- -d|--debug)
- FFOO_DEBUG=true
- shift
- ;;
- -f|--force)
- FORCE=true
- shift
- ;;
- -i|--intermediate)
- intermediate=$2
- shift 2
- ;;
- -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 "$intermediate" && intermediate=$(load intermediate)
- 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 intermediate target
-
- mkdir -p $target
-
- if test -n "$intermediate";
- then
- mkdir -p $intermediate
- link $src $intermediate/$name
- link $intermediate/$name $target/$name
- else
- link $src $target/$name
- fi
|