Last active
April 5, 2020 10:18
-
-
Save alphapapa/ca1ea75675a826e572bced86f69f51b6 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
# Please see the script's new home: https://github.com/alphapapa/magit.sh |
Don't know whether you have tested it, but it doesn't work for me. (bash: GNU bash, version 5.0.7(1)-release)
I tweaked it a little bit. Now it works great.
-h
doesn't work, sincegetopt
doesn't handle-h/--help
usage
function doesn't work, usecat
instead ofecho
- without specifying git repo, open magit and it will ask for repo (the original action)
- with specifying git repo, open magit in that git repo directly
- I'm using maxdepth=3 since I'm using Spacemacs. (change it back to 1 if you are not using Spacemacs)
#!/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 3 -type d -iname "$package-2*" \
| sort -r | head -n1 | \
while read path; do
printf -- '-L %q ' "$path"
done
done
}
function usage {
cat <<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 hx -l help,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
if [ -z "$1" ]; then
emacs -q $gui \
$(load_paths "${dependencies[@]}") \
-l magit -f magit-status \
--eval "(local-set-key \"q\" #'kill-emacs)" \
-f delete-other-windows
else
emacs -q $gui \
$(load_paths "${dependencies[@]}") -l magit \
--eval "(magit-status \"$1\")" \
--eval "(local-set-key \"q\" #'kill-emacs)" \
-f delete-other-windows
fi
@c02y Thanks, please see the latest revision.
Also consider to change the bangline. On NixOS and other systems not using the standard path for bash it wont work.
Instead of
#!/bin/bash
it should be
#!/usr/bin/env bash
I get this:
command-line-1: Cannot open load file: No such file or directory, magit
@dprae show the whole process, how did you get this error?
@c02y, sorry for the late response, I figured out what the problem was. My packages weren't directly in elpa/, but in elpa/28.0/develop, I modified the script and it works perfectly.
FYI, I've put the script in a repo of its own: https://github.com/alphapapa/magit.sh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wonderful, thanks!