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.
<!-- }}} --> <!-- }}} -->

62
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,6 +983,7 @@ getgtk () {
esac esac
# Check for gtk2 theme # Check for gtk2 theme
if [ "$gtk2" == "on" ]; then
if [ -f "$HOME/.gtkrc-2.0" ]; then if [ -f "$HOME/.gtkrc-2.0" ]; then
gtk2theme=$(grep "^[^#]*$name" "$HOME/.gtkrc-2.0") gtk2theme=$(grep "^[^#]*$name" "$HOME/.gtkrc-2.0")
@ -985,7 +991,12 @@ getgtk () {
gtk2theme=$(grep "^[^#]*$name" /etc/gtk-2.0/gtkrc) gtk2theme=$(grep "^[^#]*$name" /etc/gtk-2.0/gtkrc)
fi fi
gtk2theme=${gtk2theme/${name}*=}
gtk2theme=${gtk2theme//\"}
fi
# Check for gtk3 theme # Check for gtk3 theme
if [ "$gtk3" == "on" ]; then
if type -p gsettings >/dev/null 2>&1; then if type -p gsettings >/dev/null 2>&1; then
gtk3theme="$(gsettings get org.gnome.desktop.interface $gsettings)" gtk3theme="$(gsettings get org.gnome.desktop.interface $gsettings)"
gtk3theme=${gtk3theme//\'} gtk3theme=${gtk3theme//\'}
@ -997,36 +1008,29 @@ getgtk () {
gtk3theme=$(grep "^[^#]*$name" /etc/gtk-3.0/settings.ini) gtk3theme=$(grep "^[^#]*$name" /etc/gtk-3.0/settings.ini)
fi fi
# Format the strings
gtk2theme=${gtk2theme/${name}*=}
gtk2theme=${gtk2theme//\"}
[ "$gtk2theme" ] && \
gtk2theme="$gtk2theme [GTK2], "
# Format the string
gtk3theme=${gtk3theme/${name}*=} gtk3theme=${gtk3theme/${name}*=}
gtk3theme=${gtk3theme//\"} gtk3theme=${gtk3theme//\"}
gtk3theme=${gtk3theme/[[:space:]]/ } gtk3theme=${gtk3theme/[[:space:]]/ }
gtktheme="${gtk2theme}${gtk3theme} [GTK3] " fi
# Check to see if gtk2 and gtk3 theme are identical # Format the string based on which themes exist
if [ "$gtk2theme" ] && [ "$gtk2theme" == "$gtk3theme" ]; then if [ "$gtk2theme" ] && [ "$gtk2theme" == "$gtk3theme" ]; then
gtktheme="$gtk2theme [GTK2/3]" gtk3theme+=" [GTK2/3]"
unset gtk2theme
elif [ -z "$gtk2theme" ] && [ -z "$gtk3theme" ]; then elif [ "$gtk2theme" ] && [ "$gtk3theme" ]; then
gtktheme="None" gtk2theme+=" [GTK2], "
gtk3theme+=" [GTK3] "
else
[ "$gtk2theme" ] && gtk2theme+=" [GTK2] "
[ "$gtk3theme" ] && gtk3theme+=" [GTK3] "
fi fi
# Hide gtk2 from gtk theme output # Final string
if [ "$gtk2" == "off" ]; then gtktheme="${gtk2theme}${gtk3theme}"
gtktheme=${gtktheme/*'[GTK2], '}
fi
# Hide gtk3 from gtk theme output # If the final string is empty print "None"
if [ "$gtk3" == "off" ]; then [ -z "$gtktheme" ] && gtktheme="None"
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