From 315ae5209a55a5b9b3e7ba0d11f3fe6a5afbea5a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 24 Dec 2016 14:41:56 +1100 Subject: [PATCH 1/4] Term: Move pid handling to separate functions --- neofetch | 103 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 39 deletions(-) diff --git a/neofetch b/neofetch index 3ae1e775..4d70991f 100755 --- a/neofetch +++ b/neofetch @@ -1506,47 +1506,29 @@ get_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 + [[ "$TERM_PROGRAM" ]] && return + # Check $PPID for terminal emulator. - case "$os" in - "Mac OS X") - # 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 - return - ;; + while [[ -z "$term" ]]; do + parent="$(get_ppid "$parent")" + name="$(get_process_name "$parent")" - "Windows") - parent="$(ps -p "${1:-$PPID}" | awk '{printf $2}')" - parent="${parent/'PPID'}" - - name="$(ps -p "$parent" | awk '{printf $8}')" - name="${name/'COMMAND'}" - name="${name/*\/}" - ;; - - "Linux") - parent="$(grep -i -F "PPid:" "/proc/${1:-$PPID}/status")" - name="$(< "/proc/$(trim "${parent/PPid:}")/comm")" - ;; - - *) - parent="$(ps -p "${1:-$PPID}" -o ppid=)" - name="$(ps -p "$parent" -o comm=)" - ;; - esac - - case "${name// }" in - "${SHELL/*\/}" | *"sh" | "tmux"* | "screen" | "su") get_term "$parent" ;; - "login"* | *"Login"* | "init" | "(init)") term="$(tty)" ;; - "ruby" | "1" | "systemd" | "sshd"* | "python"* | "USER"*"PID"*) unset term ;; - "gnome-terminal-") term="gnome-terminal" ;; - *) term="${name##*/}" ;; - esac + case "${name// }" in + "${SHELL/*\/}" | *"sh" | "tmux"* | "screen" | "su") ;; + "login"* | *"Login"* | "init" | "(init)") term="$(tty)" ;; + "ruby" | "1" | "systemd" | "sshd"* | "python"* | "USER"*"PID"*) unset term; break ;; + "gnome-terminal-") term="gnome-terminal" ;; + *) term="${name##*/}" ;; + esac + done # Log that the function was run. term_run=1 @@ -3065,6 +3047,49 @@ convert_time() { printf "%s" "$week_day $day $month $year $time" } +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" +} + + # FINISH UP usage() { printf "%s" "\ From a60cf636f69b71b23b8ba2884ba453b067e30156 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 24 Dec 2016 19:50:44 +1100 Subject: [PATCH 2/4] Update neofetch --- neofetch | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/neofetch b/neofetch index 4d70991f..4e41b708 100755 --- a/neofetch +++ b/neofetch @@ -1514,7 +1514,6 @@ get_term() { "Hyper") term="HyperTerm" ;; *) term="${TERM_PROGRAM/\.app}" ;; esac - [[ "$TERM_PROGRAM" ]] && return # Check $PPID for terminal emulator. while [[ -z "$term" ]]; do @@ -1524,7 +1523,7 @@ get_term() { case "${name// }" in "${SHELL/*\/}" | *"sh" | "tmux"* | "screen" | "su") ;; "login"* | *"Login"* | "init" | "(init)") term="$(tty)" ;; - "ruby" | "1" | "systemd" | "sshd"* | "python"* | "USER"*"PID"*) unset term; break ;; + "ruby" | "1" | "systemd" | "sshd"* | "python"* | "USER"*"PID"*) break ;; "gnome-terminal-") term="gnome-terminal" ;; *) term="${name##*/}" ;; esac From dfd287ca9b122ac360a0369d069218e853505709 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 25 Dec 2016 08:39:25 +1100 Subject: [PATCH 3/4] Term: Match sudo --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 4e41b708..5feb8757 100755 --- a/neofetch +++ b/neofetch @@ -1521,7 +1521,7 @@ get_term() { name="$(get_process_name "$parent")" case "${name// }" in - "${SHELL/*\/}" | *"sh" | "tmux"* | "screen" | "su") ;; + "${SHELL/*\/}" | *"sh" | "tmux"* | "screen" | "su"*) ;; "login"* | *"Login"* | "init" | "(init)") term="$(tty)" ;; "ruby" | "1" | "systemd" | "sshd"* | "python"* | "USER"*"PID"*) break ;; "gnome-terminal-") term="gnome-terminal" ;; From 918a684b7a2d656ef698679f44e4eda9555f167b Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 25 Dec 2016 08:41:39 +1100 Subject: [PATCH 4/4] General: Remove linebreak --- neofetch | 1 - 1 file changed, 1 deletion(-) diff --git a/neofetch b/neofetch index 5feb8757..d840fa6f 100755 --- a/neofetch +++ b/neofetch @@ -3088,7 +3088,6 @@ get_process_name() { printf "%s" "$name" } - # FINISH UP usage() { printf "%s" "\