File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -111,6 +111,15 @@ builds:
111111 - amd64
112112 - arm
113113 - arm64
114+ -
115+ id : " get-epochtime"
116+ main : ./cmd/get-epochtime
117+ binary : bin/resh-get-epochtime
118+ goarch :
119+ - 386
120+ - amd64
121+ - arm
122+ - arm64
114123
115124# signs:
116125# - artifacts: checksum
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ GOFLAGS=-ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.de
77
88build : submodules bin/resh-session-init bin/resh-collect bin/resh-postcollect\
99 bin/resh-daemon bin/resh-control bin/resh-config bin/resh-cli\
10- bin/resh-install-utils bin/resh-generate-uuid
10+ bin/resh-install-utils bin/resh-generate-uuid bin/resh-get-epochtime
1111
1212install : build
1313 scripts/install.sh
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "time"
6+ )
7+
8+ // Small utility to get epochtime in millisecond precision
9+ // Doesn't check arguments
10+ // Exits with status 1 on error
11+ func main () {
12+ fmt .Printf ("%s" , timeToEpochTime (time .Now ()))
13+ }
14+
15+ func timeToEpochTime (t time.Time ) string {
16+ return fmt .Sprintf ("%.2f" , float64 (t .UnixMilli ())/ 1000 )
17+ }
Original file line number Diff line number Diff line change @@ -20,8 +20,7 @@ __resh_collect() {
2020 local __RESH_SHLVL=" $SHLVL "
2121 local __RESH_GIT_REMOTE; __RESH_GIT_REMOTE=" $( git remote get-url origin 2> /dev/null) "
2222
23- # __RESH_RT_BEFORE="$EPOCHREALTIME"
24- __RESH_RT_BEFORE=$( __resh_get_epochrealtime)
23+ __RESH_RT_BEFORE=$( resh-get-epochtime)
2524
2625 if [ " $__RESH_VERSION " != " $( resh-collect -version) " ]; then
2726 # shellcheck source=shellrc.sh
@@ -61,7 +60,7 @@ __resh_precmd() {
6160 local __RESH_EXIT_CODE=$?
6261 local __RESH_RT_AFTER
6362 local __RESH_SHLVL=" $SHLVL "
64- __RESH_RT_AFTER=$( __resh_get_epochrealtime )
63+ __RESH_RT_AFTER=$( resh-get-epochtime )
6564 if [ -n " ${__RESH_COLLECT} " ]; then
6665 if [ " $__RESH_VERSION " != " $( resh-postcollect -version) " ]; then
6766 # shellcheck source=shellrc.sh
Original file line number Diff line number Diff line change 22
33# util.sh - resh utility functions
44
5- __resh_get_pid () {
6- if [ -n " ${ZSH_VERSION-} " ]; then
7- # assume Zsh
8- local __RESH_PID=" $$ " # current pid
9- elif [ -n " ${BASH_VERSION-} " ]; then
10- # assume Bash
11- if [ " ${BASH_VERSINFO[0]} " -ge " 4" ]; then
12- # $BASHPID is only available in bash4+
13- # $$ is fairly similar so it should not be an issue
14- local __RESH_PID=" $BASHPID " # current pid
15- else
16- local __RESH_PID=" $$ " # current pid
17- fi
18- fi
19- echo " $__RESH_PID "
20- }
21-
22- __resh_get_epochrealtime () {
23- if date +%s.%N | grep -vq ' N' ; then
24- # GNU date
25- date +%s.%N
26- elif gdate --version > /dev/null && gdate +%s.%N | grep -vq ' N' ; then
27- # GNU date take 2
28- gdate +%s.%N
29- elif [ -n " ${ZSH_VERSION-} " ]; then
30- # zsh fallback using $EPOCHREALTIME
31- if [ -z " ${__RESH_ZSH_LOADED_DATETIME+x} " ]; then
32- zmodload zsh/datetime
33- __RESH_ZSH_LOADED_DATETIME=1
34- fi
35- echo " $EPOCHREALTIME "
36- else
37- # dumb date
38- # XXX: we lost precison beyond seconds
39- date +%s
40- if [ -z " ${__RESH_DATE_WARN+x} " ]; then
41- echo " resh WARN: can't get precise time - consider installing GNU date!"
42- __RESH_DATE_WARN=1
43- fi
44- fi
45- }
46-
475# FIXME: figure out if stdout/stderr should be discarded
486__resh_run_daemon () {
497 if [ -n " ${ZSH_VERSION-} " ]; then
You can’t perform that action at this time.
0 commit comments