diff options
author | Rasmus Steinke <rasi@xssn.at> | 2023-01-08 00:33:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-08 00:33:16 +0100 |
commit | 236c12bfb2999e56ee9e177176472f9f2701be42 (patch) | |
tree | e2d10a56d38de1f26f5887674bf94ccc2edabed5 | |
parent | 5a29565fc88e350019a8159ae054a4c36b407983 (diff) | |
parent | 6bc7735d1477f0a65e7e97cd447ad423c591c3a1 (diff) |
Merge pull request #1775 from nomoo/next
sed & realpath workaround for BSD and Darwin OS
-rwxr-xr-x | script/rofi-theme-selector | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/script/rofi-theme-selector b/script/rofi-theme-selector index 1dab0686..5a01729d 100755 --- a/script/rofi-theme-selector +++ b/script/rofi-theme-selector @@ -3,8 +3,22 @@ # This code is released in public domain by Dave Davenport <qball@gmpclient.org> # +## +# OS checking code as utilities could be different +## +OS="gnu" +case "$OSTYPE" in + *linux*|*hurd*|*msys*|*cygwin*|*sua*|*interix*) OS="gnu";; + *bsd*|*darwin*) OS="bsd";; + *sunos*|*solaris*|*indiana*|*illumos*|*smartos*) OS="sun";; +esac + ROFI=$(command -v rofi) -SED=$(command -v sed) +if [ $OS = "bsd" ]; then + SED=$(command -v gsed) +else + SED=$(command -v sed) +fi MKTEMP=$(command -v mktemp) if [ -z "${SED}" ] @@ -174,7 +188,16 @@ set_theme() then mkdir -p "${CDIR}" fi - get_link=$(readlink -f "${CDIR}/config.rasi") + # on BSD & MacOS readlink acts differently + if [ $OS = "bsd" ]; then + get_link="$(realpath "${CDIR}")/config.rasi" + else + get_link=$(readlink -f "${CDIR}/config.rasi") + fi + if [[ ! -f "${get_link}" ]] + then + touch "${get_link}" + fi ${SED} -i 's/^\s*\(@theme\s\+".*"\)/\/\/\1/' "${get_link}" echo "@theme \"${1}\"" >> "${get_link}" } |