From f721a092ca72ebbfc0ab46899c35c2ffe116172c Mon Sep 17 00:00:00 2001 From: Fabian Winter <5821180+fdw@users.noreply.github.com> Date: Sat, 8 Jan 2022 14:34:44 +0100 Subject: [PATCH] Modernize! First, let's use more modern tools for packaging. Secondly, we can ask `rofi` politely to return the selected index instead of the whole selection. This means that we can only save all the entries and not use the shortened version as a key. --- LICENSE | 2 +- pyproject.toml | 6 +++++ setup.cfg | 28 ++++++++++++++++++++++++ setup.py | 22 ------------------- {clippy => src/clippy}/__init__.py | 0 clippy/Clippy.py => src/clippy/clippy.py | 20 +++++++++-------- 6 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 pyproject.toml create mode 100644 setup.cfg delete mode 100644 setup.py rename {clippy => src/clippy}/__init__.py (100%) rename clippy/Clippy.py => src/clippy/clippy.py (74%) diff --git a/LICENSE b/LICENSE index e37691d..8b30949 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Fabian Winter +Copyright (c) 2020 - 2022 Fabian Winter Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ef18580 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=47", + "wheel" +] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..ad59157 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,28 @@ +[metadata] +name = rofi-clipster +version = attr: clippy.clippy.__version__ +author = fdw +author_email = 5821180+fdw@users.noreply.github.com +description = A rofi interface for clipster +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/fdw/rofi-clipster +project_urls = + Source = https://github.com/fdw/rofi-clipster + Bug Tracker = https://github.com/fdw/rofi-clipster/issues + Changelog = https://github.com/fdw/rofi-clipster/CHANGELOG.md +license: MIT +classifiers = + License :: OSI Approved :: MIT License + +[options] +package_dir = + = src +packages = clippy +python_requires = >=3.7 +install_requires = + ConfigArgParse>0.15,<2.0.0 + +[options.entry_points] +console_scripts = + rofi-clipster = clippy.clippy:main diff --git a/setup.py b/setup.py deleted file mode 100644 index 399e002..0000000 --- a/setup.py +++ /dev/null @@ -1,22 +0,0 @@ -from setuptools import setup - -setup( - name='rofi-clipster', - version='0.0.1', - description='A rofi interface for clipster', - author='fdw', - author_email='5821180+fdw@users.noreply.github.com', - url='https://github.com/fdw/rofi-clipster', - keywords='rofi clipster clipboard', - license='MIT', - classifiers=[ - 'License :: OSI Approved :: MIT License' - ], - - packages=['clippy'], - entry_points={ - 'console_scripts': [ - 'rofi-clipster = clippy.Clippy:main' - ] - } -) diff --git a/clippy/__init__.py b/src/clippy/__init__.py similarity index 100% rename from clippy/__init__.py rename to src/clippy/__init__.py diff --git a/clippy/Clippy.py b/src/clippy/clippy.py similarity index 74% rename from clippy/Clippy.py rename to src/clippy/clippy.py index 5417840..5b2ceea 100755 --- a/clippy/Clippy.py +++ b/src/clippy/clippy.py @@ -2,11 +2,12 @@ # -*- coding: utf-8 -*- import sys from subprocess import run -from typing import Tuple, Dict +from typing import Tuple, List +__version__ = '0.2.0' -class Clippy: +class Clippy: def __init__(self) -> None: self.entries = self.get_entries_from_clipster() @@ -15,8 +16,7 @@ def __init__(self) -> None: if return_code != 0: sys.exit() - actual_entry = self.fetch_actual_entry(stdout[:-1]) - + actual_entry = self.fetch_actual_entry(int(stdout)) self.save_to_clipboard(actual_entry) def open_main_rofi_window(self) -> Tuple[int, str]: @@ -24,18 +24,20 @@ def open_main_rofi_window(self) -> Tuple[int, str]: [ 'rofi', '-dmenu', + '-format', + 'i', '-i', '-sep', 'nul' ], - input='\n'.join(self.entries.keys()), + input='\n'.join([line.replace('\n', ' ')[0:250] for line in self.entries]), capture_output=True, encoding='utf-8' ) return rofi.returncode, rofi.stdout - def get_entries_from_clipster(self) -> Dict[str, str]: + def get_entries_from_clipster(self) -> List[str]: lines = run( [ 'clipster', @@ -48,10 +50,10 @@ def get_entries_from_clipster(self) -> Dict[str, str]: encoding='utf-8' ).stdout.split('\0') - return {line.replace('\n', ' ')[0:250]: line for line in lines} + return lines - def fetch_actual_entry(self, view: str) -> str: - return self.entries[view] + def fetch_actual_entry(self, index: int) -> str: + return self.entries[index] def save_to_clipboard(self, chosen_text: str): run(