+count_jobs() {
+ # Desc: Count and return total number of jobs
+ # Usage: count_jobs
+ # Input: None.
+ # Output: stdout integer number of jobs
+ # Depends: Bash 5.1.16
+ # Example: while [[$(count_jobs) -gt 0]]; do echo "Working..."; sleep 1; done;
+ # Version: 0.0.1
+
+ local job_count;
+ job_count="$(jobs -r | wc -l | tr -d ' ' )";
+ #yell "DEBUG:job_count:$job_count";
+ if [[ -z $job_count ]]; then job_count="0"; fi;
+ echo "$job_count";
+}; # Return number of background jobs
+wait_for_jobslot() {
+ # Desc: Does not return until count_jobs() falls below $max_job_count
+ # Input: var max_job_count
+ # Output: return code 0
+ # Depends: count_jobs(), yell();
+ while [[ $(count_jobs) -ge $max_job_count ]]; do
+ printf "\r%d:Working..." "$SECONDS";
+ sleep 1;
+ done;
+ return 0;
+};