this post was submitted on 27 Dec 2025
52 points (96.4% liked)

Linux

60459 readers
652 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 6 years ago
MODERATORS
 

Paste this into Bash:

get_screen_time() {
since=${1:-today}
until_opt=${2:+--until "$2"}

journalctl --output json -u systemd-logind --since "$since" $until_opt | \
jq -r 'select(.MESSAGE_ID and .__REALTIME_TIMESTAMP) |
if (.MESSAGE | test("Lid opened|Starting systemd-logind|Operation .suspend. finished")) then
  .__REALTIME_TIMESTAMP + " start"
elif (.MESSAGE | test("Lid closed|Stopping systemd-logind|system will suspend")) then
  .__REALTIME_TIMESTAMP + " stop"
else
  empty
end' | \
awk -v current_time=$(date +%s%6N) '
{
    if ($2 == "start") {
        last_start = $1
    } else if ($2 == "stop" && last_start != 0) {
        total += ($1 - last_start) / 1000000
        last_start = 0
    }
}
END {
    if (last_start != 0) {
        total += (current_time - last_start) / 1000000
    }
    seconds = int(total)
    hours = int(seconds/3600)
    minutes = int((seconds%3600)/60)
    printf "%02d:%02d", hours, minutes
}'
}
PS1='$(get_screen_time) '$PS1

Now you have screen time for today in your prompt:

00:21 user@asus:~/Documents$ 
00:21 user@asus:~/Documents$ cd ../Pictures/
00:21 user@asus:~/Pictures$

Cool?

you are viewing a single comment's thread
view the rest of the comments
[–] Sanguine@lemmy.dbzer0.com 2 points 1 day ago (2 children)

Yawn. Oh no youre using a different init than I would have preferred 🥺🥺🥺😣😭

This is what I picture everytime someone complains about systemd.

Systemd is great and at this point y'all just like being contrarian.

[–] MonkderVierte@lemmy.zip 6 points 1 day ago* (last edited 23 hours ago) (2 children)

Stop complaining. I just mentioned the requirement because you didn't.

There's a whole cross-compatible command called ~~uptime~~last, you know?

[–] Sanguine@lemmy.dbzer0.com 1 points 3 hours ago

You right I was being mean, sorry.

[–] floquant@lemmy.dbzer0.com 4 points 23 hours ago (1 children)

Does uptime count or skip the time a system is in suspend? On mobile, can't check man

[–] MonkderVierte@lemmy.zip 0 points 23 hours ago* (last edited 22 hours ago)

What, the logind thing?

[–] etsy@hexbear.net 4 points 1 day ago