Skip to content

freeze --execute doesn't work with pipes/redirects #67

@jacksonmcafee

Description

@jacksonmcafee

Feature / Bug

I really like the --execute functionality of freeze but I am somewhat annoyed with the fact that I cannot execute commands with pipes or redirects. To provide a simple example, I created a file named file.txt with the contents:

bar1
foo1
bar2
foo2

cat file.txt | grep 'foo' will return:

foo1
foo2

freeze --execute "cat file.txt | grep 'foo'" will return:
freeze

It appears to stops parsing at the pipe and only executes cat file.txt. I checked shellwords.Parse(), which is called by pty.go, executeCommand(), and the behavior might stem from there.

I have no experience in Go so I can't be sure, but someone more knowledgeable than me might be able to verify. When I added test cases to check this in the parsing library, it appears to parse up until a pipe or redirect as expected. Apologies if my analysis is wrong, but in my cursory look at the code, that's what stood out to me.

Describe the solution you'd like

It would be nice if --execute would take any command and execute it to completion before creating the output image. Ideally, in the example above, that command should function identically and return the following image:
freeze

Describe alternatives you've considered

To get the above image, I used cat file.txt | grep 'foo' | freeze --language bash. This isn't too complex of an alternative, but has two immediate downsides:

  • It requires that the user pass a language.
  • It seems to go against the initial instinct to use --execute in the first place.

This also highlights that syntax highlighting will not work on --executed inputs. If I wanted to do something like freeze --execute "cat main.cpp", it would fail to properly highlight the syntax. I don't really think this is that problematic, but it is worthy of note. The --language flag will not fix this and will output the same image.

Additional context

I am using a non-standard freeze config but I can't imagine that's affecting anything in this case. I just like less padding & rounded corners on my images :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions