Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

put result in clipboard #58

Open
maxandersen opened this issue Mar 29, 2024 · 8 comments · May be fixed by #97
Open

put result in clipboard #58

maxandersen opened this issue Mar 29, 2024 · 8 comments · May be fixed by #97
Labels
enhancement New feature or request

Comments

@maxandersen
Copy link

Is your feature request related to a problem? Please describe.
I like to take snippet of code and paste image into chat or twitter directly,.

Describe the solution you'd like
freeze --clipboard mycode.java or similar to then just be able to paste result without intermediate files

@Moulick
Copy link

Moulick commented Apr 4, 2024

Also, if freeze could simply output to stdout, on MacOS we could simply do ls | freeze | pbcopy. That also allows piping to any other program, like a image compressor before copying.

@ndom91
Copy link

ndom91 commented Apr 4, 2024

Came here looking for clipboard output as well. But actually outputting to stdout would this and many other use-cases and also be much simpler for yall to implement / maintain.

Folks can then pipe it into the clipboard app of their platform of choice (xcopy for x11 linux, pbcopy for mac os x, wl-copy for linux wayland, etc.)

@bashbunni bashbunni added the enhancement New feature or request label Apr 4, 2024
@AlejandroSuero
Copy link
Contributor

The problem I think at least in MacOS, from what I am working on freeze-code.nvim, is that pbcopy unlike xclip or wl-copy can't copy images itself. But using osascript to set the clipboard to read an image file and copy it it works fine. Same goes for Windows.

  • MacOS:
on run args
  set the clipboard to (read (POSIX file (first item of args)) as JPEG picture)
end
-- or just png
on run args
  set the clipboard to (read (POSIX file (first item of args)) as {«class PNGf»})
end
-- without args
set the clipboard to (read (POSIX file "<full-path-to-image>/image.png") as JPEG picture)
-- or just png
set the clipboard to (read (POSIX file "<full-path-to-image>/image.png") as {«class PNGf»})
  • Windows
Add-Type -AssemblyName System.Windows.Forms; [Windows.Forms.Clipboard]::SetImage($[System.Drawing.Image]::FromFile("$args[0]")))
# without args
Add-Type -AssemblyName System.Windows.Forms; [Windows.Forms.Clipboard]::SetImage($[System.Drawing.Image]::FromFile("<full-path-to-image>/image.png")))

If you want to do it natively to the OS and executing a shell command.

In go there is this repo for cross-platform clipboard which also allows you to use it from the terminal with gclip -copy -f image.png as well as the API, haven't tried the API so I don't know in that regard.

  • Image generated with freeze and using any of the commands mentioned:
    freeze.nix generated with freeze

AlejandroSuero added a commit to AlejandroSuero/freeze that referenced this issue May 19, 2024
AlejandroSuero added a commit to AlejandroSuero/freeze that referenced this issue May 19, 2024
AlejandroSuero added a commit to AlejandroSuero/freeze that referenced this issue May 19, 2024
AlejandroSuero added a commit to AlejandroSuero/freeze that referenced this issue May 19, 2024
@AlejandroSuero AlejandroSuero linked a pull request May 19, 2024 that will close this issue
3 tasks
@AlejandroSuero
Copy link
Contributor

@maxandersen @ndom91 @Moulick @bashbunni

I made a PR (#97) using the previously mentioned cross-platform clipboard package if anyone want to test it out to see if solves this issue.

@Moulick
Copy link

Moulick commented May 20, 2024

@AlejandroSuero sweet! This solves the clipboard problem.

I still think that freeze should also have an option to write to stdout for other programs.

nvm, it can write to stdout apparently
https://github.com/charmbracelet/freeze?tab=readme-ov-file#output

Change the output file location, defaults to out.svg or stdout if piped. This value supports .svg, .png, .webp.

@AlejandroSuero
Copy link
Contributor

@Moulick When I tried on MacOS for example freeze Makefile | pbcopy it will copy it but raw, without transformation.

That is what you are referring to right?

To be sure, if I need to change something in #97

AlejandroSuero added a commit to AlejandroSuero/freeze that referenced this issue Jun 3, 2024
@AlejandroSuero
Copy link
Contributor

@maxandersen @ndom91 @Moulick I added stdout support on #102

@maxandersen
Copy link
Author

awesome! looking forward for this to be in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants