Skip to content

Instantly share code, notes, and snippets.

@andrwj
Forked from padawanphysicist/emacs-pkg-install.sh
Created June 11, 2021 18:49
Show Gist options
  • Save andrwj/0a86de4f8e443995226fd23f377e886a to your computer and use it in GitHub Desktop.
Save andrwj/0a86de4f8e443995226fd23f377e886a 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