tide/functions/_tide_detect_os.fish

48 lines
1.3 KiB
Fish
Raw Normal View History

2020-07-27 09:07:34 +03:00
function _tide_detect_os
2020-07-30 03:30:32 +03:00
switch (uname | string lower)
case darwin
2021-04-05 06:20:26 +03:00
printf '%s'
2020-07-30 03:30:32 +03:00
case freebsd openbsd dragonfly
2021-04-05 06:20:26 +03:00
printf '%s'
2020-07-30 03:30:32 +03:00
case linux
2020-12-26 03:32:03 +03:00
_tide_detect_os_linux_cases /etc/os-release ID ||
2021-03-02 20:46:40 +03:00
_tide_detect_os_linux_cases /etc/os-release ID_LIKE ||
_tide_detect_os_linux_cases /etc/lsb-release DISTRIB_ID ||
2021-04-05 06:20:26 +03:00
printf '%s'
2020-07-27 09:07:34 +03:00
case '*'
2021-04-05 06:20:26 +03:00
printf '%s' '?'
2020-07-27 09:07:34 +03:00
end
2020-07-30 03:30:32 +03:00
end
2020-09-23 23:48:55 +03:00
function _tide_detect_os_linux_cases -a file key
2021-03-21 04:03:07 +03:00
test -e $file || return
set -l splitFile (string split '=' <$file)
2021-02-06 19:18:43 +03:00
set -l keyIndex (contains --index $key $splitFile) || return
set -l value (string trim --chars='"' $splitFile[(math $keyIndex + 1)] | string lower)
set -l distroIcons \
alpine\
aosc\
arch\
centos\
coreos\
debian\
devuan\
elementary\
fedora\
gentoo\
mageia\
manjaro\
mint\
nixos\
opensuse\
raspbian\
sabayon\
slackware\
tumbleweed\
ubuntu
set -l distroIndex (contains --index $value $distroIcons) || return
2021-04-05 06:20:26 +03:00
printf '%s' $distroIcons[(math $distroIndex + 1)]
2020-07-30 03:30:32 +03:00
end