Skip to content

Commit

Permalink
v5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Mar 18, 2021
1 parent 5d3a4e0 commit 4a2d8e8
Show file tree
Hide file tree
Showing 24 changed files with 392 additions and 303 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"gitignore",
"icanhazip",
"ifconfig",
"imagemagick",
"ipecho",
"ipify",
"ipinfo",
Expand All @@ -35,6 +36,7 @@
"maxdepth",
"meminfo",
"mobi",
"multichoice",
"multiline",
"mylib",
"notpushed",
Expand Down
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# Change Log

## 5.1.0

- Smooth percentage for `fn progress`.
- `echo text` and `echo variable` snippet added.
- assign variable value via `variable assign` | `variable set` snippet.
- `iterate files` snippet for iterating specific file extensions inside a path.
- read/expand variable value via `var` | `variable read` | `variable expand` snippet.

Now there is a `input` namespace for getting user input:

- `input text`: formerly `ask question`.
- `input password`: don't show input on screen.
- `fn/fx input choice`: formerly `fn/fx options`.

## 5.0.0

- Default command substitution to `$(command)`.
- Default variable expansion to `"${variable}"`.
- Unified `TAB` ordering.
- Unified <kbd>TAB</kbd> ordering.
- Some functions and snippets enhanced.
- Descriptive aliases added to some snippets.

Expand Down
139 changes: 102 additions & 37 deletions COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@

