@@ -63,7 +63,7 @@ use crate::io_mods::get_user_home;
6363// Here we use a const and not let because is a global variable
6464// As we know the size of each word we can use "&str" and then we specify the number
6565// of elements. This is because a const must have know size at compiling time.
66- const LBUILTINS : [ & str ; 38 ] = [ "base64" , "basename" , "cd" , "clear" , "count" , "cp" , "date" , "decodebase64" , "disable_history" , "echo_raw" , "enable_history" , "env" , "exit" , "expand" , "false" , "history" , "head" , "help" , "home" , "id" , "join" , "info" , "mkdir" , "mkfile" , "move" , "nl" , "list" , "ln" , "ls" , "proc" , "pwd" , "rm" , "seq" , "show" , "sleep" , "tail" , "which" , "$?" ] ;
66+ const LBUILTINS : [ & str ; 39 ] = [ "base64" , "basename" , "cd" , "clear" , "count" , "cp" , "date" , "decodebase64" , "disable_history" , "du ", "echo_raw" , "enable_history" , "env" , "exit" , "expand" , "false" , "history" , "head" , "help" , "home" , "id" , "join" , "info" , "mkdir" , "mkfile" , "move" , "nl" , "list" , "ln" , "ls" , "proc" , "pwd" , "rm" , "seq" , "show" , "sleep" , "tail" , "which" , "$?" ] ;
6767
6868const HBUILTINS : & str = "Help;
6969Remember respect the positions of each argument
@@ -77,6 +77,7 @@ _cp [source] [destination]: copy file or directory from [source] to [destination
7777_date: display the current time and date in UTC-0 (which is the same that GTM-0).
7878_decodebase64 [input] [file]: decocde input from base64 to file.
7979_disable_history: disable save commands to history without truncate the file.
80+ _du [path]: show disk usage ('du') in [path], read recusively.
8081_enable_history: enable save commands to history.
8182_echo_raw: show string into stdout without interpreting special characters.
8283_env: show environment variables.
@@ -106,7 +107,7 @@ _tail [number] [file] : show the last [number] lines of [file].
106107_which [binary]: show where is located the binary based in PATH environment variable.
107108_$?: print the latest command exit return, not include builtins" ;
108109
109- const RUNE_VERSION : & str = "v0.41 .19" ;
110+ const RUNE_VERSION : & str = "v0.42 .19" ;
110111
111112// Builtins
112113// Are private for only be executed by rbuiltins
@@ -333,6 +334,41 @@ fn decodebase64(input: &String) -> Option<String> {
333334 }
334335}
335336
337+ fn disk_usage ( input : & String ) -> Option < String > {
338+ let mut input = input. clone ( ) ;
339+
340+ if input. split ( ' ' ) . map ( |e| e. to_string ( ) ) . collect :: < Vec < String > > ( ) . len ( ) > 1 {
341+ return Some ( "Too many arguments. Pass just one path" . to_string ( ) ) ;
342+ } else if input. len ( ) == 0 {
343+ return Some ( "Too few arguments. Pass just one path" . to_string ( ) ) ;
344+ }
345+
346+ let fs_struct = input. readdir_recursive ( ) ;
347+ let mut temp_buff = HashMap :: new ( ) ;
348+ let mut result = String :: new ( ) ;
349+
350+ for dir in fs_struct. dbuff {
351+ let size = fs:: metadata ( dir. clone ( ) ) . unwrap ( ) . size ( ) . size_to_human ( ) ;
352+ temp_buff. insert ( size, dir) ;
353+ }
354+
355+ for file in fs_struct. fbuff {
356+ let size = fs:: metadata ( file. clone ( ) ) . unwrap ( ) . size ( ) . size_to_human ( ) ;
357+ temp_buff. insert ( size, file) ;
358+ }
359+
360+ for ( k, i) in temp_buff {
361+ result = result + & format ! ( "{k} {i}\n " ) ;
362+ }
363+
364+ if result. is_empty ( ) {
365+ return None ;
366+ } else {
367+ return Some ( result) ;
368+ }
369+
370+ }
371+
336372fn environmentvar ( ) -> String {
337373 let mut buffer: Vec < String > = Vec :: new ( ) ;
338374 let mut buffer2: String = String :: new ( ) ;
@@ -1407,10 +1443,15 @@ pub fn rbuiltins(command: &str, b_arguments: String) -> Result<String,&str> {
14071443 Some ( d) => Ok ( d) ,
14081444 None => Err ( "error converting" ) ,
14091445 }
1446+ } else if command == "du" {
1447+ match disk_usage ( & b_arguments) {
1448+ Some ( d) => Ok ( d) ,
1449+ None => Err ( "Error reading path" ) ,
1450+ }
14101451 } else if command == "echo_raw" {
14111452 result = echo_raw ( & b_arguments) ;
14121453 Ok ( result)
1413- } else if command == "expand" {
1454+ } else if command == "expand" {
14141455 result = expand ( b_arguments) ;
14151456 Ok ( result)
14161457 } else if command == "head" {
0 commit comments