You can now use ANY bash syntax when customizing what gets displayed, for example you could use an if statment to only show info when condition is true!

This commit is contained in:
Dylan 2016-01-21 08:58:50 +11:00
parent c5c34637b8
commit 9daacddda1
1 changed files with 94 additions and 109 deletions

203
fetch
View File

@ -28,39 +28,47 @@ export LANGUAGE=C
# Info
# What to display and in what order.
# You can use ANY bash syntax in the function below!
# For example you could use if statments to only print info
# when a condition is true!
#
# Format is: "Subtitle: function name"
# Additional lines you can use include:
# "underline" "linebreak" "echo: msg here" "title: title here"
# The script comes with two helper functions:
# info:
# info "subtitle" funcname
# prin:
# prin "Custom message to print"
# prin "Subtitle: Custom message to print"
# prin "Subtitle: $(date)"
#
# You can also include your own custom lines by using:
# "echo: subtitlehere: $(custom cmd here)"
# "echo: Custom string to print"
# You can also just use printf / echo to add lines but you'll
# need to prefix your msg with "${padding}", for example:
# echo "${padding} My custom message here"
#
# Optional info lines that are disabled by default are:
# "getresolution" "getsong" "getvisualstyle" "getgpu"
# Info functions enabled by default are:
# "title" "distro" "kernel" "uptime" "packages"
# "shell" "resolution" "windowmanager" "gtktheme"
# "gtkicons" "cpu" "memory" "cols"
#
# Info lines enabled by default are:
# "gettitle" "getdistro" "getkernel" "getuptime" "getpackages"
# "getshell" "getresolution" "getwindowmanager" "getgtktheme"
# "getgtkicons" "getcpu" "getmemory" "getcols"
info=(
"gettitle"
"underline"
"OS: getdistro"
"Kernel: getkernel"
"Uptime: getuptime"
"Packages: getpackages"
"Shell: getshell"
"Resolution: getresolution"
"Window Manager: getwindowmanager"
"GTK Theme: getgtktheme"
"Icons: getgtkicons"
"CPU: getcpu"
"Memory: getmemory"
"linebreak"
"getcols"
)
# Info functions that are disabled by default are:
# "resolution" "song" "visualstyle" "gpu"
printinfo () {
info title
info underline
info "OS" distro
info "Kernel" kernel
info "Uptime" uptime
info "Packages" packages
info "Shell" shell
info "Window Manager" windowmanager
info "GTK Theme" gtktheme
info "Icons" gtkicons
info "CPU" cpu
info "Memory" memory
info linebreak
info cols
}
# Window Manager
@ -688,6 +696,7 @@ getgpu () {
nvidia*)
gpu=${gpu/'NVIDIA Corporation' }
gpu=${gpu/'nVidia Corporation' }
gpu=${gpu/G????M }
gpu=${gpu/G???? }
gpu=${gpu/'['}
gpu=${gpu/']'}
@ -1103,7 +1112,62 @@ takescrot () {
# Text Formatting {{{
underline () {
info () {
# Call the function and update variable
if [ -z "$2" ]; then
get$1 2>/dev/null
eval output="\$${1}"
else
get$2 2>/dev/null
eval output="\$${2}"
fi
case "$1" in
title)
string="${bold}${title_color}${output}"
string="${string/@/${at_color}@${title_color}}"
length=${#output}
;;
underline)
string="${underline_color}${output}"
;;
linebreak | cols)
string=""
;;
*)
string="${bold}${subtitle_color}${1}${clear}"
string+="${colon_color}: ${info_color}${output}"
length=$((${#subtitle} + ${#output} + 2))
;;
esac
printf "%b%s\n" "${padding}${string}${clear}"
}
prin () {
case "$1" in
*:*)
subtitle=${1%%:*}
output=${1#*: }
string="${bold}${subtitle_color}${subtitle}${clear}"
string+="${colon_color}: ${info_color}${output}"
length=$((${#subtitle} + ${#output} + 1))
;;
*)
string="${info_color}${1}"
length=${#1}
;;
esac
printf "%b%s\n" "${padding}${string}${clear}"
}
getunderline () {
underline=$(printf %"$length"s)
underline=${underline// /$underline_char}
}
@ -1307,85 +1371,6 @@ done
# }}}
# Print Info {{{
printinfo () {
for info in "${info[@]}"; do
function=${info#*: }
subtitle=${info%:*}
case "$function" in
"get"*)
# Call the function
$function 2>/dev/null
# Update the variable
eval output="\$${function/get/}"
;;
esac
case "$info" in
echo:*:*)
info=${function#*: }
subtitle=${function/:*/}
string="${bold}${subtitle_color}${subtitle}${clear}"
string+="${colon_color}: ${info_color}${info}"
length=${#function}
;;
echo:*)
string="${info_color}${function}"
length=${#function}
;;
title:*)
string="${bold}${title_color}${function}"
length=${#function}
;;
linebreak)
string=""
;;
underline)
if [ "$underline" == "on" ]; then
underline
string="${underline_color}${underline}"
fi
;;
"")
continue
;;
gettitle)
string="${bold}${title_color}${output}"
string="${string/@/${at_color}@${title_color}}"
length=${#output}
;;
*:*)
string="${bold}${subtitle_color}${subtitle}${clear}"
string+="${colon_color}: ${info_color}${output}"
length=$((${#subtitle} + ${#output} + 2))
;;
*)
string="$output"
length=${#output}
;;
esac
printf "%b%s\n" "${padding}${string}${clear}"
done
}
# }}}
# Call Functions and Finish Up {{{