File tree Expand file tree Collapse file tree 5 files changed +29
-46
lines changed Expand file tree Collapse file tree 5 files changed +29
-46
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,15 @@ builds:
111
111
- amd64
112
112
- arm
113
113
- 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
114
123
115
124
# signs:
116
125
# - 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
7
7
8
8
build : submodules bin/resh-session-init bin/resh-collect bin/resh-postcollect\
9
9
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
11
11
12
12
install : build
13
13
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() {
20
20
local __RESH_SHLVL=" $SHLVL "
21
21
local __RESH_GIT_REMOTE; __RESH_GIT_REMOTE=" $( git remote get-url origin 2> /dev/null) "
22
22
23
- # __RESH_RT_BEFORE="$EPOCHREALTIME"
24
- __RESH_RT_BEFORE=$( __resh_get_epochrealtime)
23
+ __RESH_RT_BEFORE=$( resh-get-epochtime)
25
24
26
25
if [ " $__RESH_VERSION " != " $( resh-collect -version) " ]; then
27
26
# shellcheck source=shellrc.sh
@@ -61,7 +60,7 @@ __resh_precmd() {
61
60
local __RESH_EXIT_CODE=$?
62
61
local __RESH_RT_AFTER
63
62
local __RESH_SHLVL=" $SHLVL "
64
- __RESH_RT_AFTER=$( __resh_get_epochrealtime )
63
+ __RESH_RT_AFTER=$( resh-get-epochtime )
65
64
if [ -n " ${__RESH_COLLECT} " ]; then
66
65
if [ " $__RESH_VERSION " != " $( resh-postcollect -version) " ]; then
67
66
# shellcheck source=shellrc.sh
Original file line number Diff line number Diff line change 2
2
3
3
# util.sh - resh utility functions
4
4
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
-
47
5
# FIXME: figure out if stdout/stderr should be discarded
48
6
__resh_run_daemon () {
49
7
if [ -n " ${ZSH_VERSION-} " ]; then
You can’t perform that action at this time.
0 commit comments