Здравствуйте. Решил вынести за пределы локалхоста сие поделие. Как доучу Rakudo, перепишу на Rakudo.
Есть возможность создавать правильные документы с хешбангом и шарить их (подробнее можно увидеть в коде). Программа на англ. языке.
Зависит от: rakudo, perl6, bash, GNU coreutils.
#!/usr/bin/env bash
#
#
# ____ by _ Lev _____ Zagatov _
#| _ \ __ _| | ___ |_ _|__ ___ | |____
#| |_) / _` | |/ / | | || |/ _ \ / _ \| |_ /
#| _ < (_| | <| |_| || | (_) | (_) | |/ /
#|_| \_\__,_|_|\_\\__,_||_|\___/ \___/|_/___|
# RakuToolz v0.1 -- tools for lazy Rakudo programmers
#
EDITOR='emacs -nw'
tmp=`mktemp`
VERSION='0.1'
args="${@:2}"
# environment variables are created
make(){
/usr/bin/echo '#!/usr/bin/env rakudo' > $tmp # making hashbang
/usr/bin/echo -e "use v6\n" >> $tmp # making hashbang
/usr/bin/env bash -c "cat $args >> $tmp" 2> /dev/null # copying text
cat $tmp > $args # copying text to main file
}
execute(){
echo -n "Do you want to execute program? [Y/n] "; read -n 1 -s result; read -n 10000 -t 0.1 # asking to execute program
case $result in
'N'|'n') /usr/bin/echo '';; # if no -- quit
*) /usr/bin/echo ''; /usr/bin/env rakudo $args;; # else -- execute
esac
}
check(){
if [[ `cat $args | grep '#!/usr/bin' | grep -E 'perl6$|raku$|rakudo$'` = '' ]]; then # if no correct hashbang
echo "It does not look like $args is correct Rakudo source code file. Continue? [Y/n] "; read -n 1 -s result; read -n 10000 -t 0.1 # continue?
case $result in
'N'|'n') /usr/bin/echo -n ''; exit 1;; # if no --exiting
esac
fi
}
help(){ # printing help!
echo "Help for RakuToolz v$VERSION"
echo "======================================="
echo "Keys | Description"
echo "make m | Makes correct Rakudo file"
echo "edit e | Makes file and opens editor"
echo "open o | Opens editor"
echo "share s | Uploads file to 0x0.st"
echo "help h | Shows this help"
echo "version v | Shows version of RakuToolz"
}
case $1 in
'make'|'m')
make; execute;;
'new'|'n')
make; $EDITOR $args; execute;;
'edit'|'e')
check; $EDITOR $args; execute;;
'share'|'s')
check; link=`curl -F"file=@$args" http://0x0.st || echo error` # uploading files to 0x0
case $link in
'error') echo 'Error while uploading, sorry.';; # if error -- say about error
*) echo "Your $args file was succesfully uploaded to 0x0.st! Link: < $link >";; # else -- give link
esac;;
'help'|'h')
help;; # help
'version'|'v')
echo "RakuToolz v$VERSION";; # version
'')
echo 'Error: no keys given'; help;; # say about error and show help
*)
echo "Error: no key $1 found"; help;; # say about error and show help
esac
Написано на коленке. Возможно, и вам пригодится.
Что можно добавить, что лучше разъяснить? Нужно ли это вообще?