1. ZyX_I
  2. frawor


ZyX_I  committed aaa0e8e

@/os: Made relpath be aware of paths with trailing path separators

  • Participants
  • Parent commits d5f79c3
  • Branches default

Comments (0)

Files changed (3)

File plugin/frawor/os.vim

View file
  • Ignore whitespace
     let tcomponents=s:os.path.split(s:os.path.abspath(
                 \                               (a:0)?(s:os.path.normpath(a:1)):
                 \                                     ('.')))
+    call map([components, tcomponents], 'empty(v:val[-1])?remove(v:val, -1):0')
     if components[0] isnot# tcomponents[0]
         " This is valid for windows: you can't construct a relative path if 
         " directory to which path should be relative is on another drive
     while i<l && components[i] is# tcomponents[i]
         let i+=1
-    return s:os.path.join(repeat([".."], len(tcomponents)-i)+components[(i):])
+    return s:os.path.join(repeat(['..'], len(tcomponents)-i)+components[(i):])
 "▶3 os.path.basename  :: path → component
 function s:os.path.basename(path)
     let components=copy((a:0 && type(a:1)==type([]))?
                 \           (a:1):
                 \           (a:000))
-    call filter(components, 'type(v:val)=='.type(""))
+    call filter(components, 'type(v:val)=='.type(''))
     return substitute(join(components, s:os.sep), s:eps.'\+',
                 \     escape(s:os.sep, '\&~'), 'g')

File test/os.ok

  • Ignore whitespace
Binary file modified.

File test/rtp/plugin/os.vim

View file
  • Ignore whitespace
             \  'a/b:   '.os.path.isdir(ab),
             \  'a/b/c: '.os.path.isdir(abc))
+call WriteFile('a/b/c relative to a: '.os.path.relpath(abc,fnamemodify(a,':p')))
+call WriteFile('a/b/c relative to .: '.os.path.relpath(abc))
+call WriteFile('a/b/c relative to d: '.os.path.relpath(abc, 'd'))
 W: rmdir
 call os.rmdir(abc)
 call WriteFile('a:     '.os.path.isdir(a),