Sublime 构建系统在本地服务器地址打开文件
Sublime build system to open file at local server address
对于我在本地服务器(运行 在 http://127.0.0.1:4000
的帮助下开发的网站,我尝试为我的 Sublime Text 项目设置编写一个构建系统。
我可以访问这些变量(由 Sublime Text 提供):
$file
:存储文件在磁盘上的绝对路径:
C:\Users\User\dev\repos\base\dir\index.html
$project_path
:存放项目文件的位置(通常是项目的根目录):
C:\Users\User\dev\repos\base
现在我想要的是 $file
的内容,而不是 $project_path
我想要 http://127.0.0.1:4000/~base
的内容。对于该任务,我尝试了以下 Bash cmd.exe:
CALL SET result=%file:%project_path%=http://127.0.0.1:4000\~base\% && echo %result%
这给出了预期的结果,但是我似乎无法将它应用到 Sublime Text 中的构建系统。
现在,我尝试生成正确的地址并通过 cmd.exe:
输出它
{
"build_systems":
[
{
"name": "Preview in browser",
"selector": "text.html",
"windows":
{
"shell": true,
"cmd": [
"start", "cmd", "/k",
"CALL SET result=$file:$project_path=http://127.0.0.1:4000\~base\ && echo $result"
]
}
}
]
}
结果:
> echo %result%
C:\Users\Philipp\dev\repos\base\dir\index.html:C:\Users\Philipp\dev\repos
\base=http://127.0.0.1:4000\~base\
因此,在构建系统中进行替换时,替换不起作用,但在 cmd.exe 中却可以。我很困惑。
你可以这样做:
{
"build_systems":
[
{
"name": "Preview in browser",
"selector": "text.html",
"windows":
{
"shell_cmd": "CALL SET filePath=$file && CALL SET result=%filePath:$project_path=http://127.0.0.1:4000\~base% && CALL C:/Progra~2/Google/Chrome/Application/chrome.exe %result%"
}
}
]
}
问题在于 windows 替换和变量赋值,而不是 sublime 构建。
正如在聊天和评论中所说,多次 CALL 是使用真实值变量所必需的,因为如果不使用,windows 将在执行时分配所需值之前在解析时扩展它们的值。此外,shell_cmd
可用于 运行 shell 中的唯一命令。
对于我在本地服务器(运行 在 http://127.0.0.1:4000
的帮助下开发的网站,我尝试为我的 Sublime Text 项目设置编写一个构建系统。
我可以访问这些变量(由 Sublime Text 提供):
$file
:存储文件在磁盘上的绝对路径:C:\Users\User\dev\repos\base\dir\index.html
$project_path
:存放项目文件的位置(通常是项目的根目录):C:\Users\User\dev\repos\base
现在我想要的是 $file
的内容,而不是 $project_path
我想要 http://127.0.0.1:4000/~base
的内容。对于该任务,我尝试了以下 Bash cmd.exe:
CALL SET result=%file:%project_path%=http://127.0.0.1:4000\~base\% && echo %result%
这给出了预期的结果,但是我似乎无法将它应用到 Sublime Text 中的构建系统。
现在,我尝试生成正确的地址并通过 cmd.exe:
输出它{
"build_systems":
[
{
"name": "Preview in browser",
"selector": "text.html",
"windows":
{
"shell": true,
"cmd": [
"start", "cmd", "/k",
"CALL SET result=$file:$project_path=http://127.0.0.1:4000\~base\ && echo $result"
]
}
}
]
}
结果:
> echo %result%
C:\Users\Philipp\dev\repos\base\dir\index.html:C:\Users\Philipp\dev\repos
\base=http://127.0.0.1:4000\~base\
因此,在构建系统中进行替换时,替换不起作用,但在 cmd.exe 中却可以。我很困惑。
你可以这样做:
{
"build_systems":
[
{
"name": "Preview in browser",
"selector": "text.html",
"windows":
{
"shell_cmd": "CALL SET filePath=$file && CALL SET result=%filePath:$project_path=http://127.0.0.1:4000\~base% && CALL C:/Progra~2/Google/Chrome/Application/chrome.exe %result%"
}
}
]
}
问题在于 windows 替换和变量赋值,而不是 sublime 构建。
正如在聊天和评论中所说,多次 CALL 是使用真实值变量所必需的,因为如果不使用,windows 将在执行时分配所需值之前在解析时扩展它们的值。此外,shell_cmd
可用于 运行 shell 中的唯一命令。