Skip to content

Instantly share code, notes, and snippets.

@padawanphysicist
Last active February 24, 2023 02:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save padawanphysicist/d6299870de4ef8ad892f to your computer and use it in GitHub Desktop.
Save padawanphysicist/d6299870de4ef8ad892f to your computer and use it in GitHub Desktop.
Install emacs packages from the command-line
#!/bin/bash
#
# I wrapped the code constructed in
#
# http://hacks-galore.org/aleix/blog/archives/2013/01/08/install-emacs-packages-from-command-line
#
# in a single bash script, so I would a single code snippet.
#
# Package to be installed
pkg_name=$1
# Elisp script is created as a temporary file, to be removed after installing
# the package
elisp_script_name=$(mktemp /tmp/emacs-pkg-install-el.XXXXXX)
elisp_code="
;;
;; Install package from command line. Example:
;;
;; $ emacs --batch --expr \"(define pkg-to-install 'smex)\" -l emacs-pkg-install.el
;;
(require 'package)
(package-initialize)
(add-to-list 'package-archives
'(\"melpa\" . \"http://melpa.milkbox.net/packages/\") t)
(add-to-list 'package-archives
'(\"marmalade\" . \"http://marmalade-repo.org/packages/\") t)
;; Fix HTTP1/1.1 problems
(setq url-http-attempt-keepalives nil)
(package-refresh-contents)
(package-install pkg-to-install)"
echo "$elisp_code" > $elisp_script_name
if [ $# -ne 1 ]
then
echo "Usage: `basename $0` <package>"
exit 1
fi
emacs --batch --eval "(defconst pkg-to-install '$pkg_name)" -l $elisp_script_name
# Remove tmp file
rm "$elisp_script_name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment