| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,41 @@ |
| 1 |
+__prompt_time_dir='' |
|
| 2 |
+[ -d "$__prompt_time_dir" ] || __prompt_time_dir="${XDG_RUNTIME_DIR:-"/var/run/user/$(id -u)"}"
|
|
| 3 |
+[ -d "$__prompt_time_dir" ] || __prompt_time_dir="${XDG_CACHE_HOME:-"$HOME/.cache"}"
|
|
| 4 |
+ |
|
| 5 |
+__prompt_time_file="$__prompt_time_dir/prompt_time/$$" |
|
| 6 |
+ |
|
| 7 |
+mkdir -p "$(dirname "$__prompt_time_file")" |
|
| 8 |
+ |
|
| 9 |
+__prompt_time_start() |
|
| 10 |
+{
|
|
| 11 |
+ date '+%s' >| "$__prompt_time_file" |
|
| 12 |
+} |
|
| 13 |
+ |
|
| 14 |
+__prompt_time_stop() |
|
| 15 |
+{
|
|
| 16 |
+ [ -r "$__prompt_time_file" ] || return 0 |
|
| 17 |
+ __prompt_time="$(("$(date '+%s')" - "$(cat "$__prompt_time_file")"))"
|
|
| 18 |
+ rm "$__prompt_time_file" |
|
| 19 |
+ [ "$__prompt_time" -gt 0 ] || return 0 |
|
| 20 |
+ __prompt_time_d="$((__prompt_time / (24*60*60)))" |
|
| 21 |
+ __prompt_time_h="$((__prompt_time % (24*60*60) / (60*60)))" |
|
| 22 |
+ __prompt_time_m="$((__prompt_time % (60*60) / (60)))" |
|
| 23 |
+ __prompt_time_s="$((__prompt_time % (60)))" |
|
| 24 |
+ __prompt_time_d="$([ "$__prompt_time_d" -eq 0 ] || printf '%02dd' "$__prompt_time_d")" |
|
| 25 |
+ __prompt_time_h="$([ "$__prompt_time_h" -eq 0 ] || printf '%02dh' "$__prompt_time_h")" |
|
| 26 |
+ __prompt_time_m="$([ "$__prompt_time_m" -eq 0 ] || printf '%02dm' "$__prompt_time_m")" |
|
| 27 |
+ __prompt_time_s="$([ "$__prompt_time_s" -eq 0 ] || printf '%02ds' "$__prompt_time_s")" |
|
| 28 |
+ printf '%s' \ |
|
| 29 |
+ "$__prompt_time_d" \ |
|
| 30 |
+ "$__prompt_time_h" \ |
|
| 31 |
+ "$__prompt_time_m" \ |
|
| 32 |
+ "$__prompt_time_s" |
|
| 33 |
+} |
|
| 34 |
+ |
|
| 35 |
+__prompt_time() |
|
| 36 |
+{
|
|
| 37 |
+ if [ "$2" ] |
|
| 38 |
+ then |
|
| 39 |
+ printf "$1" "$2" |
|
| 40 |
+ fi |
|
| 41 |
+} |