From 1d4f082dcb8a7f248244f0c6c27272249b7334a8 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Tue, 14 Apr 2015 23:36:13 +0200 Subject: [PATCH] Ranger: Update mkcd and `A` binding with 1.7 makedirs and rename_append --- .config/ranger/commands.py | 25 +++++++++++++++++-------- .config/ranger/rc.conf | 6 ++++++ .config/ranger/scope.sh | 3 +++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.config/ranger/commands.py b/.config/ranger/commands.py index f79e8b33..669a4d12 100644 --- a/.config/ranger/commands.py +++ b/.config/ranger/commands.py @@ -101,17 +101,26 @@ class mkcd(Command): """ def execute(self): - from os.path import join, expanduser, lexists, basename - from os import mkdir + 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): - mkdir(dirname) + makedirs(dirname) - if self.rest(1).startswith('.') and not self.fm.settings['show_hidden']: - self.fm.cd(dirname) - else: - self.fm.thisdir.load_content(schedule=False) - self.fm.execute_console('scout -ae ^{}$'.format(self.rest(1))) + 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) diff --git a/.config/ranger/rc.conf b/.config/ranger/rc.conf index fea779b0..d67b6796 100644 --- a/.config/ranger/rc.conf +++ b/.config/ranger/rc.conf @@ -102,6 +102,12 @@ map shell -w file %s map console touch map console mkcd + +# =================================================================== +# == Overrides +# =================================================================== +map A rename_append + # =================================================================== # == Personal shorcuts # =================================================================== diff --git a/.config/ranger/scope.sh b/.config/ranger/scope.sh index c3dee9ad..f55ad4f5 100755 --- a/.config/ranger/scope.sh +++ b/.config/ranger/scope.sh @@ -103,6 +103,9 @@ case "$mimetype" in # # Use sed to remove spaces so the output fits into the narrow window try mediainfo "$path" && { dump | trim | sed 's/ \+:/: /;'; exit 5; } || exit 1;; + # Image preview for videos, disabled by default: + # video/*) + # ffmpegthumbnailer -i "$path" -o "$cached" -s 0 && exit 6 || exit 1;; # Display information about media files: video/* | audio/*) # Use sed to remove spaces so the output fits into the narrow window