eeln.in 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/bash
  2. . <(ffoom init)
  3. ffoo import core
  4. DEFAULT_TARGET=$HOME
  5. TRY_RELPATH=true
  6. FORCE=false
  7. PY_SCRIPT="
  8. import os.path
  9. import sys
  10. src, dst = sys.argv[1:]
  11. r = os.path.relpath(src, dst)
  12. a = os.path.abspath(src)
  13. if len(a) < len (r):
  14. print a
  15. else:
  16. print r
  17. "
  18. usage() {
  19. local u
  20. u="[-d|--debug] [-f|--force] [-v|--verbose]"
  21. u="$u [-t|--target TARGET] SOURCE [NAME]"
  22. usage_is "$u"
  23. }
  24. link() {
  25. local src=$1
  26. local dst=$2
  27. debug -v src dst
  28. if $TRY_RELPATH;
  29. then
  30. src=$(python <(echo "$PY_SCRIPT") "$src" "$(dirname $dst)")
  31. fi
  32. think "linking $src to $dst"
  33. rm -f $dst
  34. ln -s $src $dst
  35. }
  36. load() {
  37. eeini -p ln.dir.$1 | expand_tilde | debug_pipe out
  38. }
  39. while true; do case $1 in
  40. -d|--debug) FFOO_DEBUG=true; shift ;;
  41. -f|--force) FORCE=true; shift ;;
  42. -v|--verbose) FFOO_VERBOSE=true; shift ;;
  43. -t|--target) target=$2 shift 2 ;;
  44. "") usage ;;
  45. *) src=$1; name=$2; break ;;
  46. esac done
  47. test -z "$target" && target=$(load target)
  48. test -z "$prefix" && prefix=$(load prefix)
  49. test -z "$target" && target=$DEFAULT_TARGET
  50. case $prefix.$name in
  51. .) die "provide at least name or set prefix in ln.ini";;
  52. $prefix.) name=$prefix;;
  53. .$name) :;;
  54. *) name=$prefix.$name;;
  55. esac
  56. debug -v name target
  57. mkdir -p $target
  58. link $src $target/$name