mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 22:57:46 +00:00
Additional clip copy
options (#1028)
Addition to `clip` module (#1009): * Passes complex values through `table -e` to render properly * By default, strips ansi codes, unless `--ansi (-a)` switch is used * Adds a `clip prefex` command which can accept a prefix string like `# => ` to be added to the beginning of each line.
This commit is contained in:
parent
10b22626f7
commit
bab7845ed4
1 changed files with 38 additions and 2 deletions
|
@ -9,8 +9,29 @@
|
||||||
# ```nushell
|
# ```nushell
|
||||||
# >_ "Hello" | clip copy
|
# >_ "Hello" | clip copy
|
||||||
# ```
|
# ```
|
||||||
export def copy []: [string -> nothing] {
|
export def copy [
|
||||||
print -n $'(ansi osc)52;c;($in | encode base64)(ansi st)'
|
--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
|
# Paste contenst of system clipboard
|
||||||
|
@ -33,3 +54,18 @@ export def paste []: [nothing -> string] {
|
||||||
| decode base64
|
| decode base64
|
||||||
| decode
|
| 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