Skip to content

Commit

Permalink
v5.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Jul 5, 2021
1 parent ad46e27 commit f2851c8
Show file tree
Hide file tree
Showing 51 changed files with 191 additions and 162 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"semvers",
"setaf",
"shasum",
"shellcheck",
"shellman",
"sitm",
"somefile",
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 5.6.0

- `shellcheck` compatible (99.99%).
- Added `array print` snippet.

## 5.5.1

- `build.go` now generates `COMMANDS.md` as well.
Expand Down
22 changes: 8 additions & 14 deletions COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

- [array length](#array-length)

- [array print , echo array](#array-print-,-echo-array)

- [array push , array add](#array-push-,-array-add)

- [array slice , array range](#array-slice-,-array-range)
Expand Down Expand Up @@ -144,8 +146,6 @@

- [remove old/new files/directories](#remove-old/new-files/directories)

- [remove old files](#remove-old-files)

### float

- [if float = , if double =](#if-float-=-,-if-double-=)
Expand Down Expand Up @@ -258,7 +258,7 @@

- [function , func](#function-,-func)

- [function return value , func return value](#function-return-value-,-func-return-value)
- [function return value , func return value , func ret val](#function-return-value-,-func-return-value-,-func-ret-val)

### git

Expand Down Expand Up @@ -436,8 +436,6 @@

- [argument parsing , parse args](#argument-parsing-,-parse-args)

- [echo array](#echo-array)

- [echo text , print text](#echo-text-,-print-text)

- [echo variable , print variable](#echo-variable-,-print-variable)
Expand Down Expand Up @@ -646,6 +644,10 @@ iterate array elements [↑](#Commands)

length of an array [↑](#Commands)

## array print , echo array

iterate array elements [↑](#Commands)

## array push , array add

push new item to the end of array [↑](#Commands)
Expand Down Expand Up @@ -842,10 +844,6 @@ if path exists (file, directory, link...) [↑](#Commands)

find and remove files(f)/directories(d) older(+)/newer(-) than x days [↑](#Commands)

## remove old files

find and remove files older than x days [↑](#Commands)

## if float = , if double =

if numbers are equal [↑](#Commands)
Expand Down Expand Up @@ -1054,7 +1052,7 @@ number of function arguments [↑](#Commands)

function [↑](#Commands)

## function return value , func return value
## function return value , func return value , func ret val

last function/command return code [↑](#Commands)

Expand Down Expand Up @@ -1378,10 +1376,6 @@ define animation frame [↑](#Commands)

parse command line arguments (flags/switches) [↑](#Commands)

## echo array

print array elements [↑](#Commands)

## echo text , print text

print text, variable or both [↑](#Commands)
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ Sometimes doing a job takes more than a `snippet`. `Shellman` has ready to use f

### Latest release Notes

## 5.5.1
## 5.6.0

- `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.
- `shellcheck` compatible (99.99%).
- Added `array print` snippet.
2 changes: 1 addition & 1 deletion nsroot/array/contains.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"prefix": "array contains",
"body": [
"if [[ \"\\${${1:myArray}[@]}\" =~ ${2|'element',\"${value}\"|} ]]; then",
"if [[ \"\\${${1:myArray}[*]}\" =~ ${2|'element',\"${value}\"|} ]]; then",
"\techo 'array contains element'",
"fi\n"
],
Expand Down
2 changes: 1 addition & 1 deletion nsroot/array/delete-at.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "array delete at",
"body": "unset ${1:myArray}[${2:index}]\n",
"body": "unset \"${1:myArray}[${2:index}]\"\n",
"description": "delete element at index from array"
}
2 changes: 1 addition & 1 deletion nsroot/array/filter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "array filter",
"body": "${1:filtered}=(\\$(for i in ${${2:myArray}[@]} ; do echo \\${i\\}; done | grep ${3|',\"|}${4:pattern}${3}))\n",
"body": "readarray -t ${1:filtered} < <(for i in \"${${2:myArray}[@]}\" ; do echo \"\\${i\\}\"; done | grep ${3|',\"|}${4:pattern}${3})\n",
"description": "filter elements of an array based on given grep pattern"
}
8 changes: 8 additions & 0 deletions nsroot/array/print.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"prefix": [
"array print",
"echo array"
],
"body": "echo \"\\${${1:myArray}[@]}\"\n",
"description": "iterate array elements"
}
2 changes: 1 addition & 1 deletion nsroot/array/range.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"array slice",
"array range"
],
"body": "${1:newArray}=\"${${2:myArray}[@]:${3:fromIndex}:${4:n}}\"\n",
"body": "${1:newArray}=\"${${2:myArray}[*]:${3:fromIndex}:${4:n}}\"\n",
"description": "n elements of an array from specified index (zero based)"
}
2 changes: 1 addition & 1 deletion nsroot/array/replace.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "array replace",
"body": "${1:newArray}=${${2:myArray}[@]//${3:find}/${4:replace}}\n",
"body": "${1:newArray}=${${2:myArray}[*]//${3:find}/${4:replace}}\n",
"description": "find and replace elements in array using regex"
}
10 changes: 9 additions & 1 deletion nsroot/array/reverse.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"prefix": "array reverse",
"body": "${1:reversedArray}=( \\$(echo \"\\${${2:array}[@]}\" | rev) )\n",
"body": [
"for((i=\\${#${1:myArray}[@]}-1;i>=0;i--)); do",
"\t${2:reversed}+=(\"\\${${1:myArray}[i]}\")",
"done",
"",
"unset \"${1:myArray}\" # optional",
"echo \"\\${${2:reversed}[@]}\"",
""
],
"description": "reverse order of array elements"
}
6 changes: 4 additions & 2 deletions nsroot/command/failure-check.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"cmd failure check"
],
"body": [
"if (( \\$? != 0 )); then",
"\t${1:echo \"Last command failed\"}",
"if ! ${1:command} >/dev/null 2>&1; then",
"\techo \"failed\"",
"else",
"\techo \"succeed\"",
"fi\n"
],
"description": "check if last command failed"
Expand Down
2 changes: 1 addition & 1 deletion nsroot/command/if-exists.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"if cmd exists"
],
"body": [
"if [ \\$(command -v ${1:command}) ]; then",
"if [ \"\\$(command -v ${1:command})\" ]; then",
"\t${2:echo \"command \\\"${1:command}\\\" exists on system\"}",
"fi\n"
],
Expand Down
6 changes: 4 additions & 2 deletions nsroot/command/success-check.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"cmd success check"
],
"body": [
"if (( \\$? == 0 )); then",
"\t${1:echo \"Last command succeed\"}",
"if ${1:command} >/dev/null 2>&1; then",
"\techo \"succeed\"",
"else",
"\techo \"failed\"",
"fi\n"
],
"description": "check if last command succeed"
Expand Down
6 changes: 3 additions & 3 deletions nsroot/filesystem/file-read.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"prefix": "file read",
"body": [
"cat \"${1|/path/to/file,${filePath}|}\" | while read ${2:line}; do",
"\t${3:echo \"\\${${2:line}\\}\"}",
"done\n"
"while IFS= read -r line; do",
"\techo \"\\$line\"",
"done < ${1|/path/ro/file,\"${inputFile}\"|}\n"
],
"description": "read a file"
}
5 changes: 3 additions & 2 deletions nsroot/filesystem/file-write.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"prefix": "file write",
"body": [
"echo \"${1:sample header}\" > \"${2|/path/to/file,${pathToFile}|}\"",
"for ${3:line} in \\${${4:lines}[@]}; do",
"\techo \"\\${${3:line}\\}\" >> \"${2}\"",
"echo # Empty line",
"for ${3:line} in \"\\${${4:lines}[@]}\"; do",
"\techo \"\\${${3:line}\\}\" >> \"${2}\" # >> means append",
"done\n"
],
"description": "write to a file"
Expand Down
4 changes: 2 additions & 2 deletions nsroot/filesystem/files-iterate.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"prefix": "iterate files",
"body": [
"# Make sure path ends with /",
"for file in ${1|'/path/to/files/',\"${pathToFiles}\"|}*.{jpg,png\\}; do",
"# Searching in the current directory",
"for file in ${1|*,*.{jpg\\,png}|}; do",
"\t${2:echo \"\\${file\\}\"}",
"done\n"
],
Expand Down
2 changes: 1 addition & 1 deletion nsroot/filesystem/find-files-or-directories.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"file find",
"directory find"
],
"body": "${1:resultArray}=(\\$(find \"${2|/path/to/search,${pathToSearch}|}\" -maxdepth ${3|1,2,3,4,5,6,7,8,9|} -type ${4|f,d|} -name \"${5:criteria}\"))\n",
"body": "readarray -t resultArray < <(find \"/path/to/search\" -maxdepth 1 -type f -name \"criteria\")\n",
"description": "find files (-type f) or directories (-type d) by name or pattern (*.jpg)"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prefix": "remove old/new files/directories",
"body": "find \"${1|/path/to/directory/,${pathToDirectory}|}\"* -type ${2|f,d|} -mtime ${3|-,+|}${4:days} | xargs rm -f\n",
"body": "find \"${1|/path/to/directory/,${pathToDirectory}|}\"* -type ${2|f,d|} -mtime ${3|-,+|}${4:days} -delete\n",
"description": "find and remove files(f)/directories(d) older(+)/newer(-) than x days"
}
5 changes: 0 additions & 5 deletions nsroot/filesystem/remove-files-older-than.json

This file was deleted.

4 changes: 2 additions & 2 deletions nsroot/fn-fx/fn-math-product.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"# Usage: product int1 int2 ...",
"function product () {",
"\tlocal result=1",
"\tfor int in $@; do",
"\tfor int in \"$@\"; do",
"\t\t((result *= int))",
"\tdone",
"\techo \\${result\\}",
"\techo \"\\${result\\}\"",
"}\n"
],
"description": "calculate product of given integers"
Expand Down
4 changes: 2 additions & 2 deletions nsroot/fn-fx/fn-math-sum.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"# Usage: sum int1 int2 ...",
"function sum () {",
"\tlocal result=0",
"\tfor int in \\$@; do",
"\tfor int in \"\\$@\"; do",
"\t\t((result += int))",
"\tdone",
"\techo \\${result\\}",
"\techo \"\\${result\\}\"",
"}\n"
],
"description": "calculate sum of given integers"
Expand Down
4 changes: 2 additions & 2 deletions nsroot/fn-fx/fn-progress.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"# Usage: progressBar \"message\" currentStep totalSteps",
"function progressBar() {",
"\tlocal bar='████████████████████'",
"\tlocal space=' '",
"\tlocal space='....................'",
"\tlocal wheel=('\\' '|' '/' '-')",
"",
"\tlocal msg=\"\\${1\\}\"",
Expand All @@ -14,7 +14,7 @@
"\tlocal position=\\$((100 * current / total))",
"\tlocal barPosition=\\$((position / 5))",
"",
"\techo -ne \"\\r|\\${bar:0:\\$barPosition}\\${space:\\$barPosition:20}| \\${wheel[wheelIndex]} \\${position}% [ \\${msg} ] \"",
"\techo -ne \"\\r|\\${bar:0:\\$barPosition}\\$(tput dim)\\${space:\\$barPosition:20}\\$(tput sgr0)| \\${wheel[wheelIndex]} \\${position}% [ \\${msg} ] \"",
"}\n"
],
"description": "progress bar function"
Expand Down
2 changes: 1 addition & 1 deletion nsroot/fn-fx/fn-scan.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"function scan () {",
"\tlocal openPortsArray=()",
"\tfor ((port=\\${3\\}; port<=\\${4\\}; port++)); do",
"\t\t(echo >/dev/\\${1\\}/\\${2\\}/\\${port\\}) >/dev/null 2>&1 && openPortsArray+=(\"\\${port}\")",
"\t\t(echo >/dev/\"\\${1\\}\"/\"\\${2\\}\"/\"\\${port\\}\") >/dev/null 2>&1 && openPortsArray+=(\"\\${port}\")",
"\tdone",
"\techo \"\\${openPortsArray[@]}\"",
"}\n"
Expand Down
8 changes: 4 additions & 4 deletions nsroot/fn-fx/fn-time-format-seconds.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"\tlocal S=\\$((T%60))",
"\tlocal result=\"\"",
"",
"\t(( \\$D > 0 )) && result=\"\\${D}d \"",
"\t(( \\$H > 0 )) && result=\"\\${result}\\${H}h \"",
"\t(( \\$M > 0 )) && result=\"\\${result}\\${M}m \"",
"\t(( \\$S > 0 )) && result=\"\\${result}\\${S}s \"",
"\t(( D > 0 )) && result=\"\\${D}d \"",
"\t(( H > 0 )) && result=\"\\${result}\\${H}h \"",
"\t(( M > 0 )) && result=\"\\${result}\\${M}m \"",
"\t(( S > 0 )) && result=\"\\${result}\\${S}s \"",
"\techo -e \"\\${result}\" | sed -e 's/[[:space:]]*\\$//'",
"}\n"
],
Expand Down
2 changes: 1 addition & 1 deletion nsroot/fn-fx/fn-urlencode.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"\tfor (( i = 0; i < length; i++ )); do",
"\t\tlocal c=\"\\${1:i:1}\"",
"\t\tcase \"\\${c\\}\" in",
"\t\t\t[a-zA-Z0-9.~_-]) printf \"\\${c\\}\" ;;",
"\t\t\t[a-zA-Z0-9.~_-]) printf \"%s\" \"\\${c\\}\" ;;",
"\t\t\t*) printf '%%%02X' \"'\\${c\\}\" ;;",
"\t\tesac",
"\tdone",
Expand Down
17 changes: 10 additions & 7 deletions nsroot/fn-fx/fn-version-compare.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"# Usage: versionCompare \"1.2.3\" \"1.1.7\"",
"function versionCompare () {",
"\tfunction subVersion () {",
"\t\ttemp=${1%%\".\"*} && indexOf=\\$(echo ${1%%\".\"*} | echo ${#temp})",
"\t\techo -e \"\\${1:0:indexOf}\"",
"\t\techo -e \"\\${1%%\".\"*}\"",
"\t}",
"\tfunction cutDot () {",
"\t\tlocal offset=${#1}",
Expand All @@ -18,16 +17,20 @@
"\tif [ -z \"\\${1\\}\" ] || [ -z \"\\${2\\}\" ]; then",
"\t\techo \"=\" && exit 0",
"\tfi",
"\tlocal v1=\\$(echo -e \"\\${1}\" | tr -d '[[:space:]]')",
"\tlocal v2=\\$(echo -e \"\\${2}\" | tr -d '[[:space:]]')",
"\tlocal v1Sub=\\$(subVersion \\$v1)",
"\tlocal v2Sub=\\$(subVersion \\$v2)",
"\tlocal v1",
"\tv1=\\$(echo -e \"\\${1}\" | tr -d '[:space:]')",
"\tlocal v2",
"\tv2=\\$(echo -e \"\\${2}\" | tr -d '[:space:]')",
"\tlocal v1Sub",
"\tv1Sub=\\$(subVersion \"\\$v1\")",
"\tlocal v2Sub",
"\tv2Sub=\\$(subVersion \"\\$v2\")",
"\tif (( v1Sub > v2Sub )); then",
"\t\techo \">\"",
"\telif (( v1Sub < v2Sub )); then",
"\t\techo \"<\"",
"\telse",
"\t\tversionCompare \\$(cutDot \\$v1Sub \\$v1) \\$(cutDot \\$v2Sub \\$v2)",
"\t\tversionCompare \"\\$(cutDot \"\\$v1Sub\" \"\\$v1\")\" \"\\$(cutDot \"\\$v2Sub\" \"\\$v2\")\"",
"\tfi",
"}\n"
],
Expand Down
2 changes: 1 addition & 1 deletion nsroot/fn-fx/fx-progress.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"",
"for ((${3:currentStep}=${4:1}; ${3} <= ${1}; ${3}++)); do",
"\tsleep 0.1 # simulating one step of job",
"\tprogressBar \"Installing foo...\" \\${${3}\\} \\${${1}\\}",
"\tprogressBar \"Installing foo...\" \"\\${${3}\\}\" \"\\${${1}\\}\"",
"done\n",
"echo\n"
],
Expand Down
Loading

0 comments on commit f2851c8

Please sign in to comment.