[feature] add fzf_select with <C-p> hotkey
This commit is contained in:
parent
7fd30ad7e4
commit
128156338f
|
@ -116,3 +116,34 @@ class compress(Command):
|
|||
|
||||
extension = ['.zip', '.tar.gz', '.rar', '.7z']
|
||||
return ['compress ' + os.path.basename(self.fm.thisdir.path) + ext for ext in extension]
|
||||
|
||||
|
||||
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
|
||||
import os.path
|
||||
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, universal_newlines=True, stdout=subprocess.PIPE)
|
||||
stdout, stderr = fzf.communicate()
|
||||
if fzf.returncode == 0:
|
||||
fzf_file = os.path.abspath(stdout.rstrip('\n'))
|
||||
if os.path.isdir(fzf_file):
|
||||
self.fm.cd(fzf_file)
|
||||
else:
|
||||
self.fm.select_file(fzf_file)
|
||||
|
|
|
@ -6,3 +6,4 @@ default_linemode devicons
|
|||
set draw_borders both
|
||||
set vcs_aware true
|
||||
map cg eval import subprocess;fm.cd(subprocess.getoutput('git rev-parse --show-toplevel'))
|
||||
map <C-p> fzf_select
|
||||
|
|
Loading…
Reference in New Issue
Block a user