Skip to content

Instantly share code, notes, and snippets.

@neetsdkasu
Last active October 15, 2019 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neetsdkasu/2b0017719e8bca609a6f191c9ad4cd35 to your computer and use it in GitHub Desktop.
Save neetsdkasu/2b0017719e8bca609a6f191c9ad4cd35 to your computer and use it in GitHub Desktop.
(自分用)コマンドラインからエディタ起動
@echo off
setlocal
set ntpp=start "NotePad++" "C:\Program Files\Notepad++\notepad++.exe"
set gpad=start "gPad" "C:\Program Files\gPad\gPad.exe"
set mery=start "Mery" "C:\Program Files\Mery\Mery.exe"
set tera=start "TeraPad" "C:\Program Files\TeraPad\TeraPad.exe"
set gvim=start "gvim" "C:\Dev\vim74\gvim.exe"
set note=start notepad.exe
rem Check Options
rem select editor
set file="%~f3"
set some="%~4"
set args=%1 %2
for %%i in ("-e" "/e" "-s" "/s") do if /I "%~1"==%%i goto SELECT_EDITOR
rem choice editor
set file="%~f2"
set some="%~3"
set args=%1 %3
set editor=%ntpp%
for %%i in ("-p" "/p") do if /I "%~1"==%%i goto EXIST_CHECK
set editor=%gpad%
for %%i in ("-g" "/g") do if /I "%~1"==%%i goto EXIST_CHECK
set editor=%mery%
for %%i in ("-m" "/m") do if /I "%~1"==%%i goto EXIST_CHECK
set editor=%tera%
for %%i in ("-t" "/t") do if /I "%~1"==%%i goto EXIST_CHECK
set editor=%note%
for %%i in ("-n" "/n") do if /I "%~1"==%%i goto EXIST_CHECK
set editor=%gvim%
for %%i in ("-v" "/v") do if /I "%~1"==%%i goto EXIST_CHECK
rem help
if "%~1"=="-?" goto HELP_TEXT
if "%~1"=="/?" goto HELP_TEXT
if "%~1"=="?" goto HELP_TEXT
for %%i in ("-help" "/help") do if /I "%~1"==%%i goto HELP_TEXT
:DEFAULT_EDITOR
set ext="%~x1"
set file="%~f1"
set some="%~2"
set args=%2 %3
set editor=%ntpp%
if /I %ext%==".bat" set editor=%ntpp%
if /I %ext%==".wsf" set editor=%ntpp%
goto EXIST_CHECK
:SELECT_EDITOR
set editor=%ntpp%
for %%i in ("p" "Notepad++" "plus") do if /I "%~2"==%%i goto EXIST_CHECK
set editor=%gpad%
for %%i in ("g" "gPad") do if /I "%~2"==%%i goto EXIST_CHECK
set editor=%mery%
for %%i in ("m" "Mery") do if /I "%~2"==%%i goto EXIST_CHECK
set editor=%tera%
for %%i in ("t" "TeraPad" "Tera") do if /I "%~2"==%%i goto EXIST_CHECK
set editor=%note%
for %%i in ("n" "notepad" "note") do if /I "%~2"==%%i goto EXIST_CHECK
set editor=%gvim%
for %%i in ("v" "gvim") do if /I "%~2"==%%i goto EXIST_CHECK
goto HELP_TEXT
:HELP_TEXT
echo Discription:
echo Open file by editor (cannot use wild card)
echo Syntax:
echo ed [-e (editor)^|-p^|-g^|-m^|-t^|-n^|-v] (file) [(file) [(file) ...]]
echo editor [-e (editor)^|-p^|-g^|-m^|-t^|-n^|-v] (file) [(file) [(file) ...]]
echo Options:
echo -e select editor
echo (editor) editor name : gPad(g) Mery(m) TeraPad(t) notepad(n) gvim(v)
echo -p editor is Notepad++ *default editor
echo -g editor is gPad
echo -m editor is Mery
echo -t editor is TeraPad
echo -n editor is notepad
echo -v editor is gvim
goto END_OF_BATCH
:EXIST_CHECK
if %file%=="" goto OPEN_FILE
if exist %file% goto DIR_CHECK
echo create %file% ? (y/n)
set /p res=
if /i "%res%"=="y" goto CREATE_FILE
if /i "%res%"=="yes" goto CREATE_FILE
goto SM_CHECK
:CREATE_FILE
touch %file%
goto OPEN_FILE
:DIR_CHECK
pushd %file% 2>nul
if ERRORLEVEL 1 goto OPEN_FILE
popd
for %%i in (%file%) do @echo %%~nxi is directory
echo if editor support argument directry, open all files in the directory
echo open the directory ? (y/n)
set /p res=
if /i "%res%"=="y" goto OPEN_FILE
if /i "%res%"=="yes" goto OPEN_FILE
goto SM_CHECK
:OPEN_FILE
%editor% %file%
goto SM_CHECK
:SM_CHECK
if not %some%=="" call ed.bat %args% %4 %5 %6 %7 %8 %9
goto END_OF_BATCH
:END_OF_BATCH
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment