#!/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 } trim_quotes() { trim_output="${1//\'}" trim_output="${trim_output//\"}" printf "%s" "$trim_output" } 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 # Workaround for macOS systems that # don't support the block below. case "$TERM_PROGRAM" in "iTerm.app") term="iTerm2" ;; "Terminal.app") term="Apple Terminal" ;; "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"|"screen"|"su"*) ;; "login"*|*"Login"*|"init"|"(init)") term="$(tty)" ;; "ruby"|"1"|"tmux"*|"systemd"|"sshd"*|"python"*|"USER"*"PID"*|"kdeinit"*|"launchd"*) break ;; "gnome-terminal-") term="gnome-terminal" ;; "urxvtd") term="urxvt" ;; *"nvim") term="Neovim Terminal" ;; *"NeoVimServer"*) term="VimR Terminal" ;; *) term="${name##*/}" ;; esac done # Log that the function was run. # term_run=1 echo "${term}" } get_term_font() { local term="${1}" # ((term_run != 1)) && get_term case "$term" in "alacritty"*) setopt nullglob confs=({$XDG_CONFIG_HOME,$HOME}/{alacritty,}/{.,}alacritty.ym?) unsetopt nullglob [[ -f "${confs[1]}" ]] || return term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${confs[1]}")" term_font="${term_font/*family:}" term_font="${term_font/$'\n'*}" term_font="${term_font/\#*}" ;; "Apple_Terminal") term_font="$(osascript <