Skip to content

Commit

Permalink
FreeBSD support, preffer xsel unstead of xclip, fix bug, move Support…
Browse files Browse the repository at this point in the history
… to top in Readme
  • Loading branch information
NikitaBeloglazov committed Sep 30, 2023
1 parent 5e216fd commit 36469d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ __Python3 module for working with clipboard. Created because pyperclip is discon
__Mostly made for [✨ YTCON](https://github.com/NikitaBeloglazov/ytcon)__

# 📘 Features:
* Simple use and simple architecture by KISS
* Easy use and simple architecture by KISS
* User-friendly
* No additional modules
* Supports many engines
* We use PyLint and we comment all our code
* Active development
* Just good dev 😇

# 👽 Using
```python3
Expand Down Expand Up @@ -50,17 +51,28 @@ except clipman.exceptions.ClipmanBaseException as e:
pip3 install clipman
```

# Support
__•‎ 🟩 Linux - FULL SUPPORT__, some additional deps needed

__•‎ 🟩 Android - FULL SUPPORT in Termux__, some additional deps needed too

__•‎ 🟩 BSD Systems - Works__ on FreeBSD/GhostBSD. Deps needed, same as Linux

__•‎ 🟩 Windows - Works__ natively

__•‎ 🟩 MacOS - Works__ on macOS HighSierra 10.13

# 📙 Additional deps
__Unstead zypper you need to use system package manager: apt, dnf, pacman, etc__
__Unstead zypper you need to use system package manager: pkg, apt, dnf, pacman, etc__

`- = - = -`
### 🐧 On Linux - X11
- Install `xclip` or `xsel` package
### 🐧 On Linux/BSD - X11
- Install `xsel` or `xclip` package

Example: _sudo zypper install xclip_ __OR__ _sudo zypper install xsel_
Example: _sudo zypper install xsel_ __OR__ _sudo zypper install xclip_

`- = - = -`
### 🐧 On Linux - Wayland
### 🐧 On Linux/BSD - Wayland
- Install `wl-clipboard` package

Example: _sudo zypper install wl-clipboard_
Expand All @@ -73,15 +85,6 @@ And you need install additional deps in it.
* Run ```pkg install termux-api```
* Check it - run ```termux-clipboard-get```

# Support
__•‎ 🟩 Linux - FULL SUPPORT__, some additional deps needed

__•‎ 🟩 Android - FULL SUPPORT in Termux__, some additional deps needed too

__•‎ 🟩 Windows - Works natively__

__•‎ 🟩 MacOS - Works fine__ on macOS HighSierra 10.13

# License
This code is under [Mozilla Public License Version 2.0](/../../blob/main/LICENSE).

Expand Down
20 changes: 10 additions & 10 deletions src/clipman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run_command(command, timeout=5):
raise exceptions.EngineTimeoutExpired(f"The timeout for executing the command was exceeded: subprocess.TimeoutExpired: {e}")

if runner.returncode != 0:
raise exceptions.EngineError(f"Command returned non-zero exit status: {str(runner.returncode)}.\n- = -\nSTDERR: {runner.stdout.decode('UTF-8')}")
raise exceptions.EngineError(f"Command returned non-zero exit status: {str(runner.returncode)}.\n- = -\nSTDERR: {runner.stderr.decode('UTF-8')}")

return runner.stdout.decode("UTF-8").removesuffix("\n") # looks like all commands returns \n in the end

Expand Down Expand Up @@ -95,19 +95,19 @@ def detect_clipboard_engine():
Detects clipboard engine based on many factors, and in many cases gives the user friendly advice.
Returns name of detected engine
"""
if dataclass.os_name == "Linux":
if dataclass.os_name in ("Linux", "FreeBSD"):
try:
# Detect graphical backend from ENV
graphical_backend = os.environ["XDG_SESSION_TYPE"]
except KeyError:
graphical_backend = "< NOT SET >"

if graphical_backend == "x11":
if check_binary_installed("xsel"): # Preffer xsel because is it less laggy and more fresh
return check_run_command(['xsel'], "xsel")
if check_binary_installed("xclip"):
return check_run_command(['xclip', '-selection', 'c', '-o'], "xclip")
if check_binary_installed("xsel"):
return check_run_command(['xsel'], "xsel")
raise exceptions.NoEnginesFoundError("Clipboard engines not found on your system. For Linux X11, you need to install \"xclip\" or \"xsel\" via your system package manager.")
raise exceptions.NoEnginesFoundError("Clipboard engines not found on your system. For Linux X11, you need to install \"xsel\" or \"xclip\" via your system package manager.")

if graphical_backend == "wayland":
if check_binary_installed("wl-paste"):
Expand Down Expand Up @@ -175,16 +175,16 @@ def call(method, text=None): # pylint: disable=R0911 # too-many-return-statement
text = str(text)

# - = LINUX - = - = - = - = - = - = - =
if dataclass.engine == "xclip":
if method == "set":
return run_command_with_paste(['xclip', '-selection', 'c', '-i'], text)
if method == "get":
return run_command(['xclip', '-selection', 'c', '-o'])
if dataclass.engine == "xsel":
if method == "set":
return run_command_with_paste(['xsel', '-b', '-i'], text)
if method == "get":
return run_command(["xsel"])
if dataclass.engine == "xclip":
if method == "set":
return run_command_with_paste(['xclip', '-selection', 'c', '-i'], text)
if method == "get":
return run_command(['xclip', '-selection', 'c', '-o'])
if dataclass.engine == "wl-clipboard":
if method == "set":
try:
Expand Down

0 comments on commit 36469d1

Please sign in to comment.