English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. Scripting (https://eab.abime.net/forumdisplay.php?f=117)
-   -   AmigaOS 1.3 ' ls ' command (https://eab.abime.net/showthread.php?t=108488)

malko 12 October 2021 14:29

AmigaOS 1.3 ' ls ' command
 
Building on the momentum of my previous achievement with the AskL/AskM commands & the use of environment variable in WB 1.3 scripts, I decided to try to script another thing that I missed BitD : an 'ls' command (by this I mean : a columned and coloured listing of a given folder).

As previously, any comments or tips to improve the way it has been done are welcome.

NEW VERSION OF THE SCRIPT AVAILABLE BELOW. SEE POST #8

Code:

ls :
.key repertoire
.bra {
.ket }
.def repertoire ""
echo >NIL: t:lsefs "0(f/.info/;d )*Nw"
echo >NIL: t:lsees "0(f/[mlk/;e/[mlk/[26C/;f/[mlk/;e/[mlk/[52C/;f/[mlk/;e/[mlk/N/)*Nw"
echo >NIL: t:lsejl "0(2CL//;n)*Nw"
list >t:lsd "{repertoire}" dirs lformat="*e[33m%s*e[1E*e[1A*e[mlk"
list >t:lsf "{repertoire}" files lformat="*e[31m%s*e[1E*e[1A*e[mlk"
list >t:lsi "{repertoire}" files pat=#?.info lformat="*e[32m%s*e[1E*e[1A*e[mlk"
edit >NIL: FROM t:lsf TO t:lsf. WITH t:lsefs
join t:lsd t:lsf. t:lsi TO t:lsm
sort FROM t:lsm TO t:lsm. COLSTART 6
edit >NIL: FROM t:lsm. TO t:lsm.. WITH t:lsees
edit >NIL: FROM t:lsm.. TO t:lsm. WITH t:lsejl
delete t:lsefs t:lsees t:lsejl t:lsd t:lsf t:lsi t:lsf. t:lsm t:lsm.. QUIET
type t:lsm.
delete t:lsm. QUIET
echo ""

And here is the result : (folders in orange, files in white & .info in black)
https://i.ibb.co/SRPKb6B/WB13-ls.gif

thomas 12 October 2021 15:55

On the List command you don't need quick if you have lformat. Quick is like lformat=%s.

malko 12 October 2021 16:24

Thank you thomas :great .
Source in 1st post has been updated accordingly.

lmimmfn 13 October 2021 03:31

Sorry if OT but did any Amiga OS have "ls" command?
I know "dir" works, but just seems a bit unconventional that it wasnt "ls" by default as its more aligned with Unix than DOS.

thomas 13 October 2021 09:18

"Dir" gives sorted list of names only.

"List" gives unsorted list of details with the option to reformat the output.

So List is what comes next to ls. And I don't see why AmigaOS should align with anything. Especially if it's worse than what we have.

daxb 13 October 2021 12:20

PFS comes with an unix like ls command.

redblade 13 October 2021 21:24

Imimmfn: AmiTCP 4.x came with 'ls' in the /bin/ directory, possibly GNU AmiTCP version 2.x and 3.x as well.

Excellent scripting work Malko

malko 13 October 2021 22:43

Today I changed a bit the script in order to allow the display to be on 2, 3 or 4 columns. This is done through the COLS argument. Default is now 4 columns.
I also have reorganised the script to try to make it bit faster. I gained 2 seconds as now it only takes a max of 7 seconds to display the result. Not bad considering how it works :p .
Furthermore the temporary files are now identified to the shell meaning that it is possible to launch simultaneous ls commands from different Shells.

Here is the code of the v1.1 :

Code:

ls (v1.1) :
.key DIR,COLS/K
.bra {
.ket }
.def DIR ""
.def COLS 4
run >NIL: list >t:lsf.{$$} "{DIR}" files lformat="*e[31m%s*e[0m*e[1E*e[1A*e[mlk" +
echo >t:lsefs{$$} "0(f/.info/;d )*Nw" +
edit >NIL: FROM t:lsf.{$$} TO t:lsf{$$} WITH t:lsefs{$$}
run >NIL: list >t:lsd{$$} "{DIR}" dirs lformat="*e[33m%s*e[0m*e[1E*e[1A*e[mlk"
list >t:lsi{$$} "{DIR}" files pat=#?.info lformat="*e[32m%s*e[0m*e[1E*e[1A*e[mlk"
if VAL {COLS} EQ 2
  skip 2cols
endif
if VAL {COLS} EQ 3
  skip 3cols
endif
lab 4cols
run >NIL: echo >t:lsees{$$} "0(f/[mlk/;e/[mlk/[19C/;f/[mlk/;e/[mlk/[38C/;f/[mlk/;e/[mlk/[57C/;f/[mlk/;e/[mlk/N/)*Nw"
echo >t:lsejl{$$} "0(3CL//;n)*Nw"
skip mlk
lab 3cols
run >NIL: echo >t:lsees{$$} "0(f/[mlk/;e/[mlk/[26C/;f/[mlk/;e/[mlk/[52C/;f/[mlk/;e/[mlk/N/)*Nw"
echo >t:lsejl{$$} "0(2CL//;n)*Nw"
skip mlk
lab 2cols
run >NIL: echo >t:lsees{$$} "0(f/[mlk/;e/[mlk/[40C/;f/[mlk/;e/[mlk/N/)*Nw"
echo >t:lsejl{$$} "0(1CL//;n)*Nw"
skip mlk
lab mlk
join t:lsd{$$} t:lsf{$$} t:lsi{$$} TO t:lsc{$$}
sort FROM t:lsc{$$} TO t:lss{$$} COLSTART 6
edit >NIL: FROM t:lss{$$} TO t:lse{$$} WITH t:lsees{$$}
edit >NIL: OPT W186 FROM t:lse{$$} TO t:lsm{$$} WITH t:lsejl{$$}
type t:lsm{$$}
echo ""
run >NIL: delete t:lsd{$$} t:lsf.{$$} t:lsi{$$} t:lsefs{$$} t:lsf{$$} t:lsees{$$} t:lsejl{$$} t:lsc{$$} t:lss{$$} QUIET
run >NIL: delete t:lse{$$} t:lsm{$$} QUIET

Here is how it looks :
https://i.ibb.co/x1PyKM2/ls-v1-1.gif

Quote:

Originally Posted by redblade (Post 1511268)
[...] Excellent scripting work Malko

Thank you :) .

idrougge 13 October 2021 23:34

Quote:

Originally Posted by lmimmfn (Post 1511088)
Sorry if OT but did any Amiga OS have "ls" command?

Yes, it’s called "List".

E-Penguin 19 November 2021 16:43

I like the colours :)

malko 19 November 2021 21:09

Thanks . I think it helps finding a files as you can focus your eyes on the needed colour :)


All times are GMT +2. The time now is 04:13.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.07760 seconds with 11 queries