From 59e0ac82a79ebea29469664424602b7ff0a128f1 Mon Sep 17 00:00:00 2001 From: Aidan Harris Date: Sun, 8 Apr 2018 18:30:42 +0100 Subject: [PATCH 1/4] Font detection for suckless terminal (st) --- neofetch | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/neofetch b/neofetch index 1b455e56..bb5e337d 100755 --- a/neofetch +++ b/neofetch @@ -2178,6 +2178,32 @@ END "${XDG_CONFIG_HOME}/sakura/sakura.conf")" ;; + "st") + if term_font="$(ps -o command= -p $parent | grep -E '\-f\s?.*?:?')"; then + term_font="${term_font/*-f/}" + term_font="${term_font/ -*/}" + else + binary="" + + # On Linux we can get the exact path to the running binary through the procfs + # on other systems we just have to guess and assume `st` is invoked from somewhere + # in the users $PATH + [[ -L /proc/$parent/exe ]] && binary="/proc/$parent/exe" + [[ -z "$binary" ]] && binary="$(command -v st)" + + # Grep the output of strings on the `st` binary for anything that looks vaguely + # like a font definition. NOTE: There is a slight limitation in this approach. + # Technically "Font Name" is a valid font. As it doesn't specify any font options + # though it is hard to match it correctly amongst the rest of the noise. + [[ -n "$binary" ]] && \ + term_font="$(strings "$binary" | \ + grep -E '(pixelsize=|size=|antialias=|autohint=)' | head -1)" + fi + + term_font="${term_font/xft:}" + term_font="${term_font/:*}" + ;; + "terminology") term_font="$(strings "${XDG_CONFIG_HOME}/terminology/config/standard/base.cfg" |\ awk '/^font\.name$/{print a}{a=$0}')" From 9d4a127f72d936f32507ec103d3ef46c7a4cb864 Mon Sep 17 00:00:00 2001 From: Aidan Harris Date: Sun, 8 Apr 2018 19:09:06 +0100 Subject: [PATCH 2/4] Keep shellcheck happy --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index bb5e337d..4b101c49 100755 --- a/neofetch +++ b/neofetch @@ -2179,7 +2179,7 @@ END ;; "st") - if term_font="$(ps -o command= -p $parent | grep -E '\-f\s?.*?:?')"; then + if term_font="$(ps -o command= -p "$parent" | grep -E '\-f\s?.*?:?')"; then term_font="${term_font/*-f/}" term_font="${term_font/ -*/}" else From 8fc70c980186dfe9ee21072de79263b80d65e1d5 Mon Sep 17 00:00:00 2001 From: Aidan Harris Date: Tue, 10 Apr 2018 02:55:08 +0000 Subject: [PATCH 3/4] Refactor Code --- neofetch | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/neofetch b/neofetch index 4b101c49..23af5eeb 100755 --- a/neofetch +++ b/neofetch @@ -2179,17 +2179,15 @@ END ;; "st") - if term_font="$(ps -o command= -p "$parent" | grep -E '\-f\s?.*?:?')"; then + term_font="$(ps -o command= -p "$parent" | grep -F -- "-f")" + if [[ "$term_font" ]]; then term_font="${term_font/*-f/}" term_font="${term_font/ -*/}" else - binary="" - # On Linux we can get the exact path to the running binary through the procfs - # on other systems we just have to guess and assume `st` is invoked from somewhere - # in the users $PATH - [[ -L /proc/$parent/exe ]] && binary="/proc/$parent/exe" - [[ -z "$binary" ]] && binary="$(command -v st)" + # (in case `st` is launched from outside of $PATH) on other systems we just + # have to guess and assume `st` is invoked from somewhere in the users $PATH + [[ -L /proc/$parent/exe ]] && binary="/proc/$parent/exe" || binary="$(type -p st)" # Grep the output of strings on the `st` binary for anything that looks vaguely # like a font definition. NOTE: There is a slight limitation in this approach. @@ -2197,7 +2195,7 @@ END # though it is hard to match it correctly amongst the rest of the noise. [[ -n "$binary" ]] && \ term_font="$(strings "$binary" | \ - grep -E '(pixelsize=|size=|antialias=|autohint=)' | head -1)" + grep -F -m 1 -e "pixelsize=" -e "size=" -e "antialias=" -e "autohint=")" fi term_font="${term_font/xft:}" From 0302d8eb9bc070eee2b84a3e8611c3c20cc94b6a Mon Sep 17 00:00:00 2001 From: Aidan Harris Date: Tue, 10 Apr 2018 08:54:06 +0000 Subject: [PATCH 4/4] Set parent if it's unset --- neofetch | 2 ++ 1 file changed, 2 insertions(+) diff --git a/neofetch b/neofetch index 23af5eeb..1f948785 100755 --- a/neofetch +++ b/neofetch @@ -2179,6 +2179,8 @@ END ;; "st") + [[ -z "$parent" ]] && parent="$(get_ppid "$PPID")" + term_font="$(ps -o command= -p "$parent" | grep -F -- "-f")" if [[ "$term_font" ]]; then term_font="${term_font/*-f/}"