Skip to content

Instantly share code, notes, and snippets.

@paul-d-ray
Last active February 8, 2026 03:59
Show Gist options
  • Select an option

  • Save paul-d-ray/a94fa981acc733b1bc5df742984bbc46 to your computer and use it in GitHub Desktop.

Select an option

Save paul-d-ray/a94fa981acc733b1bc5df742984bbc46 to your computer and use it in GitHub Desktop.
Nushell showing RG output as a table

Using RG to find and have Nushell show the results as a table

Nuushell code

rg 'get -o' -g '*.nu' --max-depth 1 --json
| from ndjson
| where type == "match"
| each {|row|
    {
        file: $row.data.path.text
        line: $row.data.line_number
        text: ($row.data.lines.text | str trim)
    }
}
| group-by file
| transpose file matches

RG Output

╭───┬───────────────┬──────────────────────────────────────────────────────────────────────╮
│ # │     file      │                               matches                                │
├───┼───────────────┼──────────────────────────────────────────────────────────────────────┤
│ 0 │ auto_KO.nu    │ ╭───┬────────────┬──────┬───────────────╮                            │
│   │               │ │ # │    file    │ line │     text      │                            │
│   │               │ ├───┼────────────┼──────┼───────────────┤                            │
│   │               │ │ 0 │ auto_KO.nu │   75 │ | get -o $col │                            │
│   │               │ ╰───┴────────────┴──────┴───────────────╯                            │
│ 1 │ bible.nu      │ ╭───┬──────────┬──────┬────────────────────────────────────────────╮ │
│   │               │ │ # │   file   │ line │                    text                    │ │
│   │               │ ├───┼──────────┼──────┼────────────────────────────────────────────┤ │
│   │               │ │ 0 │ bible.nu │   45 │ | where {|w| ($stop | get -o $w) == null } │ │
│   │               │ ╰───┴──────────┴──────┴────────────────────────────────────────────╯ │
│ 2 │ ping_hosts.nu │ ╭───┬───────────────┬──────┬──────────────────────────────────────╮  │
│   │               │ │ # │     file      │ line │                 text                 │  │
│   │               │ ├───┼───────────────┼──────┼──────────────────────────────────────┤  │
│   │               │ │ 0 │ ping_hosts.nu │   27 │ let ip = ($parsed | get -o 0.ip)     │  │
│   │               │ │ 1 │ ping_hosts.nu │   28 │ let time = ($parsed | get -o 0.time) │  │
│   │               │ ╰───┴───────────────┴──────┴──────────────────────────────────────╯  │
╰───┴───────────────┴──────────────────────────────────────────────────────────────────────╯

Using Find command

Nushell Code

nuls
| where ext == 'nu'
| get name
| each {|file|
    let matches = (
        open $file
        | decode utf-8
        | lines
        | enumerate
        | each {|row| { file: $file line_number: ($row.index + 1), line: $row.item } }
        | where line =~ 'get -o'
        # | find 'get -o'
        | str trim
        | rename file line text
    )

    if ($matches | is-not-empty) {
        {
            file: $file
            matches: $matches
        }
    }
}
| compact

Find Output

╭───┬───────────────┬───────────────────────────────────────────────────────────────────────────╮
│ # │     file      │                                  matches                                  │
├───┼───────────────┼───────────────────────────────────────────────────────────────────────────┤
│ 0 │ auto_ko.nu    │ ╭───┬────────────┬──────┬────────────────────────────╮                    │
│   │               │ │ # │    file    │ line │            text            │                    │
│   │               │ ├───┼────────────┼──────┼────────────────────────────┤                    │
│   │               │ │ 0 │ auto_ko.nu │   75 │ | get -o $col              │                    │
│   │               │ ╰───┴────────────┴──────┴────────────────────────────╯                    │
│ 1 │ bible.nu      │ ╭───┬──────────┬──────┬──────────────────────────────────────────────╮    │
│   │               │ │ # │   file   │ line │                     text                     │    │
│   │               │ ├───┼──────────┼──────┼──────────────────────────────────────────────┤    │
│   │               │ │ 0 │ bible.nu │   45 │ | where {|w| ($stop | get -o $w) == null }   │    │
│   │               │ ╰───┴──────────┴──────┴──────────────────────────────────────────────╯    │
│ 2 │ ping_hosts.nu │ ╭───┬───────────────┬──────┬────────────────────────────────────────────╮ │
│   │               │ │ # │     file      │ line │                    text                    │ │
│   │               │ ├───┼───────────────┼──────┼────────────────────────────────────────────┤ │
│   │               │ │ 0 │ ping_hosts.nu │   27 │ let ip = ($parsed | get -o 0.ip)           │ │
│   │               │ │ 1 │ ping_hosts.nu │   28 │ let time = ($parsed | get -o 0.time)       │ │
│   │               │ ╰───┴───────────────┴──────┴────────────────────────────────────────────╯ │
╰───┴───────────────┴───────────────────────────────────────────────────────────────────────────╯
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment