Skip to content

Instantly share code, notes, and snippets.

@flipeador
Last active August 28, 2025 05:49
Show Gist options
  • Save flipeador/ae8b33d009c2f31c5e600ed82baa29a8 to your computer and use it in GitHub Desktop.
Save flipeador/ae8b33d009c2f31c5e600ed82baa29a8 to your computer and use it in GitHub Desktop.
CLI tool to read files and copy text to the Windows clipboard.
;@Ahk2Exe-ConsoleApp
#Requires AutoHotkey v2
#SingleInstance Off
Persistent(true)
FileEncoding('UTF-8')
SetWorkingDir(A_InitialWorkingDir)
parent := ProcessGetName(ProcessGetParent())
message := '
(
Usage:
clip.exe [parameters] [file-path]
Parameters:
-h `tDisplays this help message.
-d `tSet the delimiter.
-t `tSet a literal string.
Examples:
echo text | clip.exe `tCopy a literal string.
clip.exe < file.txt `tCopy the content from a file.
clip.exe -t text `tCopy a literal string.
clip.exe a.txt b.txt `tCopy the content from 2 files.
)'
if Args(1, '-h') == '-h' {
Print(message)
if parent == 'explorer.exe'
return
ExitApp()
}
delimiter := ''
content := FileOpen('*', 'r').Read()
loop A_Args.Length {
cmd := Args(A_Index)
arg := Args(A_Index + 1)
if cmd == '-d'
A_Index++, delimiter := arg
else if cmd == '-t'
A_Index++, content .= arg
else {
if content != ''
content .= delimiter
try content .= FileRead(cmd)
}
}
A_Clipboard := content
ExitApp()
Args(index, defarg:='') {
try return A_Args[index]
return defarg
}
Print(str:='', values*) {
FileAppend(Format(str . '`n', values*), '*')
}
@flipeador
Copy link
Author

flipeador commented Jul 25, 2025

Clip

CLI tool to read files and copy text to the Windows clipboard.

Instructions

Download AutoHotkey 2 and compile clip.ahk.

Run clip.exe -h in the Terminal to display the help message.
You can also open clip.exe directly from the Windows file explorer.

Download

https://asset.cloudinary.com/flipeador/e0fcce61b23fb62d83912c1974ced0ac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment