Jump to content

- - - - -

[Release] LIST.G4B: front-end for grub4dos' function 'ls'


  • Please log in to reply
No replies to this topic

#1 deomsh


    Frequent Member

  • Advanced user
  • 193 posts

Posted 19 May 2023 - 04:13 PM

Lately I was working on a sub-directory to test more advanced wildcards. But things run a bit 'out of hand', so I scripted a full front-end for grub4dos' internal function 'ls': https://github.com/deomsh/LIST.G4B


This script can be used as a replacement for 'ls', output should be the same, but with a few modifications:

  • pager is working, I made my own pager (not working on grub4efi)
  • empty directories are greyed out (except on NTFS only, not possible to discriminate between empty directories and  zero-byte files on this file-system. I choose to show zero-byte files as directories - 'ls' can SHOW the difference)
  • sub-directories can be parsed too (with the well known switch '-s')
  • colors can be set on file-names, file-extensions, not-empty directories, empty directories and on sub-directories

I took idea's for switches from the Linux/ Unix BASH command-line, MS-DOS 7.1 and Windows 10 CMD.


Starting with LIST.G4B is easiest without any other parameter, small-help will show up. The small-help will also be shown if an error is made about the actual commands (an idea steve6375 gave me when I published TEXTSTAT.G4B). See first print-screen:


01 LIST.G4B v0.7 with empty command-line and with bad switch.png


There are six basic forms of output. The two 'wide' outputs are self-adjusting to the actual graphics mode: number of column's between 5 and 12 (I am afraid 320x240 or 200? is not fully supported with 'wide'). See next six print-screens.


02 LIST v0.7 root.png 03 LIST v0.7 -b root.png 04 LIST v0.7 -l root.png 05 LIST v0.7 -lh root.png 06 LIST v0.7 -w root.png 07 LIST v0.7 -c root.png


BTW escaped spaces '\ ' are only visible in the default 'ls'-mode, in al other modes removed.


Following wildcards are supported: '?' and multiple '*' in file-names and file-extensions. In directories only ONE '*' at the end of the LAST directory-name in the PATH. Default LIST.G4B is not case-sensitive, but this can be altered with switch '-case'. See next three print-screens:


08 LIST v0.7 -b root+several wildcard tests.png 09 LIST v0.7 -root-G+asterisk- wildcard in dir compared with -b switch.png 10 LIST v0.7 test with -case after vol and set lscol=BDE6F on EXT2 (hd6,4).png


Also sorting is added. There are three sorting possibilities: name, extension and file-size. Also 'grouping' on directories/ files is available. See next print-screen for an example:


12 LIST v0.7 -ogn -c root.png


BTW my second programmer-son helped me a lot. First with the algorithm of 'selection sort' - which was quite easy because I (re)invented my own pointers (24 bits for memory address of files and 8 bits for their length).

Later he insisted I had to try 'quick sort' too, which should be faster in theory.

But because I pre-sorted in 35 'buckets', in most cases selection sort is still faster (number of 'swaps' seems to be best with selection sort - I found 'break-even' in case of about 15 pointers in a bucket). This sorting method also has the virtue the sorted file is immediate available for echoing, so output is more fluently.

However with switch '-qs' quick sort is available too.



With switch '-n' the number of folders and files is counted and echo'd at the end (with -nq exported to a set-variable). See next two print-screens. On the second print-screen can be seen the file names with leading spaces can not be displayed with sorting (they are NOT according to the Microsoft's Long File Name specification anyway).


13 LIST v0.7 -n -w -og root (including starting spaces).png 14 LIST v0.7 -n -w -ogn root (NOT including starting spaces).png


BTW ment is the folder: '  LFN Starting Spaces in Total Commander'


With switch '-e'/ '--e' only empty directories are displayed/ not displayed. With switches '-d'/ '-f' directories/ files only. Colors can be set with switch '-col:NXDES' (for details see the 'Help'). Next two print-screens give examples (empty folders brown, not-empty folders yellow and device+path+sub-directories high-white:


15 LIST v0.7 -e -w -on -s -d -col=77F6F root on graphicsmode 1600.png 16 LIST v0.7 --e -w -on -s -d -col=77E6F root on graphicsmode 1600.png


BTW it is also possible to set colors with variable 'lscol', active until grub4dos command-line is left.


Another possibility is to filter on Short File Names/ Long File Names, but only as far 'ls' is showing them. So no truncated file names here. See next print-screen for some examples:


17 LIST v0.7 tests with -sfn and --sfn on (hd0,0)-windows-.png


Inspired by the '-e' switch from the BASH command-line I added multiple extensions: switch '-me'. Also multiple directories ('-md') OR multiple subdirectories ('-ms'). Can all be used with and without switch '-s'. See next three print-screens:


18 LIST v0.7 -me -w -oe -s (hd0,0)-asterisk.DLL asterisk.TLB asterisk.CPL asterisk.OCX on graphicsmode 1280.png 19 LIST7M -col=BDE6F -oge -md -s (hd0,0)-windows-Asterisk- -sAsterisk- -cAsterisk- -inf- -tAsterisk- -appliAsterisk -allAsterisk-.png 20 LIST v0.7 tests with -ms -s -oge -w -col=BDE6F (hd0,0)-windows- SYSasterisk- IOSUBSYS- COMMAND- notSTSTEM- ALLasterisk-.png


For the more advanced users (if any) my implementation of redirecting, piping and adding other commands after 'FILE'. This is more complicated, but there are some instructions in the Help. A few examples can be seen in next print-screen:


22 LIST v0.7 tests with redirect, pipe and CMD on (hd0,0)-windwos-.png


About the support of grub4efi: although (almost fully supported) quite unstable, even with switch '-mdbase:startsector' to use a free memory area on grub4efi. See last print-screen:


24 LIST.G4B v0.7 -mdbase=0x22000 -s -w -oge -col=BDE6F (hd0,0)- on grub4efi graphicsmode 1024 + crashes.png









#2 steve6375


    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
    United Kingdom

Posted 20 May 2023 - 11:57 AM

Looks really useful!  Thanks!


column  has only one letter L in it. not two


Seems to have problems under grub4efi (malloc errors after several runs) but that is problems with grub4efi not your code!

#3 deomsh


    Frequent Member

  • Advanced user
  • 193 posts

Posted 20 May 2023 - 07:48 PM



During this project I became aware column is without one 'l' (I used it as a variable name too) - but I see in the 'Help' I failed.

Also my Pagestat sub-routine has still variable 'collumn'. :ph34r:


BTW under grub4efi I observed earlier these malloc errors after several runs. I hope this will become better in the future.




In my first post I forgot to mention a few details, and I want to add some clarifications (that post became already quite long).


1) about differing behavior with 'pager' compared to 'ls': if pager is 'on' and using 'ls' it is not possible to quit with 'Q' (only a bit of a problem in case of large directories).


2) if before using LIST.G4B pager is set 'off', it is still possible to end the script with 'Q' (or pause with 'Escape'). Of course Ctrl+C can be used, is not always working if piping output of 'ls' if a large directory to a call.

BTW a technical detail: I used 'beep 0 1' to 'break' processing of the 'call command-line' (in sub-routine :lastkey).


3) with most switches no memory is used.


4) total size of counted files is not included with switch '-n'/ '-nq'. Will this be useful to anyone?



Also tagged with one or more of these keywords: grub4dos

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users