Skip to content

Commit

Permalink
Throbber & Spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
JV-conseil committed Jan 26, 2024
1 parent 651ebce commit 206d7cd
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions bash.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,26 @@ title: Bash
<!-- omit in toc -->
## Table of Content

- [Create Symbolic Links πŸ”—](#create-symbolic-links-)
- [Extract a substring from a string](#extract-a-substring-from-a-string)
- [Extract a value from a file](#extract-a-value-from-a-file)
- [Read a JSON stream](#read-a-json-stream)
- [Create Symbolic Links πŸ”—](#create-symbolic-links-)
- [Padding characters with printf](#padding-characters-with-printf)
- [Read a JSON stream](#read-a-json-stream)
- [Throbber \& Spinner](#throbber--spinner)
- [Tools for Shell Script Development βš™οΈ](#tools-for-shell-script-development-️)
- [Features πŸ”Ž](#features-)
- [Coding Guidelines, Style, Linter ✍️](#coding-guidelines-style-linter-️)

## Create Symbolic Links πŸ”—

`ln` is a command-line utility for creating links between files. By default, the ln command creates hard links. To create a symbolic link, use the -s (--symbolic) option.

The ln command syntax for creating symbolic links is as follows: `ln -s [OPTIONS] FILE LINK`

e.g.: `ln -s source_file symbolic_link`

_src πŸ‘‰ [Create Symbolic Links](https://linuxize.com/post/how-to-create-symbolic-links-in-linux-using-the-ln-command/#how-to-use-the-ln-command)_

## Extract a substring from a string

With `grep -Eo` and a [regex](https://regex101.com/library/wUcSv4) pattern
Expand Down Expand Up @@ -92,6 +103,12 @@ will output
https://github.com/JV-conseil/docs
```

## Padding characters with printf

`printf '%0.1s' "."{0..10}` will output `...........`

_src πŸ‘‰ [Padding characters in printf](https://stackoverflow.com/a/4410103/2477854) and [printf syntax](https://www.warp.dev/terminus/bash-printf)_

## Read a JSON stream

With `jq`
Expand Down Expand Up @@ -120,21 +137,42 @@ will output

_src πŸ‘‰ [jq/manual](https://stedolan.github.io/jq/manual/)_

## Create Symbolic Links πŸ”—
## Throbber & Spinner

`ln` is a command-line utility for creating links between files. By default, the ln command creates hard links. To create a symbolic link, use the -s (--symbolic) option.
> A throbber, also known as a loading icon, is an animated graphical control element used to show that a computer program is performing an action in background β€” [wikipedia](https://en.wikipedia.org/wiki/Throbber)
The ln command syntax for creating symbolic links is as follows: `ln -s [OPTIONS] FILE LINK`
```bash
# Usage: throbber & my_long_process ; kill %-1
throbber() {
printf "Please wait..."
while true; do
printf "."
sleep .3
done
}
```

e.g.: `ln -s source_file symbolic_link`
Add a display to let user wait in bash

_src πŸ‘‰ [Create Symbolic Links](https://linuxize.com/post/how-to-create-symbolic-links-in-linux-using-the-ln-command/#how-to-use-the-ln-command)_
- `kill %-1` will kill the n-1'th backgrounded process

## Padding characters with printf
```bash
throbber &
sleep 10
kill %-1
```

`printf '%0.1s' "."{0..10}` will output `...........`
will output

_src πŸ‘‰ [Padding characters in printf](https://stackoverflow.com/a/4410103/2477854) and [printf syntax](https://www.warp.dev/terminus/bash-printf)_
`Please wait.............`

Spinner alternative

```bash
alias spinner='while :; do for s in / - \\ \|; do printf "\n$s"; sleep .1; done; done'
```

_src πŸ‘‰ [How to kill the (last - 1) PID](https://unix.stackexchange.com/a/75685/473393) and [How to Write Better Bash Spinners](https://willcarh.art/blog/how-to-write-better-bash-spinners)_

## Tools for Shell Script Development βš™οΈ

Expand Down

0 comments on commit 206d7cd

Please sign in to comment.