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

标签 shell emacs

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

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

M-x org-publish-project

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

最佳答案

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

emacs -batch --load publish-doc.el --eval '(org-publish "publish-doc")'

哪里publish-doc.el包含“publish-doc”项目的定义。如果您可以通过 ssh 连接到您的服务器,您甚至可以拥有 publishing-directory远程:组织将使用 tramp将文件复制过来。
publish-doc.el如有必要,应初始化 org-mode 并定义项目 - 详细信息可能取决于您是使用 emacs 附带的 org-mode,还是使用 MELPA 或 git repo 的上游版本。但是您应该能够模仿您在正常初始化中所做的事情并开始执行。就我而言,我必须修改我的加载路径以找到 org,因为我从上游 git repo 克隆:您可能根本不需要它,但是如果您确实需要它,您将需要修改您所在位置的路径org 是从.以下最小publish-doc.el~/org 中发布了一组组织文件至 ~/public_html - 这是改编自 example in the manual除了我必须添加发布功能:
(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\"/>")))

然后命令行调用
 emacs -batch -l publish-doc.el --eval '(org-publish "org")'

哈。

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

关于shell - 如何从 shell 运行组织模式命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46295511/

相关文章:

python - 使用来自 cron 的日志文件重定向 stderr

bash - 在 Bash 中使用函数

emacs - 显示组织模式大纲直至特定标题级别

linux - 从shell脚本中的字符串中删除单引号

bash - sed 打印一行,其中至少有 3 位数字在第 4 位数字后重复数字

shell - Magento 产品平面数据不会重新索引

emacs - 格式异常 SML

emacs - 你如何在 emacs 中指定后备字体?

emacs - 在 dired 中调用相同 shell 命令的函数

macos - Shift-选择和 emacs 24