From 37e7d8e4b3b410f0973eee9503039aca257c1a8f Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 28 May 2016 11:38:41 +1000 Subject: [PATCH] Condense term function --- neofetch | 63 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/neofetch b/neofetch index 0efd9a89..f008c50e 100755 --- a/neofetch +++ b/neofetch @@ -1739,39 +1739,40 @@ getfont () { # Terminal Emulator {{{ getterm () { - # Workaround for OS X systems that - # don't support the block below. - case "$TERM_PROGRAM" in - "iTerm.app") term="iTerm2" ;; - "Terminal.app") term="Apple Terminal" ;; - *) term="${TERM_PROGRAM/\.app}" ;; + # Check $PPID for terminal emulator. + case "$os" in + "Mac OS X") + # Workaround for OS X systems that + # don't support the block below. + case "$TERM_PROGRAM" in + "iTerm.app") term="iTerm2" ;; + "Terminal.app") term="Apple Terminal" ;; + *) term="${TERM_PROGRAM/\.app}" ;; + esac + return + ;; + + "Windows") + parent="$(ps -p ${1:-$PPID} | awk '{printf $2}')" + parent=${parent/'PPID'} + + name="$(ps -p $parent | awk '{printf $8}')" + name=${name/'COMMAND'} + name=${name/*\/} + ;; + + *) + parent="$(ps -p ${1:-$PPID} -o ppid=)" + name="$(ps -p $parent -o comm=)" + ;; esac - # Check $PPID for terminal emulator. - if [ -z "$term" ]; then - case "$os" in - "Windows") - parent="$(ps -p ${1:-$PPID} | awk '{printf $2}')" - parent=${parent/'PPID'} - - name="$(ps -p $parent | awk '{printf $8}')" - name=${name/'COMMAND'} - name=${name/*\/} - ;; - - *) - parent="$(ps -p ${1:-$PPID} -o ppid=)" - name="$(ps -p $parent -o comm=)" - ;; - esac - - case "${name// }" in - "${SHELL/*\/}" | *"sh" | "tmux" | "screen") getterm "$parent" ;; - "login" | "init") term="$(tty)"; term=${term/*\/} ;; - "ruby" | "1" | "systemd" | "sshd") unset term ;; - *) term="$name" ;; - esac - fi + case "${name// }" in + "${SHELL/*\/}" | *"sh" | "tmux" | "screen") getterm "$parent" ;; + "login" | "init") term="$(tty)"; term=${term/*\/} ;; + "ruby" | "1" | "systemd" | "sshd") unset term ;; + *) term="$name" ;; + esac } # }}}