-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description Add `clip copy` and `clip paste` for interacting with system clipboard, making use of OSC 52. I'm not sure how to write tests for these commands. > [!TIP] > No platform specific external binary is required. > [!WARNING] > - Not all terminal emulators will support this > - Terminal multiplexers may interfere with it, depending on their configuration. # Related - nushell/nushell#11131 - #674
- Loading branch information
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Commands for interacting with the system clipboard | ||
# | ||
# > These commands require your terminal to support OSC 52 | ||
# > Terminal multiplexers such as screen, tmux, zellij etc may interfere with this command | ||
|
||
# Copy input to system clipboard | ||
# | ||
# # Example | ||
# ```nushell | ||
# >_ "Hello" | clip copy | ||
# ``` | ||
export def copy []: [string -> nothing] { | ||
print -n $'(ansi osc)52;c;($in | encode base64)(ansi st)' | ||
} | ||
|
||
# Paste contenst of system clipboard | ||
# | ||
# # Example | ||
# ```nushell | ||
# >_ clip paste | ||
# "Hello" | ||
# ``` | ||
export def paste []: [nothing -> string] { | ||
try { | ||
term query $'(ansi osc)52;c;?(ansi st)' -p $'(ansi osc)52;c;' -t (ansi st) | ||
} catch { | ||
error make -u { | ||
msg: "Terminal did not responds to OSC 52 paste request." | ||
help: $"Check if your terminal supports OSC 52." | ||
} | ||
} | ||
| decode | ||
| decode base64 | ||
| decode | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export module aggregate | ||
export module clip |