【问题标题】:Is there an editor that allows to evaluate the current line as a bash command?是否有允许将当前行评估为 bash 命令的编辑器?
【发布时间】:2015-02-19 09:19:50
【问题描述】:

我想逐行评估 bash 脚本。我也可能想跳回并再次执行上一行。

How execute bash script line by line? 中所述,可以使用内置调试选项-x,但这不是很方便,因为您没有以前和未来命令的概览。

为了用 R 编写软件,我使用了RStudio。编辑器允许通过点击Ctrl+Enter 将当前行评估为 R-Command。然后结果显示在一个内置的 shell 中,并且光标跳转到下一个命令。

是否有一个简单的文本编辑器(如 gedit)允许将当前行发送到内置的 shell/控制台(bash、zsh、...),然后在 shell 中查看评估结果?

【问题讨论】:

  • 在 Emacs 中,您可以轻松地将这样的功能添加到编辑器中,如果它还没有的话。
  • 怎么样? (我浏览了所有菜单,但找不到任何东西)

标签: linux bash shell editor eval


【解决方案1】:

它不是 Emacs 内置的,但很容易做到。

(defun shell-eval-line (pos)
  "Evaluate the line around position as a shell command.
In interactive mode, use the cursor's position."
  (interactive "d")
  (save-excursion
    (goto-char pos)
    (shell-command (buffer-substring
            (line-beginning-position) (line-end-position))) ))

绑定到您喜欢的键(C-c ! 可能?)然后开始。

(save-excursion) 之外添加(next-line) 使其在完成后前进到下一行,或者在其周围创建一个简单的宏来调用函数并跳转到下一行。

【讨论】:

  • 通常在您的 $HOME/.emacs.d/init.el 文件中。如果您只想在需要时加载它,而不是让init.el 负担您很少使用的东西,请将其放在单独的文件中并从那里加载。对于快速的临时实验,只需将其粘贴到 *scratch* 缓冲区和 M-x eval-defun 另请参阅 emacswiki.org/emacs/InitFile
【解决方案2】:

您也可以使用编辑器geany 进行操作。在他们的 Wiki 中,他们有一个 detailed instruction。简而言之:

  • 安装 geany
  • 打开文件~/.config/geany/geany.conf并设置send_selection_unsafe=true
  • 重启geany
  • 设置键绑定Edit > Preferences > Keybindings(在Format / Send selection to terminal下)

实际上,您不必选择要发送的代码。到目前为止,我无法找到如何指示 geany 之后跳转到下一行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-06
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    • 2017-02-01
    • 2018-10-25
    • 2011-09-06
    • 2023-04-09
    相关资源
    最近更新 更多