diff options
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | ranger/container/tags.py | 29 | ||||
-rwxr-xr-x | ranger/data/scope.sh | 5 |
3 files changed, 25 insertions, 12 deletions
diff --git a/Makefile b/Makefile index 0cb35bd4..3479bb2d 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,8 @@ test_py: test_pylint test_flake8 test_doctest test_pytest test_other test_shellcheck: @echo "$(bold)Running shellcheck...$(normal)" - sed '2,$$s/^\(\s*\)#/\1/' ./ranger/data/scope.sh | shellcheck -a - + sed '2,$$s/^\([[:blank:]]*\)#/\1/' ./ranger/data/scope.sh \ + | shellcheck -a - @echo test_other: diff --git a/ranger/container/tags.py b/ranger/container/tags.py index 50d5ff72..50525848 100644 --- a/ranger/container/tags.py +++ b/ranger/container/tags.py @@ -5,30 +5,34 @@ from __future__ import (absolute_import, division, print_function) -from os.path import isdir, exists, dirname, abspath, realpath, expanduser, sep +from os.path import exists, abspath, realpath, expanduser, sep import string from ranger import PY3 +from ranger.core.shared import FileManagerAware ALLOWED_KEYS = string.ascii_letters + string.digits + string.punctuation -class Tags(object): +class Tags(FileManagerAware): default_tag = '*' def __init__(self, filename): + # COMPAT: The intent is to get abspath/normpath's behavior of + # collapsing `symlink/..`, abspath is retained for historical reasons + # because the documentation states its behavior isn't necessarily in + # line with normpath's. self._filename = realpath(abspath(expanduser(filename))) - if isdir(dirname(self._filename)) and not exists(self._filename): - open(self._filename, 'w') - self.sync() def __contains__(self, item): return item in self.tags def add(self, *items, **others): + if len(*items) == 0: + return tag = others.get('tag', self.default_tag) self.sync() for item in items: @@ -36,6 +40,8 @@ class Tags(object): self.dump() def remove(self, *items): + if len(*items) == 0: + return self.sync() for item in items: try: @@ -45,6 +51,8 @@ class Tags(object): self.dump() def toggle(self, *items, **others): + if len(*items) == 0: + return tag = others.get('tag', self.default_tag) tag = str(tag) if tag not in ALLOWED_KEYS: @@ -71,8 +79,11 @@ class Tags(object): fobj = open(self._filename, 'r', errors='replace') else: fobj = open(self._filename, 'r') - except OSError: - pass + except OSError as err: + if exists(self._filename): + self.fm.notify(err, bad=True) + else: + self.tags = dict() else: self.tags = self._parse(fobj) fobj.close() @@ -80,8 +91,8 @@ class Tags(object): def dump(self): try: fobj = open(self._filename, 'w') - except OSError: - pass + except OSError as err: + self.fm.notify(err, bad=True) else: self._compile(fobj) fobj.close() diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index f403ed83..16adaf91 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -104,7 +104,7 @@ handle_extension() { ;; ## JSON - json) + json|ipynb) jq --color-output . "${FILE_PATH}" && exit 5 python -m json.tool -- "${FILE_PATH}" && exit 5 ;; @@ -218,7 +218,8 @@ handle_image() { # { [ "$rar" ] && fn=$(unrar lb -p- -- "${FILE_PATH}"); } || \ # { [ "$zip" ] && fn=$(zipinfo -1 -- "${FILE_PATH}"); } || return # - # fn=$(echo "$fn" | python -c "import sys; import mimetypes as m; \ + # fn=$(echo "$fn" | python -c "from __future__ import print_function; \ + # import sys; import mimetypes as m; \ # [ print(l, end='') for l in sys.stdin if \ # (m.guess_type(l[:-1])[0] or '').startswith('image/') ]" |\ # sort -V | head -n 1) |