CLI tool to read files and copy text to the Windows clipboard.
0
clip.ahk
74 lines 1.5 kB View raw
1;@Ahk2Exe-ConsoleApp 2 3#Requires AutoHotkey v2 4#SingleInstance Off 5 6Persistent(true) 7FileEncoding("UTF-8") 8SetWorkingDir(A_InitialWorkingDir) 9 10message := " 11( 12Usage: 13 clip.exe [parameters] [file-path] 14 15Parameters: 16 -h `tDisplays this help message. 17 -d `tSet the delimiter. 18 -t `tSet a literal string. 19 20Examples: 21 echo text | clip.exe `tCopy a literal string. 22 clip.exe < file.txt `tCopy the content from a file. 23 24 clip.exe -t text `tCopy a literal string. 25 clip.exe a.txt b.txt `tCopy the content from 2 files. 26)" 27 28if ProcessGetName(ProcessGetParent()) == "explorer.exe" { 29 Run(Format('"{}" /k call "{}" -h', A_ComSpec, A_ScriptFullPath)) 30 ExitApp() 31} 32 33if Args(1) == "-h" { 34 Print(message) 35 ExitApp() 36} 37 38delimiter := "" 39content := FileOpen("*", "r").Read() 40 41loop A_Args.Length { 42 cmd := Args(A_Index) 43 arg := Args(A_Index + 1) 44 if cmd == "-d" { 45 delimiter := arg 46 A_Index++ 47 } 48 else if cmd == "-t" { 49 if content !== "" 50 content .= delimiter 51 content .= arg 52 A_Index++ 53 } 54 else { 55 if content !== "" 56 content .= delimiter 57 try content .= FileRead(cmd) 58 catch Error as e { 59 Print(e.Message, "**") 60 } 61 } 62} 63 64A_Clipboard := content 65ExitApp() 66 67Args(index, defarg:="") { 68 try return A_Args[index] 69 return defarg 70} 71 72Print(str:="", fn:="*", values*) { 73 FileAppend(Format(str . "`n", values*), fn) 74}
Sign up or login to add to the discussion