Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

notepad++

cmd

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 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..

like image 997
Fluffy Avatar asked Jul 09 '09 19:07

Fluffy


People also ask

How do I run a bat file from Notepad ++?

Run -> Run (F5) Type command line into "The Program to Run" Save, type the name (choose the shortcut if you need)

How do you run a Run command in Notepad ++?

How to run CMD console commands in Notepad++ If you want to work with Notepad++ and CMD (Command Line) Console at once you can install NPPExec plugin. Once you install this plugin using Plugin Manager, go to Plugins -> NppExec -> Execute..., or press F6 key.

How do I run a script in Windows?

To run a script using the default engine:Double click the script in Windows Explorer or on the desktop. Click Start, select Run, and enter the script name. On Windows NT and Windows 2000 only, simply enter the script name on a command line.


1 Answers

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
like image 163
akf Avatar answered Oct 08 '22 05:10

akf