-
-
Save willmcclellan/05a07e4a63f7e686ae5437dddb24a503 to your computer and use it in GitHub Desktop.
Run a standalone Magit editor!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run a standalone Magit editor! To improve startup speed, this | |
# script ignores the user's Emacs init files and only loads the Emacs | |
# libraries Magit requires. | |
# Note that this does NOT install any packages. Magit and its | |
# dependencies must already be installed in ~/.emacs.d. | |
dependencies=(magit async dash with-editor git-commit transient) | |
function load_paths { | |
# Echo the "-L PATH" arguments for Emacs. Since multiple versions | |
# of a package could be installed, and we want the latest one, we | |
# sort them and take the top one. | |
for package in "$@" | |
do | |
find ~/.emacs.d/elpa -maxdepth 1 -type d -iname "$package-2*" \ | |
| sort -r | head -n1 | \ | |
while read path | |
do | |
printf -- '-L %q ' "$path" | |
done | |
done | |
} | |
function usage { | |
echo <<EOF | |
It's Magit! | |
Options: | |
-h, --help This. | |
-x, --no-x Display in terminal instead of in a GUI window. | |
EOF | |
} | |
# * Args | |
args=$(getopt -n "$0" -o x -l no-x -- "$@") || { usage; exit 1; } | |
eval set -- "$args" | |
while true | |
do | |
case "$1" in | |
-h|--help) | |
usage | |
exit | |
;; | |
-x|--no-x) | |
gui="-nw" | |
;; | |
--) | |
# Remaining args (required; do not remove) | |
shift | |
rest=("$@") | |
break | |
;; | |
esac | |
shift | |
done | |
# * Main | |
emacs -q $gui \ | |
$(load_paths "${dependencies[@]}") \ | |
-l magit -f magit-status \ | |
--eval "(local-set-key \"q\" #'kill-emacs)" \ | |
-f delete-other-windows |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment