From ab09bf9670648765a44c48e4bf95d8030913e611 Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 30 Mar 2016 14:00:13 +1100 Subject: [PATCH 1/7] Implement cache function and add caching for GPU --- neofetch | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/neofetch b/neofetch index 94afddc8..05adb5b1 100755 --- a/neofetch +++ b/neofetch @@ -949,6 +949,12 @@ getcpu () { # GPU {{{ getgpu () { + # Use cache if it exists + if [ -f "/tmp/neofetch/gpu" ]; then + source "/tmp/neofetch/gpu" + return + fi + case "$os" in "Linux") gpu="$(PATH="/sbin:$PATH" lspci | grep -F "3D")" @@ -1069,6 +1075,9 @@ getgpu () { gpu=${gpu//+( )/ } gpu="${gpu}${count}" + + # Cache the output + cache "gpu" "$gpu" } # }}} @@ -2449,6 +2458,14 @@ bar() { # }}} +# Cache {{{ + +cache () { + mkdir -p "/tmp/neofetch" + echo "${1/*-}=\"$2\"" > "/tmp/neofetch/${1/*-}" +} + +# }}} # }}} From 53505207eb4f921753684abfbb0179b92e725db0 Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 30 Mar 2016 14:13:40 +1100 Subject: [PATCH 2/7] Only cache OS X GPU output --- neofetch | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/neofetch b/neofetch index 05adb5b1..56526e3c 100755 --- a/neofetch +++ b/neofetch @@ -949,12 +949,6 @@ getcpu () { # GPU {{{ getgpu () { - # Use cache if it exists - if [ -f "/tmp/neofetch/gpu" ]; then - source "/tmp/neofetch/gpu" - return - fi - case "$os" in "Linux") gpu="$(PATH="/sbin:$PATH" lspci | grep -F "3D")" @@ -1027,7 +1021,13 @@ getgpu () { ;; "Mac OS X") - gpu=$(system_profiler SPDisplaysDataType | awk -F': ' '/^\ *Chipset Model:/ {printf $2 ", "}') + # Use cache if it exists + if [ -f "/tmp/neofetch/gpu" ]; then + source "/tmp/neofetch/gpu" + else + gpu=$(system_profiler SPDisplaysDataType | awk -F': ' '/^\ *Chipset Model:/ {printf $2 ", "}') + cache "gpu" "$gpu" + fi gpu=${gpu//'/ $'} gpu=${gpu%,*} ;; @@ -1075,9 +1075,6 @@ getgpu () { gpu=${gpu//+( )/ } gpu="${gpu}${count}" - - # Cache the output - cache "gpu" "$gpu" } # }}} From 90fd0cf1bea734fd5ae6f231ffb9557cc6fff1e4 Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 30 Mar 2016 14:14:51 +1100 Subject: [PATCH 3/7] Move more lines into the cache block --- neofetch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index 56526e3c..c275d055 100755 --- a/neofetch +++ b/neofetch @@ -1026,10 +1026,10 @@ getgpu () { source "/tmp/neofetch/gpu" else gpu=$(system_profiler SPDisplaysDataType | awk -F': ' '/^\ *Chipset Model:/ {printf $2 ", "}') + gpu=${gpu//'/ $'} + gpu=${gpu%,*} cache "gpu" "$gpu" fi - gpu=${gpu//'/ $'} - gpu=${gpu%,*} ;; *"BSD") From 8ef9c1b4c3beff993e511638e553c086a0c12603 Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 30 Mar 2016 19:24:03 +1100 Subject: [PATCH 4/7] Move cache to /Library/Caches on OS X --- neofetch | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/neofetch b/neofetch index c275d055..7dede0f4 100755 --- a/neofetch +++ b/neofetch @@ -1022,13 +1022,13 @@ getgpu () { "Mac OS X") # Use cache if it exists - if [ -f "/tmp/neofetch/gpu" ]; then - source "/tmp/neofetch/gpu" + if [ -f "/Library/Caches/neofetch/gpu" ]; then + source "/Library/Caches/neofetch/gpu" else gpu=$(system_profiler SPDisplaysDataType | awk -F': ' '/^\ *Chipset Model:/ {printf $2 ", "}') gpu=${gpu//'/ $'} gpu=${gpu%,*} - cache "gpu" "$gpu" + cache "gpu" "$gpu" "/Library/Caches/" fi ;; @@ -2458,8 +2458,8 @@ bar() { # Cache {{{ cache () { - mkdir -p "/tmp/neofetch" - echo "${1/*-}=\"$2\"" > "/tmp/neofetch/${1/*-}" + mkdir -p "$3/neofetch" + echo "${1/*-}=\"$2\"" > "$3/neofetch/${1/*-}" } # }}} From c2557873fca742f2789bf2af922193cf82c87211 Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 30 Mar 2016 19:30:37 +1100 Subject: [PATCH 5/7] "--clean" remove cache folder and files --- neofetch | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 7dede0f4..b263fc20 100755 --- a/neofetch +++ b/neofetch @@ -2687,7 +2687,11 @@ while [ "$1" ]; do --xoffset) xoffset="$2" ;; --yoffset) yoffset="$2" ;; --gap) gap="$2" ;; - --clean) rm -rf "$thumbnail_dir" || exit ;; + --clean) + rm -rf "$thumbnail_dir" + rm -rf "/Library/Caches/neofetch/" + exit + ;; # Ascii --ascii) From 7c6fcb789fd20ebaf689d0985338a451a771a85c Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 30 Mar 2016 19:39:03 +1100 Subject: [PATCH 6/7] Add cache support for CPU --- neofetch | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index b263fc20..0590c248 100755 --- a/neofetch +++ b/neofetch @@ -839,8 +839,13 @@ getcpu () { ;; "Mac OS X") - cpu="$(sysctl -n machdep.cpu.brand_string)" - cores=$(sysctl -n hw.ncpu) + if [ -f "/Library/Caches/neofetch/cpu" ]; then + source "/Library/Caches/neofetch/cpu" + else + cpu="$(sysctl -n machdep.cpu.brand_string)" + cores=$(sysctl -n hw.ncpu) + cache "cpu" "$cpu" "/Library/Caches/" + fi ;; *"BSD" | "Windows") From aa18135b24992b178fb42b6e2c772f64794db8ce Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 30 Mar 2016 19:43:38 +1100 Subject: [PATCH 7/7] Revert CPU cache --- neofetch | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/neofetch b/neofetch index 0590c248..b263fc20 100755 --- a/neofetch +++ b/neofetch @@ -839,13 +839,8 @@ getcpu () { ;; "Mac OS X") - if [ -f "/Library/Caches/neofetch/cpu" ]; then - source "/Library/Caches/neofetch/cpu" - else - cpu="$(sysctl -n machdep.cpu.brand_string)" - cores=$(sysctl -n hw.ncpu) - cache "cpu" "$cpu" "/Library/Caches/" - fi + cpu="$(sysctl -n machdep.cpu.brand_string)" + cores=$(sysctl -n hw.ncpu) ;; *"BSD" | "Windows")