Skip to content

Instantly share code, notes, and snippets.

@ajchemist
Forked from padawanphysicist/emacs-pkg-install.sh
Created March 17, 2019 15:34
Show Gist options
  • Save ajchemist/12f45cba0fadf566660236d18541c90c to your computer and use it in GitHub Desktop.
Save ajchemist/12f45cba0fadf566660236d18541c90c 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