Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.

Commit af87379

Browse files
committed
move no suffix option into into -r/-l
1 parent c00224b commit af87379

4 files changed

Lines changed: 33 additions & 23 deletions

File tree

fn/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
fn [-m] [-t]
1717
fn -g
1818
fn -p
19-
fn -r [-a|-A] [<dir>]
20-
fn -l [-a|-A] [<dir>]
21-
fn -R [<dir>]
19+
fn -r [-a|-A] [-f] [<dir>]
20+
fn -l [-a|-A] [-f] [<dir>]
2221
fn -s [<dir>]
2322
2423
@@ -29,12 +28,12 @@
2928
-t return timestamp only.
3029
3130
-r return all files with the most recent prochash.
32-
-R return most recent file name with no suffix.
3331
-l return all files with current git sha.
3432
-s return most recent prochash.
3533
3634
-a show file name only.
3735
-A show absolute paths.
36+
-f remove file suffix. resulting duplicates will be removed.
3837
3938
-h --help show this screen.
4039
--version show version.
@@ -68,13 +67,15 @@ def handle_path_args(args):
6867
def handle_args(fn, args):
6968
args = handle_path_args(args)
7069
if args['-l']:
71-
return fn.lst(d=args['<dir>'], path_style=args['path_style'])
70+
return fn.lst(d=args['<dir>'],
71+
path_style=args['path_style'],
72+
suffix=not args['-f'])
7273
if args['-r']:
73-
return fn.recent(d=args['<dir>'], path_style=args['path_style'])
74+
return fn.recent(d=args['<dir>'],
75+
path_style=args['path_style'],
76+
suffix=not args['-f'])
7477
if args['-s']:
7578
return fn.recent_prochash(d=args['<dir>'])
76-
if args['-R']:
77-
return fn.recent_nosuffix(d=args['<dir>'])
7879
if args['-p']:
7980
return [fn.get_pid_sha()]
8081
if args['-g']:
@@ -83,7 +84,7 @@ def handle_args(fn, args):
8384

8485

8586
def main():
86-
args = docopt(__doc__, version='fn 2.2.1')
87+
args = docopt(__doc__, version='fn 2.3.0')
8788

8889
if args['-t']:
8990
print(get_time(milli=args['-m']))

fn/fn.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from .utils import rel_abs_path
1212
from .utils import remove_extension
1313
from .utils import sortfx
14+
from .utils import overlay
15+
from .utils import deduplicate_files
1416

1517
SEP = '-'
1618

@@ -49,15 +51,19 @@ def name(self, milli=True, postfix=None):
4951
l.append(self.postfix)
5052
return ''.join(l)
5153

52-
def __get_current_files(self, d=None, path_style='rel'):
54+
def __get_current_files(self, d=None, path_style='rel', suffix=True):
5355
if d:
5456
try:
5557
chdir(d)
5658
except FileNotFoundError:
5759
raise ValueError('no folder: {:s}'.format(d))
5860

59-
return rel_abs_path(
60-
d, path_style, sorted(self.tokenizer(glob('*')), key=sortfx))
61+
files = self.tokenizer(glob('*'))
62+
if not suffix:
63+
files = deduplicate_files(
64+
[overlay(f, {'_raw': remove_extension(f['_raw'])}) for f in files])
65+
66+
return rel_abs_path(d, path_style, sorted(files, key=sortfx))
6167

6268
def get_pid_sha(self):
6369
return self.pid_sha
@@ -75,16 +81,6 @@ def recent(self, **args):
7581
lambda f: f['_raw'],
7682
filter(lambda f: f['prochash'] == prochash, current))
7783

78-
def recent_nosuffix(self, d):
79-
current = list(self.__get_current_files(d, path_style='file'))
80-
if current:
81-
yield remove_extension(current[-1]['_raw'])
82-
83-
def recent_prochash(self, d):
84-
current = list(self.__get_current_files(d))
85-
if current:
86-
yield current[-1]['prochash']
87-
8884
def lst(self, **args):
8985
self.__is_git()
9086
files = list(self.__get_current_files(**args))
@@ -95,3 +91,8 @@ def lst(self, **args):
9591
lambda x: x['_raw'],
9692
filter(lambda x: x['gitsha'] == prochash, files))
9793

94+
def recent_prochash(self, d):
95+
current = list(self.__get_current_files(d))
96+
if current:
97+
yield current[-1]['prochash']
98+

fn/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def rel_abs_path(d, path, files):
5151
yield overlay(f, {'_raw': normpath(fx(f['_raw']))})
5252

5353

54+
def deduplicate_files(files):
55+
d = set()
56+
for f in files:
57+
if f['_raw'] not in d:
58+
d.update([f['_raw']])
59+
yield f
60+
61+
5462
def get_time(milli=True, sep='-'):
5563
now = datetime.now()
5664
if milli:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
setup(name='fn',
12-
version='2.2.1',
12+
version='2.3.0',
1313
description='fn',
1414
url='https://github.com/inconvergent/fn',
1515
license='MIT License',

0 commit comments

Comments
 (0)