English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System > Coders. Scripting

 
 
Thread Tools
Old 12 October 2021, 14:29   #1
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,856
Lightbulb 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)

Last edited by malko; 13 October 2021 at 22:45.
malko is offline  
Old 12 October 2021, 15:55   #2
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
On the List command you don't need quick if you have lformat. Quick is like lformat=%s.
thomas is offline  
Old 12 October 2021, 16:24   #3
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,856
Thank you thomas .
Source in 1st post has been updated accordingly.
malko is offline  
Old 13 October 2021, 03:31   #4
lmimmfn
Registered User
 
Join Date: May 2018
Location: Ireland
Posts: 672
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.
lmimmfn is offline  
Old 13 October 2021, 09:18   #5
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
"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.
thomas is offline  
Old 13 October 2021, 12:20   #6
daxb
Registered User
 
Join Date: Oct 2009
Location: Germany
Posts: 3,303
PFS comes with an unix like ls command.
daxb is offline  
Old 13 October 2021, 21:24   #7
redblade
Zone Friend
 
redblade's Avatar
 
Join Date: Mar 2004
Location: Middle Earth
Age: 40
Posts: 2,127
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

Last edited by redblade; 13 October 2021 at 21:47.
redblade is offline  
Old 13 October 2021, 22:43   #8
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,856
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 .
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 :


Quote:
Originally Posted by redblade View Post
[...] Excellent scripting work Malko
Thank you .
malko is offline  
Old 13 October 2021, 23:34   #9
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
Quote:
Originally Posted by lmimmfn View Post
Sorry if OT but did any Amiga OS have "ls" command?
Yes, it’s called "List".
idrougge is offline  
Old 19 November 2021, 16:43   #10
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,213
I like the colours
E-Penguin is offline  
Old 19 November 2021, 21:09   #11
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,856
Thanks . I think it helps finding a files as you can focus your eyes on the needed colour
malko is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a WB command at all that can... MethodGit request.Other 43 10 October 2010 09:06
What is the WB command that..... MethodGit request.Other 4 08 October 2010 04:21
The 'FreeAnim' command MethodGit request.Apps 5 14 June 2009 14:43
Assign command fc.studio support.Apps 2 28 December 2005 18:36
final command runamuck request.Old Rare Games 10 23 September 2003 20:55

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 21:31.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09122 seconds with 15 queries