Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
602 views
in Technique[技术] by (71.8m points)

cmd - How to make Notepad++ run script based on its name?

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"

Now I can use it from the command line like C:Program FilesNotepad++>runscript "Dpl.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..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to put the file name at the end of the command. In the Run(F5) dialog, try this:

runscript $(FULL_CURRENT_PATH)

If you want to test it out, you could put a & pause at the end, just to see if it worked.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...