Commits

ZyX_I committed aaa0e8e

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

Comments (0)

Files changed (3)

plugin/frawor/os.vim

     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
     endwhile
-    return s:os.path.join(repeat([".."], len(tcomponents)-i)+components[(i):])
+    return s:os.path.join(repeat(['..'], len(tcomponents)-i)+components[(i):])
 endfunction
 "▶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')
 endfunction

Binary file modified.

test/rtp/plugin/os.vim

             \  '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),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.