Skip to content

Instantly share code, notes, and snippets.

@willmcclellan
Forked from alphapapa/magit.sh
Created August 17, 2019 05:13

Revisions

  1. @alphapapa alphapapa revised this gist Aug 17, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion magit.sh
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@ EOF

    # * Args

    args=$(getopt -n "$0" -o x -l --no-x -- "$@") || { usage; exit 1; }
    args=$(getopt -n "$0" -o x -l no-x -- "$@") || { usage; exit 1; }
    eval set -- "$args"

    while true
  2. @alphapapa alphapapa created this gist Aug 17, 2019.
    69 changes: 69 additions & 0 deletions magit.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    #!/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