adieyal / comfyui-dynamicprompts

ComfyUI custom nodes for Dynamic Prompts
MIT License
187 stars 20 forks source link

Autocomplete wildcards #23

Open halr9000 opened 9 months ago

halr9000 commented 9 months ago

Would be great if I could type "__" and then invoke completion based on folder and filenames of my wildcard collection!

MrLogic85 commented 8 months ago

Run this in command prompt when you are inside wildcards folder. Then use Cusomt Scripts to add autocompletion. for %f in ("*.txt") do @echo %~nf

https://github.com/pythongosssss/ComfyUI-Custom-Scripts

halr9000 commented 8 months ago

Run this in command prompt when you are inside wildcards folder. Then use Cusomt Scripts to add autocompletion. for %f in ("*.txt") do @echo %~nf

https://github.com/pythongosssss/ComfyUI-Custom-Scripts

Oooh that's creative, great idea! But come on man, PowerShell has been around for 13 years!! (I am a bit biased, google "halr9000 powershell" to understand why.) We can do better! Also, that won't help with the underscores or recursion (all of mine are organized into folders). Hmm...

Ok this is going to be a PITA due to the relative sub-folders :D I'll hack on it for a bit. Almost got it.

halr9000 commented 8 months ago

Ok try this:

Get-ChildItem -Recurse -Include *.txt | Resolve-Path -Relative | ForEach-Object { "__" + $_.substring(2,$_.length-6) + "__" } YES that works awesome. Thanks for the tip!

Screenshot 2023-10-09 213504

image

halr9000 commented 8 months ago

I'll leave this open in case @adieyal wants to document this tip.

tusharbhutt commented 8 months ago

Does the ComfyUI version still load from subfolders? I can't get this node to run at all anymore because it seems to want a text input

L-o-z commented 8 months ago

On linux, so the powershell version isn't an option. Instead I ran the following command in my wildcards directory and pasted the output into the wildcards.txt file from the wildcards plugin I am using, at ComfyUI/custom_nodes/ComfyUI-Custom-Scripts/user/wildcards.txt

find . | sed 's/.\///' | sed 's/.txt//' > fulllist.txt

halr9000 commented 8 months ago

On linux, so the powershell version isn't an option

Imma well acktually you here real quick, but in a good way, in case you're interested. No worries if not. :)

Pwsh has been available as "just another shell" for Linux since 2016, believe it or not! Here's an old episode of my podcast where I interviewed Jeffrey Snover on the day they launched it. I have no illusions as to its popularity on non-windows platforms, but I can tell you that the shell and language is perfectly consistent across all the supported platforms (macos also), and in fact this project supplanted the original Windows-only codebase a couple of years later.

The same team also added full support for OpenSSH into Windows. Microsoft is a much different company than they used to be. As a contrived example, from your familiar Linux box and bash shell, you could take a .ps1 script which uses a shebang to reference pwsh, a single private key or ssh agent you've configured as needed, and scp & use ssh (or ansible etc) to run that script across linux, windows, macos, and expect it to do what's in the script consistently across each platform.

References:

L-o-z commented 8 months ago

I was unaware of that, but also have no need of it working on multiple platforms. I could create a more involved script using zsh that would keep my wildcards autocomplete list updated in pretty much the same way if I wanted to.

But I have learned something today, so thank you

NeedsMoar commented 7 months ago

Oooh that's creative, great idea! But come on man, PowerShell has been around for 13 years!! (I am a bit biased, google "halr9000 powershell" to understand why.) We can do better! Also, that won't help with the underscores or recursion (all of mine are organized into folders). Hmm...

I feel like I've seen you before, probably when I was looking up how to do something in powershell. Anyway I only use powershell for the sysadmin stuff it was clearly made for (like applying the 9 million 1weirdTrick registry "hacks" people list with no explanation, verifying that when MS said Pro Workstation had RDMA support for SMB3 they were very loosely defining "SMB3 and Support", and turning off memory compression like microsoft tells you to do and they should have done automatically on the machine with 512GB of ram because it isn't necessary and wasn't designed to cope with that much data.

It's very useful for things like that. I hate the .NET-esque syntax and I'm still stuck using cmd to pipe output from ffmpeg into various programs, especially x265 since the built in library is 20-30% slower than a pipe to the external executable since that one was built with MSVC instead of the abortion that passes for a compiler that is GCC targeting Windows.

Anway I don't use this extension but here's the cmd version that preserves relative paths, run from your wildcards directory etc in case anyone wants another option. It's similar to the original one, the only oddball portion is the weird find and replace substring-in-variable syntax in the second set command in the loop, which looks even weirder here since it has to be wrapped in a call (which forces evaluation of the %CD% hidden variable and goes farther in a batch file where you might want to put it if you're not like me and insane enough to remember how to do things like this where the %F needs to be %%F


cmd
for /r %F IN (*.txt) DO @(set "_o=%~dpfF" & call set "_result=%_o:%CD%\=%" & @echo __!_result!__)

EnableDelayedExpansion has to be on, so either cmd /v:on, the registry setting, or setlocal in a batch needs to be done first. I don't think it can be done without that since the search string is a (hidden) environment variable rather than a string. I'm sure I could write a shorter version in perl but those tend to summon elder gods so I avoid it if it's not necessary.

I'm surprised you didn't make the powershell version call the GET and POST interfaces to update the user defined wildcards text file via the web APIs:

GET /pysssss/autocomplete returns the whole list

POST /pysssss/autocomplete with open(file, "w", encoding="utf-8") as f: f.write(await request.text())

I'm assuming it'll want the UTF-8 text file wrapped in JSON or some silly crap too, that's just a snippet from the code over there. :-) Invoke-Webrequest with a POST structure followed by streaming a file over is the example 2 in Get-Help Invoke-Webrequest --Examples so it should manage it.

rjgoif commented 4 months ago

Ok try this:

Get-ChildItem -Recurse -Include *.txt | Resolve-Path -Relative | ForEach-Object { "__" + $_.substring(2,$_.length-6) + "__" } YES that works awesome. Thanks for the tip!

I am adding this for people coming to this thread but not understanding the steps:

  1. windows explorer to your wildcards folder, then type "powershell" in the address bar and hit enter
  2. run the code in powershell Get-ChildItem -Recurse -Include *.txt | Resolve-Path -Relative | ForEach-Object { "__" + $_.substring(2,$_.length-6) + "__" }
  3. highlight and copy the output (Ctrl C)
  4. go to ComfyUI in your browser and hit the gear, then hit the button do define autocomplete terms (needs ComfyUI-Custom-Scripts installed)
  5. paste in your list of terms
wardensc2 commented 3 months ago

Ok try this: Get-ChildItem -Recurse -Include *.txt | Resolve-Path -Relative | ForEach-Object { "__" + $_.substring(2,$_.length-6) + "__" } YES that works awesome. Thanks for the tip!

I am adding this for people coming to this thread but not understanding the steps:

  1. windows explorer to your wildcards folder, then type "powershell" in the address bar and hit enter
  2. run the code in powershell Get-ChildItem -Recurse -Include *.txt | Resolve-Path -Relative | ForEach-Object { "__" + $_.substring(2,$_.length-6) + "__" }
  3. highlight and copy the output (Ctrl C)
  4. go to ComfyUI in your browser and hit the gear, then hit the button do define autocomplete terms (needs ComfyUI-Custom-Scripts installed)
  5. paste in your list of terms

Hi I follow your guide and success run autocomplete with wild txt file but what about yaml file.

Can you help me

Thank you