如何从 shell 运行组织模式命令?

sbi*_*mis 4 emacs shell

我想通过 bash 脚本运行 org-mode 命令。例如,在我定义的项目下,我有几个组织模式文件要导出到 html。然后我将文件同步到 Web 服务器等。出于这个原因,我想在不打开 emacs 并将文件导出到 html 文件的情况下从 bash 脚本执行此操作。

我如何运行组织模式命令,如

M-x org-publish-project
Run Code Online (Sandbox Code Playgroud)

然后输入项目名称让我们说,trial_project。我怎样才能在shell脚本中做到这一点?

Nic*_*ckD 5

我发布了一个这样的项目:

emacs -batch --load publish-doc.el --eval '(org-publish "publish-doc")'
Run Code Online (Sandbox Code Playgroud)

其中publish-doc.el包含“publish-doc”项目的定义。如果您可以通过 ssh 连接到您的服务器,您甚至可以publishing-directory使用远程:org 将用于tramp复制文件。

publish-doc.el如有必要,应初始化 org-mode 并定义项目 - 详细信息可能取决于您是使用 emacs 附带的 org-mode,还是使用 MELPA 或 git repo 的上游版本。但是你应该能够模仿你在正常初始化中所做的事情并让它继续下去。就我而言,我必须修改我的加载路径以找到 org,因为我从上游 git repo 克隆:你可能根本不需要它,但如果你确实需要它,你将需要修改所在位置的路径org 是从. 以下最小publish-doc.el将一组组织文件发布~/org~/public_html- 这是根据手册中示例改编的,除了我必须添加发布功能:

(add-to-list 'load-path "~/src/emacs/org/org-mode/lisp/")

(require 'org)
(require 'ox-html)

(setq org-publish-project-alist
  '(("org"
     :base-directory "~/org/"
     :publishing-directory "~/public_html"
     :publishing-function org-html-publish-to-html
     :section-numbers nil
     :with-toc nil
     :html-head "<link rel=\"stylesheet\"
             href=\"../other/mystyle.css\"
             type=\"text/css\"/>")))
Run Code Online (Sandbox Code Playgroud)

然后命令行调用

 emacs -batch -l publish-doc.el --eval '(org-publish "org")'
Run Code Online (Sandbox Code Playgroud)

哈。

编辑:如评论中所述,在使用时-batch,您必须加载一个初始化文件:-batch意味着不会加载-q您的.emacs或等效的文件。您可以使用但它通常包含很多无关的东西,因此在准备从命令行运行的脚本时,大多数人更喜欢使用修剪过的初始化文件,其中仅包含手头任务所需的内容(参见上面的文件)。-l ~/.emacspublish-doc.el