ranger mkcd func

This commit is contained in:
David Chen 2019-07-07 16:36:23 +09:00
parent caf5780657
commit 5d60a35107
2 changed files with 32 additions and 1 deletions

View file

@ -1,5 +1,36 @@
from ranger.api.commands import Command
class mkcd(Command):
"""
:mkcd <dirname>
Creates a directory with the name <dirname> and enters it.
"""
def execute(self):
from os.path import join, expanduser, lexists
from os import makedirs
import re
dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
if not lexists(dirname):
makedirs(dirname)
match = re.search('^/|^~[^/]*/', dirname)
if match:
self.fm.cd(match.group(0))
dirname = dirname[match.end(0):]
for m in re.finditer('[^/]+', dirname):
s = m.group(0)
if s == '..' or (s.startswith('.') and not self.fm.settings['show_hidden']):
self.fm.cd(s)
else:
## We force ranger to load content before calling `scout`.
self.fm.thisdir.load_content(schedule=False)
self.fm.execute_console('scout -ae ^{}$'.format(s))
else:
self.fm.notify("file/directory exists!", bad=True)
class fzf_select(Command):
"""

View file

@ -304,7 +304,7 @@ map V console shell vim%space
map <Space> mark_files toggle=True
map M console mkdir%space
map M console mkcd%space
# Jumping around
map H history_go -1