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