memoscan
← all memos

Memo 0xf7621f8a…59aeaf on Ethereum

https://github.com/Floflis/mlq.git --------------------------------------------------------------------------------------------------------------------------- /media/daniell/B/git/Floflis/Utilities/mlq/README.md ----> --------------------------------------------------------------------------------------------------------------------------- # mlq jq, but HTML instead of JSON 🧚 ---- ## Reading the content inside a given tag by id `mlq -r '#imAnID' file.html` More usage, in the next lines; so please continue reading. Let's focus first in the first: # Installing ## Easy (option 1) Open the Withcraft/Terminal/Prompt and type + press `[ENTER]`: ```sh curl --proto '=https' --tlsv1.3 -sSf https://raw.githubusercontent.com/Floflis/mlq/main/install.sh | sh ``` ## Locally (option 2) If you don't trust downloading+executing a script, you can do it locally. Open terminal and type following by pressing `[ENTER]`: ### Floflis, Floflis-based distros such as UniOS and any other that uses [nu shell](https://github.com/nushell/nushell): ```nu git clone https://github.com/Floflis/mlq.git ; cd mlq ``` After reviewing the code of install.sh: ```nu chmod +x install.sh ; sh ./install.sh ``` ### Any other *nix distro (Ubuntu/Arch/MacOS/etc): ```sh git clone https://github.com/Floflis/mlq.git && cd mlq ``` After reviewing the code of install.sh: ```sh chmod +x install.sh && sh ./install.sh ``` ---- ## Writing any desired content inside a given tag by id on-the-fly: `mlq '#imAnID = "<desired>CONTENT</desired>"' file.html` You can write out the output to any file/place; its up to your creativity. ## Writing any desired content inside a given tag by id, writing directly to the file (be cautious): ```sh contents="$(mlq '#imAnID = "<desired>CONTENT</desired>"' file.html)" && \ echo "${contents}" > file.html ``` Note: this tool isn't professional nor native. You are free to make a program with the same name (mlq) in Rust, then ask us to replace this by yours; but a better idea would be to contribute to/complete something existing: [htmlq](https://github.com/mgdm/htmlq) The positive points about mlq: - short name/command - lower entry barrier, as there are more Bash than C/Rust/Perl developers (so it can have more features than others and developed in a faster pace) ---- ## mlq is used by: - [Floflis Status server](http://status.floflis.com/) - [Firedoge browser](https://github.com/zilldao/firedoge) --------------------------------------------------------------------------------------------------------------------------- <---- /media/daniell/B/git/Floflis/Utilities/mlq/README.md --------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------- /media/daniell/B/git/Floflis/Utilities/mlq/dependencies.txt ----> --------------------------------------------------------------------------------------------------------------------------- xmlstarlet --------------------------------------------------------------------------------------------------------------------------- <---- /media/daniell/B/git/Floflis/Utilities/mlq/dependencies.txt --------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------- /media/daniell/B/git/Floflis/Utilities/mlq/Tasks.txt ----> --------------------------------------------------------------------------------------------------------------------------- Make a custom "shc -f " which finds "bash <path/path> flags" and replaces "bash <path/path>" to the compiled dependencies (use on Plugz) get all tags that contain "version" cat Floflis\ Central.caproj | grep -oE ".?version[^<>]*>[^<>]+" | cut -d'>' -f get only the second tag that contain "version" cat Floflis\ Central.caproj | grep -oE ".?version[^<>]*>[^<>]+" | cut -d'>' -f2 | sed -n '2 p' make examples at README.md compatible with sample.html support to HTML classes/CSS selectors example use variable mlq "#first = \"$use\"" sample.html tests: ❯ echo "#imAnID#childID" | grep -o '#[[:alpha:]]\+*' | awk 'NF { print "\""$0"\""}' | tr "\n" " " | tr '"' "'" | tr -d '#' 'imAnID' 'childID' ❯ echo '#imAnID = "replaceinsidetag"' | grep -o '"[[:alpha:]]\+*"' | tr -d '"' replaceinsidetag Support stdout in place of file.html (like jq) add <html xmlns="http://www.w3.org/1999/xhtml"> then remove (except when its already present before) Support to append: xmlstarlet ed -L -N X='http://www.w3.org/1999/xhtml' \ --var peg '//X:element[@id="daipeg"]' \ #--var res "usetextvariable" \ #-u '$peg' -x 'concat($peg," and then ",$res)' index.html -u '$peg' -x 'concat($peg," use text or variable")' index.html --------------------------------------------------------------------------------------------------------------------------- <---- /media/daniell/B/git/Floflis/Utilities/mlq/Tasks.txt --------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------- /media/daniell/B/git/Floflis/Utilities/mlq/sample.html ----> --------------------------------------------------------------------------------------------------------------------------- <?xml version="1.0"?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"/> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Title</title> </head> <body><h1>Title</h1><ul><li><p>Element 1 to change: <b><element id="first">First content</element></b></p></li><li><p>Another to change: <b><element id="element">...</element> is this.</b></p></li></ul> </body> </html> --------------------------------------------------------------------------------------------------------------------------- <---- /media/daniell/B/git/Floflis/Utilities/mlq/sample.html --------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------- /media/daniell/B/git/Floflis/Utilities/mlq/install.sh ----> --------------------------------------------------------------------------------------------------------------------------- #!/bin/sh echo "Installing mlq..." sudo cp -f mlq /usr/bin/mlq sudo mkdir /usr/lib/mlq sudo cp -f mlq-parser.sh /usr/lib/mlq/mlq-parser.sh sudo cp -f mlq-parser_worker.sh /usr/lib/mlq/mlq-parser_worker.sh sudo cp -f sample.html /usr/lib/mlq/sample.html installfail(){ echo "Installation has failed." exit 1 } if [ -f /usr/bin/mlq ];then echo "- Turning mlq into an executable..." sudo chmod +x /usr/bin/mlq if mlq babyisalive; then echo "Done! Running \"mlq -r '#first' sample.html\" command as example to use it:" && (mlq -r '#first' /usr/lib/mlq/sample.html &);exit 0; else installfail; fi else installfail fi --------------------------------------------------------------------------------------------------------------------------- <---- /media/daniell/B/git/Floflis/Utilities/mlq/install.sh --------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------- /media/daniell/B/git/Floflis/Utilities/mlq/mlq ----> --------------------------------------------------------------------------------------------------------------------------- #!/bin/bash -e if [ "$1" = "-r" ];then if [ "$2" != "" ];then if [ "$3" != "" ];then singletagid=$(echo "$2" | tr -d "#") cat $3 | grep -oE "id=.?\"$singletagid\"[^<>]*>[^<>]+" | cut -d'>' -f2; exit 0 else echo "Missing the HTML file you want to use."; exit 1 fi else echo "Missing the HTML tag ID you want to operate."; exit 1 fi fi if [ "$1" != "-r" ];then if [ "$1" != "" ];then if [ "$2" != "" ];then if [ "$1" != "babyisalive" ] || [ "$1" != "--help" ] || [ "$1" != "-h" ];then bash /usr/lib/mlq/mlq-parser.sh --write "${1}" "$2" else echo "Missing the HTML file you want to use."; exit 1 fi fi else echo "Missing the HTML tag ID you want to operate."; exit 1 fi fi if [ "$1" = "babyisalive" ]; then exit 0 fi if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then echo "Use these commands after/together with 'mlq' command." echo "Available commands:" echo " mlq -r '#imAnID' file.html Reads the content of a given tag by its ID" echo " mlq '#imAnID = \"<desired>CONTENT</desired>\"' file.html Writes any desired content inside a given tag by id on-the-fly" echo " --help, -h Shows all available commands" # echo " --version, -v Shows info about OS name, version and build version" fi #mlq '#imAnID = "replaceinsidetag"' file.html #parser receives instruction/flag from mlq, validates and passes its own flags to worker #parser_worker runs/loops the flags it received # when extracting content of a tag, also enable to parse its nested tags: #mlq -r '#imAnID#childID' # also extract classes: #mlq -r '#imAnID#childID.anotherchild' # be able to replace or append content into tags/ids --------------------------------------------------------------------------------------------------------------------------- <---- /media/daniell/B/git/Floflis/Utilities/mlq/mlq --------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------- /media/daniell/B/git/Floflis/Utilities/mlq/mlq-parser.sh ----> --------------------------------------------------------------------------------------------------------------------------- #!/bin/bash -e if [ "$1" = "--write" ];then # text_to_insert=$(echo "$2" | grep -o '"...\+"' | tr -d '"') text_to_insert=$(echo "$2" | grep -o '".\+"' | tr -d '"') # echo "it have to work: $2" # echo "the previous did work. But: $text_to_insert" tagtree=$(echo "$2" | grep -o '#[[:alpha:]]\+*' | awk 'NF { print "\""$0"\""}' | tr "\n" " " | tr '"' "'" | tr -d '#') # sh ./mlq-parser_worker.sh --tree # sh ./mlq-parser_worker.sh --insert tagtreesingle=$(echo "$tagtree" | tr -d "'") # echo "mitigate ok: $3" # echo "mitigate all: $tagtreesingle, $text_to_insert" bash /usr/lib/mlq/mlq-parser_worker.sh --singletag $tagtreesingle "$text_to_insert" "$3" fi --------------------------------------------------------------------------------------------------------------------------- <---- /media/daniell/B/git/Floflis/Utilities/mlq/mlq-parser.sh --------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------- /media/daniell/B/git/Floflis/Utilities/mlq/mlq-parser_worker.sh ----> --------------------------------------------------------------------------------------------------------------------------- #!/bin/bash -e if [ "$1" = "--tree" ];then echo "Not implemented yet" fi if [ "$1" = "--insert" ];then echo "Not implemented yet" fi if [ "$1" = "--singletag" ];then cp $4 /tmp/mlq-output.html # echo "mitigate 1: $1" # echo "mitigate 2: $2" # echo "mitigate 3: $3" # echo "mitigate 4: $4" # xmlstarlet ed --inplace -N X='http://www.w3.org/1999/xhtml' \ #--update '//X:element[@id="daipeg"]' --value 'new' index.html # <-- most solid # one line with tricks --> xmlstarlet ed -L -u "//_:*[@id='$2']" -v "$3" /tmp/mlq-output.html cat /tmp/mlq-output.html #- cat /tmp/mlq-output.html | htmlq -p rm -f /tmp/mlq-output.html fi --------------------------------------------------------------------------------------------------------------------------- <---- /media/daniell/B/git/Floflis/Utilities/mlq/mlq-parser_worker.sh ---------------------------------------------------------------------------------------------------------------------------