eeln.in 1.6KB

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