diff options
| author | NPScript <nathan.p.reiner@gmail.com> | 2021-09-26 17:32:36 +0200 |
|---|---|---|
| committer | NPScript <nathan.p.reiner@gmail.com> | 2021-09-26 17:32:36 +0200 |
| commit | 8ab603f8d631278c14a93ef28144e988692fd711 (patch) | |
| tree | ffbcb5c381e7aa36ff00217b50873d6e5122bbf1 | |
first commit
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | README.md | 54 | ||||
| -rw-r--r-- | example.cpp | 98 | ||||
| -rwxr-xr-x | scrubs | 122 |
4 files changed, 279 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0877ca5 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +install: + install scrubs /usr/local/bin/ + +uninstall: + rm /usr/local/bin/scrubs diff --git a/README.md b/README.md new file mode 100644 index 0000000..e2f4bfc --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +# SCRUBS - Let's Prepare The Operation + +Scrubs is a little documentation tool written in POSIX-Shell. It should make easier to work in teams in a suckless way. + +## Features + +There are two kinds of tags which are displayed in scrubs, `DOC` and `TODO`. + +`DOC` is used to document your functions or classes. It has the following structur: + +``` c++ +/** DOC + * @type function + * @name some_random_function + * + * @param input * data + * the input data for processing + * + * @return output + * + * @description + * Here you have the function description. + * It is allowed to have multiple lines. + * Isn't that cool? + */ +``` + +The `TODO` tag has the following structur: + +``` c++ +/** TODO + * @category some_bug + * + * @description + * Some weared bug lol + * what is this??? + */ +``` + +*For more examples see `example.cpp`* + +## Install + +There is a *Makefile* so you are able to install `scrubs` with: + +``` bash +sudo make install +``` + +To uninstall + +``` bash +sudo make uninstall +``` diff --git a/example.cpp b/example.cpp new file mode 100644 index 0000000..6cceeb6 --- /dev/null +++ b/example.cpp @@ -0,0 +1,98 @@ +#include <iostream> +#include "some_other_header.hpp" + +/** DOC + * @type function + * @name some_random_function + * + * @param input * data + * the input data for processing + * + * @return output + * + * @description + * Here you have the function description. + * It is allowed to have multiple lines. + * Isn't that cool? + */ + +output some_random_function(input * data) { + output some_value; + + /** TODO + * @category not_finished + * + * @description + * This is the description of + * the task which is not yet finished + */ + + return some_value; +} + +/** DOC + * @type class + * @name TheBestClass + * + * @description + * This class handles everything and is because of + * that very bloated but I am as every other programmer + * too lazy to fix this, so not my problem. + */ + +class TheBestClass { + public: + TheBestClass(); + void do_everithing(); +} + +/** DOC + * @type method + * @name TheBestClass::TheBestClass + * + * @description + * This is the initializer for + * TheBestClass it does nothing. + */ + +TheBestClass::TheBestClass() { +} + +/** DOC + * @type method + * @name TheBestClass::do_everything + * + * @return void + * + * @description + * This is the function do_everything + * it does everything what this class does. + * Because of this case this function is so + * mal-formed and you cannot understand it. + */ + +void TheBestClass::do_everything() { +} + +/** TODO + * @category some_bug + * + * @description + * Some weared bug lol + * what is this??? + */ + +void some_weard_fun() { + +} + +/** TODO + * @category not_finished + * + * @description + * This thing is not finished yet. + * why? + */ + +int other_thing(int a, int b) { +} @@ -0,0 +1,122 @@ +#!/bin/sh + +files=$(find . -name "*.cpp") + +get_todos() { + if [ -z "$1" ]; then + grep -HPzo '/\*\*\sTODO(\n\s*\*\N*)*\n\s*\*/\n' $files + else + grep -HPzo "/\*\*\sTODO(\n\s*\*\N*)*\n\s*\*\s*@category\s*\N*$1\N*(\n\s*\*\N*)*\n\s*\*/\n" $files + fi +} + +todos() { + hline=$(printf "%0.s─" $(seq $(($(tput cols) - 2)))) + hbordertop=$(printf "┌%s┐" $hline) + hborderbot=$(printf "└%s┘" $hline) + titleline=$(printf "%s" $hline) + + newline + + printf "$(get_todos $1 | \ + sed -e "s/^.*\/\*\* TODO/\\\\033[2;3;39m${hbordertop}\\\\033[0m\\\\n &\\\\033[2;3;39m ${titleline}\\\\033[0m/g" | \ + sed -e 's/^\s*\*/\*/g' -e 's/\/\*\* TODO/\n/g' | \ + sed -e "s/^\*\//\\\\033[2;3;39m$hborderbot\\\\033[0m\\\\n/g" | \ + sed -e 's/^\*/ /g' | \ + sed -E 's/@category (.*)/\\033[34m\1\\033[0m/g' | \ + sed -E 's/@description/\\033[2mdescription\\033[0m/g')\n" +} + +get_docs() { + if [ -z "$1" ]; then + grep -HPzo '/\*\*\sDOC(\n\s*\*\N*)*\n\s*\*/\n' $files + else + if [ -z "$2" ]; then + grep -HPzo "/\*\*\sDOC(\n\s*\*\N*)*\n\s*\*\s*@type\s*\N*$1\N*(\n\s*\*\N*)*\n\s*\*/\n" $files + else + grep -HPzo "/\*\*\sDOC(\n\s*\*\N*)*\n\s*\*\s*@type\s*\N*$1\N*\n\s*\*\s*@name\s*\N*$2\N*(\n\s*\*\N*)*\n\s*\*/\n" $files + fi + fi +} + +doc() { + hline=$(printf "%0.s─" $(seq $(($(tput cols) - 2)))) + hbordertop=$(printf "┌%s┐" $hline) + hborderbot=$(printf "└%s┘" $hline) + titleline=$(printf "%s" $hline) + + newline + + output=$(get_docs $1 $2 | \ + sed -e "s/^.*\/\*\* DOC/\\\\033[2;3;39m${hbordertop}\\\\033[0m\\\\n &\\\\033[2;3;39m ${titleline}\\\\033[0m/g" | \ + sed -e 's/^\s*\*/\*/g' -e 's/\/\*\* DOC/\n/g' | \ + sed -e "s/^\*\//\\\\033[2;3;39m$hborderbot\\\\033[0m\\\\n/g" | \ + sed -e 's/^\*/ /g' | \ + sed -E 's/@type (.*)/\\033[32m\1\\033[0m/g' | \ + sed -E 's/@name (.*)/\\033[34m\1\\033[0m/g' | \ + sed -E 's/@param (.*)/\\033[2mparam\\033[0m \\033[33m\1\\033[0m/g' | \ + sed -E 's/@inherit (.*)/\\033[2minherit from\\033[0m \\033[33m\1\\033[0m/g' | \ + sed -E 's/@return (.*)/\\033[2mreturn\\033[0m \\033[33m\1\\033[0m/g' | \ + sed -E 's/@description/\\033[2mdescription\\033[0m/g') + + if [ $(printf "$output" | wc -l) -eq 0 ]; then + printf "There is no documentation for '$1' '$2'\n" + newline + else + printf "${output}\n" + fi +} + +search() { + docs=$(get_docs "" "") + list=$(echo "$docs" | grep -Pzo '@type\N*\n\s*\*\s*@name\N*\n' | sed -Ez 's/@type\s*(.*)\n\s*\*\s*@name\s*(.*)\n/\\033[32m\1\\033[0m \\033[34m\2\\033[0m\n/g') + + selected=$(printf "${list}" | fzf --ansi --preview './scrubs doc {} | less -R') + + while [ -n "$selected" ]; do + doc $selected | less -R + selected=$(printf "${list}" | fzf --ansi --preview './scrubs doc {} | less -R') + done +} + +title() { + printf '\033[34m' + printf "$1" + printf '\033[2;3;39m - ' + printf "$2" + printf '\033[0m\n' +} + +newline() { + printf '\n' +} + +comment() { + printf '\033[2;3;39m' + printf "$1" + printf '\033[0m' +} + +help() { + newline + title "scrubs" "Let's Prepare The Operation" + newline + comment "Overview" + newline + newline + printf " todo [category] - list todos [in this category]\n" + printf " doc [type] [name] - list documentation for specific type\n" + printf " search - browse through the docs (fzf needed)\n" + newline + + comment "To report bugs, or if you need help send a message to <nathan@reinerweb.ch> or see github.com/NPScript." + newline + newline +} + +case "$1" in + todo) todos $2;; + doc) doc $2 $3;; + search) search;; + *) help;; +esac |