emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master b2693d1 160/399: counsel.el (counsel-locate-db-path): New


From: Oleh Krehel
Subject: [elpa] master b2693d1 160/399: counsel.el (counsel-locate-db-path): New defcustom
Date: Sat, 20 Jul 2019 14:57:15 -0400 (EDT)

branch: master
commit b2693d16941dbb3ac9b48c588f5cebbf4036e026
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    counsel.el (counsel-locate-db-path): New defcustom
    
    * counsel.el (counsel-locate): Automatically update db for encrypted
      home.
---
 counsel.el | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/counsel.el b/counsel.el
index 19e3062..e1a733c 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2287,11 +2287,30 @@ string - the full shell command to run."
       (funcall counsel-locate-cmd input))
      '("" "working..."))))
 
+(defcustom counsel-locate-db-path "~/.local/mlocate.db"
+  "Location where to put the locatedb in case your home folder is encrypted."
+  :type 'file)
+
+(defun counsel--locate-updatedb ()
+  (when (file-exists-p "~/.Private")
+    (let ((db-fname (expand-file-name counsel-locate-db-path)))
+      (setenv "LOCATE_PATH" db-fname)
+      (when (or (not (file-exists-p db-fname))
+                (> (time-to-seconds
+                    (time-subtract
+                     (current-time)
+                     (nth 5 (file-attributes db-fname))))
+                   60))
+        (message "Updating %s..." db-fname)
+        (counsel--command
+         "updatedb" "-l" "0" "-o" db-fname "-U" (expand-file-name "~"))))))
+
 ;;;###autoload
 (defun counsel-locate (&optional initial-input)
   "Call the \"locate\" shell command.
 INITIAL-INPUT can be given as the initial minibuffer input."
   (interactive)
+  (counsel--locate-updatedb)
   (ivy-read "Locate: " #'counsel-locate-function
             :initial-input initial-input
             :dynamic-collection t



reply via email to

[Prev in Thread] Current Thread [Next in Thread]