aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2018-06-15 13:37:08 -0300
committerSilvio Rhatto <rhatto@riseup.net>2018-06-15 13:37:08 -0300
commite5566ba0691223b6d48c92a68a843a5710a87ac8 (patch)
tree2da7e8d083297112961afaf9e86bb9f2c44f614e
parent1283fd6991a5a83e1dc3aa50056fc53ebe5d121a (diff)
downloadranger-e5566ba0691223b6d48c92a68a843a5710a87ac8.tar.gz
ranger-e5566ba0691223b6d48c92a68a843a5710a87ac8.tar.bz2
Add some commands and bindings
-rw-r--r--config.dot/ranger/commands.py.link50
-rw-r--r--config.dot/ranger/rc.conf.link11
2 files changed, 61 insertions, 0 deletions
diff --git a/config.dot/ranger/commands.py.link b/config.dot/ranger/commands.py.link
new file mode 100644
index 0000000..b8706a3
--- /dev/null
+++ b/config.dot/ranger/commands.py.link
@@ -0,0 +1,50 @@
+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 toggle_flat(Command):
+ """
+ :toggle_flat
+
+ Flattens or unflattens the directory view.
+ """
+
+ def execute(self):
+ if self.fm.thisdir.flat == 0:
+ self.fm.thisdir.unload()
+ self.fm.thisdir.flat = -1
+ self.fm.thisdir.load_content()
+ else:
+ self.fm.thisdir.unload()
+ self.fm.thisdir.flat = 0
+ self.fm.thisdir.load_content()
diff --git a/config.dot/ranger/rc.conf.link b/config.dot/ranger/rc.conf.link
index b2a218b..ab83a3f 100644
--- a/config.dot/ranger/rc.conf.link
+++ b/config.dot/ranger/rc.conf.link
@@ -13,3 +13,14 @@ set use_preview_script true
#set preview_images_method urxvt
#set preview_images_method mpv
set preview_script ~/.config/ranger/scope.sh
+
+# Slow feature
+# https://github.com/ranger/ranger/wiki/VCS-integration
+#set vcs_aware true
+#setlocal path=/home/hut/repos/ranger vcs_aware true
+
+# Keybindings
+# https://github.com/ranger/ranger/wiki/Keybindings
+map F console scout -ftsea%space
+map cw eval fm.execute_console("bulkrename") if fm.thisdir.marked_items else fm.open_console("rename ")
+map go eval from ranger.ext.spawn import spawn; fm.select_file(spawn("grep ^music_directory /etc/mpd.conf | grep -oP '(?<=\").*(?=\")'").strip() + "/" + spawn("mpc -f %file% | head -1"))