flatgrep 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
flatgrep/__init__.py ADDED
File without changes
flatgrep/main.py ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env python3
2
+ import sys, subprocess, re, pyperclip
3
+ from pyfzf.pyfzf import FzfPrompt
4
+ from rich.console import Console
5
+
6
+ console = Console()
7
+ fzf = FzfPrompt()
8
+
9
+ def run(cmd):
10
+ return subprocess.run(cmd, text=True, capture_output=True).stdout.splitlines()
11
+
12
+ def pick(items, header):
13
+ if not items:
14
+ console.print("[red]Nothing to Show.[/]")
15
+ sys.exit(1)
16
+
17
+ sel = fzf.prompt(items, fzf_options=f"--header='{header}'")
18
+ if not sel:
19
+ console.print("[red]Abort.[/]")
20
+ sys.exit(1)
21
+
22
+ return sel[0]
23
+
24
+ def search_flatpaks(term, remote=False, skipfzf=False):
25
+ cmd = (
26
+ ["flatpak", "search", term, "--columns=application"]
27
+ if remote
28
+ else ["flatpak", "list", "--columns=application"]
29
+ )
30
+
31
+ lines = run(cmd)
32
+ apps = [l.strip() for l in lines if l.strip()]
33
+ filtered = [a for a in apps if term.lower() in a.lower()]
34
+
35
+ if len(filtered) == 1:
36
+ return filtered[0]
37
+
38
+ if skipfzf:
39
+ raise Exception("Skip fzf")
40
+
41
+ return pick(filtered or apps, f"Choose '{term}' application id.")
42
+
43
+ def install(term):
44
+ app = search_flatpaks(term, remote=True)
45
+ try:
46
+ result = subprocess.run(
47
+ ["flatpak", "install", "flathub", app],
48
+ text=True,
49
+ )
50
+ if result.returncode == 0:
51
+ console.print(f"[green]Installed:[/] {app}")
52
+ copycmd = f"flatpak run {app}"
53
+ pyperclip.copy(copycmd)
54
+ console.print(f"[blue]Copied to clipboard:[/] {copycmd}")
55
+ else:
56
+ console.print(f"[yellow]Installation cancelled by user[/]")
57
+ pyperclip.copy(app)
58
+ console.print(f"[blue]Copied to clipboard:[/] {app}")
59
+ except Exception as e:
60
+ console.print(f"[red]Error:[/] {e}")
61
+
62
+ return app
63
+
64
+ def remove(term):
65
+ app = search_flatpaks(term, remote=False)
66
+ try:
67
+ result = subprocess.run(
68
+ ["flatpak", "remove", "-y", app],
69
+ text=True,
70
+ )
71
+ if result.returncode == 0:
72
+ console.print(f"[green]Removed:[/] {app}")
73
+ pyperclip.copy(app)
74
+ console.print(f"[blue]Copied to clipboard:[/] {app}")
75
+ except Exception as e:
76
+ console.print(f"[red]Error:[/] {e}")
77
+
78
+
79
+
80
+ def copy(term):
81
+ app = search_flatpaks(term)
82
+ pyperclip.copy(app)
83
+ console.print(f"[blue]Copied to clipboard:[/] {app}")
84
+ return app
85
+
86
+ def auto(term):
87
+ try:
88
+ app = search_flatpaks(term, remote=False, skipfzf=True)
89
+ pyperclip.copy(app)
90
+ console.print(f"[blue]Copied to clipboard:[/] {app}")
91
+ return
92
+ except Exception:
93
+ pass
94
+ app = install(term)
95
+
96
+ def main():
97
+ if len(sys.argv) == 2:
98
+ term = sys.argv[1]
99
+ auto(term)
100
+ return
101
+
102
+ if len(sys.argv) < 3:
103
+ console.print("[bold]Uso:[/] flat.py [install|remove|run|copy] app_id")
104
+ sys.exit(1)
105
+
106
+ action, term = sys.argv[1], sys.argv[2]
107
+
108
+ if action == "install": install(term)
109
+ elif action in ("remove", "uninstall"): remove(term)
110
+ elif action == "run": run_app(term)
111
+ elif action in ("copy", "search"): copy(term)
112
+ else:
113
+ console.print("[red]Invalid action[/]")
114
+
115
+ if __name__ == "__main__":
116
+ main()
117
+
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.4
2
+ Name: flatgrep
3
+ Version: 0.2.0
4
+ Summary: Quicky interact with flatpak cli
5
+ Author-email: Rodolfo Franca <souzafrodolfo@gmail.com>
6
+ License: Copyright (c) 2025 Rodolfo Souza
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software with restriction for profit activities.
11
+ User can use, copy, modify, merge, publish, distribute, copies of the Software,
12
+ and to permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ * Do not profit with this software, it is created to be free in all sense of libre.
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ License-File: LICENSE
28
+ Requires-Python: >=3.13
29
+ Requires-Dist: pyfzf==0.3.1
30
+ Requires-Dist: pyperclip==1.9.0
31
+ Requires-Dist: rich==14.1.0
32
+ Requires-Dist: setuptools==80.9.0
33
+ Description-Content-Type: text/markdown
34
+
35
+ # Flatgrep ⚡*Alpha v0.1.3*
36
+ > Automated searches for boring CLI tools.
37
+
38
+ Tired of typing by hand `flatpak run com.something.veryobnoxious`?
39
+ Try **Flatgrep** for fuzzy search and grep what you want in just seconds.
40
+
41
+ * **Quick test :**
42
+ ```bash
43
+ flatgrep run mpv
44
+ ```
45
+
46
+ * **Fast and easy install apps from Flathub:**
47
+ ```bash
48
+ flatgrep install firefox
49
+ ```
50
+
51
+ ## What is Flatgrep?
52
+
53
+ **Flatgrep** is a smart, fuzzy-finding command-line wrapper for Flatpak that makes searching, installing, and managing your applications a breeze. It enhances the standard `flatpak` commands with an interactive `fzf` interface, ensuring you find and select the right application quickly, even with typos or partial names.
54
+
55
+ ## Why Flatgrep?
56
+
57
+ Tired of trying to guess the exact application ID for a Flatpak? The default `flatpak search` can be cumbersome. Flatgrep solves this by providing a powerful and intuitive search layer on top of Flatpak.
58
+
59
+ * **Typo-proof Searching**: Can't remember if it's `Discord` or `discord`? Just type `disc` and let the fuzzy finder show you the options.
60
+ * **Interactive Selection**: No more manually copying and pasting long app IDs like `org.gimp.GIMP`. Just search, select from the list, and let Flatgrep handle the rest. The selected ID is copied to your clipboard automatically.
61
+ * **Unified Workflow**: Use one consistent and powerful search tool to find, install, run, and uninstall your Flatpak apps.
62
+
63
+ ## Features
64
+
65
+ * ✅ **Smart Interactive Search**: Uses `fzf` to provide a fuzzy search interface for both locally installed apps and the entire Flathub repository.
66
+ * 🧠 **Intelligent Filtering**:
67
+ * If there's one perfect match, it's selected automatically.
68
+ * If there are multiple matches, you can choose from an interactive list using `fzf`.
69
+ * If no initial match is found, it falls back to a fuzzy search over the entire list of apps.
70
+ * 📋 **Clipboard Integration**: The selected application ID is automatically copied to your clipboard for convenience.
71
+ * 🎨 **Rich Terminal Output**: Utilizes the `rich` library for clean, modern, and colorful command-line feedback.
72
+ * 🚀 **Full Management Suite**: Provides intuitive commands for `search`, `install`, `run`, and `uninstall`.
73
+
74
+ ## Command Table
75
+
76
+ | Action | Linux Command |
77
+ |---------------------------------|----------------------------------------|
78
+ | **Search on Flathub** | `flatgrep search "app name" --flathub` |
79
+ | **List locally installed apps** | `flatgrep search "app name"` |
80
+ | **Install an app from Flathub** | `flatgrep install "app name"` |
81
+ | **Run an app** | `flatgrep run "app name"` |
82
+ | **Uninstall an app** | `flatgrep uninstall "app name"` |
83
+
84
+ ---
85
+
86
+ ## Building Instructions
87
+
88
+ #### Prerequisites
89
+
90
+ Before you begin, make sure you have the following installed on your system:
91
+ * Python 3.8+
92
+ * Flatpak
93
+ * `fzf` (a command-line fuzzy finder)
94
+
95
+ You can install `fzf` using your system's package manager:
96
+ ```bash
97
+ # Debian/Ubuntu
98
+ sudo apt install fzf
99
+
100
+ # Fedora
101
+ sudo dnf install fzf
102
+
103
+ # Arch Linux
104
+ sudo pacman -S fzf
105
+ ```
106
+
107
+ #### Clone Git Repository
108
+ ```bash
109
+ git clone git@github.com:rodhfr/flatgrep.git
110
+ cd flatgrep/src
111
+ ```
112
+
113
+ #### Setup Python Virtual Environment
114
+ ```bash
115
+ # Create python virtual environment (isolated dependencies)
116
+ python -m venv .venv
117
+
118
+ # Activate the virtual python shell
119
+ source .venv/bin/activate # also works for zsh
120
+ #source .venv/bin/activate.fish # uncomment this line for fish shell
121
+
122
+ # Install python library requeriments
123
+ pip install -r requirements.txt
124
+ ```
125
+
126
+ #### Install
127
+ ```bash
128
+ # installation is just a binary in $HOME/.local/bin
129
+ sh build_and_install.sh
130
+ ```
131
+
132
+ #### Uninstall
133
+ ```bash
134
+ # Or just remove the binary located in $HOME/.local/bin
135
+ sh uninstall.sh
136
+ ```
137
+
138
+ ---
139
+
140
+ ## Management
141
+
142
+ ### Released Features ✅
143
+ - [x] Search installed Flatpak app IDs.
144
+ - [x] Copy app IDs to the clipboard.
145
+ - [x] Install Flatpaks via fuzzy search with `--flathub` flag.
146
+ - [x] Rich-text console.
147
+ - [x] Run Flatpaks with `run` mode 'feature: 2025-09-15.v0.1.1'
148
+ - [x] Write building instructions and program description. 'feature: 2025-09-16.v0.1.3'
149
+
150
+ ### Planned 🛠️
151
+ - [ ] Write installation guide.
152
+ - [ ] Release in some package manager.
153
+ - [ ] Write documentation.
154
+ - [ ] Search mode also searches by app names not only app ids.
155
+ - [ ] Run mode update: Auto install app if not available.
156
+ - [ ] Proper sanitize search command.
157
+
158
+ ### Potential Features 🤔
159
+ - [ ] Other package managers like dnf/pacman/aur helpers.
@@ -0,0 +1,7 @@
1
+ flatgrep/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ flatgrep/main.py,sha256=zLHOTkMWeWv_ViNCFVvMMrIh9aAEBeGQilF9IucuQDs,3183
3
+ flatgrep-0.2.0.dist-info/METADATA,sha256=dgDtviszM6Fcbsv569glhp3b2MegwHSqggu16RjBQ7c,6157
4
+ flatgrep-0.2.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
5
+ flatgrep-0.2.0.dist-info/entry_points.txt,sha256=H-Jyn_ahGMElboMMu6JU0xyFzJwl_XuMqP83U37nkxU,48
6
+ flatgrep-0.2.0.dist-info/licenses/LICENSE,sha256=zIuJtH5CImTT2Ho9HCb1N44xKbCeROyLdYZfdZAyMzM,1106
7
+ flatgrep-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ flatgrep = flatgrep.main:main
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2025 Rodolfo Souza
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software with restriction for profit activities.
6
+ User can use, copy, modify, merge, publish, distribute, copies of the Software,
7
+ and to permit persons to whom the Software is furnished to do so, subject to
8
+ the following conditions:
9
+
10
+ * Do not profit with this software, it is created to be free in all sense of libre.
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.