Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commit d7e680e

Browse files
author
js-d-coder
committed
add option to output one file per line: -1
1 parent 9647d6e commit d7e680e

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# lsi
22
ls command alternative. Output is either cleanly formatted table or string of null terminated file names parseable by xargs command. Default behaviour is to show only non-hidden files and directories of directory passed or current directory if no directory is given, in table format.
33
Written in Python version 3 for UNIX like OS
4-
Version 1.0.0
4+
Version 1.1.0
55

66
## Usage
77

‎lsi‎

100644100755
Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ Default behaviour is to show only non-hidden files and directories of
2626
directory passed or current directory if no directory is given, in table format.
2727
""")
2828

29-
parser.add_argument('-x','--xargs', action="store_true",
29+
outputFormat = parser.add_mutually_exclusive_group();
30+
outputFormat.add_argument("-t",action="store_true",
31+
help="output in table format; this is default")
32+
outputFormat.add_argument("-1", dest="one", action="store_true",
33+
help="output on file per line")
34+
outputFormat.add_argument('-x','--xargs', action="store_true",
3035
help="""output will be string of null terminated file names;
3136
can be used as input to other commands like xargs;
3237
absense of this option makes output to be a table, which is default""")
@@ -66,7 +71,7 @@ def version():
6671
"""Print version, license and exit"""
6772
if args.version:
6873
print(
69-
"""lsi version 1.0.0
74+
"""lsi version 1.1.0
7075
7176
Copyright (c) 2017 js-d-coder (www.github.com/js-d-coder)
7277
@@ -138,24 +143,30 @@ def xargsInput():
138143

139144
def prettyPrint(list):
140145
"""print files in table format"""
141-
maxlen = 0
142-
for l in list:
143-
if len(l) > maxlen:
144-
maxlen = len(l)
145-
colWidth = maxlen + 4
146-
noOfCol = int(int(terminalColumnSize)/colWidth)
147-
n = 1
148-
if noOfCol == 0:
146+
if args.one:
149147
for f in list:
150-
print("{!r}".format(f))
148+
print('{!r}'.format(f))
149+
print()
151150
else:
151+
maxlen = 0
152152
for f in list:
153-
print('{!r}'.format(f).ljust(colWidth), end="")
154-
if n == noOfCol:
155-
n = 0
156-
print("")
157-
n += 1
158-
print("\n")
153+
if len(f) > maxlen:
154+
maxlen = len(f)
155+
# 2 for enclosing single qoutes, 2 for spaces after filename
156+
colWidth = maxlen + 4
157+
noOfCol = int(int(terminalColumnSize)/colWidth)
158+
n = 1
159+
if noOfCol == 0:
160+
for f in list:
161+
print("{!r}".format(f))
162+
else:
163+
for f in list:
164+
print('{!r}'.format(f).ljust(colWidth), end="")
165+
if n == noOfCol:
166+
n = 0
167+
print("")
168+
n += 1
169+
print("\n")
159170

160171
"""function declarations ENDS here"""
161172

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /