diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml new file mode 100644 index 0000000..d863bdb --- /dev/null +++ b/.github/workflows/quality.yml @@ -0,0 +1,29 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + + shellcheck: + name: Shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master + + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run Makefile tests + run: | + make samples + make tests \ No newline at end of file diff --git a/EXAMPLES.md b/EXAMPLES.md new file mode 100644 index 0000000..271992a --- /dev/null +++ b/EXAMPLES.md @@ -0,0 +1,205 @@ +# VIM Header Composer Examples + + > **Warning:** this file was generated by the execution of `make samples`, manual changes possible will be overwritten. + + Instead of using the characters and the standard format you can set the string to process using styles as seen below. + + + + +------ +### Using 'sides' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:sides;Example using 'sides'."`. +``` +⎡ ⎤ +⎢ Example using 'sides'. ⎥ +⎣ ⎦ +``` + + + +------ +### Using 'prettybox' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:prettybox;Example using 'prettybox'."`. +``` +┌────────────────────────────┐ +│ Example using 'prettybox'. │ +└────────────────────────────┘ +``` + + + +------ +### Using 'pretty' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:pretty;Example using 'pretty'."`. +``` +┌─────────────────────────┐ +│ Example using 'pretty'. │ +└─────────────────────────┘ +``` + + + +------ +### Using 'quotes' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:quotes;Example using 'quotes'."`. +``` + " + Example using 'quotes'. +" +``` + + + +------ +### Using 'docblock' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:docblock;Example using 'docblock'."`. +``` +/** + * Example using 'docblock'. + **/ +``` + + + +------ +### Using 'cccomment' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:cccomment;Example using 'cccomment'."`. +``` +/** + ** Example using 'cccomment'. + **/ +``` + + + +------ +### Using 'ccomment' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:ccomment;Example using 'ccomment'."`. +``` +/* + * Example using 'ccomment'. + */ +``` + + + +------ +### Using 'lcomment' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:lcomment;Example using 'lcomment'."`. +``` +// +// Example using 'lcomment'. +// +``` + + + +------ +### Using 'box' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:box;Example using 'box'."`. +``` ++----------------------+ +| Example using 'box'. | ++----------------------+ +``` + + + +------ +### Using 'star' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:star;Example using 'star'."`. +``` +************************* +* Example using 'star'. * +************************* +``` + + + +------ +### Using 'stars' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:stars;Example using 'stars'."`. +``` +************************** +* Example using 'stars'. * +************************** +``` + + + +------ +### Using 'asterisk' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:asterisk;Example using 'asterisk'."`. +``` +***************************** +* Example using 'asterisk'. * +***************************** +``` + + + +------ +### Using 'ernjs' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:ernjs;Example using 'ernjs'."`. +``` +################################ +#### Example using 'ernjs'. #### +################################ +``` + + + +------ +### Using 'ernando' + +Example using `#!/usr/bin/env bash + +./vhc <<< "vhc:ernando;Example using 'ernando'."`. +``` +################################## +#### Example using 'ernando'. #### +################################## +``` + + + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bd4f902 --- /dev/null +++ b/Makefile @@ -0,0 +1,136 @@ +# +# λ::Makefile +# +# For further information see `README.md`. + +PREFIX?= /bin +TARGET?= ~/.local +SOURCE?= vhc +NULL ?= /dev/null +VIMRC = ~/.vimrc + +INSTALL= $(TARGET)$(PREFIX) +VIMCONF= echo 'map :!vhc' >> $(VIMRC) + +ifneq (,$(DESTDIR)) +TARGET =$(DESTDIR) +endif + + +CMD = "\\e[1m%-10s\\e[0m%s\n" +STR = "\\e[0;2;3m%s\\e[0m\n" +HLP = sed -E 's/(`.*`)/\\e[1m\1\\e[0m/' + + +DEFAULT: help + + + +backup: + @\ + cp $(VIMRC) $(VIMRC)_$(shell date +'%Y%m%d%H%M%S') + + +# +install: backup # Installs application. + @\ + mkdir -p $(INSTALL) 2>$(NULL) ; \ + install -D $(SOURCE) $(INSTALL)/$(SOURCE) ; \ + chmod +x $(INSTALL)/$(SOURCE) ; \ + echo Installed into '$(INSTALL)/$(SOURCE)' + + @\ + LINE=$$(cat $(VIMRC)"" | grep -n "$(SOURCE)"\ + | awk -F':' '''{ print($$1); }'); (( sed -i \ + "$${LINE},1 s/^[\"| ]*//g" $(VIMRC))) + + @\ + VIM=$$(cat $(VIMRC)"" | grep "$(SOURCE)") ; \ + [ -e $(INSTALL)/$(SOURCE) -a -z "$${VIM}" ] \ + && ((echo 'Configuring VIM'; $(VIMCONF) )) \ + || ((echo "VIM configured with '$${VIM}'")) + + + +uninstall: backup # Uninstalls application. + @\ + rm -Rf $(INSTALL)/$(SOURCE); \ + echo "'$(INSTALL)/$(SOURCE)' removed." + + @\ + LINE=$$(cat $(VIMRC) | grep -n "$(SOURCE)" | awk -F':' '{print($$1)}'); \ + sed -i "$${LINE},1 s/^/\" /" $(VIMRC) + + +# +help: # Shows this help. + @\ + echo """"""""""""""""""""""""""" \ + $$(awk 'BEGIN { FS=":.*?#" } \ + /^(\w+:.*|)#/ { \ + gsub("^( : |)#( |)", """""""" ); \ + LEN=length($$2); COND=(LEN < 1); \ + FORMAT=(COND ? $(STR) : $(CMD)); \ + printf(FORMAT, $$1, """"""$$2 ); \ + }' $(MAKEFILE_LIST) | ($(HLP)))" + + +# +samples: # Build tests and EXAMPLES.md using possible style options. + @\ + mkdir -p tests; \ + NUM(){ cat vhc | grep -n "$${1}OPTIONS" | awk -F':' '{print($$1)}'; }; \ + INI=$$(NUM "# "); \ + END=$$(NUM "#/"); \ + MAX=$$(cat vhc | wc -l); \ + GET=$$((MAX - INI - 1)); \ + LEN=$$((END - INI - 3)); \ + TARGET=EXAMPLES.md \ + OPTIONS=$$(cat vhc \ + | tail -n"$${GET}" \ + | head -n"$${LEN}" \ + | sed -E 's/^\s+([a-z0-9\-\|\*]*)\).*$$/\1/; s/\|/ /g; s/\*//g'); \ + echo "# VIM Header Composer Examples\n\n" \ + "> **Warning:** this file was generated by the execution of \`make samples\`, manual changes possible will be overwritten.\n\n" \ + "Instead of using the characters and the standard format you can set the string to process using styles as seen below.\n\n\n\n" \ + > $$TARGET; \ + for opt in $$OPTIONS; \ + do TEST=tests/testing_style_$${opt}.sh; \ + echo "Creating test \e[1m$${opt}\e[0m.."; \ + echo "------\n### Using '$${opt}'\n" >> $$TARGET; \ + echo "#!/usr/bin/env bash\n\n""./vhc <<< \"vhc:"$${opt}";Example using '$${opt}'.\"" > $${TEST}; \ + echo "Example using \`$$(cat $${TEST})\`.\n\`\`\`" >> $$TARGET; \ + echo "vhc:$${opt};Example using '$${opt}'." | ./vhc > $${TEST}.result;\ + echo "$$(cat $${TEST}.result)\n\`\`\`\n\n\n" >> $$TARGET; \ + done + + +# +.PHONY: tests +tests: # Execute tests. + @\ + gMD5(){ cat $$1 | md5sum | awk '{print($$1)}'; };\ + for each in ./tests/*.sh; \ + do bash "$${each}" >.test ; \ + TESTS=$$(echo $${each} | sed -E 's/_/ /g; s/\.sh$$//g; s/^.*\///'); \ + printf "%*s%s\r%s" 5 "" "$${TESTS}"; \ + VALID=$$(gMD5 ".test"); \ + CHECK=$$(gMD5 $${each}.result); \ + VALUE="\e[31mFail\e[0m"; \ + [ "$${VALID}" = "$${CHECK}" ] \ + && VALUE="\e[32mDone\e[0m" \ + || FAIL=true; \ + echo "$${VALUE}"; \ + done; \ + rm -Rf .test; \ + [ -z $${FAIL} ] || exit 1 + + + +clear: # Clear. + @\ + rm -Rf tests .test + +# +%: + @: diff --git a/README.md b/README.md index 6c173a6..fbe1f10 100644 --- a/README.md +++ b/README.md @@ -1,108 +1,64 @@ # VIM Header Composer +[url-codacy ]: https://www.codacy.com/app/jmurowaniecki/vim-header-composer +[ico-codacy ]: https://img.shields.io/codacy/grade/9ac72e1294504b06b245a7b4d8253029?logo=codacy&logoColor=green&style=flat-square +[url-styleci]: https://github.styleci.io/repos/103320898 +[ico-styleci]: https://github.styleci.io/repos/103320898/shield +[ico-version]: https://img.shields.io/github/v/tag/jmurowaniecki/vim-header-composer?sort=semver&style=flat-square + +[![StyleCI][ico-styleci]][url-styleci] +[![Codacy ][ico-codacy ]][url-codacy] +[![Version][ico-version]](#) + VIM header composer is an utility script wrote in shell very simple to make header's based on comments in vim such as above. The string will be formated and fulfilled with characters following your desired style. -```sh +```text ############################################ #### CREATE FILE BAR AND SEND TO SERVER #### ############################################ -$ RUN echo "foo" > bar -$ RUN scp -i bar example.com:/dev/null +RUN echo "foo" > bar +RUN scp -i bar example.com:/dev/null ``` -# Installation +## Installation +### Yes, you can do it by the old-fashioned way +Clonning this repository and linking it to your `.../bin/` folder. ```sh -$ git clone https://github.com/ernandos/vim-header-composer.git -$ sudo mv vim-header-composer /opt/ -$ sudo ln -s /opt/vim-header-composer/vhc /usr/local/bin -$ echo 'map :!vhc' >> ~/.vimrc +git clone git@github.com:ernandojs/vim-header-composer.git +sudo mv vim-header-composer /opt/ +sudo ln -s /opt/vim-header-composer/vhc /usr/local/bin +echo 'map :!vhc' >> ~/.vimrc ``` -# Basic usage +### Makefile +You can also perform installation with `make install`. -``` -1 - Open any file -2 - In normal VIM mode (press ), select the line with SHIT + V -3 - Press and -``` -## Using styles -Instead of using the characters and the standard format you can set the string to process using styles as seen below. -``` -$ echo "vhc:prettybox;Woooow I'm using prettybox!"|vhc +## Basic usage steps -┌─────────────────────────────┐ -│ Woooow I'm using prettybox! │ -└─────────────────────────────┘ +1. Install this script _globally or **not**_; +2. Open any file using **VI/VIM**; +3. In normal VIM mode (press ****); +4. Goto VISUAL mode (select the line - or lines - with **SHIT + V**); +5. Press **** then ****; -$ -``` -### `sides` -`$ echo "vhc:sides;Woooow I'm using sides!"|vhc` produces: -``` -⎡ ⎤ -⎢ Woooow I'm using sides! ⎥ -⎣ ⎦ -``` -### `prettybox` -`$ echo "vhc:prettybox;Woooow I'm using prettybox!"|vhc` produces: -``` +### Using styles +Instead of using the characters and the standard format you can set the string to process using styles as seen below. + + +#### Prettybox +`vhc <<< "vhc:prettybox;Woooow I'm using prettybox!"` produces: +```text ┌─────────────────────────────┐ │ Woooow I'm using prettybox! │ └─────────────────────────────┘ ``` -### `quotes` -`$ echo "vhc:quotes;Woooow I'm using quotes!"|vhc` produces: -``` - " - Woooow I'm using quotes! -" -``` - -### `ccomment` -`$ echo "vhc:ccomment;Woooow I'm using ccomment!"|vhc` produces: -``` -/* -* Woooow I'm using ccomment! -*/ -``` - -### `lcomment` -`$ echo "vhc:lcomment;Woooow I'm using lcomment!"|vhc` produces: -``` -// -// Woooow I'm using lcomment! -// -``` - -### `box` -`$ echo "vhc:box;Woooow I'm using box!"|vhc` produces: -``` -+-----------------------+ -| Woooow I'm using box! | -+-----------------------+ -``` - -### `star`, `stars` or `asterisk` -`$ echo "vhc:stars;Woooow I'm using stars!"|vhc` produces: -``` -*************************** -* Woooow I'm using stars! * -*************************** -``` - -### Standart `ernjs` or `ernando` -`$ echo "vhc:awesome;Woooow I'm using VHC!"|vhc` produces: -``` -############################### -#### Woooow I'm using VHC! #### -############################### -``` +For further information about styles see [more examples](EXAMPLES.md). \ No newline at end of file diff --git a/tests/testing_style_asterisk.sh b/tests/testing_style_asterisk.sh new file mode 100644 index 0000000..1351517 --- /dev/null +++ b/tests/testing_style_asterisk.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:asterisk;Example using 'asterisk'." diff --git a/tests/testing_style_asterisk.sh.result b/tests/testing_style_asterisk.sh.result new file mode 100644 index 0000000..1816011 --- /dev/null +++ b/tests/testing_style_asterisk.sh.result @@ -0,0 +1,3 @@ +***************************** +* Example using 'asterisk'. * +***************************** diff --git a/tests/testing_style_box.sh b/tests/testing_style_box.sh new file mode 100644 index 0000000..0a6b40a --- /dev/null +++ b/tests/testing_style_box.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:box;Example using 'box'." diff --git a/tests/testing_style_box.sh.result b/tests/testing_style_box.sh.result new file mode 100644 index 0000000..eadfb1a --- /dev/null +++ b/tests/testing_style_box.sh.result @@ -0,0 +1,3 @@ ++----------------------+ +| Example using 'box'. | ++----------------------+ diff --git a/tests/testing_style_cccomment.sh b/tests/testing_style_cccomment.sh new file mode 100644 index 0000000..a4b4f34 --- /dev/null +++ b/tests/testing_style_cccomment.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:cccomment;Example using 'cccomment'." diff --git a/tests/testing_style_cccomment.sh.result b/tests/testing_style_cccomment.sh.result new file mode 100644 index 0000000..e2cbaca --- /dev/null +++ b/tests/testing_style_cccomment.sh.result @@ -0,0 +1,3 @@ +/** + ** Example using 'cccomment'. + **/ diff --git a/tests/testing_style_ccomment.sh b/tests/testing_style_ccomment.sh new file mode 100644 index 0000000..57b2d41 --- /dev/null +++ b/tests/testing_style_ccomment.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:ccomment;Example using 'ccomment'." diff --git a/tests/testing_style_ccomment.sh.result b/tests/testing_style_ccomment.sh.result new file mode 100644 index 0000000..9ce2ebc --- /dev/null +++ b/tests/testing_style_ccomment.sh.result @@ -0,0 +1,3 @@ +/* + * Example using 'ccomment'. + */ diff --git a/tests/testing_style_docblock.sh b/tests/testing_style_docblock.sh new file mode 100644 index 0000000..7d991b3 --- /dev/null +++ b/tests/testing_style_docblock.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:docblock;Example using 'docblock'." diff --git a/tests/testing_style_docblock.sh.result b/tests/testing_style_docblock.sh.result new file mode 100644 index 0000000..230b12d --- /dev/null +++ b/tests/testing_style_docblock.sh.result @@ -0,0 +1,3 @@ +/** + * Example using 'docblock'. + **/ diff --git a/tests/testing_style_ernando.sh b/tests/testing_style_ernando.sh new file mode 100644 index 0000000..fcdee27 --- /dev/null +++ b/tests/testing_style_ernando.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:ernando;Example using 'ernando'." diff --git a/tests/testing_style_ernando.sh.result b/tests/testing_style_ernando.sh.result new file mode 100644 index 0000000..ba5c307 --- /dev/null +++ b/tests/testing_style_ernando.sh.result @@ -0,0 +1,3 @@ +################################## +#### Example using 'ernando'. #### +################################## diff --git a/tests/testing_style_ernjs.sh b/tests/testing_style_ernjs.sh new file mode 100644 index 0000000..439055f --- /dev/null +++ b/tests/testing_style_ernjs.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:ernjs;Example using 'ernjs'." diff --git a/tests/testing_style_ernjs.sh.result b/tests/testing_style_ernjs.sh.result new file mode 100644 index 0000000..b74d7ee --- /dev/null +++ b/tests/testing_style_ernjs.sh.result @@ -0,0 +1,3 @@ +################################ +#### Example using 'ernjs'. #### +################################ diff --git a/tests/testing_style_lcomment.sh b/tests/testing_style_lcomment.sh new file mode 100644 index 0000000..4d340d5 --- /dev/null +++ b/tests/testing_style_lcomment.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:lcomment;Example using 'lcomment'." diff --git a/tests/testing_style_lcomment.sh.result b/tests/testing_style_lcomment.sh.result new file mode 100644 index 0000000..cf9f6e3 --- /dev/null +++ b/tests/testing_style_lcomment.sh.result @@ -0,0 +1,3 @@ +// +// Example using 'lcomment'. +// diff --git a/tests/testing_style_pretty.sh b/tests/testing_style_pretty.sh new file mode 100644 index 0000000..286e92e --- /dev/null +++ b/tests/testing_style_pretty.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:pretty;Example using 'pretty'." diff --git a/tests/testing_style_pretty.sh.result b/tests/testing_style_pretty.sh.result new file mode 100644 index 0000000..4d0a6a4 --- /dev/null +++ b/tests/testing_style_pretty.sh.result @@ -0,0 +1,3 @@ +┌─────────────────────────┐ +│ Example using 'pretty'. │ +└─────────────────────────┘ diff --git a/tests/testing_style_prettybox.sh b/tests/testing_style_prettybox.sh new file mode 100644 index 0000000..80981b2 --- /dev/null +++ b/tests/testing_style_prettybox.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:prettybox;Example using 'prettybox'." diff --git a/tests/testing_style_prettybox.sh.result b/tests/testing_style_prettybox.sh.result new file mode 100644 index 0000000..8f5c430 --- /dev/null +++ b/tests/testing_style_prettybox.sh.result @@ -0,0 +1,3 @@ +┌────────────────────────────┐ +│ Example using 'prettybox'. │ +└────────────────────────────┘ diff --git a/tests/testing_style_quotes.sh b/tests/testing_style_quotes.sh new file mode 100644 index 0000000..728f91e --- /dev/null +++ b/tests/testing_style_quotes.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:quotes;Example using 'quotes'." diff --git a/tests/testing_style_quotes.sh.result b/tests/testing_style_quotes.sh.result new file mode 100644 index 0000000..e763f6b --- /dev/null +++ b/tests/testing_style_quotes.sh.result @@ -0,0 +1,3 @@ + " + Example using 'quotes'. +" diff --git a/tests/testing_style_sides.sh b/tests/testing_style_sides.sh new file mode 100644 index 0000000..99f0cd8 --- /dev/null +++ b/tests/testing_style_sides.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:sides;Example using 'sides'." diff --git a/tests/testing_style_sides.sh.result b/tests/testing_style_sides.sh.result new file mode 100644 index 0000000..57684f1 --- /dev/null +++ b/tests/testing_style_sides.sh.result @@ -0,0 +1,3 @@ +⎡ ⎤ +⎢ Example using 'sides'. ⎥ +⎣ ⎦ diff --git a/tests/testing_style_star.sh b/tests/testing_style_star.sh new file mode 100644 index 0000000..39c6418 --- /dev/null +++ b/tests/testing_style_star.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:star;Example using 'star'." diff --git a/tests/testing_style_star.sh.result b/tests/testing_style_star.sh.result new file mode 100644 index 0000000..8fa92a2 --- /dev/null +++ b/tests/testing_style_star.sh.result @@ -0,0 +1,3 @@ +************************* +* Example using 'star'. * +************************* diff --git a/tests/testing_style_stars.sh b/tests/testing_style_stars.sh new file mode 100644 index 0000000..43ad26f --- /dev/null +++ b/tests/testing_style_stars.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./vhc <<< "vhc:stars;Example using 'stars'." diff --git a/tests/testing_style_stars.sh.result b/tests/testing_style_stars.sh.result new file mode 100644 index 0000000..770a987 --- /dev/null +++ b/tests/testing_style_stars.sh.result @@ -0,0 +1,3 @@ +************************** +* Example using 'stars'. * +************************** diff --git a/vhc b/vhc index e0b6278..f677e10 100755 --- a/vhc +++ b/vhc @@ -1,6 +1,4 @@ #!/usr/bin/env bash -# -# wat if we have more than one template? temporary=$(mktemp) || exit 1 _e='echo -e' @@ -8,50 +6,57 @@ option= string= size=0 -function config { - search='s/vhc:([a-zA-Z0-9,]*);(.*)$/' - option=$($_e "$1"|sed -r "${search}"'\1/') - string=$($_e "$1"|sed -r "${search}"'\2/') + + +config() { + search="s/[vhc|λ]+:([a-zA-Z0-9,]*);(.*)\$/""" + option=$($_e "${1}" | sed -r "${search}"'\1/') + string=$($_e "${1}" | sed -r "${search}"'\2/') + strlen=${#string} } -while read -r string -do [[ "${string:0:4}" == "vhc:" ]] && config "${string}" - [[ ${#string} -gt ${size} ]] && size=${#string} - $_e "${string}" >> "${temporary}" +while read -r string +do config """${string}" + $_e """""${string}" >> "${temporary}" + [[ 0 -lt ${strlen} ]] && size=${strlen} done +# OPTIONS case "${option,,}" in - sides) adjust=2; corner=('⎣' '⎦' '⎡' '⎤'); lines=(' ' ' ⎥' ' ' '⎢ ' );; - prettybox) adjust=2; corner=('└' '┘' '┌' '┐'); lines=('─' ' │' '─' '│ ' );; - quotes) adjust=2; corner=('"' ' ' ' ' '"'); lines=(' ' ' ' ' ' ' ' );; - ccomment) adjust=2; corner=(' */' ' ' '/*' ' '); lines=(' ' ' ' ' ' ' * ');; - lcomment) adjust=2; corner=('//' ' ' '//' ' '); lines=(' ' ' ' ' ' '// ');; - box) adjust=2; corner=('+' '+' '+' '+'); lines=('-' ' |' '-' '| ' );; - star|stars|asterisk) adjust=2; corner=('*' '*' '*' '*'); lines=('*' ' *' '*' '* ' );; - ernjs|ernando|*) adjust=8; corner=('#' '#' '#' '#'); lines=('#' ' ####' '#' '#### ') + sides) adjust=2; corner=('⎣' '⎦' '⎡' '⎤'); lines=(' ' ' ⎥' ' ' '⎢ ' );; + prettybox|pretty) adjust=2; corner=('└' '┘' '┌' '┐'); lines=('─' ' │' '─' '│ ' );; + quotes) adjust=2; corner=('"' ' ' ' ' '"'); lines=(' ' ' ' ' ' ' ' );; + docblock) adjust=2; corner=(' **/' ' ' '/**' ' '); lines=(' ' ' ' ' ' ' * ' );; + cccomment) adjust=2; corner=(' **/' ' ' '/**' ' '); lines=(' ' ' ' ' ' ' ** ' );; + ccomment) adjust=2; corner=(' */' ' ' '/*' ' '); lines=(' ' ' ' ' ' ' * ' );; + lcomment) adjust=2; corner=('//' ' ' '//' ' '); lines=(' ' ' ' ' ' '// ' );; + box) adjust=2; corner=('+' '+' '+' '+'); lines=('-' ' |' '-' '| ' );; + star|stars|asterisk) adjust=2; corner=('*' '*' '*' '*'); lines=('*' ' *' '*' '* ' );; + ernjs|ernando|*) adjust=8; corner=('#' '#' '#' '#'); lines=('#' ' ####' '#' '#### ') esac +#/OPTIONS -function str_repeat { - n=$1 - while [[ $n -gt 0 ]] - do $_e -n "$2" - n=$(( n - 1 )) +str_repeat() { + n="${1}" + while [[ ${n} -gt 0 ]] + do $_e -n "${2}" + n=$(( n - 1 )) done } -function line { +line() { [ $# -eq 1 ] \ - && str_repeat "$((size + adjust))" "$1" \ - && exit + && str_repeat "$((size + adjust))" "${1}" \ + && exit - $_e "${corner[$1]}$(line "${lines[$1]}")${corner[$2]}" + $_e "${corner[${1}]}$(line "${lines[${1}]}")${corner[${2}]}" } -function line_top { +line_top() { line 0 1 } -function line_bottom { +line_bottom() { line 2 3 } @@ -59,7 +64,7 @@ trap line_top \ EXIT; line_bottom while read -r string -do spacing=$(printf '%*s' $((size - ${#string}))) - $_e "${lines[3]}${string}${spacing}${lines[1]}" +do tab=$(printf '%*s' $((size - ${#string})) "") + $_e "${lines[3]}${string}${tab}${lines[1]}" done < "${temporary}" rm "${temporary}"