From f481d9f59cfa4cab4cbd081e6c64e492d72becce Mon Sep 17 00:00:00 2001 From: Steve Forget Date: Sun, 22 Sep 2019 16:58:51 +0200 Subject: [PATCH 1/3] Added font detection for ConEmu --- neofetch | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/neofetch b/neofetch index a2bbc2a0..66968b21 100755 --- a/neofetch +++ b/neofetch @@ -3202,6 +3202,49 @@ END # Default fallback font hardcoded in terminal-preferences.c [[ -z "$term_font" ]] && term_font="Monospace 12" ;; + + "conemu-"*) + local ce_arg_list + local ce_arg_idx + local ce_conf + + # Could have used `eval set -- "$ConEmuArgs"` instead for arg parsing but eval is evil... + readarray -t ce_arg_list < <(xargs -n1 printf "%s\n" <<< "${ConEmuArgs-}") + + for ce_arg_idx in "${!ce_arg_list[@]}"; do + # Search for "-LoadCfgFile" arg + [[ "${ce_arg_list[$ce_arg_idx]}" != -LoadCfgFile ]] && continue + + # Conf path is the next arg + ((++ce_arg_idx)) + ce_conf="${ce_arg_list[$ce_arg_idx]}" + break + done + + # https://conemu.github.io/en/ConEmuXml.html#search-sequence + local ce_seq=( + "$ce_conf" + "$ConEmuDir\ConEmu.xml" + "$ConEmuDir\.ConEmu.xml" + "$ConEmuBaseDir\ConEmu.xml" + "$ConEmuBaseDir\.ConEmu.xml" + "$APPDATA\ConEmu.xml" + "$APPDATA\.ConEmu.xml" + ) + + for ce_conf in "${ce_seq[@]}"; do + # Search for first conf file available + [[ ! -f "$ce_conf" ]] && continue + + # Very basic XML parsing + term_font="$(awk '/name="FontName"/ && match($0, /data="([^"]*)"/) {print substr($0, RSTART+6, RLENGTH-7)}' "$ce_conf")" + break + done + + # Null-terminated contents in /proc/registry files triggers a Bash warning. Use read instead + [[ -z "$term_font" ]] && \ + read -r term_font < /proc/registry/HKEY_CURRENT_USER/Software/ConEmu/.Vanilla/FontName + ;; esac } From aaf4a5497e823b3a5d6af5c6479f6ff91c27837d Mon Sep 17 00:00:00 2001 From: Steve Forget Date: Sun, 22 Sep 2019 19:33:28 +0200 Subject: [PATCH 2/3] Fixed line length compliance --- neofetch | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/neofetch b/neofetch index 66968b21..cc193efb 100755 --- a/neofetch +++ b/neofetch @@ -3208,7 +3208,7 @@ END local ce_arg_idx local ce_conf - # Could have used `eval set -- "$ConEmuArgs"` instead for arg parsing but eval is evil... + # Could have used `eval set -- "$ConEmuArgs"` instead for arg parsing readarray -t ce_arg_list < <(xargs -n1 printf "%s\n" <<< "${ConEmuArgs-}") for ce_arg_idx in "${!ce_arg_list[@]}"; do @@ -3237,13 +3237,14 @@ END [[ ! -f "$ce_conf" ]] && continue # Very basic XML parsing - term_font="$(awk '/name="FontName"/ && match($0, /data="([^"]*)"/) {print substr($0, RSTART+6, RLENGTH-7)}' "$ce_conf")" + term_font="$(awk '/name="FontName"/ && match($0, /data="([^"]*)"/) \ + {print substr($0, RSTART+6, RLENGTH-7)}' "$ce_conf")" break done - # Null-terminated contents in /proc/registry files triggers a Bash warning. Use read instead - [[ -z "$term_font" ]] && \ - read -r term_font < /proc/registry/HKEY_CURRENT_USER/Software/ConEmu/.Vanilla/FontName + # Null-terminated contents in /proc/registry files triggers a Bash warning + [[ -z "$term_font" ]] && read -r term_font < \ + /proc/registry/HKEY_CURRENT_USER/Software/ConEmu/.Vanilla/FontName ;; esac } From 9b9ea1b9773fc0bf89f4b779ea6a0b21de581d95 Mon Sep 17 00:00:00 2001 From: Steve Forget Date: Sun, 22 Sep 2019 21:12:30 +0200 Subject: [PATCH 3/3] Refactoring according to reviews --- neofetch | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/neofetch b/neofetch index cc193efb..41665860 100755 --- a/neofetch +++ b/neofetch @@ -3203,7 +3203,7 @@ END [[ -z "$term_font" ]] && term_font="Monospace 12" ;; - "conemu-"*) + conemu-*) local ce_arg_list local ce_arg_idx local ce_conf @@ -3213,37 +3213,28 @@ END for ce_arg_idx in "${!ce_arg_list[@]}"; do # Search for "-LoadCfgFile" arg - [[ "${ce_arg_list[$ce_arg_idx]}" != -LoadCfgFile ]] && continue - - # Conf path is the next arg - ((++ce_arg_idx)) - ce_conf="${ce_arg_list[$ce_arg_idx]}" - break + [[ "${ce_arg_list[$ce_arg_idx]}" == -LoadCfgFile ]] && { + # Conf path is the next arg + ce_conf=${ce_arg_list[++ce_arg_idx]} + break + } done # https://conemu.github.io/en/ConEmuXml.html#search-sequence - local ce_seq=( - "$ce_conf" - "$ConEmuDir\ConEmu.xml" - "$ConEmuDir\.ConEmu.xml" - "$ConEmuBaseDir\ConEmu.xml" - "$ConEmuBaseDir\.ConEmu.xml" - "$APPDATA\ConEmu.xml" - "$APPDATA\.ConEmu.xml" - ) - - for ce_conf in "${ce_seq[@]}"; do + for ce_conf in "$ce_conf" "${ConEmuDir-}\ConEmu.xml" "${ConEmuDir-}\.ConEmu.xml" \ + "${ConEmuBaseDir-}\ConEmu.xml" "${ConEmuBaseDir-}\.ConEmu.xml" \ + "$APPDATA\ConEmu.xml" "$APPDATA\.ConEmu.xml"; do # Search for first conf file available - [[ ! -f "$ce_conf" ]] && continue - - # Very basic XML parsing - term_font="$(awk '/name="FontName"/ && match($0, /data="([^"]*)"/) \ - {print substr($0, RSTART+6, RLENGTH-7)}' "$ce_conf")" - break + [[ -f "$ce_conf" ]] && { + # Very basic XML parsing + term_font="$(awk '/name="FontName"/ && match($0, /data="([^"]*)"/) { + print substr($0, RSTART+6, RLENGTH-7)}' "$ce_conf")" + break + } done # Null-terminated contents in /proc/registry files triggers a Bash warning - [[ -z "$term_font" ]] && read -r term_font < \ + [[ "$term_font" ]] || read -r term_font < \ /proc/registry/HKEY_CURRENT_USER/Software/ConEmu/.Vanilla/FontName ;; esac