view emacs/e @ 630:ad57cd9cc810

'run' utility detach from terminal, need special care.
author Oleksandr Gavenko <gavenkoa@gmail.com>
date Tue, 07 Mar 2017 18:48:53 +0200
parents 815567721a82
children 44b6346fd952
line wrap: on
line source

#!/bin/sh
# Written by Oleksandr Gavenko <gavenkoa@gmail.com>, 2008-2014.

usage() {
  echo "Shortcut for emacsclient. See e(1) man page."
  echo "Usage:"
  echo "  e  file..."
}

case "$1" in
  -h|-help|--help)
    usage
    exit 0
    ;;
  "")
    set "$PWD"
    ;;
esac

if [[ "$MAKECYGEMACSADMIN" = yes ]]; then
    unset MAKECYGEMACSADMIN
    exec cygstart --action=runas run emacs-w32
fi

emacs_cmd=emacs
if [ -n "$COMSPEC" ]; then
    # We probably under Windows like OS. I like Cygwin emacs-w32.
    emacs_cmd=emacs-w32
fi

case ${0##*/} in
  ew) args="-a ${emacs_cmd}" ;;
  ec) args="-c" ;;
  et) args="-t" ;;
  *) args="-a ${emacs_cmd} -n" ;;
esac

if [ -n "$COMSPEC" ]; then
    # We probably under Windows like OS. I like Cygwin emacs-w32.
    case ${0##*/} in
      # 'run' utility detach from terminal, need special care.
      et) exec emacsclient-w32 $args -- "$@" ;;
      *) exec run --quote emacsclient-w32 $args -- "$@" ;;
    esac
fi

f=`readlink -f "$1"`
d="${f%/*}"
if [ '(' -f "$f" -a ! -w "$f" ')' -o '(' ! -e "$f" -a -e "$d" -a ! -w "$d" ')' ]; then
    shift
    exec emacsclient $args -- "/sudo::$f" "$@"
fi
exec emacsclient $args -- "$@"