Skip to content

Commit f721a09

Browse files
committed
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.
1 parent 7c5102a commit f721a09

6 files changed

Lines changed: 46 additions & 32 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Fabian Winter
3+
Copyright (c) 2020 - 2022 Fabian Winter
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build-system]
2+
requires = [
3+
"setuptools>=47",
4+
"wheel"
5+
]
6+
build-backend = "setuptools.build_meta"

setup.cfg

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[metadata]
2+
name = rofi-clipster
3+
version = attr: clippy.clippy.__version__
4+
author = fdw
5+
author_email = 5821180+fdw@users.noreply.github.com
6+
description = A rofi interface for clipster
7+
long_description = file: README.md
8+
long_description_content_type = text/markdown
9+
url = https://github.com/fdw/rofi-clipster
10+
project_urls =
11+
Source = https://github.com/fdw/rofi-clipster
12+
Bug Tracker = https://github.com/fdw/rofi-clipster/issues
13+
Changelog = https://github.com/fdw/rofi-clipster/CHANGELOG.md
14+
license: MIT
15+
classifiers =
16+
License :: OSI Approved :: MIT License
17+
18+
[options]
19+
package_dir =
20+
= src
21+
packages = clippy
22+
python_requires = >=3.7
23+
install_requires =
24+
ConfigArgParse>0.15,<2.0.0
25+
26+
[options.entry_points]
27+
console_scripts =
28+
rofi-clipster = clippy.clippy:main

setup.py

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# -*- coding: utf-8 -*-
33
import sys
44
from subprocess import run
5-
from typing import Tuple, Dict
5+
from typing import Tuple, List
66

7+
__version__ = '0.2.0'
78

8-
class Clippy:
99

10+
class Clippy:
1011
def __init__(self) -> None:
1112
self.entries = self.get_entries_from_clipster()
1213

@@ -15,27 +16,28 @@ def __init__(self) -> None:
1516
if return_code != 0:
1617
sys.exit()
1718

18-
actual_entry = self.fetch_actual_entry(stdout[:-1])
19-
19+
actual_entry = self.fetch_actual_entry(int(stdout))
2020
self.save_to_clipboard(actual_entry)
2121

2222
def open_main_rofi_window(self) -> Tuple[int, str]:
2323
rofi = run(
2424
[
2525
'rofi',
2626
'-dmenu',
27+
'-format',
28+
'i',
2729
'-i',
2830
'-sep',
2931
'nul'
3032
],
31-
input='\n'.join(self.entries.keys()),
33+
input='\n'.join([line.replace('\n', ' ')[0:250] for line in self.entries]),
3234
capture_output=True,
3335
encoding='utf-8'
3436
)
3537

3638
return rofi.returncode, rofi.stdout
3739

38-
def get_entries_from_clipster(self) -> Dict[str, str]:
40+
def get_entries_from_clipster(self) -> List[str]:
3941
lines = run(
4042
[
4143
'clipster',
@@ -48,10 +50,10 @@ def get_entries_from_clipster(self) -> Dict[str, str]:
4850
encoding='utf-8'
4951
).stdout.split('\0')
5052

51-
return {line.replace('\n', ' ')[0:250]: line for line in lines}
53+
return lines
5254

53-
def fetch_actual_entry(self, view: str) -> str:
54-
return self.entries[view]
55+
def fetch_actual_entry(self, index: int) -> str:
56+
return self.entries[index]
5557

5658
def save_to_clipboard(self, chosen_text: str):
5759
run(

0 commit comments

Comments
 (0)