- [file write](#file-write)

- [iterate files](#iterate-files)

- [file find](#file-find)

- [if directory exists](#if-directory-exists)
Expand Down Expand Up @@ -140,10 +142,10 @@

- [fn banner simple](#fn-banner-simple)

- [fn options](#fn-options)

- [fn import](#fn-import)

- [fn options](#fn-options)

- [fn math average](#fn-math-average)

- [fn math product](#fn-math-product)
Expand All @@ -168,10 +170,10 @@

- [fx banner simple](#fx-banner-simple)

- [fx options](#fx-options)

- [fx import](#fx-import)

- [fx options](#fx-options)

- [fx math average](#fx-math-average)

- [fx math product](#fx-math-product)
Expand Down Expand Up @@ -276,6 +278,8 @@

- input

- [input password](#input-password)

- [input text](#input-text)

- integer
Expand Down Expand Up @@ -380,6 +384,10 @@

- [argument parsing](#argument-parsing)

- [echo text](#echo-text)

- [echo variable](#echo-variable)

- [region](#region)

- [shebang](#shebang)
Expand Down Expand Up @@ -508,8 +516,12 @@

- variable

- [variable assign](#variable-assign)

- [variable default value](#variable-default-value)

- [var](#var)

## `archive compress tar.gz`

compress file/folder to a .tar.gz file [&uarr;](#Commands)
Expand Down Expand Up @@ -910,6 +922,16 @@ for line in ${lines[@]}; do
done
```

## `iterate files`

write to a file [&uarr;](#Commands)

```bash
for file in ${1|'/path/to/files/',"${pathToFiles}"|}*.{jpg,png\}; do
echo "${file\"}
done
```

## `file find,directory find`

find files (-type f) or directories (-type d) by name or pattern (*.jpg) [&uarr;](#Commands)
Expand Down Expand Up @@ -1155,13 +1177,30 @@ function bannerSimple() {
}
```

## `fn import`

import functions from other shellscript files [&uarr;](#Commands)

```bash
# Usage: import "mylib"
function import() {
local file="./lib/${1\}.sh"
if [ -f "${file\}" ]; then
source "${file\}"
else
echo "Error: Cannot find library at: ${file\}"
exit 1
fi
}
```

## `fn options,fn input choice`

provide a list of options to user and return the index of selected option [&uarr;](#Commands)

```bash
# Usage: options=("one" "two" "three"); chooseOption "Choose:" 1 "${options[@]}"; choice=$?; echo "${options[$choice]}"
function chooseOption() {
# Usage: options=("one" "two" "three"); inputChoice "Choose:" 1 "${options[@]}"; choice=$?; echo "${options[$choice]}"
function inputChoice() {
echo "${1\}"; shift
echo $(tput dim)-"Change selection: [up/down], Select: [ENTER]" $(tput sgr0)
local selected="${1\}"; shift
Expand Down Expand Up @@ -1203,23 +1242,6 @@ function chooseOption() {
}
```

## `fn import`

import functions from other shellscript files [&uarr;](#Commands)

```bash
# Usage: import "mylib"
function import() {
local file="./lib/${1\}.sh"
if [ -f "${file\}" ]; then
source "${file\}"
else
echo "Error: Cannot find library at: ${file\}"
exit 1
fi
}
```

## `fn math average`

calculate average of given integers [&uarr;](#Commands)
Expand Down Expand Up @@ -1280,9 +1302,10 @@ function progressBar() {
local current=${2\}
local total=${3\}
local wheelIndex=$((current % 4))
local position=$((20 * current / total))
local position=$((100 * current / total))
local barPosition=$((position / 5))

echo -ne "\r|${bar:0:$position}${space:$position:20}| ${wheel[wheelIndex]} $(($position*5))% [ ${msg} ] "
echo -ne "\r|${bar:0:$barPosition}${space:$barPosition:20}| ${wheel[wheelIndex]} ${position}% [ ${msg} ] "
}
```

Expand Down Expand Up @@ -1403,24 +1426,24 @@ call bannerSimple function [&uarr;](#Commands)
bannerSimple "my title" "${2|*,:,+,.,x,o,$|}"
```

## `fx options,fn input choice`
## `fx import`

call options function [&uarr;](#Commands)
import functions from other shellscript files located in a directory (default: lib) relative to current file [&uarr;](#Commands)

```bash
# Usage: options=("one" "two" "three"); chooseOption "Choose:" 1 "${options[@]}"; choice=$?; echo "${options[$choice]}"
options=(${2:"one" "two" "three"})
chooseOption "Choose:" ${4|0,1,2,3,4,5,6,7,8,9|} "${${1}[@]}"; choice=$?
echo "${${1}[$choice]}" selected
# Usage: import "filename"
import "libname"
```

## `fx import`
## `fx options,fx input choice`

import functions from other shellscript files located in a directory (default: lib) relative to current file [&uarr;](#Commands)
call options function [&uarr;](#Commands)

```bash
# Usage: import "filename"
import "libname"
# Usage: options=("one" "two" "three"); inputChoice "Choose:" 1 "${options[@]}"; choice=$?; echo "${options[$choice]}"
options=(${2:"one" "two" "three"})
inputChoice "Choose:" ${4|0,1,2,3,4,5,6,7,8,9|} "${${1}[@]}"; choice=$?
echo "${${1}[$choice]}" selected
```

## `fx math average`
Expand Down Expand Up @@ -1834,9 +1857,19 @@ curl --request ${1|POST,PUT|} -sL \
--data ${4|'key=value',"${key}"="${value}"|}
```

## `input password`

get text as input from user without showing characters [&uarr;](#Commands)

```bash
echo "Please enter your password: "
read -s password
echo "${password\"}
```

## `input text,ask question`

ask question with default answer [&uarr;](#Commands)
get text as input from user [&uarr;](#Commands)

```bash
read -ep "Question here? " -i "Default answer" answer
Expand Down Expand Up @@ -2231,7 +2264,7 @@ result=$((min + RANDOM % $((max-min))))
square root of var up to scale decimal places [&uarr;](#Commands)

```bash
result=$(echo "scale=${2|0,1,2,3,4,5,6,7,8,9|};sqrt(${num\})" | bc)
result=$(echo "scale=${2|0,1,2,3,4,5,6,7,8,9|};sqrt(${3|num,${num}|})" | bc)
```

## `math -`
Expand Down Expand Up @@ -2279,6 +2312,22 @@ done
set -- "${POSITIONAL[@]}" # restore positional params
```

## `echo text,print text`

print text, variable or both [&uarr;](#Commands)

```bash
echo 'text here'
```

## `echo variable,print variable`

print text, variable or both [&uarr;](#Commands)

```bash
echo "${variable\}"
```

## `region,section`

comment out a special region (i.e. variable declarations) [&uarr;](#Commands)
Expand Down Expand Up @@ -2785,10 +2834,26 @@ timeNowUTC=$(date -u +%R)
echo ${${1\}}
```

## `variable assign,variable set`

assign a value or another variable to a new variable [&uarr;](#Commands)

```bash
variable=${2|'value',"${anotherVariable}"|}
```

## `variable default value,assign if empty`

assign default value to variable if variable is empty otherwise assign null [&uarr;](#Commands)

```bash
: "${variable:=defaultValue}"
```

## `var,variable read,variable expand`

read the value of a variable [&uarr;](#Commands)

```bash
"${variable\}"
```
Loading

0 comments on commit 4a2d8e8

Please sign in to comment.