Browse Source

Replace Fastfoo's misc.expand_tilde with own

... as it's going away from Fastfoo pretty soon.
Alois Mahdal 9 years ago
parent
commit
4d9d756954
1 changed files with 24 additions and 1 deletions
  1. 24
    1
      src/libexec/saturnin-ln

+ 24
- 1
src/libexec/saturnin-ln View File

2
 
2
 
3
 . $(ffoom path)
3
 . $(ffoom path)
4
 
4
 
5
-ffoo import misc
6
 ffoo import pretty
5
 ffoo import pretty
7
 
6
 
8
 DEFAULT_TARGET=$HOME
7
 DEFAULT_TARGET=$HOME
25
     usage_is "[-f|--force] [-t|--target TARGET] [SOURCE] [NAME]"
24
     usage_is "[-f|--force] [-t|--target TARGET] [SOURCE] [NAME]"
26
 }
25
 }
27
 
26
 
27
+expand_tilde() {
28
+    #
29
+    # Exchange "~" for home
30
+    #
31
+    perl -pe "s|^[[:space:]]*~|$HOME|"
32
+}
33
+
34
+maybe_relpath() {
35
+    local src="$1"
36
+    local dst="$2"
37
+    $TRY_RELPATH || { echo "$src"; return 0; }
38
+    {
39
+        echo 'import os.path'
40
+        echo 'import sys'
41
+        echo 'src, dst = sys.argv[1:]'
42
+        echo 'r = os.path.relpath(src, dst)'
43
+        echo 'a = os.path.abspath(src)'
44
+        echo 'if len(a) < len (r):'
45
+        echo '    print a'
46
+        echo 'else:'
47
+        echo '    print r'
48
+    } | python "$src" "$dst"
49
+}
50
+
28
 link() {
51
 link() {
29
     local src=$1
52
     local src=$1
30
     local dst=$2
53
     local dst=$2