#!/bin/bash # # Syntax: eml [-h] # # Purpose: Runs emacs on the the most recently changed .tex file # in the current directory, if it is present; otherwise, # the most recently changed file in the current directory # is opened with emacs. # The -h flag shows the help info for this command. # Created: Feb 2, 2001 by Bart De Schutter # Last revised: Aug 1, 2007 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: emacs if [ $# -ge 1 -a "$1" = "-h" ]; then sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi if [ $# -ne 0 ]; then echo >&2 echo >&2 "ERROR: ${0##*/} requires no input arguments." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi texfile=$( (ls -t *.tex | head -n 1) 2>/dev/null) if [ -n "$texfile" ]; then emacs "$texfile" & else # List directory contents sorted by modification time, filter out # directories, select the most recent file, and remove any trailing # @ or *. lastfile=$( (ls -tF | grep -v '/$' | head -n 1 | sed -e 's/[@*]$//' ) 2>/dev/null) if [ -n "$lastfile" -a -f "$lastfile" ]; then emacs "$lastfile" & else echo "No files found." fi fi