1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-07-30 21:57:44 +00:00

replace filter with where (#1135)

This PR tries to clean up the use of `filter` by replacing it with
`where`. I did not test each script.

closes #1134
closes #1133
This commit is contained in:
Darren Schroeder 2025-06-12 06:42:16 -05:00 committed by GitHub
parent 84c25bbc6d
commit 32cdc96414
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 66 additions and 66 deletions

View file

@ -279,7 +279,7 @@ def columns [
]
if not ($query | is-empty) {
$columns = $columns | filter {
$columns = $columns | where {
$in | str contains --ignore-case $query
}
}

View file

@ -14,7 +14,7 @@ def "nu-complete flutter commands" [] {
| into string
| str replace --regex --multiline '(Manage[\s\S]*(?=Flutter SDK))' ''
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| each { str trim }
| parse "{value} {description}"
| str trim
@ -33,7 +33,7 @@ def "nu-complete pub commands" [] {
| into string
| str replace --regex --multiline '(Commands[\s\S]*(?=Available subcommands))' ''
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| each { str trim }
| parse "{value} {description}"
| str trim

View file

@ -2,7 +2,7 @@
def "nu-complete gh" [] {
^gh --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -16,7 +16,7 @@ export extern "gh" [
def "nu-complete gh auth" [] {
^gh auth --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -43,7 +43,7 @@ export extern "gh browse" [
def "nu-complete gh codespace" [] {
^gh codespace --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -57,7 +57,7 @@ export extern "gh codespace" [
def "nu-complete gh gist" [] {
^gh gist --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -129,7 +129,7 @@ export extern "gh gist view" [
def "nu-complete gh issue" [] {
^gh issue --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -144,7 +144,7 @@ export extern "gh issue" [
def "nu-complete gh org" [] {
^gh org --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -156,7 +156,7 @@ export extern "gh org" [
]
def "nu-complete gh pr" [] {
^gh pr --help | lines | filter { str starts-with " " } | skip 1 | parse "{value}: {description}" | str trim
^gh pr --help | lines | where { str starts-with " " } | skip 1 | parse "{value}: {description}" | str trim
}
export extern "gh pr" [
@ -182,7 +182,7 @@ export extern "gh pr checkout" [
def "nu-complete gh project" [] {
^gh project --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -196,7 +196,7 @@ export extern "gh project" [
def "nu-complete gh release" [] {
^gh release --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -211,7 +211,7 @@ export extern "gh release" [
def "nu-complete gh repo" [] {
^gh repo --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -310,7 +310,7 @@ export extern "gh repo fork" [
def "nu-complete gh cache" [] {
^gh cache --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -325,7 +325,7 @@ export extern "gh cache" [
def "nu-complete gh run" [] {
^gh run --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -339,7 +339,7 @@ export extern "gh run" [
def "nu-complete gh workflow" [] {
^gh workflow --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -354,7 +354,7 @@ export extern "gh workflow" [
def "nu-complete gh alias" [] {
^gh alias --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -403,7 +403,7 @@ export extern "gh completion" [
def "nu-complete gh config" [] {
^gh config --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -417,7 +417,7 @@ export extern "gh config" [
def "nu-complete gh extension" [] {
^gh extension --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -431,7 +431,7 @@ export extern "gh extension" [
def "nu-complete gh gpg-key" [] {
^gh gpg-key --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -445,7 +445,7 @@ export extern "gh gpg-key" [
def "nu-complete gh label" [] {
^gh label --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -460,7 +460,7 @@ export extern "gh label" [
def "nu-complete gh ruleset" [] {
^gh ruleset --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -475,7 +475,7 @@ export extern "gh ruleset" [
def "nu-complete gh search" [] {
^gh search --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -501,7 +501,7 @@ export extern "gh search" [
def "nu-complete gh secret" [] {
^gh secret --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -516,7 +516,7 @@ export extern "gh secret" [
def "nu-complete gh ssh-key" [] {
^gh ssh-key --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
@ -536,7 +536,7 @@ export extern "gh status" [
def "nu-complete gh variable" [] {
^gh variable --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim

View file

@ -37,7 +37,7 @@ def "nu-complete args" [context:string,offset:int] {
def get-just-arg [name:string,position:int] {
let recipes = (
get-recipes
| filter {|r| $r.name == $name }
| where {|r| $r.name == $name }
| get parameters
| flatten)
let len = $recipes | length

View file

@ -85,7 +85,7 @@ def "nu-complete kw configs" [] {
def "nu-complete kw remotes" [] {
^kw remote --list
| lines
| filter {|line| not ($line | str contains " ")}
| where {|line| not ($line | str contains " ")}
}
# The inglorious kernel developer workflow tool

View file

@ -44,7 +44,7 @@ module lftp-completion-utils {
let files = [
'/etc/ssh/ssh_config',
'~/.ssh/config'
] | filter {|file| $file | path exists }
] | where {|file| $file | path exists }
let first_result: record<hosts: list<record<name: string, addr: string>>, includes: list<string>> = $files | par-each {|file|

View file

@ -34,7 +34,7 @@ def "nu-complete mask args" [context: string, offset: int] {
$rt ++= ($c | get named_flags | each {|x|
let v = if not ($x.long | is-empty) { $"`--($x.long)`" } else if not ($x.short | is-empty) { $"`-($x.short)`" } else { $"---($x.name)" }
let a = ["required", "multiple", "takes_value", "validate_as_number"]
| filter {|y| ($x | get $y) == true }
| where {|y| ($x | get $y) == true }
| str join ','
let d = if ($a | is-empty) { $x.description } else { $"($x.description) \(($a))" }
{value: $v , description: $d }

View file

@ -21,7 +21,7 @@ export def "nu-complete pass-directories" [] {
let dir = (pass_completions_directory)
ls ($dir | path join **)
| get name
| filter { |it| not (ls $it | is-empty) }
| where { |it| not (ls $it | is-empty) }
| each {|it| ( $it | path relative-to $dir) }
}

View file

@ -5,7 +5,7 @@ export extern "rye" [
def "nu-complete rye" [] {
^rye --help
| lines
| filter { str starts-with " " }
| where { str starts-with " " }
| each {str trim}
| parse "{value} {description}"
| str trim
@ -120,7 +120,7 @@ def "nu-complete rye tools" [] {
^rye tools --help
| lines
| drop 1
| filter { str starts-with " " }
| where { str starts-with " " }
| each {str trim}
| parse "{value} {description}"
| str trim
@ -135,7 +135,7 @@ def "nu-complete rye self" [] {
^rye self --help
| lines
| drop 1
| filter { str starts-with " " }
| where { str starts-with " " }
| each {str trim}
| parse "{value} {description}"
| str trim
@ -150,7 +150,7 @@ def "nu-complete rye toolchain" [] {
^rye toolchain --help
| lines
| drop 1
| filter { str starts-with " " }
| where { str starts-with " " }
| each {str trim}
| parse "{value} {description}"
| str trim

View file

@ -79,7 +79,7 @@ def "nu-complete ssh-host" [] {
let files = [
'/etc/ssh/ssh_config',
'~/.ssh/config'
] | filter {|file| $file | path exists }
] | where {|file| $file | path exists }
use ssh-completion-utils process

View file

@ -369,7 +369,7 @@ export def "winget list" [
(do $flagify help $help)
]
| flatten
| filter { not ($in | is-empty) })
| where { not ($in | is-empty) })
)
let output = ^winget ...$params

View file

@ -28,7 +28,7 @@ export def 'from tree' [
if not ($fst in ['list', 'record']) {
$acc
} else {
let r = $acc.schema | filter {|i| ($i | get $selector.value) == $x}
let r = $acc.schema | where {|i| ($i | get $selector.value) == $x}
if ($r | is-empty) {
$acc
} else {

View file

@ -97,7 +97,7 @@ export def image-select [name] {
let imgs = (image-list)
let fs = [image tag repo]
for i in 2..0 {
let r = $imgs | filter {|x|
let r = $imgs | where {|x|
$fs | slice 0..$i | all {|y| ($n | get $y) == ($x | get $y) }
}
if ($r | is-not-empty) {

View file

@ -60,7 +60,7 @@ def "nu-complete git log" [] {
def "nu-complete git branches" [] {
git branch
| lines
| filter {|x| not ($x | str starts-with '*')}
| where {|x| not ($x | str starts-with '*')}
| each {|x| $"($x|str trim)"}
}

View file

@ -141,7 +141,7 @@ def list_merged [
run-external "git" "branch" ...$args
| lines
| filter {|branch|
| where {|branch|
$keep
| all {|pattern|
$branch !~ $'\A($pattern)\z'

View file

@ -101,7 +101,7 @@ export def gb [
git branch -D $b
}
if ($dels | is-not-empty) and (agree 'delete remote branch?!') {
for b in ($dels | filter { $"($remote)/($in)" in $remote_branches }) {
for b in ($dels | where { $"($remote)/($in)" in $remote_branches }) {
tips $"delete (ansi yellow)($remote)/($b)"
git branch -D -r $'($remote)/($b)'
git push $remote -d $b
@ -657,13 +657,13 @@ def "nu-complete git branch files" [context: string, offset:int] {
let files = $token | skip 2
git ls-tree -r --name-only $branch
| lines
| filter {|x| not ($x in $files)}
| where {|x| not ($x in $files)}
}
def "nu-complete git branches" [] {
git branch
| lines
| filter {|x| not ($x | str starts-with '*')}
| where {|x| not ($x | str starts-with '*')}
| each {|x| $"($x|str trim)"}
}
@ -671,7 +671,7 @@ export def remote_branches [] {
git branch -r
| lines
| str trim
| filter {|x| not ($x | str starts-with 'origin/HEAD') }
| where {|x| not ($x | str starts-with 'origin/HEAD') }
}
def "nu-complete git remotes" [] {

View file

@ -3,7 +3,7 @@ def quote [...t] {
}
def flatten_fields [args] {
let f = $in | default [] | filter {|x| $x | is-not-empty }
let f = $in | default [] | where {|x| $x | is-not-empty }
let prefix = $args.0
let inner = $args.1
let outer = $args.2

View file

@ -16,7 +16,7 @@ export def kube-refine [
let cns = kubectl get namespace
| from ssv -a
| get NAME
| filter $nsf
| where $nsf
let resource = kubectl get crd | from ssv | get NAME
let resource = kubectl api-resources | from ssv -a | get NAME | append $resource
@ -24,7 +24,7 @@ export def kube-refine [
$resource
} else {
$resource
| filter {|x| $x in $kind }
| where {|x| $x in $kind }
}
mut data = []

View file

@ -77,7 +77,7 @@ export def --wrapped level [
| each (do $env.lg.line_formatter $theme $align $mkl)
| str join (char newline)
let head = [$time $label $txt]
| filter {|x| $x | is-not-empty }
| where {|x| $x | is-not-empty }
| str join $theme.delimiter
[$head $body] | str join (char newline)
} else {
@ -85,7 +85,7 @@ export def --wrapped level [
| each {|y| $"($theme.bg)($y.k)=($theme.fg)($y.v)"}
| str join ' '
[$time $label $tag $txt]
| filter {|x| $x | is-not-empty }
| where {|x| $x | is-not-empty }
| str join $theme.delimiter
}
$r + $theme.terminal | do $output

View file

@ -3,5 +3,5 @@ export def ls-hidden [
--dir(-d):any # The directory you want to list
] {
let dir = if ($dir | is-empty) { "." } else { $dir }
ls -a $dir | filter { ($in.name | into string | str starts-with '.') }
ls -a $dir | where { ($in.name | into string | str starts-with '.') }
}

View file

@ -60,7 +60,7 @@ flag_record:record # A object filled all known flags and their values.
}
| filter { |value| ( $value | describe ) != nothing }
| where { |value| ( $value | describe ) != nothing }
}

View file

@ -25,7 +25,7 @@ module cdpath {
$env.CDPATH
| path expand
| uniq
| filter {|| $in | path exists }
| where {|| $in | path exists }
}
# Children of a path
@ -59,7 +59,7 @@ module cdpath {
let first = $path | first
complete_from_cdpath
| filter {|| $in.value | str contains $first }
| where {|| $in.value | str contains $first }
| upsert value {|| $"($in.value)/" }
# Complete a child of a CDPATH entry
} else {
@ -86,14 +86,14 @@ module cdpath {
| each {||
$in | path join $prefix
}
| filter {||
| where {||
$in | path exists
}
| first
}
children $chosen_path
| filter {||
| where {||
$in | str contains $last
}
| each {|child|

View file

@ -60,7 +60,7 @@ $set ++ $set_b | uniq
### Intersection
$set | filter { |elem| $elem in $set_b }
$set | where { |elem| $elem in $set_b }
# Result: [2 3]
@ -68,7 +68,7 @@ $set | filter { |elem| $elem in $set_b }
# $set - $set_b
$set | filter { |elem| $elem not-in $set_b }
$set | where { |elem| $elem not-in $set_b }
# or

View file

@ -53,7 +53,7 @@ def todo [
get_todo
| reverse
# change ($num - 1) to $num to have zero-based indexing
| filter {|it, n| $n != ($num - 1) }
| where {|it, n| $n != ($num - 1) }
| reverse
| save $env.TODO -f
}

View file

@ -335,20 +335,20 @@ export def run-tests [
commands: (get-annotated $row.name)
}
}
| filter {|x| ($x.commands|length) > 0}
| where {|x| ($x.commands|length) > 0}
| upsert commands {|module|
$module.commands
| create-test-record
}
| flatten
| filter {|x| ($x.test|length) > 0}
| filter {|x| if ($exclude_module|is-empty) {true} else {$x.name !~ $exclude_module}}
| filter {|x| if ($test|is-empty) {true} else {$x.test|any {|y| $y =~ $test}}}
| filter {|x| if ($module|is-empty) {true} else {$module == $x.name}}
| where {|x| ($x.test|length) > 0}
| where {|x| if ($exclude_module|is-empty) {true} else {$x.name !~ $exclude_module}}
| where {|x| if ($test|is-empty) {true} else {$x.test|any {|y| $y =~ $test}}}
| where {|x| if ($module|is-empty) {true} else {$module == $x.name}}
| update test {|x|
$x.test
| filter {|y| if ($test|is-empty) {true} else {$y =~ $test}}
| filter {|y| if ($exclude|is-empty) {true} else {$y !~ $exclude}}
| where {|y| if ($test|is-empty) {true} else {$y =~ $test}}
| where {|y| if ($exclude|is-empty) {true} else {$y !~ $exclude}}
}
)
if $list {