From 7786934995d9e702f726905fa501aecfa7890eb1 Mon Sep 17 00:00:00 2001 From: Michael Straube Date: Fri, 30 Dec 2016 14:43:02 +0100 Subject: [PATCH 1/2] Term: Rewrite Konsole font detection, closes #576 --- neofetch | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/neofetch b/neofetch index 5bc1aa05..b71df31a 100755 --- a/neofetch +++ b/neofetch @@ -1568,25 +1568,47 @@ get_term_font() { ;; "konsole"*) + get_konsole_profile() { + konsole_windows=($(qdbus "${1}" | awk '/Windows\//')) + for window in "${konsole_windows[@]}"; do + konsole_session="$(qdbus "${1}" "${window}" currentSession)" + if ((child == "$(qdbus "${1}" /Sessions/"${konsole_session}" processId)")); then + konsole_profile="$(qdbus "${1}" /Sessions/"${konsole_session}" environment |\ + awk -F '=' '/KONSOLE_PROFILE_NAME/ {print $2}')" + break + fi + done + } + + get_konsole_font() { + profile_path="$("${1}" --path data | awk -F':' '{print $1}')/konsole" + + # Profile filename can differ from profile name, so find the filename first, take first match + # It's possible that we have more than one file containing the same profile name + profile_filename="$(grep -l "Name=${konsole_profile}" "${profile_path}"/*.profile | head -n 1)" + [[ "${profile_filename}" ]] && term_font="$(awk -F '=|,' '/Font=/ {print $2 " " $3}' "${profile_filename}")" + + # If there are no profiles or no font is defined in the profile, Konsole falls back to system's monospace font + # This fails if no fixed font is defined in kdeglobals, Konsole internally uses + # QFontDatabase::systemFont(QFontDatabase::FixedFont) or KGlobalSettings::fixedFont() in qt4 versions + [[ ! "${term_font}" ]] && term_font="$(awk -F '=|,' '/fixed=/ {print $2 " " $3}' "$("${1}" --path config --locate kdeglobals)")" + } + # Use Process ID from get_term(). # The variable can include 'PPid:' and also whitespace # so we get rid of it here. parent="$(trim "${parent/PPid:}")" - # Get PID of current child window / tab + # Get Process ID of current konsole window / tab child="$(get_ppid "$$")" - # Get all konsole sessions of the parent (all child windows and tabs) - konsole_sessions=($(qdbus org.kde.konsole-"${parent}" | awk '/Sessions\//')) + # We could have both: org.kde.konsole-PPID and org.kde.konsole + get_konsole_profile "org.kde.konsole-${parent}" + [[ ! "${konsole_profile}" ]] && get_konsole_profile "org.kde.konsole" - # Get profile of current session (window / tab) - for session in "${konsole_sessions[@]}"; do - if ((child == "$(qdbus org.kde.konsole-"${parent}" "${session}" processId)")); then - profile="$(qdbus org.kde.konsole-"${parent}" "${session}" environment | awk -F '=' '/KONSOLE_PROFILE_NAME/ {print $2}')" - break - fi - done - term_font="$(awk -F '=|,' '/Font=/ {print $2}' "${HOME}/.local/share/konsole/${profile}".profile)" + # Try both: kde5 and kde4 + [[ "$(which kf5-config)" ]] && get_konsole_font "kf5-config" + [[ ! "${term_font}" && "$(which kde4-config)" ]] && get_konsole_font "kde4-config" ;; esac } From f1c61c597e49328f0f0d69c33431e60fff8baf8b Mon Sep 17 00:00:00 2001 From: Michael Straube Date: Tue, 3 Jan 2017 18:01:30 +0100 Subject: [PATCH 2/2] Term: Simplify Konsole font detection --- neofetch | 53 ++++++++++++++++------------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/neofetch b/neofetch index b71df31a..b79d655a 100755 --- a/neofetch +++ b/neofetch @@ -1568,47 +1568,26 @@ get_term_font() { ;; "konsole"*) - get_konsole_profile() { - konsole_windows=($(qdbus "${1}" | awk '/Windows\//')) - for window in "${konsole_windows[@]}"; do - konsole_session="$(qdbus "${1}" "${window}" currentSession)" - if ((child == "$(qdbus "${1}" /Sessions/"${konsole_session}" processId)")); then - konsole_profile="$(qdbus "${1}" /Sessions/"${konsole_session}" environment |\ - awk -F '=' '/KONSOLE_PROFILE_NAME/ {print $2}')" - break - fi - done - } - - get_konsole_font() { - profile_path="$("${1}" --path data | awk -F':' '{print $1}')/konsole" - - # Profile filename can differ from profile name, so find the filename first, take first match - # It's possible that we have more than one file containing the same profile name - profile_filename="$(grep -l "Name=${konsole_profile}" "${profile_path}"/*.profile | head -n 1)" - [[ "${profile_filename}" ]] && term_font="$(awk -F '=|,' '/Font=/ {print $2 " " $3}' "${profile_filename}")" - - # If there are no profiles or no font is defined in the profile, Konsole falls back to system's monospace font - # This fails if no fixed font is defined in kdeglobals, Konsole internally uses - # QFontDatabase::systemFont(QFontDatabase::FixedFont) or KGlobalSettings::fixedFont() in qt4 versions - [[ ! "${term_font}" ]] && term_font="$(awk -F '=|,' '/fixed=/ {print $2 " " $3}' "$("${1}" --path config --locate kdeglobals)")" - } - - # Use Process ID from get_term(). - # The variable can include 'PPid:' and also whitespace - # so we get rid of it here. - parent="$(trim "${parent/PPid:}")" - # Get Process ID of current konsole window / tab child="$(get_ppid "$$")" - # We could have both: org.kde.konsole-PPID and org.kde.konsole - get_konsole_profile "org.kde.konsole-${parent}" - [[ ! "${konsole_profile}" ]] && get_konsole_profile "org.kde.konsole" + konsole_instances=($(qdbus | grep 'org.kde.konsole')) - # Try both: kde5 and kde4 - [[ "$(which kf5-config)" ]] && get_konsole_font "kf5-config" - [[ ! "${term_font}" && "$(which kde4-config)" ]] && get_konsole_font "kde4-config" + for i in "${konsole_instances[@]}"; do + konsole_sessions=($(qdbus "${i}" | grep '/Sessions/')) + for session in "${konsole_sessions[@]}"; do + if ((child == "$(qdbus "${i}" "${session}" processId)")); then + profile="$(qdbus "${i}" "${session}" environment | awk -F '=' '/KONSOLE_PROFILE_NAME/ {print $2}')" + break + fi + done + [[ "$profile" ]] && break + done + + # We could have two profile files for the same profile name, take first match + profile_filename="$(grep -l "Name=${profile}" "${HOME}"/.local/share/konsole/*.profile)" + profile_filename="${profile_filename/$'\n'*}" + [[ "$profile_filename" ]] && term_font="$(awk -F '=|,' '/Font=/ {print $2 " " $3}' "$profile_filename")" ;; esac }