smc*_*mcs 36 text-editor scripts
我经常会在 gedit 中更改一个小脚本,然后从终端运行它。是不是有一个简单的文本编辑器,带有一个“运行”按钮或其他东西来简化它?即使在 Eclipse 中,这也不是小事。我正在寻找有关哪些文本编辑器支持此功能或如何扩展它们以支持此功能的具体建议。
小智 33
在vim并使用:!bash file.sh或只是为它创建一个快捷方式.vimrc
在 Emacs 中,您使用M-!. 所以你按住Alt然后按!。您甚至可以通过选择要传递给命令的内容然后按 将当前缓冲区中的文本传递给命令M-|。因此,您可以突出显示您的代码并将其传递给命令bash。
每个工具都有它自己的方式!
find和entr运行此命令,以便每当.sh目录中的任何文件发生更改时,它将自动再次运行:
find . -name '*.sh' | entr -cs file.sh
Run Code Online (Sandbox Code Playgroud)
tmux,vim和entr活编码我很久以前就写了这个c++,然后在其他语言中更多地使用它,现在你也可以将它用于 shell 编程。
这是它的样子:
为了让程序运行,我所要做的就是将它保存在 vim ( :w) 中,然后它就会运行。
将其保存在~/bin/ide:
#!/usr/bin/bash
tmpdir=""
template="simple"
for i in "$@"
do
case $i in
-t=*|--template=*)
template="${i#*=}"
shift # past argument=value
;;
-n=*|--name=*)
dir="${i#*=}"
mkdir -p ~/cppshells/$dir
tmpdir=~/cppshells/$dir
shift
;;
-h|--help)
echo "-n=*|--name=* \t\t the name of the project"
echo "-t=*|--template \t\t the template to use"
exit;
;;
*)
# nothing to do
;;
esac
done
if [ -z "$tmpdir" ]; then
tmpdir=$(mktemp -d)
fi;
tmpdir=$(realpath ${tmpdir});
window="cpp-$1-$((1 + RANDOM % 10000000))"
if [ -z "$EDITOR" ]; then
EDITOR="nvim";
fi;
template_dir="$(dirname $0)/templates/${template}"
if [ ! -d $template_dir ]; then
echo "The specified template ($template) does not exists."
exit;
fi;
tmux new -s ${window} -d -c "${tmpdir}"
tmux split-window -t ${window} -h
tmux select-pane -t ${window}.right
tmux resize-pane -t ${window}.right -R 18
tmux send-keys -t ${window}.left "cd ${tmpdir}" C-m
tmux send-keys -t ${window}.right "cd ${tmpdir}" C-m
# copy files if the directory does not exists
if [ `ls -A ${tmpdir} | wc -m` == "0" ]; then
cp -nr $template_dir/* ${tmpdir}/.
fi;
# run build commands
if [ -f ${template_dir}/Makefile ]; then # make
tmux send-keys -t ${window}.right "find . -name '*.cpp' | entr -cs 'make -j8 && ./a.out'" C-m
tmux send-keys -t ${window}.left "${EDITOR} ${tmpdir}/main.cpp" C-m
elif [ -f ${template_dir}/CMakeLists.txt ]; then # CMake
mkdir -p ${tmpdir}/build
cmake -G "Unix Makefiles" -B${tmpdir}/build -S${tmpdir}
tmux send-keys -t ${window}.right "find . -name '*.cpp' | entr -cs 'make -j8 -Cbuild/ && ./build/a.out'" C-m
tmux send-keys -t ${window}.left "${EDITOR} ${tmpdir}/main.cpp" C-m
elif [ -f ${template_dir}/main.py ]; then # Python
chmod +x ${tmpdir}/main.py
tmux send-keys -t ${window}.right "find . -name 'main.py' | entr -cs '${tmpdir}/main.py'" C-m
tmux send-keys -t ${window}.left "${EDITOR} ${tmpdir}/main.py" C-m
elif [ -f ${template_dir}/main.sh ]; then # Bash
chmod +x ${tmpdir}/main.sh
tmux send-keys -t ${window}.right "find . -name 'main.sh' | entr -cs '${tmpdir}/main.sh'" C-m
tmux send-keys -t ${window}.left "${EDITOR} ${tmpdir}/main.sh" C-m
fi;
tmux select-pane -t ${window}.left
tmux attach -t ${window}
Run Code Online (Sandbox Code Playgroud)
然后创建~/bin/templates/simple目录并main.sh在其中放置一个简单的文件,这将是您运行ide命令时的起点。您还可以创建越来越多的模板(每个模板在~/bin/templates/目录中的不同目录中)。
添加/home/$USER/bin到您的路径,以便您可以运行ide.
要运行脚本,您可以使用以下 3 种方式:
ide它会用mktemp -d命令创建一个临时目录~/cppshell/[something]/目录中:ide -n=somethingide -t=not-simple -n=some_name正如我所说,你可以使用这个脚本来制作类似 shell 的工具来运行 python、C++、bash,甚至添加你自己的。
Win*_*nix 17
从:
gedit外部端子插件您可以使用gedit终端插件。步骤相当简单:
gedit-pluginsgedit插件第一步是确保Universe从Settings-> Software & Updates->激活存储库,Ubuntu Software并确保选中第三个选项:
gedit-pluginsgedit-plugs使用以下命令安装:
sudo apt install gedit-plugins
Run Code Online (Sandbox Code Playgroud)
打开gedit(不要使用sudo)并选择Edit-> Preferences->Plugins并勾选Embedded Terminal:
在下面的 GIF 中,我们使用Ctrl+F9来获得一个带有命令提示符的小窗口。使用鼠标向上拖动分割线。
gedit插件如步骤 4. 中所述,您可以抓住分隔条使终端窗口变大。这是在普通图片((不是 GIF)中的样子)。
我目前在gedit编码窗口中使用了其他三个插件:
如需进一步阅读,请参阅:
小智 13
如果您对 vim 感到满意,则可以执行
:w !bash
Run Code Online (Sandbox Code Playgroud)
(子您选择的外壳),这将在当前缓冲区中执行脚本。
在图形环境中,我使用 VS Code。它是一个轻量级的 IDE,可扩展,具有内置的 GIT 支持和一个集成的终端。
您可以使用 Kate,它需要 konsole 才能工作:
sudo apt install kate konsole
Run Code Online (Sandbox Code Playgroud)
然后在:
凯特 ?配置 ?应用 ?插件并选中终端工具视图复选框。
一个很好的选择是使用我的常客,文本编辑器 Geany。默认情况下,有一个“执行”按钮,它也默认绑定到F5从主编辑器窗口中运行 shell 脚本的键。
这是 Geany 在编辑后运行一个简单更新脚本的屏幕截图:
还要注意屏幕左侧的 Geany 的“树浏览器”插件,它有助于选择我文件夹中的所有脚本~/bin。
您可以将Atom编辑器与script包一起使用。设置好后,只需按F5(不选择任何内容)即可运行脚本。它将使用 shebang 来确定要运行的解释器。然后按Esc关闭输出窗格。
Atom 不是超轻量级,但也不是超重。它还提供其他软件包,例如linter-shellcheck帮助编写和调试代码。script还支持许多其他语言,包括 Python、Perl 和 HTML。
要安装 Atom,请使用最新版本的官方 .deb 安装程序。
或者,该script-runner包的工作方式与 类似script,但具有完整的终端,因此您可以在例如标准输入上提供输入。按Alt+X启动它,然后在完成后关闭窗格。
顺便提一下,对于更多的编程类型的东西,Hydrogen可以用来交互地运行代码,就像 Jupyter 一样。
小智 5
我不确定您需要运行哪些特定的 shell 命令,但Visual Studio Code正在成为轻量级 IDE 的当前标准。
快速搜索给我带来了这个,有人问,“有没有办法从 VS Code 运行 bash 脚本/命令?” (2018-10-22),答案是:
https://code.visualstudio.com/docs/editor/tasks
是的,您可以设置任务。您还可以指定一个特定的作为默认构建任务
代码内置了命令提示符。
-- /u/cornystool -永久链接
稍后对于您正在寻找的只是一个集成外壳的情况,您可以在其中键入 ./script.sh
我浏览了所有其他答案,但并不完全同意。当然,习惯了各自编辑器(vim、emacs、vi、gedit、notepad++、Atom 等)的人总会把你指向他们最喜欢的。
但是在编码行业多年,并且已经测试了许多较新的编辑器,例如 Atom、Sublime Text 等。 VS Code 刚刚脱颖而出。这是 Atom 一直想成为的。
它小巧、快速、跨平台、可扩展,并且几乎完全可以根据您的喜好进行定制。如果你希望能够在一个非常高效、有趣和热情的个人环境中快速交付结果,VS Code 是我对你的明确推荐。
正是在那个时代,微软在其组织中进行了重大转变,目标是开源、跨平台以及对外国系统更加友好的态度。值得注意的是,编辑器的工作人员在使用他们之前选择的工具时遇到了一些糟糕的经历,并决定从头开始使这些东西变得更好。
哦耶。它也是免费的。
| 归档时间: |
|
| 查看次数: |
8114 次 |
| 最近记录: |