1

How can I retrieve the list of recent files in bash?

I'd like to get this set of files so I can use it with rofi.

I could manually parse the data file that looks something like:

;;; Automatically generated by ‘recentf’ on Sat Apr 20 13:21:26 2019.

(setq recentf-list
      '(
        "/home/chris/dotfiles/Human-Friendly-Commands/modules/misc.sh"
        "/home/chris/dotfiles/Human-Friendly-Commands/commands.sh"
        "/etc/nixos/chris.nix"
        "/home/chris/fromLaptopt/usbflash/Haskell/HeliumGrape/src/DiscreteOscillators.hs"
        "/home/chris/fromLaptopt/usbflash/Haskell/HeliumGrape/src/MyDebug.hs"
        "/home/chris/Haskell/HeliumGrape/src/Main.hs"
...

But if there is a more idiomatic way that would be ideal.

1

You can also do this with emacsclient. Here I'm using space to separate file names:

#!/bin/sh

emacsclient -e "(mapconcat #'identity recentf-list \" \")"
thescript | sed 's/\s/\n/g'
0
 emacs --script t.elisp | sed -r '/^\s*$/d' | sed -n -e '/^"/p' | sed -e 's/"//g'

Not pretty but it works... Had to use sed to remove blank lines, 'tramp entries' (which aren't string(?)) and the quotes..

t.elisp

#!/usr/local/bin/emacs --script
(defun print-if-string (x)
       (cond ((stringp x) (print x))
             (t (error "Invalid argument %s in add-on" x))))
(defun print-elements-of-list (list)
 "Print each element of LIST on a line of its own."
 (while list
   (print-if-string (car list))
   (setq list (cdr list))))
(load "~/.emacs.d/.cache/recentf")
(print-elements-of-list recentf-list)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.