diff options
-rw-r--r-- | .github/workflows/pythonpublish.yml | 31 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | LICENSE | 7 | ||||
-rw-r--r-- | MANIFEST.in | 5 | ||||
-rw-r--r-- | README.md | 52 | ||||
-rw-r--r-- | VERSION | 1 | ||||
-rw-r--r-- | pyfzf.gif | bin | 0 -> 39207 bytes | |||
-rw-r--r-- | pyfzf/__init__.py | 6 | ||||
-rwxr-xr-x | pyfzf/pyfzf.py | 67 | ||||
-rwxr-xr-x | setup.py | 61 |
11 files changed, 233 insertions, 0 deletions
diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml new file mode 100644 index 0000000..d5f3859 --- /dev/null +++ b/.github/workflows/pythonpublish.yml @@ -0,0 +1,31 @@ +# This workflows will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +name: Upload Python Package + +on: + release: + types: [created] + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d646835 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +__pycache__/ @@ -0,0 +1 @@ +2015.11.16: Initial release @@ -0,0 +1,7 @@ +Copyright (c) 2015 Nagarjuna Kumarappan + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..bf684b1 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +include VERSION +include README.md +include CHANGES +recursive-include pyfzf * + diff --git a/README.md b/README.md new file mode 100644 index 0000000..3fe0c2a --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +pyfzf +===== + +![](https://img.shields.io/badge/license-MIT-green.svg?style=flat) +![https://pypi.python.org/pypi/pyfzf](https://img.shields.io/pypi/dm/pyfzf.svg?style=flat) + +##### A python wrapper for *junegunn*'s awesome [fzf](https://github.com/junegunn/fzf). + +![](https://raw.githubusercontent.com/nk412/pyfzf/master/pyfzf.gif) + +Requirements +------------ + +* Python 3.6+ +* [fzf](https://github.com/junegunn/fzf) + +*Note*: fzf must be installed and available on PATH. + +Installation +------------ + pip install pyfzf + +Usage +----- + >>> from pyfzf.pyfzf import FzfPrompt + >>> fzf = FzfPrompt() + +If `fzf` is not available on PATH, you can specify a location + + >>> fzf = FzfPrompt('/path/to/fzf') + +Simply pass a list of options to the prompt function to invoke fzf. + + >>> fzf.prompt(range(0,10)) + +You can pass additional arguments to fzf as a second argument + + >>> fzf.prompt(range(0,10), '--multi --cycle') + +Input items are written to a temporary file which is then passed to fzf. +The items are delimited with `\n` by default, you can also change the delimiter +(useful for multiline items) + + >>> fzf.prompt(range(0,10), '--read0', '\0') + +License +------- +MIT + +Thanks +------ +@brookite for adding Windows support in v0.3.0
\ No newline at end of file @@ -0,0 +1 @@ +0.3.1 diff --git a/pyfzf.gif b/pyfzf.gif Binary files differnew file mode 100644 index 0000000..a27cf8d --- /dev/null +++ b/pyfzf.gif diff --git a/pyfzf/__init__.py b/pyfzf/__init__.py new file mode 100644 index 0000000..02d3c96 --- /dev/null +++ b/pyfzf/__init__.py @@ -0,0 +1,6 @@ +__author__ = 'Nagarjuna Kumarappan (nagarjuna.412@gmail.com)' +__license__ = 'MIT' +__version__ = '0.3.1' + + +from .pyfzf import * diff --git a/pyfzf/pyfzf.py b/pyfzf/pyfzf.py new file mode 100755 index 0000000..1d05521 --- /dev/null +++ b/pyfzf/pyfzf.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# coding: utf-8 +# Copyright (c) 2022 Nagarjuna Kumarappan +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# Author: Nagarjuna Kumarappan <nagarjuna.412@gmail.com> + +from shutil import which +import os +import tempfile + + +# constants +FZF_URL = "https://github.com/junegunn/fzf" + + +class FzfPrompt: + def __init__(self, executable_path=None): + if executable_path: + self.executable_path = executable_path + elif not which("fzf") and not executable_path: + raise SystemError( + f"Cannot find 'fzf' installed on PATH. ({FZF_URL})") + else: + self.executable_path = "fzf" + + def prompt(self, choices=None, fzf_options="", delimiter='\n'): + # convert lists to strings [ 1, 2, 3 ] => "1\n2\n3" + choices_str = delimiter.join(map(str, choices)) + selection = [] + + with tempfile.NamedTemporaryFile(delete=False) as input_file: + with tempfile.NamedTemporaryFile(delete=False) as output_file: + # Create an temp file with list entries as lines + input_file.write(choices_str.encode('utf-8')) + input_file.flush() + + # Invoke fzf externally and write to output file + os.system( + f"{self.executable_path} {fzf_options} < \"{input_file.name}\" > \"{output_file.name}\"") + + # get selected options + with open(output_file.name, encoding="utf-8") as f: + for line in f: + selection.append(line.strip('\n')) + + os.unlink(input_file.name) + os.unlink(output_file.name) + + return selection diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..da96dee --- /dev/null +++ b/setup.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# coding: utf-8 +# Copyright (c) 2015 Nagarjuna Kumarappan +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# Author: Nagarjuna Kumarappan <nagarjuna.412@gmail.com> + +import os +from setuptools import setup +from distutils.command.install import INSTALL_SCHEMES + +for scheme in INSTALL_SCHEMES.values(): + scheme['data'] = scheme['purelib'] + +prjdir = os.path.dirname(__file__) + +def read(filename): + return open(os.path.join(prjdir, filename)).read() + +LONG_DESC = read('README.md') + '\nCHANGES\n=======\n\n' + read('CHANGES') + +setup(name='pyfzf', + include_package_data=True, + version=read('VERSION').strip('\n'), + description="Python wrapper for junegunn's fuzzyfinder (fzf)", + long_description=LONG_DESC, + author='Nagarjuna Kumarappan', + license='MIT', + author_email='nagarjuna.412@gmail.com', + url='https://github.com/nk412/pyfzf', + install_requires=[], + py_modules=['pyfzf'], + packages=['pyfzf'], + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Terminals' + ] + ) + |