IDE / Emacs 模式,用于在 Bash/Sh 等中编写 Shell 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1008750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IDE / Emacs mode for Shell scripting in Bash/Sh, etc
提问by Fernando Briano
I use Emacs for shell scripts. I know I read somewhere there's some mode to make it easier (code completion, autocomplete, bracket matching, syntax highligting, check syntax) to write Shell scripts on Emacs but haven't been able to find it. In short, I would like to turn Emacs into a Bash IDE.
我将 Emacs 用于 shell 脚本。我知道我在某处读到过一些模式,可以更轻松地(代码完成、自动完成、括号匹配、语法高亮显示、检查语法)在 Emacs 上编写 Shell 脚本,但一直找不到它。总之,我想把 Emacs 变成一个 Bash IDE。
Also, is there any other tool/IDE to make scripting easier on the GNU/Linux Shell?
另外,是否有任何其他工具/IDE 可以使 GNU/Linux Shell 上的脚本编写更容易?
回答by Trey Hymanson
Well, there's a built-in shell mode that does syntax highlighting, if it's not already turned on, M-x shell-script-modewill do it for you.
嗯,有一个内置的 shell 模式可以做语法高亮,如果它还没有打开,M-x shell-script-mode会为你做。
Regarding a tool to make scripting easier. There's a bash shell debugger, so if you program in bash, that would help quite a bit.
关于使脚本编写更容易的工具。有一个bash shell 调试器,所以如果你用 bash 编程,那会有很大帮助。
Of course there's eshell, a shell written in Emacs lisp, so you can get all the syntax highlighting you'd expect from lisp, the auto-completion, and the emacs lisp debugger.
当然,还有eshell,一个用 Emacs lisp 编写的 shell,因此您可以获得您期望从 lisp、自动完成和 emacs lisp 调试器中获得的所有语法突出显示。
回答by JesperE
I don't think there is any mode for code completion for shell-scripts, at least not in Emacs. (I've actually never felt the need.) However, there is support in bash for completion when running interactively (the package is called "bash-completion", or something similar). This provides tab-completion for many shell-commands.
我认为 shell 脚本没有任何代码完成模式,至少在 Emacs 中没有。(实际上我从来没有觉得有必要。)但是,bash 支持在交互式运行时完成(该包称为“bash-completion”或类似的东西)。这为许多 shell 命令提供了制表符补全。
回答by Fritz G. Mehner
回答by Paul M Edwards
回答by ericbsd
I know it is old post, but i will like to share my settings.
我知道这是旧帖子,但我想分享我的设置。
I add the same issue and now I use the code below in my .emacs file for sh/bash code autocompletion.
我添加了同样的问题,现在我在我的 .emacs 文件中使用下面的代码来自动完成 sh/bash 代码。
(require 'auto-complete)
(require 'auto-complete-config)
(ac-config-default)
The syntax highlighted should already working if you use new version of Emacs.
如果您使用新版本的 Emacs,突出显示的语法应该已经可以使用了。
回答by Alex Ding
I am not very familiar to Emacs, but I believe it's not convenient. As I see, good ide always can do:
我对 Emacs 不是很熟悉,但我相信它不方便。正如我所见,好的想法总是可以做到:
- Jump to declaration
- Find references
- Code Outline & Show Symbols
- Highlight occurrences
- Code completion
- 跳转到声明
- 查找参考资料
- 代码大纲和显示符号
- 突出显示事件
- 代码补全
So I will recommend Jetbrain Idea(with bashsupport plugin) and Visual Studio Code(with bash ide and shell-format extension).
所以我会推荐 Jetbrain Idea(带有 bashsupport 插件)和 Visual Studio Code(带有 bash ide 和 shell-format 扩展)。
ps:
附:
bashsupport - https://plugins.jetbrains.com/plugin/4230-bashsupport/
bashsupport - https://plugins.jetbrains.com/plugin/4230-bashsupport/
bash ide - https://marketplace.visualstudio.com/items?itemName=mads-hartmann.bash-ide-vscode
bash ide - https://marketplace.visualstudio.com/items?itemName=mads-hartmann.bash-ide-vscode

