Un-hardcode getgtk formatting and cleanup the function. Added choclatey support for Windows

This commit is contained in:
Dylan 2016-01-27 11:53:12 +11:00
parent 7d8f10d528
commit 548b54e633
2 changed files with 53 additions and 49 deletions

View File

@ -83,11 +83,11 @@ https://github.com/dylanaraps/fetch/wiki/Customizing-Info
**Linux / BSD:**
- Display Wallpaper: `feh` or `nitrogen`
- Display Wallpaper: `feh`, `nitrogen` or `gsettings`
- Current Song: `mpc` or `cmus`
- Resolution Detection: `xorg-xdpyinfo`
- Take a screenshot on script finish: `scrot`
- You can change this to another program with a `--scrotcmd` and an in script option.
- You can change this to another program with a `--scrot_cmd` and an in script option.
<!-- }}} -->

98
fetch
View File

@ -8,12 +8,11 @@
# Text formatting, dynamic image size and padding: tput
# [Linux / BSD / Windows] Uptime detection: procps or procps-ng
#
#
# Optional Dependencies: (You'll lose these features without them)
# Displaying Images: w3m + w3m-img
# Image Cropping: ImageMagick
# More accurate window manager detection: wmctrl
# [ Linux / BSD ] Wallpaper Display: feh or nitrogen
# [ Linux / BSD ] Wallpaper Display: feh, nitrogen or gsettings
# [ Linux / BSD ] Current Song: mpc or cmus
# [ Linux / BSD ] Resolution detection: xorg-xdpyinfo
#
@ -76,7 +75,7 @@ printinfo () {
info "GPU" gpu
info "Memory" memory
# info "Font" font
# info "Font" gtkfont
# info "Disk" disk
# info "Resolution" resolution
# info "Song" song
@ -330,13 +329,11 @@ esac
case "$os" in
"Linux" )
if type -p crux >/dev/null 2>&1; then
distro="CRUX"
elif type -p lsb_release >/dev/null 2>&1; then
if type -p lsb_release >/dev/null 2>&1; then
distro="$(lsb_release -a 2>/dev/null | awk -F':' '/Description/ {printf $2}')"
distro=${distro/[[:space:]]}
elif type -p crux >/dev/null 2>&1; then
distro="CRUX"
else
distro="$(grep -h '^NAME=' /etc/*ease)"
distro=${distro#NAME\=*}
@ -432,6 +429,7 @@ getuptime () {
hours=$((uptime / 3600%24))
days=$((uptime / 86400))
# Format the output like Linux's "uptime -p" cmd.
case "$mins" in
0) ;;
1) uptime="up $mins minute" ;;
@ -462,6 +460,7 @@ getuptime () {
esac
# Make the output of uptime smaller.
case "$uptime_shorthand" in
"on")
uptime=${uptime/up}
@ -550,6 +549,12 @@ getpackages () {
"Windows"*)
packages=$(cygcheck -cd | wc -l)
# Count chocolatey packages
if [ -d "/cygdrive/c/ProgramData/chocolatey/lib" ]; then
choco_packages=$(ls -1 /cygdrive/c/ProgramData/chocolatey/lib | wc -l)
packages=$((packages + choco_packages))
fi
;;
*)
@ -978,55 +983,54 @@ getgtk () {
esac
# Check for gtk2 theme
if [ -f "$HOME/.gtkrc-2.0" ]; then
gtk2theme=$(grep "^[^#]*$name" "$HOME/.gtkrc-2.0")
if [ "$gtk2" == "on" ]; then
if [ -f "$HOME/.gtkrc-2.0" ]; then
gtk2theme=$(grep "^[^#]*$name" "$HOME/.gtkrc-2.0")
elif [ -f "/etc/gtk-2.0/gtkrc" ]; then
gtk2theme=$(grep "^[^#]*$name" /etc/gtk-2.0/gtkrc)
elif [ -f "/etc/gtk-2.0/gtkrc" ]; then
gtk2theme=$(grep "^[^#]*$name" /etc/gtk-2.0/gtkrc)
fi
gtk2theme=${gtk2theme/${name}*=}
gtk2theme=${gtk2theme//\"}
fi
# Check for gtk3 theme
if type -p gsettings >/dev/null 2>&1; then
gtk3theme="$(gsettings get org.gnome.desktop.interface $gsettings)"
gtk3theme=${gtk3theme//\'}
if [ "$gtk3" == "on" ]; then
if type -p gsettings >/dev/null 2>&1; then
gtk3theme="$(gsettings get org.gnome.desktop.interface $gsettings)"
gtk3theme=${gtk3theme//\'}
elif [ -f "$HOME/.config/gtk-3.0/settings.ini" ]; then
gtk3theme=$(grep "^[^#]*$name" "$HOME/.config/gtk-3.0/settings.ini")
elif [ -f "$HOME/.config/gtk-3.0/settings.ini" ]; then
gtk3theme=$(grep "^[^#]*$name" "$HOME/.config/gtk-3.0/settings.ini")
else
gtk3theme=$(grep "^[^#]*$name" /etc/gtk-3.0/settings.ini)
fi
gtk3theme=${gtk3theme/${name}*=}
gtk3theme=${gtk3theme//\"}
gtk3theme=${gtk3theme/[[:space:]]/ }
fi
# Format the string based on which themes exist
if [ "$gtk2theme" ] && [ "$gtk2theme" == "$gtk3theme" ]; then
gtk3theme+=" [GTK2/3]"
unset gtk2theme
elif [ "$gtk2theme" ] && [ "$gtk3theme" ]; then
gtk2theme+=" [GTK2], "
gtk3theme+=" [GTK3] "
else
gtk3theme=$(grep "^[^#]*$name" /etc/gtk-3.0/settings.ini)
[ "$gtk2theme" ] && gtk2theme+=" [GTK2] "
[ "$gtk3theme" ] && gtk3theme+=" [GTK3] "
fi
# Format the strings
gtk2theme=${gtk2theme/${name}*=}
gtk2theme=${gtk2theme//\"}
# Final string
gtktheme="${gtk2theme}${gtk3theme}"
[ "$gtk2theme" ] && \
gtk2theme="$gtk2theme [GTK2], "
# Format the string
gtk3theme=${gtk3theme/${name}*=}
gtk3theme=${gtk3theme//\"}
gtk3theme=${gtk3theme/[[:space:]]/ }
gtktheme="${gtk2theme}${gtk3theme} [GTK3] "
# Check to see if gtk2 and gtk3 theme are identical
if [ "$gtk2theme" ] && [ "$gtk2theme" == "$gtk3theme" ]; then
gtktheme="$gtk2theme [GTK2/3]"
elif [ -z "$gtk2theme" ] && [ -z "$gtk3theme" ]; then
gtktheme="None"
fi
# Hide gtk2 from gtk theme output
if [ "$gtk2" == "off" ]; then
gtktheme=${gtktheme/*'[GTK2], '}
fi
# Hide gtk3 from gtk theme output
if [ "$gtk3" == "off" ]; then
gtktheme=${gtktheme/'[GTK2],'*/'[GTK2]'}
fi
# If the final string is empty print "None"
[ -z "$gtktheme" ] && gtktheme="None"
# Make the output shorter by removing "[GTKX]" from the string
if [ "$gtk_shorthand" == "on" ]; then