如何使Notepad ++基于其名称运行脚本? [英] How to make Notepad++ run script based on its name?
问题描述
如果当前文件名以.rb结尾,并且perl {filename_here}以.pl结尾,则我想让notepad ++运行ruby {filename_here}我尝试使用NppExec插件,但它不能做条件的东西,所以我写了一个蝙蝠
I want to make notepad++ run the "ruby {filename_here}" command if the current filename ends with .rb and "perl {filename_here}" if it ends with .pl. I've tried to use the NppExec plugin, but it can't do conditional stuff, so I wrote a bat
@echo off
if /i %~sx1 == .pl perl "%~f1"
if /i %~sx1 == .rb ruby "%~f1"
if /i %~sx1 == .php php "%~f1"
命令行像C:\Program Files \Notepad ++> runscriptD \pl.pl,它工作正常。现在我如何将Notepad ++中的一些关键字绑定到runscript $(FULL_CURRENT_PATH)?我尝试使用Run-> Run菜单(F5),但它似乎不工作。
Now I can use it from the command line like C:\Program Files\Notepad++>runscript "D\pl.pl" and it works fine. Now how can I bind some key in Notepad++ to "runscript $(FULL_CURRENT_PATH)"? I've tried to use the Run->Run menu (F5), but it doesn't seem to work..
推荐答案
您需要将文件名放在命令结尾。
在运行(F5)对话框中,尝试:
You need to put the file name at the end of the command. In the Run(F5) dialog, try this:
runscript $(FULL_CURRENT_PATH)\$(FILE_NAME)
如果你想测试它,你可以放一个&
If you want to test it out, you could put a & pause
at the end, just to see if it worked.
您也可以调整脚本,以便每个文件都不会测试对于每个扩展程序,使用带有文件扩展名标签的可怕的 GOTO
命令:
You could also tweak your script a bit so that every file doesn't test for each extension, by using the dreaded GOTO
command with file extension labels:
@echo off
GOTO %~sx1
:.pl
perl "%~f1"
GOTO end
:.rb
ruby "%~f1"
GOTO end
:.php
php "%~f1"
GOTO end
:end
这篇关于如何使Notepad ++基于其名称运行脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!