Added: Possibilty to run date through background fifo for bash <5
							parent
							
								
									1692f22fd9
								
							
						
					
					
						commit
						576c391575
					
				
							
								
								
									
										36
									
								
								bashtop
								
								
								
								
							
							
						
						
									
										36
									
								
								bashtop
								
								
								
								
							|  | @ -200,16 +200,36 @@ if [[ -n $EPOCHREALTIME ]]; then | |||
| 		ms_out=$((${EPOCHREALTIME/[.,]/}/1000)) | ||||
| 	} | ||||
| 
 | ||||
| #* If not, use date command | ||||
| #* If not, use date command, through fifo if possible | ||||
| else | ||||
| 	get_ms() { #? Set given variable to current epoch millisecond with date command | ||||
| 		local count | ||||
| 		local -n ms_out=$1 | ||||
| 		ms_out="" | ||||
| 		while [[ -z $ms_out ]] && ((++count<=10)); do | ||||
| 	tmpdir="" | ||||
| 	if [[ -n $XDG_RUNTIME_DIR && -w "$XDG_RUNTIME_DIR" ]]; then  | ||||
| 		tmpdir="$XDG_RUNTIME_DIR" | ||||
| 	elif [[ -w /dev/shm ]]; then  | ||||
| 		tmpdir="/dev/shm" | ||||
| 	elif [[ -w /tmp ]]; then  | ||||
| 		tmpdir="/tmp" | ||||
| 	fi | ||||
| 
 | ||||
| 	if [[ -n $tmpdir ]] && command -v stdbuf >/dev/null 2>&1; then | ||||
| 		mkfifo "${tmpdir}/bashtop_datefifo" | ||||
| 		exec 5> >(exec stdbuf -o0 date -f - +%s%3N > "${tmpdir}/bashtop_datefifo" 2>&1) | ||||
| 		exec 6< "${tmpdir}/bashtop_datefifo" | ||||
| 		rm  "${tmpdir}/bashtop_datefifo" | ||||
| 		 | ||||
| 		get_ms() { #? Set given variable to current epoch millisecond with date command through background fifo | ||||
| 			local -n ms_out=$1 | ||||
|      		echo now >&5 && | ||||
|         	read -u 6 ms_out  | ||||
| 		} | ||||
| 
 | ||||
| 	else | ||||
| 		get_ms() { #? Set given variable to current epoch millisecond with forked date command | ||||
| 			local -n ms_out=$1 | ||||
| 			ms_out="" | ||||
| 			read ms_out < <(date +%s%3N) | ||||
| 		done | ||||
| 	} | ||||
| 		} | ||||
| 	fi | ||||
| fi | ||||
| 
 | ||||
| init_() { #? Collect needed information and set options before startig main loop | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 aristocratos
						aristocratos