diff options
Diffstat (limited to 'packages/finder/plugin/opener/file/rifle.py')
-rw-r--r-- | packages/finder/plugin/opener/file/rifle.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/packages/finder/plugin/opener/file/rifle.py b/packages/finder/plugin/opener/file/rifle.py new file mode 100644 index 0000000..71c0144 --- /dev/null +++ b/packages/finder/plugin/opener/file/rifle.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Finder searcher and browser REPL. +# +# Copyright (C) 2025 Silvio Rhatto <rhatto@riseup.net> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published +# by the Free Software Foundation, either version 3 of the License, +# or any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import subprocess +import os + +try: + from ranger.ext.rifle import Rifle +except ImportError: + print("Please install ranger first!") + raise ImportError + +try: + from platformdirs import user_config_dir +except ImportError: + print("Please install platformdirs first!") + raise ImportError + +from prompt_toolkit.application.current import get_app + +class FinderPluginFileRifleOpener(): + def __init__(self): + config_dir = user_config_dir('ranger') + self.config = os.path.join(config_dir, 'rifle.conf') + self.rifle = Rifle(self.config) + + self.rifle.reload_config() + + def options(self, file): + commands = self.rifle.list_commands([file]) + options = [ [label if label is not None else command, count] for count, command, label, flags in commands ] + + return options + + def open(self, file, option = 1): + # Subprocess version + #process = subprocess.Popen( + # ['rifle', file], + # stdout=subprocess.PIPE, + # stderr=subprocess.PIPE, + #) + + # API version + self.rifle.execute([file], option) + + # Make sure to "invalidate" the app after Rifle returned, to ensure the + # UI is refreshed + app = get_app() + app.invalidate() |