Code examples
Here are some Gufo code that is already working in the current experimental version: this gives an idea of the possibilities.
Sadly, I am not able to show code coloration here…
The factorial function
let $factoriel $c = if ($c != 1) then ($factoriel ($c - 1)) * $c else 1
Comment: While it looks quite simple, it shows well that Gufo can handle recursive function. Performance regarding recursive function are quite good (better than in python).
The call-ssh function
let $ssh $user $arg = ssh ($user + "@" + $addr)
Comment: Again, this is quite simple but it lets run an interactive command within a function easily. What is returned by the function is a “command result” type which both contain the result code of the command (the returned integer) and for a non-interactive command, the string printed by the command (until a limit of size).
The rename files function
let $replace $from $to =
let $allfiles = ls -1 in(
$List.iter
(fun $afile ->
let $newname = echo -n $afile | sed ("s/"+$from+"/"+$to+"/g") in(
if ($newname.Cmd.print == $afile)
then (echo ($afile + ": already ok"))
else(mv $afile $newname.Cmd.print)
))
($String.asList $allfiles.Cmd.print)
)
Comment: Finally a full function: it gets the names of the files in theĀ current directory, iterate on them and if part of their names includes the string contained in $from, it replaces it by the string contained in $to.