-
Notifications
You must be signed in to change notification settings - Fork 0
/
clip-edit.cmd
54 lines (43 loc) · 1.89 KB
/
clip-edit.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@if (@CodeSection == @Batch) @then
@echo off & setlocal
REM // The first line skips over the shell script lines until the end statement
REM // at the bottom. A simple trick so that this can also contain its own
REM // JScript for clipboard pasting.
REM // -------------------------------------------------------------------------
REM // clip-edit [editor command]
REM //
REM // This script launches an editor on the text contents of the clipboard. On
REM // editor exit, the result is pasted back to the clipboard.
REM //
REM // The editor used is determined by the following rules, using the first one
REM // that matches:
REM //
REM // 1. If command arguments are given, they are used as the editor
REM // command.
REM // 2. If the EDITOR environment variable is defined, use that.
REM // 3. Invoke Notepad.exe to edit the contents.
REM //
REM // -------------------------------------------------------------------------
echo Invoking editor for clipboard.
if not defined EDITOR (
set EDITOR=notepad.exe
)
call get-tempFile tempFileName
REM // The following line pastes the current clipboard contents into the
REM // temporary file for editing. Unfortunately, Windows comes with a standard
REM // tool to clip content, but lacks a standard tool to paste the (text)
REM // contents of the clipboard.
REM //
REM // See https://stackoverflow.com/a/15747067/566185
cscript /nologo /e:JScript "%~f0" >%tempFileName%
call "%EDITOR:"=%" %tempFileName% || (
echo clip-edit.cmd: Unable to invoke "%EDITOR:"=%". Check EDITOR environment variable. 1>&2
pause
exit /b 1
)
clip < %tempFileName%
del %tempFileName%
goto :eof
REM ________________________________________________________________________________________________
@end // Begin JScript hybrid script
WSH.Echo(WSH.CreateObject('htmlfile').parentWindow.clipboardData.getData('text'));