diff --git a/pfetch b/pfetch index 2e15cf0..cd57574 100755 --- a/pfetch +++ b/pfetch @@ -71,14 +71,15 @@ log() { # This aligns the info. # # This is ugly, I know! - printf '\033[%sC\033[3%s;1m%s\033[m%s\033[3%sm\033[%sD\033[6C%s\033[m\n' \ + printf '\033[%sC\033[3%s;1m%s\033[m%s\033[3%sm\033[%sD\033[%sC%s\033[m\n' \ "${ascii_width:--1}" \ "${PF_COL1:-5}" \ "$1" \ "${PF_SEP:- }" \ "${PF_COL2:-7}" \ "${#1}" \ - "${2:-?}" + "${PF_ALIGN:-$info_length}" \ + "$2" # Keep track of the number of times 'log()' has been run. info_height=$((info_height + 1)) @@ -103,13 +104,10 @@ get_title() { # to the OS specific detection above and finally an additional fallback # to the 'hostname' command. # - # PF_SEP and PF_COL{1,2} change printing options in the 'log()' function. - # # Disable the warning about '$HOSTNAME' being undefined in POSIX sh as # it is intended for allowing the user to overwrite the value on invocation. # shellcheck disable=SC2039 - PF_SEP=@ PF_COL1=1 PF_COL2='3;1' \ - log "${USER:-$(whoami)}" "${HOSTNAME:-${hostname:-$(hostname)}}" + log "$c4${USER:-$(whoami)}$c7@$c4${HOSTNAME:-${hostname:-$(hostname)}}" } get_distro() { @@ -166,7 +164,7 @@ get_uptime() { log uptime "${uptime:-0m}" } -get_packages() { +get_pkgs() { # Simple function to avoid '>/dev/null' spam. # This checks to see if a command is in '$PATH'. has() { command -v "$1" >/dev/null; } @@ -309,10 +307,19 @@ main() { # Disable globbing and set the positional parameters to the # contents of 'PF_INFO'. set -f - set +f ${PF_INFO-ascii title distro host kernel uptime packages memory} + set +f ${PF_INFO-ascii title distro host kernel uptime pkgs memory} + + # Iterate over the info functions to determine the lengths of the + # "info names" for output alignment. The option names and subtitles + # match 1:1 so this is thankfully simple. + for info; do + info_length=$((${#info} > info_length ? ${#info} : info_length)) + done # Iterate over the above list and run any existing "get_" functions. - for info; do "get_$info"; done + for info; do + "get_$info" + done } # Position the cursor below both the ascii art and information lines