mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 15:17:47 +00:00
Deprecate the nu_scripts
version of stdlib-candidate
(#1042)
Deprecates the existing `stdlib-candidate` directories in `nu_scripts` since `std-rfc` has now transitioned to the main repo. Updates readme and renamed directories.
This commit is contained in:
parent
a31f8490fb
commit
5869e0b529
53 changed files with 18 additions and 40 deletions
71
stdlib-candidate-archive/std-rfc/clip/mod.nu
Normal file
71
stdlib-candidate-archive/std-rfc/clip/mod.nu
Normal file
|
@ -0,0 +1,71 @@
|
|||
# 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 [
|
||||
--ansi (-a) # Copy ansi formatting
|
||||
]: any -> nothing {
|
||||
let input = $in | collect
|
||||
let text = match ($input | describe -d | get type) {
|
||||
$type if $type in [ table, record, list ] => {
|
||||
$input | table -e
|
||||
}
|
||||
_ => {$input}
|
||||
}
|
||||
|
||||
let do_strip_ansi = match $ansi {
|
||||
true => {{||}}
|
||||
false => {{|| ansi strip }}
|
||||
}
|
||||
|
||||
let output = (
|
||||
$text
|
||||
| do $do_strip_ansi
|
||||
| encode base64
|
||||
)
|
||||
|
||||
print -n $'(ansi osc)52;c;($output)(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
|
||||
}
|
||||
|
||||
# Add a prefix to each line of the content to be copied
|
||||
#
|
||||
# # Example: Format output for Nushell doc
|
||||
# ls | clip prefix '# => ' | clip copy
|
||||
export def prefix [prefix: string]: any -> string {
|
||||
let input = $in | collect
|
||||
match ($input | describe -d | get type) {
|
||||
$type if $type in [ table, record, list ] => {
|
||||
$input | table -e
|
||||
}
|
||||
_ => {$input}
|
||||
}
|
||||
| str replace -r --all '(?m)(.*)' $'($prefix)$1'
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue