From 478fa4cd09059eea4c89adf16ac31dcd975cfa8f Mon Sep 17 00:00:00 2001 From: nvbn Date: Tue, 21 Apr 2015 08:30:48 +0200 Subject: [PATCH] #71 Not fail on os error --- setup.py | 2 +- thefuck/rules/no_command.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 87a34119..1c8aaac2 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup(name='thefuck', - version=1.18, + version=1.19, description="Magnificent app which corrects your previous console command", author='Vladimir Iakovlev', author_email='nvbn.rm@gmail.com', diff --git a/thefuck/rules/no_command.py b/thefuck/rules/no_command.py index dd44675e..c3ecd4b3 100644 --- a/thefuck/rules/no_command.py +++ b/thefuck/rules/no_command.py @@ -3,11 +3,18 @@ import os from pathlib import Path +def _safe(path, method): + try: + return getattr(path, method)() + except OSError: + return [] + + def _get_all_bins(): return [exe.name for path in os.environ['PATH'].split(':') - for exe in Path(path).iterdir() - if exe.is_file()] + for exe in _safe(Path(path), 'iterdir') + if not _safe(exe, 'is_dir')] def match(command, settings):