Update
This commit is contained in:
@@ -4,18 +4,15 @@
|
|||||||
# documentation. Do NOT add them all here, or you may end up with defunct
|
# documentation. Do NOT add them all here, or you may end up with defunct
|
||||||
# commands when upgrading ranger.
|
# commands when upgrading ranger.
|
||||||
|
|
||||||
# A simple command for demonstration purposes follows.
|
# You always need to import ranger.api.commands here to get the Command class:
|
||||||
# -----------------------------------------------------------------------------
|
from ranger.api.commands import *
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
# A simple command for demonstration purposes follows.
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
# You can import any python module as needed.
|
# You can import any python module as needed.
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# You always need to import ranger.api.commands here to get the Command class:
|
|
||||||
from ranger.api.commands import Command
|
|
||||||
|
|
||||||
|
|
||||||
# Any class that is a subclass of "Command" will be integrated into ranger as a
|
# Any class that is a subclass of "Command" will be integrated into ranger as a
|
||||||
# command. Try typing ":my_edit<ENTER>" in ranger!
|
# command. Try typing ":my_edit<ENTER>" in ranger!
|
||||||
class my_edit(Command):
|
class my_edit(Command):
|
||||||
@@ -40,7 +37,7 @@ class my_edit(Command):
|
|||||||
# reference to the currently selected file.
|
# reference to the currently selected file.
|
||||||
target_filename = self.fm.thisfile.path
|
target_filename = self.fm.thisfile.path
|
||||||
|
|
||||||
# This is a generic function to print text in ranger.
|
# This is a generic function to print text in ranger.
|
||||||
self.fm.notify("Let's edit the file " + target_filename + "!")
|
self.fm.notify("Let's edit the file " + target_filename + "!")
|
||||||
|
|
||||||
# Using bad=True in fm.notify allows you to print error messages:
|
# Using bad=True in fm.notify allows you to print error messages:
|
||||||
@@ -55,8 +52,165 @@ class my_edit(Command):
|
|||||||
|
|
||||||
# The tab method is called when you press tab, and should return a list of
|
# The tab method is called when you press tab, and should return a list of
|
||||||
# suggestions that the user will tab through.
|
# suggestions that the user will tab through.
|
||||||
# tabnum is 1 for <TAB> and -1 for <S-TAB> by default
|
def tab(self):
|
||||||
def tab(self, tabnum):
|
|
||||||
# This is a generic tab-completion function that iterates through the
|
# This is a generic tab-completion function that iterates through the
|
||||||
# content of the current directory.
|
# content of the current directory.
|
||||||
return self._tab_directory_content()
|
return self._tab_directory_content()
|
||||||
|
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
class fzf_bring(Command):
|
||||||
|
"""
|
||||||
|
:fzf_bring
|
||||||
|
|
||||||
|
Find a file using fzf and bring it to the current directory.
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
from ranger.core.loader import CommandLoader
|
||||||
|
|
||||||
|
class compress(Command):
|
||||||
|
def execute(self):
|
||||||
|
""" Compress marked files to current directory """
|
||||||
|
cwd = self.fm.thisdir
|
||||||
|
marked_files = cwd.get_selection()
|
||||||
|
|
||||||
|
if not marked_files:
|
||||||
|
return
|
||||||
|
|
||||||
|
def refresh(_):
|
||||||
|
cwd = self.fm.get_directory(original_path)
|
||||||
|
cwd.load_content()
|
||||||
|
|
||||||
|
original_path = cwd.path
|
||||||
|
parts = self.line.split()
|
||||||
|
au_flags = parts[1:]
|
||||||
|
|
||||||
|
descr = "compressing files in: " + os.path.basename(parts[1])
|
||||||
|
obj = CommandLoader(args=['apack'] + au_flags + \
|
||||||
|
[os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)
|
||||||
|
|
||||||
|
obj.signal_bind('after', refresh)
|
||||||
|
self.fm.loader.add(obj)
|
||||||
|
|
||||||
|
def tab(self):
|
||||||
|
""" Complete with current folder name """
|
||||||
|
|
||||||
|
extension = ['.zip', '.tar.gz', '.rar', '.7z']
|
||||||
|
return ['compress ' + os.path.basename(self.fm.thisdir.path) + ext for ext in extension]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
from ranger.core.loader import CommandLoader
|
||||||
|
|
||||||
|
class extracthere(Command):
|
||||||
|
def execute(self):
|
||||||
|
""" Extract copied files to current directory """
|
||||||
|
copied_files = tuple(self.fm.copy_buffer)
|
||||||
|
|
||||||
|
if not copied_files:
|
||||||
|
return
|
||||||
|
|
||||||
|
def refresh(_):
|
||||||
|
cwd = self.fm.get_directory(original_path)
|
||||||
|
cwd.load_content()
|
||||||
|
|
||||||
|
one_file = copied_files[0]
|
||||||
|
cwd = self.fm.thisdir
|
||||||
|
original_path = cwd.path
|
||||||
|
au_flags = ['-X', cwd.path]
|
||||||
|
au_flags += self.line.split()[1:]
|
||||||
|
au_flags += ['-e']
|
||||||
|
|
||||||
|
self.fm.copy_buffer.clear()
|
||||||
|
self.fm.cut_buffer = False
|
||||||
|
if len(copied_files) == 1:
|
||||||
|
descr = "extracting: " + os.path.basename(one_file.path)
|
||||||
|
else:
|
||||||
|
descr = "extracting files from: " + os.path.basename(one_file.dirname)
|
||||||
|
obj = CommandLoader(args=['aunpack'] + au_flags \
|
||||||
|
+ [f.path for f in copied_files], descr=descr)
|
||||||
|
|
||||||
|
obj.signal_bind('after', refresh)
|
||||||
|
self.fm.loader.add(obj)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -352,7 +352,7 @@ map <END> move to=-1
|
|||||||
map <PAGEDOWN> move down=1 pages=True
|
map <PAGEDOWN> move down=1 pages=True
|
||||||
map <PAGEUP> move up=1 pages=True
|
map <PAGEUP> move up=1 pages=True
|
||||||
map <CR> move right=1
|
map <CR> move right=1
|
||||||
#map <DELETE> console delete
|
map <DELETE> console delete
|
||||||
map <INSERT> console touch%space
|
map <INSERT> console touch%space
|
||||||
|
|
||||||
# VIM-like
|
# VIM-like
|
||||||
@@ -390,7 +390,7 @@ map gm cd /media
|
|||||||
map gM cd /mnt
|
map gM cd /mnt
|
||||||
map gs cd /srv
|
map gs cd /srv
|
||||||
map gp cd /tmp
|
map gp cd /tmp
|
||||||
map gr cd /
|
# map gr cd /
|
||||||
map gR eval fm.cd(ranger.RANGERDIR)
|
map gR eval fm.cd(ranger.RANGERDIR)
|
||||||
map g/ cd /
|
map g/ cd /
|
||||||
map g? cd /usr/share/doc/ranger
|
map g? cd /usr/share/doc/ranger
|
||||||
@@ -675,3 +675,5 @@ map mb shell mv %f vibrant
|
|||||||
# bulk rename
|
# bulk rename
|
||||||
map cw eval fm.execute_console("bulkrename") if fm.thisdir.marked_items else fm.open_console("rename ")
|
map cw eval fm.execute_console("bulkrename") if fm.thisdir.marked_items else fm.open_console("rename ")
|
||||||
|
|
||||||
|
map gr fzf_select
|
||||||
|
# map <C-f> fzf_select
|
||||||
|
|||||||
@@ -203,3 +203,5 @@ then
|
|||||||
else
|
else
|
||||||
xrandr --dpi 150
|
xrandr --dpi 150
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
|
||||||
|
|||||||
@@ -111,3 +111,5 @@ then
|
|||||||
synclient HorizTwoFingerScroll=1
|
synclient HorizTwoFingerScroll=1
|
||||||
fi
|
fi
|
||||||
source /home/kevin/.shortcuts
|
source /home/kevin/.shortcuts
|
||||||
|
|
||||||
|
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ d ~/Downloads
|
|||||||
D ~/Documents
|
D ~/Documents
|
||||||
ho ~/
|
ho ~/
|
||||||
lc ~/linux-config/
|
lc ~/linux-config/
|
||||||
|
ro /
|
||||||
|
|
||||||
# }}} sys *
|
# }}} sys *
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
# sys {{{ *
|
# sys {{{ *
|
||||||
|
|
||||||
kd ~/.key_directories
|
|
||||||
kf ~/.key_files
|
|
||||||
3 ~/.config/i3/config
|
3 ~/.config/i3/config
|
||||||
3b ~/.config/i3blocks/i3blocks.conf
|
3b ~/.config/i3blocks/i3blocks.conf
|
||||||
|
d ~/linux-config/key_dirs.txt
|
||||||
|
f ~/linux-config/key_files.txt
|
||||||
r ~/.config/ranger/rc.conf
|
r ~/.config/ranger/rc.conf
|
||||||
|
sr ~/linux-config/configs/ranger/shortcuts.conf
|
||||||
|
ss ~/.shortcuts
|
||||||
u ~/.Xresources
|
u ~/.Xresources
|
||||||
v ~/.vimrc
|
v ~/.vimrc
|
||||||
z ~/linux-config/aliases/zsh_aliases
|
|
||||||
y ~/.zshrc
|
y ~/.zshrc
|
||||||
|
z ~/linux-config/aliases/zsh_aliases
|
||||||
|
|
||||||
# }}} sys *
|
# }}} sys *
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user