Last active
November 6, 2020 07:46
-
-
Save tzutalin/475f5ea6d3751ea2341a0cfbe9b0cd0a to your computer and use it in GitHub Desktop.
Ranger's settings and plugins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/ranger/plugins/autojump.py | |
import ranger.api | |
import subprocess | |
from ranger.api.commands import * | |
HOOK_INIT_OLD = ranger.api.hook_init | |
def hook_init(fm): | |
def update_autojump(signal): | |
subprocess.Popen(["autojump", "--add", signal.new.path]) | |
fm.signal_bind('cd', update_autojump) | |
HOOK_INIT_OLD(fm) | |
ranger.api.hook_init = hook_init | |
class j(Command): | |
""":j | |
Uses autojump to set the current directory. | |
""" | |
def execute(self): | |
directory = subprocess.check_output(["autojump", self.arg(1)]) | |
directory = directory.decode("utf-8", "ignore") | |
directory = directory.rstrip('\n') | |
self.fm.execute_console("cd " + directory) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ranger.api.commands import Command | |
# https://github.com/ranger/ranger/wiki/Integrating-File-Search-with-fzf | |
# Now, simply bind this function to a key, by adding this to your ~/.config/ranger/rc.conf: map <C-f> fzf_select | |
class fzf_select(Command): | |
""" | |
:fzf_select | |
Find a file using fzf. | |
With a prefix argument select only directories. | |
See: https://github.com/junegunn/fzf | |
""" | |
def execute(self): | |
import subprocess | |
if self.quantifier: | |
# match only directories | |
command="find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \ | |
-o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf +m" | |
else: | |
# match files and directories | |
command="find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \ | |
-o -print 2> /dev/null | sed 1d | cut -b3- | fzf +m" | |
fzf = self.fm.execute_command(command, stdout=subprocess.PIPE) | |
stdout, stderr = fzf.communicate() | |
if fzf.returncode == 0: | |
fzf_file = os.path.abspath(stdout.decode('utf-8').rstrip('\n')) | |
if os.path.isdir(fzf_file): | |
self.fm.cd(fzf_file) | |
else: | |
self.fm.select_file(fzf_file) | |
# fzf_locate | |
class fzf_locate(Command): | |
""" | |
:fzf_locate | |
Find a file using fzf. | |
With a prefix argument select only directories. | |
See: https://github.com/junegunn/fzf | |
""" | |
def execute(self): | |
import subprocess | |
if self.quantifier: | |
command="locate home media | fzf -e -i" | |
else: | |
command="locate home media | fzf -e -i" | |
fzf = self.fm.execute_command(command, stdout=subprocess.PIPE) | |
stdout, stderr = fzf.communicate() | |
if fzf.returncode == 0: | |
fzf_file = os.path.abspath(stdout.decode('utf-8').rstrip('\n')) | |
if os.path.isdir(fzf_file): | |
self.fm.cd(fzf_file) | |
else: | |
self.fm.select_file(fzf_file) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/ranger/rc.conf | |
map cj console j%space | |
map DD shell trash %s | |
set preview_images true | |
set preview_images_method iterm2 | |
map cf fzf_select | |
map cl fzf_locate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment