Browse Source

added the -n line number option to less/more

Pat Beirne 3 years ago
parent
commit
2459d68bcb
2 changed files with 10 additions and 4 deletions
  1. 1 1
      README.md
  2. 9 3
      tf_extend.py

+ 1 - 1
README.md

@@ -378,7 +378,7 @@ freq [160 | 80]           # get/set the ESP8266 frequency
 exec <python-filename>    # execute a small python file
 free                      # display the heap size: used + free
 wc <filename>             # display the line count, word count and bytes
-less <filename>           # similar to cat, but displays 30 lines at a time
+less/more [-n] <filename> # similar to cat, but displays 30 lines at a time
 ```
 Synonyms: `ip = ifconfig`, `more = less`, `dig = nslookup = host`
 

+ 9 - 3
tf_extend.py

@@ -11,11 +11,13 @@ class wc():
     self.words += len(text.split())
 
 class lessor():
-  def __init__(self):
+  def __init__(self,nums=False):
     self.i=0
+    self.nums=nums
   def write(self,text):
     if self.i==-1: return
     self.i += 1
+    if self.nums: sys.stdout.write(str(self.i)+' ')
     sys.stdout.write(text)
     if self.i%30==0:
       sys.stdout.write("====> press <enter> to see more, N or Q to quit <====\n")
@@ -33,10 +35,14 @@ def cmd(args):
     return True
 
   if cmd in ('wc','more','less'):
+    nums=False
     if cmd=='wc':
       w = wc()
     else:
-      w = lessor()
+      if args[1]=='-n':
+        nums=True
+        del(args[1])
+      w = lessor(nums)
     try:
       tf.transfer(args[1],w)
       if cmd=='wc':
@@ -95,7 +101,7 @@ def cmd(args):
     print("  ifconfig/ip        \t\thost/dig/nslookup <domain.name>")
     print("  freq [ 160 | 80 ]  \t\texec <python-filename>")
     print("  free        \t\t\twc <filename>")
-    print("  less/more <filename>")
+    print("  less/more [-n] <filename>")
   else: # command not found
     return False
   return True