Skip to content

Instantly share code, notes, and snippets.

@paul-d-ray
Last active November 9, 2025 21:13
Show Gist options
  • Select an option

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

Select an option

Save paul-d-ray/55b62e9a8ec4ea38ff6135ecedef2f4f to your computer and use it in GitHub Desktop.
Nushell Combine FD and LS

Purpose

Use FD to find a file and pipe it to Nushell's ls command to list information on the file.

Nushell Code

fd -H -I -i  -E 'Windows' -E 'Python' -E 'Steel*' -E '*ffice*' -E '*ire*' -E '*VS Code*' -E 'WindowsPowerShell' --glob  '*posh*.exe' 'c:\'  | lines | each {|file|  nuls -f  ($file |path dirname) | where name =~ ($file | path basename )  } | flatten

Nushell Code Explained

fd -H -I -i -E 'Windows' -E 'Python' -E 'Steel*' -E '*ffice*' -E '*ire*' -E '*VS Code*' -E 'WindowsPowerShell' --glob '*posh*.exe' 'c:\'

Tool: fd (a fast, user-friendly alternative to find for locating files). Flags and Options:

  • -H: Include hidden files and directories in the search.

  • -I: Ignore .gitignore files and similar ignore rules (e.g., from .fdignore).

  • -i: Case-insensitive matching (e.g., matches POSH.exe or Posh.ExE).

  • -E 'pattern': Exclude directories or files matching the given patterns (shell-style globs). This skips:

    • 'Windows': The main Windows system directory (avoids scanning ~20-30 GB of OS files).
    • 'Python': Python installations (avoids virtualenvs or large libs).
    • 'Steel*': Likely SteelSeries gaming software dirs (e.g., SteelSeries).
    • 'ffice': Microsoft Office-related dirs (e.g., Microsoft Office).
    • 'ire': Dirs with "ire" in the name (e.g., Firefox, WireGuard; broad exclusion to skip browsers/tools).
    • 'VS Code': Visual Studio Code installations.
    • 'WindowsPowerShell': The legacy PowerShell module dir (avoids duplicates since we're searching for exes anyway).
  • --glob 'posh.exe': Search specifically for files matching this glob pattern. This targets executables with "posh" anywhere in the name (e.g., powershell.exe, pwsh.exe, posh-git.exe). The * wildcards allow flexibility, and .exe ensures Windows executables. 'c:': Starting search path (entire C: drive).


Nushell Custom Command for FD

Nushell Code

# PR 20251108_1959
# help from Grok
# use FD to search for a filename
#   and join to nuls to get the filename information with path

def nufd [
     pattern: string,
     --root (-r): string = 'c:\',
     --extra-exclude (-e): list<string> = []
 ] {
     let base_excludes = [
         'Windows' 
         'Steel*' 
         '*ffice*' 
         '*ire*' 
         '*VS Code*' 
         'WindowsPowerShell'
     ]
     let all_excludes = ($base_excludes | append $extra_exclude)
     let exclude_flags = ($all_excludes | each { |e| [ '-E' $e ] } | flatten)

     # Build full fd command as a list, then run with ^
     ^fd -H -I -i ...$exclude_flags --glob $"*($pattern)*" $root
     | lines
     | each { |file|
         nuls -f ($file | path dirname)
         | where name =~ ($file | path basename)
       }
     | flatten
 }

Nushell NUFD sample Output

╭─────┬───────┬───────────┬──────────────────────┬─────────┬────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│   # │ type  │   size    │       modified       │   ext   │          name          │                                                   fullname                                                    │
├─────┼───────┼───────────┼──────────────────────┼─────────┼────────────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│   0 │ file  │      80 B │ 2025-10-23 21:18:36  │         │ .visidatarc            │ c:\users\paul_ray\.visidatarc                                                                                 │
│   1 │ file  │      66 B │ 2025-10-06 00:14:10  │ bak     │ .visidatarc.bak        │ c:\users\paul_ray\.visidatarc.bak                                                                             │
│   2 │ file  │      66 B │ 2025-10-06 00:14:10  │ bak     │ .visidatarc.bak        │ c:\users\paul_ray\.visidatarc.bak                                                                             │
│   3 │ dir   │       0 B │ 2024-10-14 21:00:28  │         │ .visidata              │ c:\users\paul_ray\.visidata                                                                                   │
│   4 │ file  │      80 B │ 2025-10-23 21:18:36  │         │ .visidatarc            │ c:\users\paul_ray\.visidatarc                                                                                 │
│   5 │ file  │      66 B │ 2025-10-06 00:14:10  │ bak     │ .visidatarc.bak        │ c:\users\paul_ray\.visidatarc.bak                                                                             │
│   6 │ file  │    1.6 kB │ 2025-10-07 22:43:20  │ txt     │ visidata.txt           │ c:\users\paul_ray\appdata\roaming\heynote\notes\coding\visidata.txt                                           │
│   7 │ file  │   60.1 kB │ 2025-09-11 10:53:02  │ 1       │ visidata.1             │ c:\users\paul_ray\appdata\local\programs\python\python313\share\man\man1\visidata.1                           │
│   8 │ file  │     125 B │ 2025-09-11 10:53:02  │ desktop │ visidata.desktop       │ c:\users\paul_ray\appdata\local\programs\python\python313\share\applications\visidata.desktop                 │
│   9 │ file  │  108.3 kB │ 2025-09-11 10:53:04  │ exe     │ visidata.exe           │ c:\users\paul_ray\appdata\local\programs\python\python313\scripts\visidata.exe                                │
│  10 │ dir   │       0 B │ 2023-08-26 20:31:31  │         │ visidata               │ c:\users\paul_ray\appdata\local\visidata                                                                      │
│  11 │ dir   │       0 B │ 2025-09-11 11:06:47  │         │ visidata               │ c:\users\paul_ray\appdata\local\visidata\visidata                                                             │
│  12 │ dir   │    4.0 kB │ 2025-09-11 10:53:04  │         │ visidata-3.3.dist-info │ c:\users\paul_ray\appdata\local\programs\python\python313\lib\site-packages\visidata-3.3.dist-info            │
│  13 │ dir   │   20.4 kB │ 2025-09-11 10:53:02  │         │ visidata               │ c:\users\paul_ray\appdata\local\programs\python\python313\lib\site-packages\visidata                          │
│  14 │ dir   │    4.0 kB │ 2025-09-11 10:53:04  │         │ visidata-3.3.dist-info │ c:\users\paul_ray\appdata\local\programs\python\python313\lib\site-packages\visidata-3.3.dist-info            │
│  15 │ file  │     125 B │ 2025-09-11 10:53:02  │ desktop │ visidata.desktop       │ c:\users\paul_ray\appdata\local\programs\python\python313\lib\site-packages\visidata\desktop\visidata.desktop │
├─────┼───────┼───────────┼──────────────────────┼─────────┼────────────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│   # │ type  │   size    │       modified       │   ext   │          name          │                                                   fullname                                                    │
╰─────┴───────┴───────────┴──────────────────────┴─────────┴────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment