-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
interactiveutil: clipboard for FreeBSD #23151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,30 +134,49 @@ if Sys.isapple() | |
end | ||
clipboard() = read(`pbpaste`, String) | ||
|
||
elseif Sys.islinux() | ||
elseif Sys.islinux() || Sys.KERNEL === :FreeBSD | ||
_clipboardcmd = nothing | ||
const _clipboardcmds = Dict( | ||
:copy => Dict( | ||
:xsel => Sys.islinux() ? | ||
`xsel --nodetach --input --clipboard` : `xsel -c`, | ||
:xclip => `xclip -silent -in -selection clipboard`, | ||
), | ||
:paste => Dict( | ||
:xsel => Sys.islinux() ? | ||
`xsel --nodetach --output --clipboard` : `xsel -p`, | ||
:xclip => `xclip -quiet -out -selection clipboard`, | ||
) | ||
) | ||
function clipboardcmd() | ||
global _clipboardcmd | ||
_clipboardcmd !== nothing && return _clipboardcmd | ||
for cmd in (:xclip, :xsel) | ||
success(pipeline(`which $cmd`, DevNull)) && return _clipboardcmd = cmd | ||
end | ||
error("no clipboard command found, please install xsel or xclip") | ||
pkgs = @static if Sys.islinux() | ||
"xsel or xclip" | ||
elseif Sys.KERNEL === :FreeBSD | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems works... is it expected? julia> @static if true
42
elseif false
24
end
42
julia> @static if false
42
elseif true
24
end
24 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but the elseif condition is getting evaluated at run time, I believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. support of |
||
"x11/xsel or x11/xclip" | ||
end | ||
error("no clipboard command found, please install $pkgs") | ||
end | ||
function clipboard(x) | ||
c = clipboardcmd() | ||
cmd = c == :xsel ? `xsel --nodetach --input --clipboard` : | ||
c == :xclip ? `xclip -silent -in -selection clipboard` : | ||
cmd = get(_clipboardcmds[:copy], c, nothing) | ||
if cmd === nothing | ||
error("unexpected clipboard command: $c") | ||
end | ||
open(pipeline(cmd, stderr=STDERR), "w") do io | ||
print(io, x) | ||
end | ||
end | ||
function clipboard() | ||
c = clipboardcmd() | ||
cmd = c == :xsel ? `xsel --nodetach --output --clipboard` : | ||
c == :xclip ? `xclip -quiet -out -selection clipboard` : | ||
cmd = get(_clipboardcmds[:paste], c, nothing) | ||
if cmd === nothing | ||
error("unexpected clipboard command: $c") | ||
end | ||
read(pipeline(cmd, stderr=STDERR), String) | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre-existing, but this'll give a pretty misleading error message if
which
isn't installedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or... we can implement a simple version of
which
in Julia?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I generally do is if I know the program I'm looking for, usually there's a safe no-op flag like
-h
or--version
that you can try executing in a try-catch.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-h
works onxclip
. unfortunately, the bsd versionxsel
doesn't have any no-op flag.