Skip to content

Commit

Permalink
v5.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Jun 30, 2021
1 parent 2304a94 commit ad46e27
Show file tree
Hide file tree
Showing 28 changed files with 374 additions and 193 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"printf",
"proto",
"quickstart",
"readarray",
"renice",
"retval",
"rwin",
Expand All @@ -64,6 +65,7 @@
"tnum",
"tprintf",
"tput",
"treadarray",
"ttput",
"uarr",
"uname",
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Change Log

## 5.?.?
## 5.5.1

- `build.go` now generates `COMMANDS.md` as well.
- Fixed #34 (Argument parsing for switches may result in infinite loop)
- Fixed #34 (Argument parsing for switches may result in infinite loop).
- Numerous bug fixed in `fn`s.

## 5.5.0

Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ Sometimes doing a job takes more than a `snippet`. `Shellman` has ready to use f

### Latest release Notes

## 5.5.0

- `process Name by ID`: Get process name by it's ID(s).
- Fixed #28 (COMMANDS.md links not working).
- Added animation examples for pendular mode.
- Fixed #29 (thanks to @rwin-novo).
- Fixed #30 and #32 (thanks to @jsbrain).
- Code section removed from `COMMANDS.md`.
## 5.5.1

- `build.go` now generates `COMMANDS.md` as well.
- Fixed #34 (Argument parsing for switches may result in infinite loop).
- Numerous bug fixed in `fn`s.
8 changes: 4 additions & 4 deletions nsroot/fn-fx/fn-animate.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"",
"\t((lastIndex=\\${#frames[@]} - 1))",
"\tlocal mode=\\${frames[lastIndex]}",
"\tunset frames[lastIndex]",
"\tunset \"frames[lastIndex]\"",
"",
"\t((lastIndex=\\${#frames[@]} - 1))",
"\tlocal interval=\\${frames[lastIndex]}",
"\tunset frames[lastIndex]",
"\tunset \"frames[lastIndex]\"",
"",
"\t# Comment out next two lines if you are using CTRL+C event handler.",
"${1:\ttrap 'tput cnorm; echo' EXIT\n\ttrap 'exit 127' HUP INT TERM}\n",
Expand All @@ -25,8 +25,8 @@
"\tmax=\"\\${#frames[@]}\"",
"\tindices=()",
"\tdirection=\"forward\"",
"\tforwardIndices=( \\$(seq 0 1 \"\\${max}\") )",
"\tbackwardIndices=( \\$(seq \"\\${max}\" -1 0) )",
"\treadarray -t forwardIndices < <(seq 0 1 \"\\${max}\")",
"\treadarray -t backwardIndices < <(seq \"\\${max}\" -1 0)",
"",
"\twhile true; do",
"\t\tif [ \"\\${mode}\" = \"circular\" ]; then",
Expand Down
3 changes: 2 additions & 1 deletion nsroot/fn-fx/fn-banner-color.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"\t\t;;",
"\tesac\n",
"\tlocal msg=\"\\${3\\} \\${1\\} \\${3\\}\"",
"\tlocal edge=\\$(echo \"\\${msg}\" | sed \"s/./\\${3}/g\")",
"\tlocal edge",
"\tedge=\\${msg\/\/?\/\\$3\\}",
"\ttput setaf \\${color\\}",
"\ttput bold",
"\techo \"\\${edge}\"",
Expand Down
3 changes: 2 additions & 1 deletion nsroot/fn-fx/fn-banner-simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"# Usage: bannerSimple \"my title\" \"*\"",
"function bannerSimple() {",
"\tlocal msg=\"\\${2\\} \\${1\\} \\${2\\}\"",
"\tlocal edge=\\$(echo \"\\${msg\\}\" | sed \"s/./\"\\${2}\"/g\")",
"\tlocal edge",
"\tedge=\\${msg\/\/?\/\\$2\\}",
"\techo \"\\${edge\\}\"",
"\techo \"\\$(tput bold)\\${msg\\}\\$(tput sgr0)\"",
"\techo \"\\${edge\\}\"",
Expand Down
19 changes: 10 additions & 9 deletions nsroot/fn-fx/fn-input-choice.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@
"# Usage: options=(\"one\" \"two\" \"three\"); inputChoice \"Choose:\" 1 \"\\${options[@]}\"; choice=\\$?; echo \"\\${options[\\$choice]}\"",
"function inputChoice() {",
"\techo \"\\${1\\}\"; shift",
"\techo \\$(tput dim)-\"Change option: [up/down], Select: [ENTER]\" \\$(tput sgr0)",
"\techo \"\\$(tput dim)\"\"- Change option: [up/down], Select: [ENTER]\" \"\\$(tput sgr0)\"",
"\tlocal selected=\"\\${1\\}\"; shift\n",
"\tESC=\\$(echo -e \"\\033\")",
"\tcursor_blink_on() { tput cnorm; }",
"\tcursor_blink_off() { tput civis; }",
"\tcursor_to() { tput cup \\$((\\$1-1)); }",
"\tprint_option() { echo \\$(tput sgr0) \"\\$1\" \\$(tput sgr0); }",
"\tprint_selected() { echo \\$(tput rev) \"\\$1\" \\$(tput sgr0); }",
"\tget_cursor_row() { IFS=';' read -sdR -p \\$'\\E[6n' ROW COL; echo \\${ROW#*[}; }",
"\tkey_input() { read -s -n3 key 2>/dev/null >&2; [[ \\$key = \\$ESC[A ]] && echo up; [[ \\$key = \\$ESC[B ]] && echo down; [[ \\$key = \"\" ]] && echo enter; }\n",
"\tprint_option() { echo \"\\$(tput sgr0)\" \"\\$1\" \"\\$(tput sgr0)\"; }",
"\tprint_selected() { echo \"\\$(tput rev)\" \"\\$1\" \"\\$(tput sgr0)\"; }",
"\tget_cursor_row() { IFS=';' read -rsdR -p \\$'\\E[6n' ROW COL; echo \"\\${ROW#*[}\"; }",
"\tkey_input() { read -rs -n3 key 2>/dev/null >&2; [[ \\$key = \\${ESC}[A ]] && echo up; [[ \\$key = \\${ESC}[B ]] && echo down; [[ \\$key = \"\" ]] && echo enter; }\n",
"\tfor opt; do echo; done\n",
"\tlocal lastrow=\\$(get_cursor_row)",
"\tlocal startrow=\\$((\\$lastrow - \\$#))",
"\tlocal lastrow",
"\tlastrow=\\$(get_cursor_row)",
"\tlocal startrow=\\$((lastrow - \\$#))",
"\ttrap \"cursor_blink_on; echo; echo; exit\" 2",
"\tcursor_blink_off\n",
"\t: selected:=0\n",
"\twhile true; do",
"\t\tlocal idx=0",
"\t\tfor opt; do",
"\t\t\tcursor_to \\$((\\$startrow + \\$idx))",
"\t\t\tif [ \\${idx\\} -eq \\${selected\\} ]; then",
"\t\t\tcursor_to \\$((startrow + idx))",
"\t\t\tif [ \\${idx\\} -eq \"\\${selected\\}\" ]; then",
"\t\t\t\tprint_selected \"\\${opt\\}\"",
"\t\t\telse",
"\t\t\t\tprint_option \"\\${opt\\}\"",
Expand Down
34 changes: 17 additions & 17 deletions nsroot/fn-fx/fn-input-multi-choice.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
"body": [
"# Usage: multiChoice \"header message\" resultArray \"comma separated options\" \"comma separated default values\"",
"# Credit: https://serverfault.com/a/949806",
"# TODO: 1) Refactoring to return result array 2) Get input options as array",
"function multiChoice {",
"\techo \"\\${1\\}\"; shift",
"\techo \\$(tput dim)-\"Change Option: [up/down], Change Selection: [space], Done: [ENTER]\" \\$(tput sgr0)",
"\techo \"\\$(tput dim)\"\"- Change Option: [up/down], Change Selection: [space], Done: [ENTER]\" \"\\$(tput sgr0)\"",
"\t# little helpers for terminal print control and key input",
"\tESC=\\$( printf \"\\033\")",
"\tcursor_blink_on() { printf \"\\$ESC[?25h\"; }",
"\tcursor_blink_off() { printf \"\\$ESC[?25l\"; }",
"\tcursor_to() { printf \"\\$ESC[\\$1;\\${2:-1}H\"; }",
"\tprint_inactive() { printf \"\\$2 \\$1 \"; }",
"\tprint_active() { printf \"\\$2 \\$ESC[7m \\$1 \\$ESC[27m\"; }",
"\tget_cursor_row() { IFS=';' read -sdR -p \\$'\\E[6n' ROW COL; echo \\${ROW#*[}; }",
"\tcursor_blink_on() { printf \"%s\" \"\\${ESC}[?25h\"; }",
"\tcursor_blink_off() { printf \"%s\" \"\\${ESC}[?25l\"; }",
"\tcursor_to() { printf \"%s\" \"\\${ESC}[\\$1;\\${2:-1}H\"; }",
"\tprint_inactive() { printf \"%s %s \" \"\\$2\" \"\\$1\"; }",
"\tprint_active() { printf \"%s \\${ESC}[7m \\$1 \\${ESC}[27m\" \"\\$2\"; }",
"\tget_cursor_row() { IFS=';' read -rsdR -p \\$'\\E[6n' ROW COL; echo \"\\${ROW#*[}\"; }",
"\tkey_input() {",
"\t\tlocal key",
"\t\tIFS= read -rsn1 key 2>/dev/null >&2",
Expand All @@ -38,7 +37,7 @@
"\t\telse",
"\t\t\tarr[option]=1",
"\t\tfi",
"\t\teval \\$arr_name='(\"\\${arr[@]}\")'",
"\t\teval \"\\$arr_name\"='(\"\\${arr[@]}\")'",
"\t}",
"",
"\tlocal retval=\\$1",
Expand All @@ -60,8 +59,9 @@
"\tdone",
"",
"\t# determine current screen position for overwriting the options",
"\tlocal lastrow=\\$(get_cursor_row)",
"\tlocal startrow=\\$((\\$lastrow - \\${#options[@]}))",
"\tlocal lastrow",
"\tlastrow=\\$(get_cursor_row)",
"\tlocal startrow=\\$((lastrow - \\${#options[@]}))",
"",
"\t# ensure cursor and input echoing back on upon a ctrl+c during read -s",
"\ttrap \"cursor_blink_on; stty echo; printf '\\n'; exit\" 2",
Expand All @@ -77,7 +77,7 @@
"\t\t\t\tprefix=\"[x]\"",
"\t\t\tfi",
"",
"\t\t\tcursor_to \\$((\\$startrow + \\$idx))",
"\t\t\tcursor_to \\$((startrow + idx))",
"\t\t\tif [ \\$idx -eq \\$active ]; then",
"\t\t\t\tprint_active \"\\$option\" \"\\$prefix\"",
"\t\t\telse",
Expand All @@ -93,24 +93,24 @@
"\t\t\tup) ((active--));",
"\t\t\t\tif [ \\$active -lt 0 ]; then active=\\$((\\${#options[@]} - 1)); fi;;",
"\t\t\tdown) ((active++));",
"\t\t\t\tif [ \\$active -ge \\${#options[@]} ]; then active=0; fi;;",
"\t\t\t\tif [ \"\\$active\" -ge \\${#options[@]} ]; then active=0; fi;;",
"\t\tesac",
"\tdone",
"",
"\t# cursor position back to normal",
"\tcursor_to \\$lastrow",
"\tcursor_to \"\\$lastrow\"",
"\tprintf \"\\n\"",
"\tcursor_blink_on",
"",
"\tindices=()",
"\tfor((i=0;i<\\${#selected[@]};i++)); do",
"\t\tif ((\\${selected[i]} == 1)); then",
"\t\t\tindices+=(\\${i})",
"\t\tif ((selected[i] == 1)); then",
"\t\t\tindices+=(\"\\${i}\")",
"\t\tfi",
"\tdone",
"",
"\t# eval \\$retval='(\"\\${selected[@]}\")'",
"\teval \\$retval='(\"\\${indices[@]}\")'",
"\teval \"\\$retval\"='(\"\\${indices[@]}\")'",
"}\n"
],
"description": "provides a list of choices to user and returns the index of selected choices"
Expand Down
2 changes: 1 addition & 1 deletion nsroot/fn-fx/fn-math-average.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"# Usage: average int1 int2 ...",
"function average () {",
"\tlocal sum=0",
"\tfor int in \\$@; do",
"\tfor int in \"\\$@\"; do",
"\t\t((sum += int))",
"\tdone",
"\techo \\$((sum / \\$#))",
Expand Down
2 changes: 1 addition & 1 deletion nsroot/fn-fx/fn-math-fibonacci.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"fibonacci ()",
"{",
"\tif ((\\$1 < 2)); then ",
"\t\techo \\$1",
"\t\techo \"\\$1\"",
"\telse",
"\t\techo \\$((\\$(fibonacci \\$((\\$1 - 1))) + \\$(fibonacci \\$((\\$1 - 2)))))",
"\tfi",
Expand Down
2 changes: 1 addition & 1 deletion nsroot/fn-fx/fx-math-average.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"prefix": "fx math average",
"body": [
"# Usage: average int1 int2 ...",
"result=\\$(average \\${${1:int1}\\} \\${${2:int2}\\} \\${${3:int3}\\})\n"
"result=\\$(average \"\\${${1:int1}\\}\" \"\\${${2:int2}\\}\" \"\\${${3:int3}\\}\")\n"
],
"description": "call math average function"
}
3 changes: 2 additions & 1 deletion nsroot/fn-fx/fx-math-factorial.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"prefix": "fx math factorial",
"body": [
"# Usage: factorial n",
"result=\\$(factorial ${1:n})\n"
"readarray -t result < <(factorial ${1:n})",
"echo \"\\${result[@]\\}\"\n"
],
"description": "calculate n!"
}
2 changes: 1 addition & 1 deletion nsroot/fn-fx/fx-math-fibonacci-series.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"prefix": "fx math fibonacci series",
"body": [
"# Usage: fibonacciSeries n",
"${1:result}=(\\$(fibonacciSeries ${2:n}))",
"readarray -t ${1:result} < <(fibonacciSeries ${2:n})",
"echo \"\\${${1}[@]}\"\n"
],
"description": "array of fibonacci series"
Expand Down
2 changes: 1 addition & 1 deletion nsroot/output/color-black.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "color black",
"body": "echo \\$(tput setaf 0)\"${1:black text}\"\\$(tput sgr0)\n",
"body": "echo \"\\$(tput setaf 0)\"${1:black text}\"\\$(tput sgr0)\"\n",
"description": "write in black"
}
2 changes: 1 addition & 1 deletion nsroot/output/color-blue.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "color blue",
"body": "echo \\$(tput setaf 4)\"${1:blue text}\"\\$(tput sgr0)\n",
"body": "echo \"\\$(tput setaf 4)\"${1:blue text}\"\\$(tput sgr0)\"\n",
"description": "write in blue"
}
2 changes: 1 addition & 1 deletion nsroot/output/color-cyan.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "color cyan",
"body": "echo \\$(tput setaf 6)\"${1:cyan text}\"\\$(tput sgr0)\n",
"body": "echo \"\\$(tput setaf 6)\"${1:cyan text}\"\\$(tput sgr0)\"\n",
"description": "write in cyan"
}
2 changes: 1 addition & 1 deletion nsroot/output/color-green.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "color green",
"body": "echo \\$(tput setaf 2)\"${1:green text}\"\\$(tput sgr0)\n",
"body": "echo \"\\$(tput setaf 2)\"${1:green text}\"\\$(tput sgr0)\"\n",
"description": "write in green"
}
2 changes: 1 addition & 1 deletion nsroot/output/color-magenta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "color magenta",
"body": "echo \\$(tput setaf 5)\"${1:magenta text}\"\\$(tput sgr0)\n",
"body": "echo \"\\$(tput setaf 5)\"${1:magenta text}\"\\$(tput sgr0)\"\n",
"description": "write in magenta"
}
2 changes: 1 addition & 1 deletion nsroot/output/color-red.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "color red",
"body": "echo \\$(tput setaf 1)\"${1:red text}\"\\$(tput sgr0)\n",
"body": "echo \"\\$(tput setaf 1)\"${1:red text}\"\\$(tput sgr0)\"\n",
"description": "write in red"
}
2 changes: 1 addition & 1 deletion nsroot/output/color-white.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "color white",
"body": "echo \\$(tput setaf 7)\"${1:white text}\"\\$(tput sgr0)\n",
"body": "echo \"\\$(tput setaf 7)\"${1:white text}\"\\$(tput sgr0)\"\n",
"description": "write in white"
}
2 changes: 1 addition & 1 deletion nsroot/output/color-yellow.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "color yellow",
"body": "echo \\$(tput setaf 3)\"${1:yellow text}\"\\$(tput sgr0)\n",
"body": "echo \"\\$(tput setaf 3)\"${1:yellow text}\"\\$(tput sgr0)\"\n",
"description": "write in yellow"
}
2 changes: 1 addition & 1 deletion nsroot/output/format-bold.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "format bold",
"body": "echo \\$(tput bold)\"${1:bold text}\"\\$(tput sgr0)\n",
"body": "echo \"\\$(tput bold)\"${1:bold text}\"\\$(tput sgr0)\"\n",
"description": "write in bold"
}
2 changes: 1 addition & 1 deletion nsroot/output/format-dim.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "format dim",
"body": "echo \\$(tput dim)\"${1:dimmed text}\"\\$(tput sgr0)\n",
"body": "echo \"\\$(tput dim)\"${1:dimmed text}\"\\$(tput sgr0)\"\n",
"description": "write in dim"
}
2 changes: 1 addition & 1 deletion nsroot/output/format-italic.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "format italic",
"body": "echo \\$(tput sitm)\"${1:italic text}\"\\$(tput sgr0)\n",
"body": "echo \"\\$(tput sitm)\"${1:italic text}\"\\$(tput sgr0)\"\n",
"description": "write in italic"
}
2 changes: 1 addition & 1 deletion nsroot/output/format-reverse.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "format reverse",
"body": "echo \\$(tput rev)\"${1:reversed text}\"\\$(tput sgr0)\n",
"body": "echo \"\\$(tput rev)\"${1:reversed text}\"\\$(tput sgr0)\"\n",
"description": "write in reverse"
}
Loading

0 comments on commit ad46e27

Please sign in to comment.