-
-
Notifications
You must be signed in to change notification settings - Fork 43
Switch to /etc/os-release to get system info #795
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
Conversation
bin/shutter
Outdated
| if (-f '/etc/os-release') { | ||
| if (File::Which::which('sed')) { | ||
| print `sed '1q;d' /etc/os-release`; | ||
| print `sed '5q;d' /etc/os-release`, "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these magic numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They grab the 1st and 5th line in the file. The complete file looks like this for me:
NAME="Manjaro Linux"
PRETTY_NAME="Manjaro Linux"
ID=manjaro
ID_LIKE=arch
BUILD_ID=rolling
ANSI_COLOR="32;1;24;144;200"
HOME_URL="https://manjaro.org/"
DOCUMENTATION_URL="https://wiki.manjaro.org/"
SUPPORT_URL="https://forum.manjaro.org/"
BUG_REPORT_URL="https://manjaro.org/help/"
PRIVACY_POLICY_URL="https://manjaro.org/privacy-policy/"
LOGO=manjarolinux
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please treat this file as key/value pairs instead of counting which line is on which position.
NAME=Gentoo
ID=gentoo
PRETTY_NAME="Gentoo Linux"
ANSI_COLOR="1;32"
HOME_URL="https://www.gentoo.org/"
SUPPORT_URL="https://www.gentoo.org/support/"
BUG_REPORT_URL="https://bugs.gentoo.org/"
VERSION_ID="2.18"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you happen to know a bash tool which can read a file this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Come on, this is perl, which is designed for text processing. Why do you need bash or other external tools?
I printed the NAME, feel free to adjust
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not everyone is a perl expert :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely, this code is way over my level! 🥲
|
I added version/build ID info. As far as I understand, only one of the variables is set in In my case I get "Manjaro Linux rolling". |
|
What happens if both are set? There's no guarantee which of them should be set |
Then we get something like "Distro 1.23rolling". So there is no space character between version and build ID. But if we add a space character, there will be two of them in "Distro rolling". |
my %map = map {
chomp;
my ($key, $value) = split /=/, $_, 2;
$value =~ s/^(['"])(.*)\1$/$2/;
($key, $value)
} <$fh>;
local $, = ' ';
say grep { $_ } map { $map{$_} } qw/NAME VERSION_ID BUILD_ID/;qw// is same as |
|
Sounds like magic! 😄 I tested the latest commit, it produces a nice output on my machine. Unfortunately, I can't approve because I created this PR. |
The currently used
/etc/issueseems to be less suiting (only gives\S{PRETTY_NAME} \r (\l)for me on Manjaro).With
/etc/os-releasewe would get