From 109fee2509e7fa6e3310bba2ffd3ce37e353db29 Mon Sep 17 00:00:00 2001 From: spl3g Date: Wed, 4 Sep 2024 19:04:44 +0300 Subject: feat: remove ranger --- home-manager/general.nix | 1 - .../homeModules/attachments/hypr-scripts/rnew.fish | 8 - home-manager/homeModules/default.nix | 1 - home-manager/homeModules/fish.nix | 11 - home-manager/homeModules/ranger/commands.py | 183 ----------- home-manager/homeModules/ranger/default.nix | 17 - .../homeModules/ranger/plugins/__init__.py | 0 .../plugins/__pycache__/__init__.cpython-310.pyc | Bin 139 -> 0 bytes .../plugins/__pycache__/__init__.cpython-311.pyc | Bin 155 -> 0 bytes .../ranger/plugins/__pycache__/fd.cpython-311.pyc | Bin 6322 -> 0 bytes .../plugins/__pycache__/quit_cd_wd.cpython-310.pyc | Bin 1682 -> 0 bytes .../plugins/__pycache__/quit_cd_wd.cpython-311.pyc | Bin 3030 -> 0 bytes .../homeModules/ranger/plugins/quit_cd_wd.py | 38 --- .../ranger/plugins/ranger_fzf_filter/.gitignore | 132 -------- .../ranger/plugins/ranger_fzf_filter/LICENSE | 21 -- .../ranger/plugins/ranger_fzf_filter/README.md | 47 --- .../ranger/plugins/ranger_fzf_filter/__init__.py | 35 -- .../ranger/plugins/ranger_fzf_filter/command.py | 59 ---- .../ranger/plugins/ranger_fzf_filter/filter.py | 84 ----- home-manager/homeModules/ranger/rc.conf | 12 - home-manager/homeModules/ranger/rifle.conf | 284 ----------------- home-manager/homeModules/ranger/scope.sh | 351 --------------------- 22 files changed, 1284 deletions(-) delete mode 100755 home-manager/homeModules/attachments/hypr-scripts/rnew.fish delete mode 100644 home-manager/homeModules/ranger/commands.py delete mode 100644 home-manager/homeModules/ranger/default.nix delete mode 100644 home-manager/homeModules/ranger/plugins/__init__.py delete mode 100644 home-manager/homeModules/ranger/plugins/__pycache__/__init__.cpython-310.pyc delete mode 100644 home-manager/homeModules/ranger/plugins/__pycache__/__init__.cpython-311.pyc delete mode 100644 home-manager/homeModules/ranger/plugins/__pycache__/fd.cpython-311.pyc delete mode 100644 home-manager/homeModules/ranger/plugins/__pycache__/quit_cd_wd.cpython-310.pyc delete mode 100644 home-manager/homeModules/ranger/plugins/__pycache__/quit_cd_wd.cpython-311.pyc delete mode 100644 home-manager/homeModules/ranger/plugins/quit_cd_wd.py delete mode 100644 home-manager/homeModules/ranger/plugins/ranger_fzf_filter/.gitignore delete mode 100644 home-manager/homeModules/ranger/plugins/ranger_fzf_filter/LICENSE delete mode 100644 home-manager/homeModules/ranger/plugins/ranger_fzf_filter/README.md delete mode 100644 home-manager/homeModules/ranger/plugins/ranger_fzf_filter/__init__.py delete mode 100644 home-manager/homeModules/ranger/plugins/ranger_fzf_filter/command.py delete mode 100644 home-manager/homeModules/ranger/plugins/ranger_fzf_filter/filter.py delete mode 100644 home-manager/homeModules/ranger/rc.conf delete mode 100644 home-manager/homeModules/ranger/rifle.conf delete mode 100755 home-manager/homeModules/ranger/scope.sh diff --git a/home-manager/general.nix b/home-manager/general.nix index 4489adf..3bced7f 100644 --- a/home-manager/general.nix +++ b/home-manager/general.nix @@ -69,7 +69,6 @@ in emacs.enable = true; alacritty.enable = true; fish.enable = true; - ranger.enable = true; firefox.enable = true; diff --git a/home-manager/homeModules/attachments/hypr-scripts/rnew.fish b/home-manager/homeModules/attachments/hypr-scripts/rnew.fish deleted file mode 100755 index 743d7fd..0000000 --- a/home-manager/homeModules/attachments/hypr-scripts/rnew.fish +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env fish - -ranger $argv -set quit_cd_wd_file "$HOME/.ranger_quit_cd_wd" -if test -s "$quit_cd_wd_file" - kitty -d "$(cat $quit_cd_wd_file)" --detach - true >"$quit_cd_wd_file" -end diff --git a/home-manager/homeModules/default.nix b/home-manager/homeModules/default.nix index c3ff492..f0f088b 100644 --- a/home-manager/homeModules/default.nix +++ b/home-manager/homeModules/default.nix @@ -1,7 +1,6 @@ { imports = [ ./emacs - ./ranger ./firefox.nix ./niri.nix ./mako.nix diff --git a/home-manager/homeModules/fish.nix b/home-manager/homeModules/fish.nix index 65d0d51..b8f3b58 100644 --- a/home-manager/homeModules/fish.nix +++ b/home-manager/homeModules/fish.nix @@ -23,18 +23,7 @@ pokemon-colorscripts -r --no-title ''; - functions = { - ranger_func = '' - ranger $argv - set -l quit_cd_wd_file "$HOME/.ranger_quit_cd_wd" - if test -s "$quit_cd_wd_file" - cd "$(cat $quit_cd_wd_file)" - true > "$quit_cd_wd_file" - end - ''; - }; shellAliases = { - rn = "ranger_func"; ls = "ls --hyperlink=auto --color=auto"; }; }; diff --git a/home-manager/homeModules/ranger/commands.py b/home-manager/homeModules/ranger/commands.py deleted file mode 100644 index a41d42f..0000000 --- a/home-manager/homeModules/ranger/commands.py +++ /dev/null @@ -1,183 +0,0 @@ -from ranger.api.commands import Command -from ranger.container.file import File -from ranger.ext.get_executables import get_executables -from collections import deque -import os -import subprocess - -# fd search - - -class fd_search(Command): - """ - :fd_search [-d] - Executes "fd -d " in the current directory and focuses the - first match. defaults to 1, i.e. only the contents of the current - directory. - - See https://github.com/sharkdp/fd - """ - - SEARCH_RESULTS = deque() - - def execute(self): - import re - import subprocess - from ranger.ext.get_executables import get_executables - - self.SEARCH_RESULTS.clear() - - if "fdfind" in get_executables(): - fd = "fdfind" - elif "fd" in get_executables(): - fd = "fd" - else: - self.fm.notify("Couldn't find fd in the PATH.", bad=True) - return - - if self.arg(1): - if self.arg(1)[:2] == "-d": - depth = self.arg(1) - target = self.rest(2) - else: - depth = "-d1" - target = self.rest(1) - else: - self.fm.notify(":fd_search needs a query.", bad=True) - return - - hidden = "--hidden" if self.fm.settings.show_hidden else "" - exclude = "--no-ignore-vcs --exclude '.git' --exclude '*.py[co]' --exclude '__pycache__'" - command = "{} --follow {} {} {} --print0 {}".format( - fd, depth, hidden, exclude, target - ) - fd = self.fm.execute_command( - command, universal_newlines=True, stdout=subprocess.PIPE - ) - stdout, _ = fd.communicate() - - if fd.returncode == 0: - results = filter(None, stdout.split("\0")) - if not self.fm.settings.show_hidden and self.fm.settings.hidden_filter: - hidden_filter = re.compile(self.fm.settings.hidden_filter) - results = filter( - lambda res: not hidden_filter.search(os.path.basename(res)), results - ) - results = map( - lambda res: os.path.abspath(os.path.join(self.fm.thisdir.path, res)), - results, - ) - self.SEARCH_RESULTS.extend(sorted(results, key=str.lower)) - if len(self.SEARCH_RESULTS) > 0: - self.fm.notify( - "Found {} result{}.".format( - len(self.SEARCH_RESULTS), - ("s" if len(self.SEARCH_RESULTS) > 1 else ""), - ) - ) - self.fm.select_file(self.SEARCH_RESULTS[0]) - else: - self.fm.notify("No results found.") - - -class fd_next(Command): - """ - :fd_next - Selects the next match from the last :fd_search. - """ - - def execute(self): - if len(fd_search.SEARCH_RESULTS) > 1: - fd_search.SEARCH_RESULTS.rotate(-1) # rotate left - self.fm.select_file(fd_search.SEARCH_RESULTS[0]) - elif len(fd_search.SEARCH_RESULTS) == 1: - self.fm.select_file(fd_search.SEARCH_RESULTS[0]) - - -class fd_prev(Command): - """ - :fd_prev - Selects the next match from the last :fd_search. - """ - - def execute(self): - if len(fd_search.SEARCH_RESULTS) > 1: - fd_search.SEARCH_RESULTS.rotate(1) # rotate right - self.fm.select_file(fd_search.SEARCH_RESULTS[0]) - elif len(fd_search.SEARCH_RESULTS) == 1: - self.fm.select_file(fd_search.SEARCH_RESULTS[0]) - - -# yank content -class YankContentWl(Command): - def execute(self): - if "wl-copy" not in get_executables(): - self.fm.notify("wl-clipboard is not found.", bad=True) - return - - arg = self.rest(1) - if arg: - if not os.path.isfile(arg): - self.fm.notify("{} is not a file".format(arg)) - return - file = File(arg) - else: - file = self.fm.thisfile - if not file.is_file: - self.fm.notify("{} is not a file".format(file.relative_path)) - return - if file.is_binary or file.image: - subprocess.check_call("wl-copy" + " < " + file.path, shell=True) - else: - self.fm.notify( - "{} is not an image file or a text file".format(file.relative_path) - ) - - -import os -import subprocess -from ranger.api.commands import Command -from ranger.container.file import File -from ranger.ext.get_executables import get_executables - - -class YankContent(Command): - """ - Copy the content of image file and text file with xclip - """ - - def execute(self): - if "xclip" not in get_executables(): - self.fm.notify("xclip is not found.", bad=True) - return - - arg = self.rest(1) - if arg: - if not os.path.isfile(arg): - self.fm.notify("{} is not a file.".format(arg)) - return - file = File(arg) - else: - file = self.fm.thisfile - if not file.is_file: - self.fm.notify("{} is not a file.".format(file.relative_path)) - return - - relative_path = file.relative_path - cmd = ["xclip", "-selection", "clipboard"] - if not file.is_binary(): - with open(file.path, "rb") as fd: - subprocess.check_call(cmd, stdin=fd) - elif file.image: - cmd += ["-t", file.mimetype, file.path] - subprocess.check_call(cmd) - self.fm.notify( - "Content of {} is copied to x clipboard".format(relative_path) - ) - else: - self.fm.notify( - "{} is not an image file or a text file.".format(relative_path) - ) - - def tab(self, tabnum): - return self._tab_directory_content() diff --git a/home-manager/homeModules/ranger/default.nix b/home-manager/homeModules/ranger/default.nix deleted file mode 100644 index 7e5fb88..0000000 --- a/home-manager/homeModules/ranger/default.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ pkgs, config, lib, ... }: - -{ - options = { - ranger.enable = lib.mkEnableOption "enable ranger"; - }; - config = lib.mkIf config.ranger.enable { - home.packages = with pkgs; [ ranger ]; - xdg.configFile = { - "ranger/rc.conf".text = builtins.readFile ./rc.conf; - "ranger/rifle.conf".text = builtins.readFile ./rifle.conf; - "ranger/scope.sh".text = builtins.readFile ./scope.sh; - "ranger/commands.py".source = ./commands.py; - "ranger/plugins".source = ./plugins; - }; - }; -} diff --git a/home-manager/homeModules/ranger/plugins/__init__.py b/home-manager/homeModules/ranger/plugins/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/home-manager/homeModules/ranger/plugins/__pycache__/__init__.cpython-310.pyc b/home-manager/homeModules/ranger/plugins/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 1a26aa3..0000000 Binary files a/home-manager/homeModules/ranger/plugins/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/home-manager/homeModules/ranger/plugins/__pycache__/__init__.cpython-311.pyc b/home-manager/homeModules/ranger/plugins/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index 87b2e7f..0000000 Binary files a/home-manager/homeModules/ranger/plugins/__pycache__/__init__.cpython-311.pyc and /dev/null differ diff --git a/home-manager/homeModules/ranger/plugins/__pycache__/fd.cpython-311.pyc b/home-manager/homeModules/ranger/plugins/__pycache__/fd.cpython-311.pyc deleted file mode 100644 index 146af23..0000000 Binary files a/home-manager/homeModules/ranger/plugins/__pycache__/fd.cpython-311.pyc and /dev/null differ diff --git a/home-manager/homeModules/ranger/plugins/__pycache__/quit_cd_wd.cpython-310.pyc b/home-manager/homeModules/ranger/plugins/__pycache__/quit_cd_wd.cpython-310.pyc deleted file mode 100644 index 49d1db9..0000000 Binary files a/home-manager/homeModules/ranger/plugins/__pycache__/quit_cd_wd.cpython-310.pyc and /dev/null differ diff --git a/home-manager/homeModules/ranger/plugins/__pycache__/quit_cd_wd.cpython-311.pyc b/home-manager/homeModules/ranger/plugins/__pycache__/quit_cd_wd.cpython-311.pyc deleted file mode 100644 index 7b3ac1c..0000000 Binary files a/home-manager/homeModules/ranger/plugins/__pycache__/quit_cd_wd.cpython-311.pyc and /dev/null differ diff --git a/home-manager/homeModules/ranger/plugins/quit_cd_wd.py b/home-manager/homeModules/ranger/plugins/quit_cd_wd.py deleted file mode 100644 index e47837f..0000000 --- a/home-manager/homeModules/ranger/plugins/quit_cd_wd.py +++ /dev/null @@ -1,38 +0,0 @@ -import ranger.api -from ranger.api.commands import * -import os - -def save_wd(command): - with open(os.path.expanduser('~/.ranger_quit_cd_wd'), 'w') as f: - f.write(command.fm.thisdir.path); - -class quit_cd_wd(Command): - """:chdir to working directory of ranger after quiting on ranger. - - """ - def _exit_no_work(self): - if self.fm.loader.has_work(): - self.fm.notify('Not quitting: Tasks in progress: Use `quit!` to force quit') - else: - self.fm.exit() - - def execute(self): - if len(self.fm.tabs) >= 2: - self.fm.tab_close() - else: - save_wd(self) - self._exit_no_work() - -class quitall_cd_wd(Command): - """:chdir to working directory of ranger after quitalling on ranger. - - """ - def _exit_no_work(self): - if self.fm.loader.has_work(): - self.fm.notify('Not quitting: Tasks in progress: Use `quitall!` to force quit') - else: - self.fm.exit() - - def execute(self): - save_wd(self) - self._exit_no_work() diff --git a/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/.gitignore b/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/.gitignore deleted file mode 100644 index 846dc44..0000000 --- a/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/.gitignore +++ /dev/null @@ -1,132 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# Pycharm -.idea diff --git a/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/LICENSE b/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/LICENSE deleted file mode 100644 index bd840f1..0000000 --- a/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 MuXiu1997 - -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/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/README.md b/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/README.md deleted file mode 100644 index 6a65e17..0000000 --- a/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# ranger-fzf-filter -This is a plugin for [`ranger`](https://github.com/ranger/ranger) that add a fuzzy filter. It depends on [`fzf`](https://github.com/junegunn/fzf) - -https://user-images.githubusercontent.com/49554020/173509108-dc3edca4-8949-4026-a3ca-0ba8dac9bbce.mp4 - - -## Install - -For ranger >= 1.9.3, use Git to clone this repository into your `~/.config/ranger/plugins` folder. For example: - -```sh -git clone git@github.com:MuXiu1997/ranger-fzf-filter.git ~/.config/ranger/plugins/ranger_fzf_filter -``` - -**Legacy Install** - -For ranger versions older than 1.9.3, or to install without Git, download `__init__.py` to your `~/.config/ranger/plugins` directory. For example: - -```shell -mkdir -p ~/.config/ranger/plugins -wget -O ~/.config/ranger/plugins/ranger_fzf_filter.py https://raw.githubusercontent.com/MuXiu1997/ranger-fzf-filter/main/__init__.py -``` - - - -## Usage - -Command: - -- `:fzf_filter [query]`: filtering files with fzf, see this [search syntax](https://github.com/junegunn/fzf#search-syntax) - - - -## Keyboard Shortcut - -Add a binding to your `~/.config/ranger/rc.conf` file to quickly use `:fzf_filter`: - -``` -map f console fzf_filter%space -``` - - - -## License - -[MIT](LICENSE) - diff --git a/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/__init__.py b/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/__init__.py deleted file mode 100644 index b5d5b46..0000000 --- a/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/__init__.py +++ /dev/null @@ -1,35 +0,0 @@ -import ranger.api -import ranger.container.directory -# noinspection PyUnresolvedReferences -from .command import fzf_filter, KEY_FZF_FILTER - -# region overwrite hook_init -HOOK_INIT_OLD = ranger.api.hook_init - - -def hook_init(fm): - def clear_fzf_filter(signal): - if fm.settings.clear_filters_on_dir_change and signal.previous: - signal.previous.__dict__[KEY_FZF_FILTER] = None - signal.previous.refilter() - - fm.signal_bind('cd', clear_fzf_filter) - return HOOK_INIT_OLD(fm) - - -ranger.api.hook_init = hook_init -# endregion overwrite hook_init - -# region overwrite accept_file -ACCEPT_FILE_OLD = ranger.container.directory.accept_file - - -def accept_file(fobj, filters): - _fzf_filter = fobj.fm.thisdir.__dict__.get(KEY_FZF_FILTER, None) - if _fzf_filter: - filters.append(_fzf_filter) - return ACCEPT_FILE_OLD(fobj, filters) - - -ranger.container.directory.accept_file = accept_file -# endregion overwrite accept_file diff --git a/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/command.py b/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/command.py deleted file mode 100644 index 92aee83..0000000 --- a/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/command.py +++ /dev/null @@ -1,59 +0,0 @@ -import ranger.api.commands -from .filter import FzfFilter - -# noinspection PyUnreachableCode -# This is done to enhance auto-completion and inference in the editor. -if False: - import ranger.core.fm - -KEY_FZF_FILTER = 'fzf_filter' - - -# noinspection PyPep8Naming,PyUnresolvedReferences -class fzf_filter(ranger.api.commands.Command): - """ - :fzf_filter - - This command allows you to use fzf fuzzy search to filter files and directories in the ranger. - """ - - def execute(self): - fm = self.fm # type: ranger.core.fm.FM - # Check if a filter is already set - _filter = fm.thisdir.__dict__.get(KEY_FZF_FILTER, None) - if isinstance(_filter, FzfFilter): - # If a filter is set, just update the query - _filter.set_query(self._get_query()) - else: - # If no filter is set, build a new one - fm.thisdir.__dict__[KEY_FZF_FILTER] = self._build_filter() - - fm.thisdir.refilter() - if self.quickly_executed: - fm.open_console(self.line) - - def cancel(self): - fm = self.fm # type: ranger.core.fm.FM - fm.thisdir.__dict__[KEY_FZF_FILTER] = None - fm.thisdir.refilter() - - def quick(self): - return True - - def _get_query(self): - """ - Get the search query. - - Returns: - str: The search query. - """ - return self.rest(1) - - def _build_filter(self): - """ - Build a new FzfFilter. - - Returns: - FzfFilter: A new FzfFilter object with the current directory and search query. - """ - return FzfFilter(self.fm.thisdir, self._get_query()) diff --git a/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/filter.py b/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/filter.py deleted file mode 100644 index 3d12756..0000000 --- a/home-manager/homeModules/ranger/plugins/ranger_fzf_filter/filter.py +++ /dev/null @@ -1,84 +0,0 @@ -import os.path -import subprocess - - -class FzfFilter: - """ - A filter class for FZF fuzzy search. - - Attributes: - thisdir (ranger.container.directory.Directory): The current directory. - query (str): The search query. - source (list[str]): List of relative paths of all files in the current directory. - result (list[str]): The result of fzf search. - """ - - def __init__(self, thisdir, query): - """ - Initialize the FzfFilter class. - - Args: - thisdir (ranger.container.directory.Directory): The current directory. - query (str): The search query. - """ - self.thisdir = thisdir - self.files_all = thisdir.files_all - - self.query = query - - self.source = [] - self.recalc_source() - - self.result = [] - self.recalc_result() - - def recalc_source(self): - """ - Recalculate the source list based on the files in the current directory. - """ - self.source = [f.relative_path for f in self.thisdir.files_all] - - def recalc_result(self): - """ - Recalculate the result list by executing the fzf command. - """ - cmd = subprocess.Popen( - ['fzf', '-f', self.query], - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - ) - stdout, _ = cmd.communicate('\n'.join(self.source).encode('utf-8')) - self.result = stdout.decode('utf-8').strip().splitlines() - - def set_query(self, query): - """ - Update the query and recalculate the result list. - - Args: - query (str): The new search query. - """ - self.query = query - self.recalc_result() - - def __call__(self, fobj): - """ - Perform the actual filtering. - - Args: - fobj (ranger.container.file.File | ranger.container.directory.Directory): The file or directory to check. - - Returns: - bool: True if the file or directory is in the result list, False otherwise. - """ - # Check if the files in the current directory have changed, and if so, recalculate source and result - if self.thisdir.files_all is not self.files_all: - self.files_all = self.thisdir.files_all - self.recalc_source() - self.recalc_result() - - # Ensure the relative path start of the file or directory is in the current directory - if os.path.relpath(fobj.path, fobj.relative_path) != '.': - return True - - # Check if the relative path of the file or directory is in the result list - return fobj.relative_path in self.result diff --git a/home-manager/homeModules/ranger/rc.conf b/home-manager/homeModules/ranger/rc.conf deleted file mode 100644 index 271d239..0000000 --- a/home-manager/homeModules/ranger/rc.conf +++ /dev/null @@ -1,12 +0,0 @@ -map f console fzf_filter%space -map x quit_cd_wd -map X quitall_cd_wd -map / console fd_search -d5%space -map n fd_next -map p fd_prev -map e shell dragon -x %p & -map yc YankContent -set preview_images true -set preview_images_method kitty -set use_preview_script True -map gj cd /run/media/jerpo/ diff --git a/home-manager/homeModules/ranger/rifle.conf b/home-manager/homeModules/ranger/rifle.conf deleted file mode 100644 index 3b565af..0000000 --- a/home-manager/homeModules/ranger/rifle.conf +++ /dev/null @@ -1,284 +0,0 @@ -# vim: ft=cfg -# -# This is the configuration file of "rifle", ranger's file executor/opener. -# Each line consists of conditions and a command. For each line the conditions -# are checked and if they are met, the respective command is run. -# -# Syntax: -# , , ... = command -# -# The command can contain these environment variables: -# $1-$9 | The n-th selected file -# $@ | All selected files -# -# If you use the special command "ask", rifle will ask you what program to run. -# -# Prefixing a condition with "!" will negate its result. -# These conditions are currently supported: -# match | The regexp matches $1 -# ext | The regexp matches the extension of $1 -# mime | The regexp matches the mime type of $1 -# name | The regexp matches the basename of $1 -# path | The regexp matches the absolute path of $1 -# has | The program is installed (i.e. located in $PATH) -# env | The environment variable "variable" is non-empty -# file | $1 is a file -# directory | $1 is a directory -# number | change the number of this command to n -# terminal | stdin, stderr and stdout are connected to a terminal -# X | A graphical environment is available (darwin, Xorg, or Wayland) -# -# There are also pseudo-conditions which have a "side effect": -# flag | Change how the program is run. See below. -# label