diff --git a/fn/__init__.py b/fn/__init__.py
index 63993f9..83b7162 100755
--- a/fn/__init__.py
+++ b/fn/__init__.py
@@ -16,9 +16,8 @@
fn [-m] [-t]
fn -g
fn -p
- fn -r [-a|-A] [
]
- fn -l [-a|-A] []
- fn -R []
+ fn -r [-a|-A] [-f] []
+ fn -l [-a|-A] [-f] []
fn -s []
@@ -29,12 +28,12 @@
-t return timestamp only.
-r return all files with the most recent prochash.
- -R return most recent file name with no suffix.
-l return all files with current git sha.
-s return most recent prochash.
-a show file name only.
-A show absolute paths.
+ -f remove file suffix. resulting duplicates will be removed.
-h --help show this screen.
--version show version.
@@ -68,13 +67,15 @@ def handle_path_args(args):
def handle_args(fn, args):
args = handle_path_args(args)
if args['-l']:
- return fn.lst(d=args[''], path_style=args['path_style'])
+ return fn.lst(d=args[''],
+ path_style=args['path_style'],
+ suffix=not args['-f'])
if args['-r']:
- return fn.recent(d=args[''], path_style=args['path_style'])
+ return fn.recent(d=args[''],
+ path_style=args['path_style'],
+ suffix=not args['-f'])
if args['-s']:
return fn.recent_prochash(d=args[''])
- if args['-R']:
- return fn.recent_nosuffix(d=args[''])
if args['-p']:
return [fn.get_pid_sha()]
if args['-g']:
@@ -83,7 +84,7 @@ def handle_args(fn, args):
def main():
- args = docopt(__doc__, version='fn 2.2.1')
+ args = docopt(__doc__, version='fn 2.3.0')
if args['-t']:
print(get_time(milli=args['-m']))
diff --git a/fn/fn.py b/fn/fn.py
index b389943..6ca66f1 100644
--- a/fn/fn.py
+++ b/fn/fn.py
@@ -11,6 +11,8 @@
from .utils import rel_abs_path
from .utils import remove_extension
from .utils import sortfx
+from .utils import overlay
+from .utils import deduplicate_files
SEP = '-'
@@ -49,15 +51,19 @@ def name(self, milli=True, postfix=None):
l.append(self.postfix)
return ''.join(l)
- def __get_current_files(self, d=None, path_style='rel'):
+ def __get_current_files(self, d=None, path_style='rel', suffix=True):
if d:
try:
chdir(d)
except FileNotFoundError:
raise ValueError('no folder: {:s}'.format(d))
- return rel_abs_path(
- d, path_style, sorted(self.tokenizer(glob('*')), key=sortfx))
+ files = self.tokenizer(glob('*'))
+ if not suffix:
+ files = deduplicate_files(
+ [overlay(f, {'_raw': remove_extension(f['_raw'])}) for f in files])
+
+ return rel_abs_path(d, path_style, sorted(files, key=sortfx))
def get_pid_sha(self):
return self.pid_sha
@@ -75,16 +81,6 @@ def recent(self, **args):
lambda f: f['_raw'],
filter(lambda f: f['prochash'] == prochash, current))
- def recent_nosuffix(self, d):
- current = list(self.__get_current_files(d, path_style='file'))
- if current:
- yield remove_extension(current[-1]['_raw'])
-
- def recent_prochash(self, d):
- current = list(self.__get_current_files(d))
- if current:
- yield current[-1]['prochash']
-
def lst(self, **args):
self.__is_git()
files = list(self.__get_current_files(**args))
@@ -95,3 +91,8 @@ def lst(self, **args):
lambda x: x['_raw'],
filter(lambda x: x['gitsha'] == prochash, files))
+ def recent_prochash(self, d):
+ current = list(self.__get_current_files(d))
+ if current:
+ yield current[-1]['prochash']
+
diff --git a/fn/utils.py b/fn/utils.py
index 52831f0..26b3da3 100644
--- a/fn/utils.py
+++ b/fn/utils.py
@@ -51,6 +51,14 @@ def rel_abs_path(d, path, files):
yield overlay(f, {'_raw': normpath(fx(f['_raw']))})
+def deduplicate_files(files):
+ d = set()
+ for f in files:
+ if f['_raw'] not in d:
+ d.update([f['_raw']])
+ yield f
+
+
def get_time(milli=True, sep='-'):
now = datetime.now()
if milli:
diff --git a/setup.py b/setup.py
index 73c77d5..5021eb9 100755
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@
setup(name='fn',
- version='2.2.1',
+ version='2.3.0',
description='fn',
url='https://github.com/inconvergent/fn',
license='MIT License',