https://github.com/gikeymarcia/pydymenu
Python wrapper for `fzf` `and `rofi`. All of your dynamic menu-ing needs in one place.
https://github.com/gikeymarcia/pydymenu
dynamic-menu fzf linux python rofi scripting
Last synced: about 1 year ago
JSON representation
Python wrapper for `fzf` `and `rofi`. All of your dynamic menu-ing needs in one place.
- Host: GitHub
- URL: https://github.com/gikeymarcia/pydymenu
- Owner: gikeymarcia
- License: gpl-3.0
- Created: 2021-06-09T17:47:45.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-09T20:05:46.000Z (over 3 years ago)
- Last Synced: 2025-03-23T23:36:01.979Z (over 1 year ago)
- Topics: dynamic-menu, fzf, linux, python, rofi, scripting
- Language: Python
- Homepage: https://pypi.org/project/pydymenu/
- Size: 102 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# pydymenu: A Pythonic interface for `fzf` and `rofi`
A single package to serve all your dynamic menu-ing needs with a simple Pythonic
interface.
## Installation
### Dependencies
```bash
sudo apt install fzf rofi -y
```
### From [PyPi][pypi]
```bash
pip3 install pydymenu
# upgrade to newest release (if previously installed)
pip3 install -U pydymenu
```
## Demonstration
To see each finder in action and get a sample code snippet to get you started
try the command-line interface.
```bash
python3 -m pydymenu --fzf
python3 -m pydymenu --rofi
```
## Basic Usage
To begin, use `fzf` to pick an item from a list.
```python
import pydymenu
with_a_list = ["apples", "grapes", "bananas", "pears", "strawberries"]
choice = pydymenu.fzf(with_a_list, prompt="Which fruit? ")
print(f"Enjoy your {choice[0]}")
# if you wanted to use rofi instead
choice = pydymenu.rofi(with_a_list, prompt="Which fruit? ")
```
My favorite way to use this tool is with a dictionary of values. Python makes it
easy to select from a list of human-readable names but retrieve programming
related values like lambda, lists, or dictionaries, or even your own custom
objects!
```python
import pydymenu
from_dict = {
"Coder": {"First": "Mikey", "Last": "Garcia", "alignment": "chaotic good"},
"square()": lambda x: x*x,
"List of fruits": ["apples", "grapes", "bananas", "pears", "strawberries"],
"rofi selector": pydymenu.rofi,
"fzf selector": pydymenu.fzf,
}
choice = pydymenu.fzf(from_dict, prompt="Which option? ")
if choice:
value = from_dict[choice[0]]
print(f"{choice[0]}: {value}")
else:
print("No selection made.")
```
### `pydymenu.MENU(items: Iterable[str], **options) -> Optional[List[str]]`
### Parameters
`items: Iterable[str]` (_required_)
: The only required argument is an iterable of objects that can be cast to `str`
: If `items` is a [generator][gen] each option will display as it is yielded
`prompt: str`
: The prompt text shown at the selection _(default: ` > `)_
`multi: bool`
: Whether or not to allow multiple selections. _(default: `multi=False`)_
`case_sensitive: bool`
: Whether or not to use case sensitive search _(default: `case_sensitive=False`)_
`preview: str` **(fzf only)**
: Command that will be run on each entry and displayed as it's preview when
using the fuzzy finder. [Read more in the fzf documentation][prev docs]
### Return Value
As soon as a selection is made the finder closes and returns the result as a
`list[str]`. If no selection is made and/or the selection is cancelled `None` is
returned. This return signature allows for the following nice pythonic use case.
```python
import pydymenu
selection = pydymenu.fzf(items)
if selection:
print(selection[0])
else:
print('No selection made.')
```
## Development
To get started with development:
- clone the repository
- install development dependencies
- `source ./tools.sh`
See my [Super Python Project Template][template] on GitHub to learn more about
the automated features of this development environment. Clone the repo to get
your own Python projects up and running quickly!
### Source of Truth
This project is available on [GitHub][github] and [GitLab][gitlab]. Each push to
`master` automatically goes to both so choose whichever platform you prefer. All
releases are uploaded to [PyPi][pypi].
Big thanks to [fzf][fzf] and [Rofi][rofi] developers for making the utilities
this tool relies upon.
[prev docs]:
"fzf on GitHub: preview window"
[fzf]:
"junegunn/fzf: A command-line fuzzy finder"
[rofi]:
"Rofi: A window switcher, application launcher, and dmenu replacement"
[github]:
"gikeymarcia/pydymenu @ GitHub: All your dynamic menu-ing needs in one place"
[gitlab]:
"gikeymarcia/pydymenu @ GitLab: All your dynamic menu-ing needs in one place"
[pypi]:
"A pythonic wrapper interface for fzf and Rofi."
[iterfzf]:
"dahlia/iterfzf: Pythonic interface to fzf, a CLI fuzzy finder"
[gen]:
"Real Python: How to use generators and yield in Python"
[template]:
"Super Python Project Template @ GitHub"