view emacs/e @ 578:7948fb9d0ced

If first file isn't owned by user - open it in TRAMP sudo.
author Oleksandr Gavenko <gavenkoa@gmail.com>
date Wed, 07 Jan 2015 23:33:54 +0200
parents dd77081b7588
children b72d9da93de6
line wrap: on
line source

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

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

case "$1" in
  -h|-help|--help)
    usage
    exit 0
    ;;
  "")
    printf "What file do you want to open?\n\n"
    usage
    exit 1
    ;;
esac

if [ -n "$COMSPEC" ]; then
  # We probably under Windows like OS. I like native Emacs over Cygwin.
  exec emacsclientw -a emacs -n -- "$@"
fi

f=`readlink -f "$1"`
if [ -e "$f" -a `stat -c %U "$f"` != $USER ] || [ -e "${f%/*}" -a `stat -c %U "${f%/*}"` != $USER ]; then
    shift
    exec emacsclient -a emacs -n -- "/sudo::$f" "$@"
fi
exec emacsclient -a emacs -n -- "$@"