@@ -277,47 +277,6 @@ box[double_right_corner_down]="╝"
277
277
box[double_title_left]=" ╟"
278
278
box[double_title_right]=" ╢"
279
279
280
- # * If using bash version 5, set timestamps with EPOCHREALTIME variable
281
- if [[ -n $EPOCHREALTIME ]]; then
282
- get_ms () { # ? Set given variable to current epoch millisecond with EPOCHREALTIME varialble
283
- local -n ms_out=$1
284
- ms_out=$(( ${EPOCHREALTIME/ [.,]/ } / 1000 ))
285
- }
286
-
287
- # * If not, use date command, through fifo if possible
288
- else
289
- tmpdir=" "
290
- if [[ -n $XDG_RUNTIME_DIR && -w " $XDG_RUNTIME_DIR " ]]; then
291
- tmpdir=" $XDG_RUNTIME_DIR "
292
- elif [[ -w /dev/shm ]]; then
293
- tmpdir=" /dev/shm"
294
- elif [[ -w /tmp ]]; then
295
- tmpdir=" /tmp"
296
- elif [[ -w " $HOME " ]]; then
297
- tmpdir=" $HOME "
298
- fi
299
-
300
- if [[ -n $tmpdir ]] && command -v ${stdbuf} > /dev/null 2>&1 ; then
301
- ${mkfifo} " ${tmpdir} /bashtop_datefifo"
302
- exec 5> >( exec ${stdbuf} -o0 ${date} -f - +%s%3N > " ${tmpdir} /bashtop_datefifo" 2>&1 )
303
- exec 6< " ${tmpdir} /bashtop_datefifo"
304
- ${rm} -f " ${tmpdir} /bashtop_datefifo"
305
-
306
- get_ms () { # ? Set given variable to current epoch millisecond with date command through background fifo
307
- local -n ms_out=$1
308
- echo now >&5 &&
309
- read -u 6 ms_out
310
- }
311
-
312
- else
313
- get_ms () { # ? Set given variable to current epoch millisecond with forked date command
314
- local -n ms_out=$1
315
- ms_out=" "
316
- read ms_out < <( ${date} +%s%3N)
317
- }
318
- fi
319
- fi
320
-
321
280
init_ () { # ? Collect needed information and set options before startig main loop
322
281
if [[ -z $1 ]]; then
323
282
local i stx=0
@@ -4801,8 +4760,28 @@ if [[ $use_psutil == true ]]; then
4801
4760
fi
4802
4761
fi
4803
4762
4804
- # * if we have been sourced by another shell, quit. Allows sourcing only function definition.
4805
- [[ " ${# BASH_SOURCE[@]} " -gt 1 ]] && { return 0; }
4763
+ # * If using bash version 5, set timestamps with EPOCHREALTIME variable
4764
+ if [[ -n $EPOCHREALTIME ]]; then
4765
+ get_ms () { # ? Set given variable to current epoch millisecond with EPOCHREALTIME varialble
4766
+ local -n ms_out=$1
4767
+ ms_out=$(( ${EPOCHREALTIME/ [.,]/ } / 1000 ))
4768
+ }
4769
+
4770
+ # * If not, but using psutil, set timestamps with python
4771
+ elif [[ $use_psutil == true ]]; then
4772
+ get_ms () {
4773
+ local -n ms_out=$1
4774
+ py_command -v ms_out " get_ms()"
4775
+ }
4776
+
4777
+ # * Else use date command
4778
+ else
4779
+ get_ms () { # ? Set given variable to current epoch millisecond with date command
4780
+ local -n ms_out=$1
4781
+ ms_out=" "
4782
+ read ms_out < <( ${date} +%s%3N)
4783
+ }
4784
+ fi
4806
4785
4807
4786
# * Setup psutil script
4808
4787
if [[ $use_psutil == true ]]; then
@@ -4870,7 +4849,8 @@ allowed_commands: Tuple[str] = (
4870
4849
'get_net',
4871
4850
'get_cmd_out',
4872
4851
'get_sensors',
4873
- 'get_sensors_check'
4852
+ 'get_sensors_check',
4853
+ 'get_ms'
4874
4854
)
4875
4855
command: str = ''
4876
4856
cpu_count: int = psutil.cpu_count()
@@ -4884,6 +4864,11 @@ def get_cmd_out(cmd: str):
4884
4864
'''Save bash the trouble of creating child processes by running through python instead'''
4885
4865
print(subprocess.check_output(cmd, shell=True, universal_newlines=True).rstrip())
4886
4866
4867
+ def get_ms():
4868
+ '''Get current epoch millisecond'''
4869
+ t = str(time.time()).split(".")
4870
+ print(f'{t[0]}{t[1][:3]}')
4871
+
4887
4872
def get_sensors():
4888
4873
'''A clone of "sensors" but using psutil'''
4889
4874
temps = psutil.sensors_temperatures()
@@ -5266,6 +5251,9 @@ else
5266
5251
exec 2> /dev/null
5267
5252
fi
5268
5253
5254
+ # * If we have been sourced by another shell, quit. Allows sourcing only function definition.
5255
+ [[ " ${# BASH_SOURCE[@]} " -gt 1 ]] && { return 0; }
5256
+
5269
5257
# * Call init function
5270
5258
init_
5271
5259
0 commit comments