From 856071716e610967843478a3f7732e28cbd3a3a8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Jul 2018 00:37:06 +0200 Subject: [PATCH 1/3] 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 166a6ac..ea3c4d6 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 Date: Sun, 22 Jul 2018 17:15:43 +0200 Subject: [PATCH 2/3] Fix debug/font-issues.zsh - Add trim function - Make our $OS and neofetchs $os compatible --- debug/font-issues.zsh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index ea3c4d6..e73830f 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -1,6 +1,21 @@ #!/usr/bin/env zsh #vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +source functions/colors.zsh +source functions/icons.zsh +source functions/utilities.zsh +# Map our $OS to neofetch $os +os="$OS" + + +trim() { + set -f + # shellcheck disable=2048,2086 + set -- $* + printf '%s\n' "${*//[[:space:]]/ }" + set +f +} + get_ppid() { # Get parent process ID of PID. case "$os" in From ebd4414c29014b5cc46a8aee87337684fbcefb9f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Jul 2018 02:16:03 +0200 Subject: [PATCH 3/3] Fix trimming of whitespace in debug/font-issues.zsh --- debug/font-issues.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index e73830f..82f8e60 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -12,7 +12,7 @@ trim() { set -f # shellcheck disable=2048,2086 set -- $* - printf '%s\n' "${*//[[:space:]]/ }" + printf '%s\n' "${*//[[:space:]]/}" set +f }