chubin / cheat.sh

the only cheat sheet you need
https://cheat.sh/
MIT License
38.47k stars 1.8k forks source link

fix: if statement breaking copy() and ccopy() on macos #395

Open tjex opened 11 months ago

tjex commented 11 months ago

Resolves issue #361.

Problem: ccopy and copy return an error on mac, "copy: supported only in the Desktop version"

This is because the cht.sh script checks for presence of the $DISPLAY environment variable, which is no longer a part of MacOS as it comes from the X11 days. So, calling the function would always return the error on mac.

pr366 attempted to fix this with a similar approach.

The solution of this PR reuses the $is_macos boolean variable, which is already a part of this script.

It now only returns the error if $DISPLAY is null/empty and the OS is not MacOS.

abitrolly commented 6 days ago

Does MacOS expose $XDG_CURRENT_DESKTOP variable? Is it possible at all to run cht.sh script on MacOS without desktop? If yes, then is clipboard copy possible in this case?

https://superuser.com/questions/1074068/what-is-the-difference-between-desktop-session-xdg-session-desktop-and-xdg-cur

tjex commented 1 day ago

I'm not following the reasoning for your questions. Should they apply to the pr or are they general questions?

abitrolly commented 1 day ago

We need to detect if clipboard is available. It probably only available if script is run in the desktop session. The way to detect desktop session on Linux is using $XDG_CURRENT_DESKTOP variable. The questions are about how it works on MacOS.

tjex commented 18 hours ago

ah ok. Well as far as I found out, $DESKTOP used to exist as an env variable on mac. But not any more. I would say that as osx effectively is a desktop environment (there is no headless / minimal install or such) then it's redundant to check? Another option could just be to check $(which pbcopy)?