From 856071716e610967843478a3f7732e28cbd3a3a8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Jul 2018 00:37:06 +0200 Subject: [PATCH] Fix font issue debugging script --- debug/font-issues.zsh | 322 +++++++++++++++++++++++++++++++++++------- 1 file changed, 274 insertions(+), 48 deletions(-) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index 166a6ac5..ea3c4d67 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -1,111 +1,221 @@ #!/usr/bin/env zsh #vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +get_ppid() { + # Get parent process ID of PID. + case "$os" in + "Windows") + ppid="$(ps -p "${1:-$PPID}" | awk '{printf $2}')" + ppid="${ppid/PPID}" + ;; + + "Linux") + ppid="$(grep -i -F "PPid:" "/proc/${1:-$PPID}/status")" + ppid="$(trim "${ppid/PPid:}")" + ;; + + *) + ppid="$(ps -p "${1:-$PPID}" -o ppid=)" + ;; + esac + + printf "%s" "$ppid" +} + +get_process_name() { + # Get PID name. + case "$os" in + "Windows") + name="$(ps -p "${1:-$PPID}" | awk '{printf $8}')" + name="${name/COMMAND}" + name="${name/*\/}" + ;; + + "Linux") + name="$(< "/proc/${1:-$PPID}/comm")" + ;; + + *) + name="$(ps -p "${1:-$PPID}" -o comm=)" + ;; + esac + + printf "%s" "$name" +} + # Taken from NeoFetch (slightly modified) get_term() { local term + # If function was run, stop here. - #((term_run == 1)) && return + # ((term_run == 1)) && return # Workaround for macOS systems that # don't support the block below. case "$TERM_PROGRAM" in - "iTerm.app") term="iTerm2" ;; + "iTerm.app") term="iTerm2" ;; "Terminal.app") term="Apple Terminal" ;; - "Hyper") term="HyperTerm" ;; - *) term="${TERM_PROGRAM/\.app}" ;; + "Hyper") term="HyperTerm" ;; + *) term="${TERM_PROGRAM/\.app}" ;; esac + # Most likely TosWin2 on FreeMiNT - quick check + [[ "$TERM" == "tw52" || "$TERM" == "tw100" ]] && \ + term="TosWin2" + + [[ "$SSH_CONNECTION" ]] && \ + term="$SSH_TTY" + # Check $PPID for terminal emulator. while [[ -z "$term" ]]; do parent="$(get_ppid "$parent")" + [[ -z "$parent" ]] && break name="$(get_process_name "$parent")" case "${name// }" in - "${SHELL/*\/}" | *"sh" | "tmux"* | "screen" | "su"*) ;; - "login"* | *"Login"* | "init" | "(init)") term="$(tty)" ;; - "ruby" | "1" | "systemd" | "sshd"* | "python"* | "USER"*"PID"*) break ;; + "${SHELL/*\/}"|*"sh"|"screen"|"su"*) ;; + + "login"*|*"Login"*|"init"|"(init)") + term="$(tty)" + ;; + + "ruby"|"1"|"tmux"*|"systemd"|"sshd"*|"python"*|"USER"*"PID"*|"kdeinit"*|"launchd"*) + break + ;; + "gnome-terminal-") term="gnome-terminal" ;; - *) term="${name##*/}" ;; + "urxvtd") term="urxvt" ;; + *"nvim") term="Neovim Terminal" ;; + *"NeoVimServer"*) term="VimR Terminal" ;; + *) term="${name##*/}" ;; esac done # Log that the function was run. - #term_run=1 + # term_run=1 echo "${term}" } get_term_font() { local term="${1}" - #((term_run != 1)) && get_term + # ((term_run != 1)) && get_term case "$term" in "alacritty"*) - term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${XDG_CONFIG_HOME}/alacritty/alacritty.yml")" + shopt -s nullglob + confs=({$XDG_CONFIG_HOME,$HOME}/{alacritty,}/{.,}alacritty.ym?) + shopt -u nullglob + + [[ -f "${confs[0]}" ]] || return + + term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${confs[0]}")" term_font="${term_font/*family:}" term_font="${term_font/$'\n'*}" term_font="${term_font/\#*}" ;; "Apple_Terminal") - term_font="$(osascript -e 'tell application "Terminal" to font name of window frontmost')" + term_font="$(osascript </dev/null | grep -c "Guid") - 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) - if [[ "${profileName}" == "${currentProfileName}" ]]; then + profiles_count="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:'" "$font_file" | \ + grep -w -c "Guid")" + + for ((i=0; i