I usually start programs from the command line.  I recently started
using Magit, and it seems natural to me to start it that way rather
than by opening an Emacs frame and typing M-x magit-status.

So, I wrote a script that would do that by creating a new Emacs frame
showing a magit-status buffer for the given directory (default=pwd).

I wrote it to use emacsclient if possible, and start a new Emacs
session if Emacs isn't already running in server mode.  I tested it on
Emacs 22 and 23, in graphical and text-only environments, with Emacs
built with and without X support.

Is this the sort of thing that Magit developers would be interested in
including?  I included the script below, with a link to its home in my
GitHub repository.

https://github.com/pjweisberg/magit/blob/shell-script/magit

======================================================================
#!/bin/sh

# Copyright (C) 2011 Peter J Weisberg.
#
# Magit is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# Magit is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Magit.  If not, see <http://www.gnu.org/licenses/>.

if [ -n "$1" ]; then
    dir=$(readlink -m "$1")
else
    dir=$(pwd)
fi

runmagit="(progn (magit-status \"$dir\")
                 (delete-other-windows))"

# Don't allow non-empty alternate editor
env | grep ^ALTERNATE_EDITOR=$ > /dev/null
if [ $? != 0 ]; then
    local ALTERNATE_EDITOR=false
fi

if [ "$DISPLAY" ]; then
    emacsclient --eval "(progn (select-frame (make-frame-on-display
\"$DISPLAY\"))
                               $runmagit)" 2>&1 |
    grep "Don't know how to create a frame on window system" > /dev/null
    #^Above is what you get when $DISPLAY is set but emacs was
    # built without X support.
    if [ $? = 0 ]; then
        emacsclient --tty --eval "$runmagit" 2>/dev/null
    fi
else
    emacsclient --create-frame --eval "$runmagit" 2>/dev/null
fi

if [ $? != 0 ]; then
    #Server not running or emacsclient not usable
    emacs --eval "$runmagit"
fi

Reply via email to