straight.el icon indicating copy to clipboard operation
straight.el copied to clipboard

List of installed packages and versions

Open ghost opened this issue 7 years ago • 7 comments

How can I find out the version of a package I have installed with straight.el?

Is there a way i can find a list of installed packages and their version numbers (where that makes sense)?

ghost avatar Mar 27 '18 21:03 ghost

How can I find out the version of a package I have installed with straight.el?

I have the following in my init file.

;; Inspired by `magit-version'
(defun chunyang-straight-git-version (package)
  (interactive
   (list
    (straight--select-package "Package" nil 'installed)))
  (let ((recipe (gethash package straight--recipe-cache))
        version)
    (straight--with-plist recipe
        (local-repo type)
      (when (and (eq type 'git) local-repo)
        (let ((default-directory (straight--repos-dir local-repo)))
          (setq version (or (magit-git-string "describe" "--tags" "--dirty")
                            (magit-rev-parse "--short" "HEAD")))
          (message "%s %s" (upcase-initials package) version)
          version)))))

(chunyang-straight-git-version "magit")
     => "2.11.0-584-g4eb84d44"

Is there a way i can find a list of installed packages and their version numbers (where that makes sense)?

(map-keys straight--recipe-cache)
(let ((magit-repository-directories
       (list (cons (straight--repos-dir) 1))))
  (magit-list-repositories))

xuchunyang avatar Mar 28 '18 15:03 xuchunyang

Yes, I like the above suggestions. (Using M-x straight-freeze-versions may also be an option, depending on what you want.) It would be a good idea to add an interactive command for this, contributions welcome.

raxod502 avatar Mar 28 '18 16:03 raxod502

Wonderful, thanks @xuchunyang. That solution works great.

ghost avatar Mar 28 '18 17:03 ghost

I would have no objection to adding these kinds of quick hacks to straight-x.el, by the way. That way people could use them even more easily. (And we can get rid of them once there is a suitable replacement in straight.el proper.)

Perhaps the name should be straight-contrib.el rather than straight-x.el? (I'm not sure.)

raxod502 avatar Mar 29 '18 05:03 raxod502

I wanted to give this issue a bump - @xuchunyang 's solution works nicely, but it would be a nice feature to have a function straight-list-all-package-versions or so, which e.g. opens a buffer and prints all installed packages with their respective versions in a list or a table or so :)

aseltmann avatar May 12 '20 20:05 aseltmann

Pull requests are always appreciated.

raxod502 avatar May 13 '20 14:05 raxod502

internal api have changed so far, so xuchungyang's function need to be adjusted:

(defun straight-package-version (package)
  (interactive
   (list
    (straight--select-package "Package" #'straight--installed-p)))
  (let ((recipe (gethash package straight--recipe-cache))
        version)
    (straight--with-plist recipe
        (local-repo type)
      (when (and (eq type 'git) local-repo)
        (let ((default-directory (straight--repos-dir local-repo)))
          (setq version (or (magit-git-string "describe" "--tags" "--dirty")
                            (magit-rev-parse "--short" "HEAD")))
          (message "%s %s" (upcase-initials package) version)
          version)))))

shibormot avatar Mar 23 '23 19:03 shibormot