rubyize PruneFiles

Fri, 27 Aug 2021 13:14:06 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Fri, 27 Aug 2021 13:14:06 -0500
changeset 943
e0ff02862951
parent 942
1d3b41412cf6
child 944
e67ad83a4265

rubyize PruneFiles

.vim/autoload/vimrc.vim file | annotate | diff | comparison | revisions
--- a/.vim/autoload/vimrc.vim
+++ b/.vim/autoload/vimrc.vim
@@ -111,13 +111,25 @@ func! vimrc#PrepDir(path) abort
   endif
 endfunc
 
+if has('ruby')
+  func! s:PruneFiles(path, days) abort
+    ruby <<END_RUBY
+      require 'pathname'
+
+      (path, days) = VIM.evaluate('[a:path, a:days]')
+      sunset       = Time.now - (days * 86400)
+
+      Pathname(path).realpath.each_child do |file|
+        file.delete if file.mtime < sunset
+      end
+END_RUBY
+  endfunc
+else
+  func! s:PruneFiles(path, days) abort
+  endfunc
+endif
+
 func! vimrc#PruneFiles(path, days) abort
-  let l:path = expand(a:path)
-  if isdirectory(l:path)
-    for file in split(globpath(l:path, "*"), "\n")
-      if localtime() > getftime(file) + 86400 * a:days
-        call delete(file)
-      endif
-    endfor
-  endif
+  call s:PruneFiles(a:path, a:days)
 endfunc
+

mercurial