Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(uptime): replace plugin with sed #163

Merged
merged 2 commits into from
Mar 22, 2024
Merged

Conversation

vdbe
Copy link
Collaborator

@vdbe vdbe commented Mar 16, 2024

The uptime plugin has some issue with minute formatting.

The sed command is based on https://stackoverflow.com/a/28353785.

$ bash uptimes
03:14:20 up 1 min,  2 users,  load average: 2.28, 1.29, 0.50
         new: 1m
         old: 1 min
04:12:29 up 59 min,  5 users,  load average: 0.06, 0.08, 0.48
         new: 59m
         old: 59 min
05:14:09 up  2:01,  5 users,  load average: 0.13, 0.10, 0.45
         new: 2h 01m
         old: 2h 01m
03:13:19 up 1 day, 0 min,  8 users,  load average: 0.01, 0.04, 0.05
         new: 1d 0m
         old: 1d 0 min
04:13:19 up 1 day,  1:00,  8 users,  load average: 0.02, 0.05, 0.21
         new: 1d 1h 00m
         old: 1d 1h 00m
12:49:10 up 25 days, 21:30, 28 users,  load average: 0.50, 0.66, 0.52
         new: 25d 21h 30m
         old: 25d 21h 30m
$ cat uptimes.sh 
#!/usr/bin/env bash

while read line; do
    echo "$line"
    echo -en "\t new: "
    echo "$line" | sed 's/^[^,]*up *//; s/, *[[:digit:]]* users.*//; s/ day.*, */d /; s/:/h /; s/ min//; s/$/m/'
    echo -en "\t old: "
    echo "$line" | awk -F, '{print $1,$2}' |
        sed 's/:/h /g;s/^.*up *//; s/ *[0-9]* user.*//;s/[0-9]$/&m/;s/ day. */d /g'
done <uptimes.txt

uptimes.txt

@vdbe vdbe marked this pull request as ready for review March 16, 2024 15:20
Copy link
Collaborator

@89iuv 89iuv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@vdbe vdbe merged commit e80cb73 into catppuccin:main Mar 22, 2024
3 checks passed
@vdbe vdbe deleted the module/uptime branch May 18, 2024 17:42
vdbe pushed a commit that referenced this pull request Jul 19, 2024
Previously, on machines where the logged-in user count is 1, the `sed`
expression to filter out "... X users, ..." doesn't filter out "... X
user, ...", leading to something like

```
1h 05,  1 user,  load average: 0.05, 0.72, 1.62m
```

being displayed in the module. When the user count is greater than 1
(e.g., after `ssh localhost`), the `uptime` module displays

```
1h 05m
```

as expected.

The Stack Overflow answer the `sed` expression is based on [^1][^2]
doesn't seem to consider the case when the user count is 1.

With this patch, the `uptime` module display correctly when the user
count is 1.

[^1]: https://stackoverflow.com/a/28353785
[^2]: #163
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants