oh-my-bash/lib/spinner.sh
Toan Nguyen 53fb803740
OMB - Major Refactor (#39)
* OMB - Major Refactor

- Aliases and completions now works like plugins (need to enabled in .bashrc)
- Removed the compatible check in spectrum.sh, OMB now works with Bash v3.x like the old days.
- Removed core plugin, added those bash functions into base.sh and load during startup.
- Updated OSH template for new installations
- Added history config and few other stuff from #17

@TODO: Added a shell script to update old version of .bashrc to new one.

* Fixed ShellCheck issues

* Fixed ShellCheck issues
2019-01-23 03:05:32 -08:00

47 lines
921 B
Bash

#!/usr/bin/env bash
#
# Move a process to background and track its progress in a smoothier way.
# Could be use if $TERM not set.
#
# Examples
#
# echo -ne "${fg[red]}I am running..."
# ( my_long_task_running ) &
# spinner
# echo -ne "...${reset_color} ${fg[green]}DONE${reset_color}"
#
# This spinner is used when there is a terminal.
term_spinner() {
local pid=$!
local delay=0.1
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
no_term_spinner() {
local pid=$!
local delay=0.1
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
printf "."
sleep 2
done
echo " ✓ "
}
spinner() {
if [[ -z "$TERM" ]]; then
no_term_spinner
else
term_spinner
fi
}