This extension now resides within the official
use-package distribution.
You’re using use-package
to manage your Emacs environment. Well played. Maybe you then want to
ensure related system binary packages exist along side of these
package/feature declarations? Oh nice, me too.
-
Obviously you need to be using
use-package. -
Make sure your
exec-pathis cognisant of all binary package names that you would like to ensure exist.exec-path-from-shellis a good way to do this. -
This package leverages
system-packagesto provide the default install behavior for different systems. If you need to customize this beforehand, you may.
Note: This is only available on MELPA.
(use-package use-package-ensure-system-package
:ensure t)Here’s an example:
(use-package rg
:ensure t
:ensure-system-package rg
:chords (":G" . rg-projecet))This will expect a global binary package to exist called rg. If it
does not, it will use your system package manager to attempt an
install of a binary by the same name asyncronously. For example, for
most macOS users it would call: brew install rg.
Good default stuff. What if you want to customize the install command?
(use-package tern
:ensure t
:ensure-system-package (tern . "npm i -g tern")):ensure-system-package can take a cons. In that case, its cdr
should be a string that will get piped to (async-shell-command) to
install the darn thing if it doesn’t exist.
Also you may also pass in a list of cons-es in the same format:
(use-package ruby-mode
:ensure-system-package
((rubocop . "gem install rubocop")
(ruby-lint . "gem install ruby-lint")
(ripper-tags . "gem install ripper-tags")
(pry . "gem install pry")))- Better compatibility with the
:deferand:defer-installkeywords.