#!/usr/bin/env -S emacs -Q --script
;;; e2ansi-cat --- Output syntax highlighted files to terminal -*- emacs-lisp -*-

;; Copyright (C) 2014,2025 Anders Lindgren

;; Author: Anders Lindgren
;; Keywords: faces, languages
;; Created: 2014-12-07
;; URL: https://github.com/Lindydancer/e2ansi

;; This program 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 of the License, or
;; (at your option) any later version.
;;
;; This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; This is a command line tool using Emacs in batch mode to render a
;; syntax highlighted version of the input files using ANSI escape
;; sequences.
;;
;; Usage:
;;
;;    e2ansi-cat [options] file ...
;;
;; See the file `e2ansi.el' for more information.

;;; Code:

;; Ensure that the `e2ansi' modules are in the path.
;;
;; `file-truename' enables people to symlink to this file.
(let ((dir (file-name-directory (file-truename load-file-name))))
  (add-to-list 'load-path (concat dir "..")))

(require 'e2ansi-load-init)

;; Ensure that dependencies are found.
(package-initialize)

(require 'e2ansi)

(setq e2ansi-batch-help-text "\
Syntax highlight files using ANSI escape sequences using Emacs as
the engine. See the file \"e2ansi.el\" for more information.

Usage:
    emacs [...Emacs options...] -l bin/e2ansi-cat [options] file ...

  Or:

    e2ansi-cat [options] file ...

When \"file\" is \"-\", standard input is read.")

(if (null command-line-args-left)
    (e2ansi-batch-usage)
  (e2ansi-batch-convert))

;;; e2ansi-cat ends here.
