From e9c8e6c2a37be1a932c375d4165a5059cfa6e8c8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Mar 2017 01:45:46 +0100 Subject: [PATCH 01/12] Add font detection for iTerm2 --- neofetch | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/neofetch b/neofetch index 2d649d88..c725aa78 100755 --- a/neofetch +++ b/neofetch @@ -1644,6 +1644,25 @@ get_term_font() { term_font="$(osascript -e 'tell application "Terminal" to font name of window frontmost')" ;; + "iTerm2") + local currentProfileName=$(osascript -e 'tell application "iTerm2" to profile name of current session of current window') + + # Count Guids in "New Bookmarks"; they should be unique + local profilesCount=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:" ~/Library/Preferences/com.googlecode.iterm2.plist | grep "Guid" | wc -l) + for idx in $(seq 0 ${profilesCount}); do + local profileName=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist) + if [[ "${profileName}" == "${currentProfileName}" ]]; then + # "Normal Font" + term_font=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Normal\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + # Font for non-ascii characters + local nonAsciiFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + if [[ "$term_font" -ne "$nonAsciiFont" ]]; then + term_font="$term_font (normal) / $nonAsciiFont (non-ascii)" + fi + fi + done + ;; + "deepin-terminal"*) term_font="$(awk -F '=' '/font=/ {a=$2} /font_size/ {b=$2} END{print a " " b}' "${XDG_CONFIG_HOME}/deepin/deepin-terminal/config.conf")" ;; From 4387233378c312648d00d09c0e5bb1c7a114cef8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Mar 2017 01:46:22 +0100 Subject: [PATCH 02/12] Add warning that false positives can occur --- neofetch | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/neofetch b/neofetch index c725aa78..2d75b0da 100755 --- a/neofetch +++ b/neofetch @@ -1655,6 +1655,12 @@ get_term_font() { # "Normal Font" term_font=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Normal\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) # Font for non-ascii characters + # This font setting may differ from normal font, but this might be a false + # positive, as there is a setting to use a different font for non-ascii + # characters and this setting does not get updated when flipping the switch. + # So it might be that the user checked the mark to use a different font, + # selected one, but then decided to uncheck the "use different font" mark + # again. local nonAsciiFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) if [[ "$term_font" -ne "$nonAsciiFont" ]]; then term_font="$term_font (normal) / $nonAsciiFont (non-ascii)" From eec7f08eee961462e5c0fa7b2582a57b991cd1c5 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Mar 2017 01:50:17 +0100 Subject: [PATCH 03/12] Add warning about possible profile name collisions --- neofetch | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/neofetch b/neofetch index 2d75b0da..9d54041e 100755 --- a/neofetch +++ b/neofetch @@ -1645,6 +1645,10 @@ get_term_font() { ;; "iTerm2") + # Unfortunately the profile name is not unique, but it seems to be the only thing + # that identifies an active profile. There is the "id of current session of current window" + # thou, but that does not match to a guid in the plist. + # So, be warned! Collisions may occur! local currentProfileName=$(osascript -e 'tell application "iTerm2" to profile name of current session of current window') # Count Guids in "New Bookmarks"; they should be unique From e2d1cb27a518cb52770479d3675c198822e49d6e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Mar 2017 01:56:29 +0100 Subject: [PATCH 04/12] Fix comparison --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 9d54041e..10bf0373 100755 --- a/neofetch +++ b/neofetch @@ -1666,7 +1666,7 @@ get_term_font() { # selected one, but then decided to uncheck the "use different font" mark # again. local nonAsciiFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) - if [[ "$term_font" -ne "$nonAsciiFont" ]]; then + if [[ "$term_font" != "$nonAsciiFont" ]]; then term_font="$term_font (normal) / $nonAsciiFont (non-ascii)" fi fi From 3cf7c5ffa27222a51464881a056cf1b55a14eb86 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Mar 2017 02:17:36 +0100 Subject: [PATCH 05/12] Only print non-ascii font if switch "use different font" is active --- neofetch | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/neofetch b/neofetch index 10bf0373..41dc8add 100755 --- a/neofetch +++ b/neofetch @@ -1659,15 +1659,14 @@ get_term_font() { # "Normal Font" term_font=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Normal\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) # Font for non-ascii characters - # This font setting may differ from normal font, but this might be a false - # positive, as there is a setting to use a different font for non-ascii - # characters and this setting does not get updated when flipping the switch. - # So it might be that the user checked the mark to use a different font, - # selected one, but then decided to uncheck the "use different font" mark - # again. - local nonAsciiFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) - if [[ "$term_font" != "$nonAsciiFont" ]]; then - term_font="$term_font (normal) / $nonAsciiFont (non-ascii)" + # Only check for a different non-ascii font, if the user checked + # the "use a different font for non-ascii text" switch. + local useDifferentFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Use\ Non-ASCII\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + if [[ "$useDifferentFont" == "true" ]]; then + local nonAsciiFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + if [[ "$term_font" != "$nonAsciiFont" ]]; then + term_font="$term_font (normal) / $nonAsciiFont (non-ascii)" + fi fi fi done From d1e81f3344a6b1f04a26dfd6e5d0b8575695ed84 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Mar 2017 02:28:23 +0100 Subject: [PATCH 06/12] Add reference to post on iTerm2 list because of ambiguous active profile name --- neofetch | 1 + 1 file changed, 1 insertion(+) diff --git a/neofetch b/neofetch index 41dc8add..d6375e9c 100755 --- a/neofetch +++ b/neofetch @@ -1649,6 +1649,7 @@ get_term_font() { # that identifies an active profile. There is the "id of current session of current window" # thou, but that does not match to a guid in the plist. # So, be warned! Collisions may occur! + # See: https://groups.google.com/forum/#!topic/iterm2-discuss/0tO3xZ4Zlwg local currentProfileName=$(osascript -e 'tell application "iTerm2" to profile name of current session of current window') # Count Guids in "New Bookmarks"; they should be unique From 38641c690e101e13b2bc4d2bc50b02f10cb60421 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Mar 2017 02:30:53 +0100 Subject: [PATCH 07/12] Add warning about iTerm2s dynamic profiles --- neofetch | 3 +++ 1 file changed, 3 insertions(+) diff --git a/neofetch b/neofetch index d6375e9c..f5162593 100755 --- a/neofetch +++ b/neofetch @@ -1652,6 +1652,9 @@ get_term_font() { # See: https://groups.google.com/forum/#!topic/iterm2-discuss/0tO3xZ4Zlwg local currentProfileName=$(osascript -e 'tell application "iTerm2" to profile name of current session of current window') + # Warning: Dynamic profiles are not taken into account here! + # https://www.iterm2.com/documentation-dynamic-profiles.html + # Count Guids in "New Bookmarks"; they should be unique local profilesCount=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:" ~/Library/Preferences/com.googlecode.iterm2.plist | grep "Guid" | wc -l) for idx in $(seq 0 ${profilesCount}); do From 24283be05d8df6b8b9efea8c3ab81f12b2d18724 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Mar 2017 18:35:13 +0100 Subject: [PATCH 08/12] Mute error message, when PlistBuddy is not installed PlistBuddy is part of XCode. It may be that users don't have it installed. --- neofetch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index f5162593..c8b23e26 100755 --- a/neofetch +++ b/neofetch @@ -1656,9 +1656,9 @@ get_term_font() { # https://www.iterm2.com/documentation-dynamic-profiles.html # Count Guids in "New Bookmarks"; they should be unique - local profilesCount=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:" ~/Library/Preferences/com.googlecode.iterm2.plist | grep "Guid" | wc -l) + local profilesCount=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null | grep "Guid" | wc -l) for idx in $(seq 0 ${profilesCount}); do - local profileName=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist) + local profileName=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null) if [[ "${profileName}" == "${currentProfileName}" ]]; then # "Normal Font" term_font=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Normal\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) From 569bef567fe4f2d17c34f2f9fd36d7490b772e0e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 3 Mar 2017 00:04:19 +0100 Subject: [PATCH 09/12] Fix code style --- neofetch | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/neofetch b/neofetch index c8b23e26..dd087428 100755 --- a/neofetch +++ b/neofetch @@ -1650,24 +1650,29 @@ get_term_font() { # thou, but that does not match to a guid in the plist. # So, be warned! Collisions may occur! # See: https://groups.google.com/forum/#!topic/iterm2-discuss/0tO3xZ4Zlwg - local currentProfileName=$(osascript -e 'tell application "iTerm2" to profile name of current session of current window') + local currentProfileName + currentProfileName=$(osascript -e 'tell application "iTerm2" to profile name of current session of current window') # Warning: Dynamic profiles are not taken into account here! # https://www.iterm2.com/documentation-dynamic-profiles.html # Count Guids in "New Bookmarks"; they should be unique - local profilesCount=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null | grep "Guid" | wc -l) - for idx in $(seq 0 ${profilesCount}); do - local profileName=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null) + local profilesCount + profilesCount=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null | grep -c "Guid") + for idx in $(seq 0 "${profilesCount}"); do + local profileName + profileName=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null) if [[ "${profileName}" == "${currentProfileName}" ]]; then # "Normal Font" term_font=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Normal\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) # Font for non-ascii characters # Only check for a different non-ascii font, if the user checked # the "use a different font for non-ascii text" switch. - local useDifferentFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Use\ Non-ASCII\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + local useDifferentFont + useDifferentFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Use\ Non-ASCII\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) if [[ "$useDifferentFont" == "true" ]]; then - local nonAsciiFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + local nonAsciiFont + nonAsciiFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) if [[ "$term_font" != "$nonAsciiFont" ]]; then term_font="$term_font (normal) / $nonAsciiFont (non-ascii)" fi From 53eafeb4145d1312742ec550e9a701fd7d451502 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 8 Mar 2017 23:19:03 +0100 Subject: [PATCH 10/12] Fix code style --- neofetch | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/neofetch b/neofetch index dd087428..20c88ac9 100755 --- a/neofetch +++ b/neofetch @@ -1650,32 +1650,31 @@ get_term_font() { # thou, but that does not match to a guid in the plist. # So, be warned! Collisions may occur! # See: https://groups.google.com/forum/#!topic/iterm2-discuss/0tO3xZ4Zlwg - local currentProfileName - currentProfileName=$(osascript -e 'tell application "iTerm2" to profile name of current session of current window') + local current_profile_name + current_profile_name="$(osascript -e 'tell application "iTerm2" to profile name of current session of current window')" # Warning: Dynamic profiles are not taken into account here! # https://www.iterm2.com/documentation-dynamic-profiles.html # Count Guids in "New Bookmarks"; they should be unique - local profilesCount - profilesCount=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null | grep -c "Guid") - for idx in $(seq 0 "${profilesCount}"); do - local profileName - profileName=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null) - if [[ "${profileName}" == "${currentProfileName}" ]]; then + local profiles_count + profiles_count="$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null | grep -c "Guid")" + for ((i=0; i<=profiles_count; i++)); do + local profile_name + profile_name="$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${i}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null)" + if [[ "$profile_name" == "$current_profile_name" ]]; then # "Normal Font" - term_font=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Normal\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + term_font="$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${i}:Normal\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)" # Font for non-ascii characters # Only check for a different non-ascii font, if the user checked # the "use a different font for non-ascii text" switch. - local useDifferentFont - useDifferentFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Use\ Non-ASCII\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) - if [[ "$useDifferentFont" == "true" ]]; then - local nonAsciiFont - nonAsciiFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) - if [[ "$term_font" != "$nonAsciiFont" ]]; then - term_font="$term_font (normal) / $nonAsciiFont (non-ascii)" - fi + local use_different_font + use_different_font="$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${i}:Use\ Non-ASCII\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)" + if [[ "$use_different_font" == "true" ]]; then + local non_ascii_font + non_ascii_font="$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${i}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)" + [[ "$term_font" != "$non_ascii_font" ]] && \ + term_font="$term_font (normal) / $non_ascii_font (non-ascii)" fi fi done From 8c783d63a2e195cf9674a405248bb899ab8308e1 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 9 Mar 2017 01:13:31 +0100 Subject: [PATCH 11/12] Add newlines --- neofetch | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/neofetch b/neofetch index 20c88ac9..c2f7b908 100755 --- a/neofetch +++ b/neofetch @@ -1659,9 +1659,11 @@ get_term_font() { # Count Guids in "New Bookmarks"; they should be unique local profiles_count profiles_count="$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null | grep -c "Guid")" + for ((i=0; i<=profiles_count; i++)); do local profile_name profile_name="$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${i}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null)" + if [[ "$profile_name" == "$current_profile_name" ]]; then # "Normal Font" term_font="$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${i}:Normal\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)" @@ -1670,11 +1672,13 @@ get_term_font() { # the "use a different font for non-ascii text" switch. local use_different_font use_different_font="$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${i}:Use\ Non-ASCII\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)" + if [[ "$use_different_font" == "true" ]]; then local non_ascii_font non_ascii_font="$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${i}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)" [[ "$term_font" != "$non_ascii_font" ]] && \ term_font="$term_font (normal) / $non_ascii_font (non-ascii)" + fi fi done From 8d250e41bac80c923851cda7edd9ecb7f526d676 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 9 Mar 2017 01:17:31 +0100 Subject: [PATCH 12/12] Fix newlines --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index c2f7b908..67bd6ed7 100755 --- a/neofetch +++ b/neofetch @@ -1676,9 +1676,9 @@ get_term_font() { if [[ "$use_different_font" == "true" ]]; then local non_ascii_font non_ascii_font="$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${i}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)" + [[ "$term_font" != "$non_ascii_font" ]] && \ term_font="$term_font (normal) / $non_ascii_font (non-ascii)" - fi fi done