Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
2.0 KiB
Markdown
Raw Permalink Normal View History

# Using the Progress Bar Script
2024-04-19 01:25:29 -04:00
## Description
2024-04-19 01:25:29 -04:00
This script provides a simple progress bar TUI for the terminal platform. It allows you to visualize the progress of a task being executed in your shell script.
## Usage
2024-04-19 01:25:29 -04:00
You can use the function `progress` from the interactive settings with Oh My
Bash. The function handles printing of the progress bar.
2024-04-19 01:25:29 -04:00
1. **Enable plugin:**
2024-04-19 01:25:29 -04:00
- Add the plugin name `progress` in the `plugins` array in `~/.bashrc`.
2024-04-19 01:25:29 -04:00
```shell
# bashrc
2024-04-19 01:25:29 -04:00
plugins=(... progress)
```
2024-04-19 01:25:29 -04:00
2. **Invoke `progress` Function:**
- Within a shell function, call the `progress` function whenever you want to display the progress bar.
2024-04-19 01:25:29 -04:00
- Pass two parameters to the `progress` function:
- `PARAM_PROGRESS`: The progress percentage (0-100) of the task.
- `PARAM_STATUS`: Optional. A status message to display alongside the progress bar.
```bash
# Example usage:
progress 25 "Processing data..." # Displays a 25% progress bar with the status "Processing data..."
```
To change the delay of the progress bar, please overwrite the `delay` function.
```bash
# Example: change the delay to 0.1 sec
function delay { sleep 0.1; }
```
_⚠ if you want to add only the plugin and not Oh My Bash, you can copy the file
`progress.plugin.sh` to a place you like and source it in `~/.basrhc` (for
interactive uses) or in a shell script (for a standalone shell program). You
may instead copy and paste the functions directly into a script file, in which
case the plugin will not receive updates and possible errors will have to be
solved by you_
2024-04-19 01:25:29 -04:00
## Example
```bash
# bashrc
2024-04-19 01:25:29 -04:00
function example {
# Example: Your code for the shell function here: Invoke the progress
# function to display the progress bar as your function progresses. This
# displays a 25% progress bar with the status "Processing data...":
progress 25 "Processing data..."
2024-04-19 01:25:29 -04:00
```
This will visually represent the progress of your function's execution in the
terminal. Adjust the `progress` function calls according to the progress of
your task.