Skip to content

Commit

Permalink
Modernize!
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fdw committed Jan 8, 2022
1 parent 7c5102a commit f721a09
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 32 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=47",
"wheel"
]
build-backend = "setuptools.build_meta"
28 changes: 28 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[metadata]
name = rofi-clipster
version = attr: clippy.clippy.__version__
author = fdw
author_email = [email protected]
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
22 changes: 0 additions & 22 deletions setup.py

This file was deleted.

File renamed without changes.
20 changes: 11 additions & 9 deletions clippy/Clippy.py → src/clippy/clippy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -15,27 +16,28 @@ 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]:
rofi = run(
[
'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',
Expand All @@ -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(
Expand Down

0 comments on commit f721a09

Please sign in to comment.