- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用的是 Ubuntu 16.04。我使用 Sublime Text 3,我可以编译 c++ 程序并在终端中运行它。以下是脚本。
{
"cmd": ["g++", "$file", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++, source.cxx, source.cpp",
"variants":
[
{
"name": "RunInShell",
"shell": true,
"cmd": ["gnome-terminal -e 'bash -c \"${file_path}/${file_base_name};echo; echo Press ENTER to continue; read line;exit; exec bash\"'"]
}
]
}
但是,当 C++ 程序的路径包含空格(如 /algorithms/Search in Rotated Sorted Array
)时,脚本无法运行!
bash:/media/algorithms/Search: No such file or directory
shows in the terminal, when I using RunInShell.
我正在尝试修改脚本,例如插入单引号。
"cmd": ["gnome-terminal -e 'bash -c\"'${file_path}/${file_base_name}';echo; echo 按 ENTER 继续;读行;退出;执行 bash\"'"]
但它不起作用。
我想知道如何修改脚本以使其正常运行。
最佳答案
因此,我们可以escape each space to a backslash and a space, for use in Bash .首先在构建系统之外使用它可能更容易,例如通过在 ST (Python) 控制台中键入以下内容:
import os.path; file_path = '/algorithms/Search in Rotated Sorted Array'; file_name = os.path.basename(file_path); sublime.expand_variables(r'${file_path/ /\\ /g}/${file_base_name/ /\\ /g}', { 'file_path': os.path.dirname(file_path), 'file': file_path, 'file_name': file_name, 'file_extension': os.path.splitext(file_name)[1], 'file_base_name': os.path.splitext(file_name)[0], 'packages': sublime.packages_path() })
请注意,上面包含的变量比我们实际需要的要多,但实际上并不包括 all the variables available from the build system , 但对于这个例子来说已经足够了,如果你想进一步试验,可以很容易地添加它们。检查ST API Reference有关详细信息,特别是缺少的项目是 Window
类的一部分。
无论如何,我们从中得到的输出是:
'/algorithms/Search\\ in\\ Rotated\\ Sorted\\ Array'
(请记住,这是一个 Python 字符串,所以两个斜线是一个转义码,代表一个斜线。)
所以我们在这里看到的是${file_path//\\\\/g}
。这告诉 ST 的是获取 file_path
变量的值并对其运行正则表达式替换。它应该用斜杠后跟空格替换空格。末尾的 /g
是全局正则表达式修饰符标志,告诉它不要在第一次匹配/替换时停止,以确保它替换所有空格。
现在,将其插入您的构建系统:
"cmd": ["gnome-terminal -e 'bash -c \"${file_path/ /\\\\ /g}/${file_base_name/ /\\\\ /g};echo; echo Press ENTER to continue; read line;exit; exec bash\"'"]
请注意,我们有 4 个斜杠 - 在我展示用于测试的 Python 代码和 JSON 字符串中都有。这是因为前两个斜杠是一个转义序列,它告诉 JSON/Python 使用文字斜杠。然后我们想再次执行相同的操作,以便正则表达式模式将使用文字斜杠。
关于c++ - Sublime Text 3 - 在终端编译运行c++程序(路径包含空格),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44050850/
我可能遗漏了明显的,但似乎无法解决这个相当简单和典型的案例(在 Debian 或 XP 上使用 v3 build 3022,以防万一): 启动 Sublime Text 打开一个项目“myprj”,在
在 Sublime 的精神中,我知道即使您以后不将更改保存到一个文件中,也可以从上次中断的地方开始。在保存文件之前,我在sublime中打开了一个新标签,并关闭了该应用程序。升华是否将临时文件保存在计
我有两个关于 Sublime Text Editor 2 的问题。 我的第一个问题是,我在 Packages/User 文件夹中保存了几个不同的 .tmLanguage 文件(例如:Console.t
我在 Mac 上。 另外,需要注意的是,路径段为“Packages/Solarized Color Scheme/Solarized (Dark).tmTheme”的文件在文件系统上任何地方都不存在。
我正在使用第三个 Sublime 版本,我想使用这个 CSS 梳子:https://github.com/vitaligo/CSScomb.sublime-settings/blob/master/C
我正在尝试创建一个 Sublime Text 3 插件,它从 .html、.css、.js 和 .php 等文件复制代码,然后将其粘贴到 txt 文档中。 我的问题是,有时当我从包含大量代码的文档中复
使用 Anaconda IDE package 运行 Sublime Text 3在 Mac OS X 上,当我编辑 .sublime-project 文件时,由于某种原因,某些更改将在一段时间后被删
这是我的 Preferences.sublime-settings文件: { "bold_folder_labels": true, "highlight_line": true,
我正在寻找一种方法来右键单击 Windows 10 中的文件,选择“打开方式”->“Sublime Text”,然后出现一个新的 Sublime Text 窗口。 如果 Sublime 已经打开,默认
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
我根本不想要它们,更喜欢 git 命令行,但它们被添加到我的命令中,就好像它们已安装一样,即使我从未安装过 sublime merge。 有没有办法从 sublime text 命令面板中完全删除它们
我根本不想要它们,更喜欢 git 命令行,但它们被添加到我的命令中,就好像它们已安装一样,即使我从未安装过 sublime merge。 有没有办法从 sublime text 命令面板中完全删除它们
我在 Ubuntu 12.04 LTS 上。调用 sublime foo.txt 通常会在 Sublime Text 2 中打开 foo.txt。最近我安装了 Sublime Text 3 .除此之外
有没有办法在Sublime Text Build中使用Windows变量?我有一个S搭建的系统:。有没有办法在Sublime Text Build中使用Windows变量?我有一个S搭建的系统:。我会
当我在 Sublime Repl 控制台 (Python) 中输入并按回车键运行命令时,我得到了 super 烦人的自动完成接管并更改命令。 如何在 SublimeRepl 控制台中关闭此功能? 谢谢
我需要从 sublime text 2 迁移到 sublime text 3,以获得与我在 sublime text2 上安装的所有相同的配置/插件。 我安装了 sublime text 3,但它没有
Sublime Text 2 无法打开。我不断收到此错误: (Error trying to parse file: Unexpected character, expected a comma or
只是尝试在 Windows 8.1 上为我的 OpenGL 编码设置 sublime-build。 这就是我所拥有的: { "cmd": [ "gcc -o \"$file\" \"$file_bas
所以我有一个错误,当我尝试构建时,命令行显示: grunt-cli: The grunt command line interface. (v0.1.13) [Finished in 0.1s wit
我正在尝试安装 https://github.com/alek-sys/sublimetext_indentxml在 Sublime Text 3中。我读了 In Sublime Text 3 - c
我是一名优秀的程序员,十分优秀!