#!/bin/sh ##-----------------------------------------------------------------## ## .xinitrc customized for dwm ## ## For dwm versions >= 5.5 ## ## By: Thiam H Lee ## ## Last updated: Jul-09-2010 ## ## NOTE : This script is tested only for Debian and Ubuntu systems ## ## Some of the sed scripts (e.g. the newline-removing ones) ## ## only work with GNU sed, ssed and HHsed. ## ## This file can also be used as a startup script ## ##-----------------------------------------------------------------## ## TODO : add a systray if desired to dwm, maybe stalonetray, and figure out placement rules. ## TODO : add script for UPS information (check nuts-hal or devicekit-power documentation) ## TODO : test extended networkinfo() that prints out wireless connection info if any ##-------------------------------------## ## Sections : 1. Environment Variables ## ## 2. Statusbar Scripts ## ## 3. Main ## ##-------------------------------------## ##--------------------------## ## 1. Environment Variables ## ##--------------------------## DWMBIN=`which dwm` # Path to dwm binary BACKGROUND=$HOME/backgrounds/dwm_1024x768.jpg # Path to desktop background image ROOTCOLOR=black # X server root window color POINTER=left_ptr # Pointer theme WEATHERLOCATION=10027 # Location string for weather script. See script comments for details DISKUSAGEMOUNTPOINTS="" # Space-delimited list of mountpoints for the diskusage script. Leave empty for all mountpoints ##----------------------## ## 2. Statusbar Scripts ## ##----------------------## ## Script for printing number of available updates in Debian ## when there are some available (and prints nothing otherwise). ## This script is useful only if the updating of package listings ## (e.g. 'aptitude update' or 'apt-get update') is automated, ## for example by a cron job. ## Running aptitude is slow, so only use this on a fast computer debupdates(){ NUMUPDATES=`aptitude search "~U" | wc -l` ## Check if variable is a number followed by checking if it is greater than 0 if ( [ $NUMUPDATES -eq $NUMUPDATES 2> /dev/null ] && [ $NUMUPDATES -gt 0 ] ); then echo "APT-Pkg-Updates:$NUMUPDATES" fi } ## Script for printing the weather at $WEATHERLOCATION ## w3m should be installed in order to use this script weather(){ ## Uncomment only one of the WEATHERTEXT lines below: ## 1. The following works for all locations supported by weather.com, but only prints the temperature #WEATHERTEXT="`w3m -dump http://www.weather.com/weather/print/$WEATHERLOCATION | grep -A 1 'To\(day\|night\)' | grep -o '[^a-z] \([0-9/-]\+.\)\+ [^%]' | sed -e 's/ //g'`" ## 2. The following uses http://mobile.weather.gov/ and supports only US locations (e.g. US zip codes), ## but prints both the weather conditions and the temperature WEATHERTEXT=`w3m -dump "http://mobile.weather.gov/port_zc.php?inputstring=$WEATHERLOCATION" -config none | grep -o '[A-Za-z /:-]* [0-9-][0-9]* .F' | sed -e 's/ //g'` echo "W:$WEATHERTEXT" } ## Script for printing out the system load average (see 'man uptime') over the past one minute. cpuload(){ CPULOAD=`sed -e 's/ .*//' /proc/loadavg` echo "L:$CPULOAD" } ## Script for printing the amount of memory used and the total memory in MB ## (not including usage for file buffers and for cached memory) memoryuse(){ MEMTOTAL=`awk '/MemTotal/{print $2}' < /proc/meminfo` MEMCACHED=`awk '/^Cached/{print $2}' < /proc/meminfo` MEMBUFFERS=`awk '/Buffers/{print $2}' < /proc/meminfo` MEMFREE=`awk '/MemFree/{print $2}' < /proc/meminfo` MEMORY=`expr $MEMTOTAL / 1024` MEMUSED=`expr \( $MEMTOTAL - $MEMFREE - $MEMBUFFERS - $MEMCACHED \) / 1024` echo "M:$MEMUSED/$MEMORY""MB" } ## Script for printing network connection information. ## This prints a space delimited list of connected network interfaces. ## Additionally, it prints the connection name and signal strength for wireless interfaces. ## For more info on wireless interfaces, see: ## http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Linux.Wireless.Extensions.html ## TODO : One possibility is to change the wifi code to parse the output of `/sbin/iwconfig` line by line ## (may result in faster code since one pass is sufficient) or using sed elegantly networkinfo(){ ## Get space delimited list of network interfaces that are up NETCONNECTIONS=`grep -o '\(ath\|eth\|wlan\)[0-9]\$' /proc/net/arp | sed -e ':a;N;$!ba;s/\n/;/g'` ## Default text is space delimited list of network interfaces that are up NETDISPLAYTEXT="$NETCONNECTIONS" ## Check if iwgetid command exists (which should be present on systems ## that have wireless management packages installed) and if so append connected wireless ## access points and link quality only to the wireless network interface names if which iwgetid > /dev/null 2>&1; then WIFIINFO=`/sbin/iwgetid 2>/dev/null` for WIFICONNECTION in `echo "$WIFIINFO" | awk '{print $1}'`; do ESSID="`echo "WIFIINFO" | grep $WIFICONNECTION | awk -F ':' '{print $2}' | sed -e 's/"//g'`" LINK="`awk "/$WIFICONNECTION:/{print \$3}" /proc/net/wireless | sed -e 's/\.//g'`" NETDISPLAYTEXT=`echo "$NETDISPLAYTEXT" | sed -e "s/$WIFICONNECTION/$WIFICONNECTION:$ESSID:$LINK"` done fi echo "N:$NETDISPLAYTEXT" } ## Script for printing out disk usage for a space-delimited list/string of mountpoints. ## If a mountpoint is incorrect, then nothing is printed for it. ## If no arguments are passed to it, it prints disk usage for all mountpoints with devices in /dev diskusage(){ ## Get mountpoints with devices in /dev and format into mountpoint:usedspace/totalspace DISKINFOALL=`df -h | awk '/^\/dev\//{print $6 "=" $3 "/" $2}'` DISKINFO="" if [ $# -gt 0 ]; then ## Args passed: filter for the matching mountpoints for DISKDEV in "$@" do DISKINFO="$DISKINFO;`echo "$DISKINFOALL" | grep -m 1 "^$DISKDEV="`" done DISKINFO=`echo "$DISKINFO" | sed -e 's/^;//'` else ## No args passed: remove newlines from $DISKINFOALL and use that DISKINFO=`echo "$DISKINFOALL" | sed -e ':a;N;$!ba;s/\n/;/g'` fi echo "D:$DISKINFO" } ## Script for printing out battery charge information. batt(){ ## Default text is for AC power BATTERYTEXT="AC" ## Check if there is a battery entry in the system hardware listing ## (there should be an entry in /sys/class/power_supply) ## and if so, extract its directory basename to BATBASENAME if [ -r /sys/class/power_supply/BAT0 ]; then BATBASENAME="BAT0" elif [ -r /sys/class/power_supply/BAT1 ]; then BATBASENAME="BAT1" elif [ -r /sys/class/power_supply/BAT2 ]; then BATBASENAME="BAT2" fi ## If a battery entry was found and is present, get the battery's charge status ## and use in in place of the default text if [ $BATBASENAME != "" ]; then FULL=`cat /sys/class/power_supply/$BATBASENAME/charge_full` PRESENT=`cat /sys/class/power_supply/$BATBASENAME/present` CHARGE=`cat /sys/class/power_supply/$BATBASENAME/charge_now` STATUS=`cat /sys/class/power_supply/$BATBASENAME/status` if [ "$PRESENT" != "0" ]; then CHARGE=`expr $CHARGE \* 100 / $FULL` case $STATUS in Full) SIGN="=";; Charging) SIGN="+";; Discharging) SIGN="-";; esac BATTERYTEXT="$CHARGE%$SIGN" fi fi echo "B:$BATTERYTEXT" } ## Script for printing out volume. ## This requires alsa (package alsa-base), and check amixer for the correct device label (here, it is Master) volume() { ONCOUNT="`amixer get Master | grep -c '\[on\]'`" VOLUMELEVEL="[M]" if [ $ONCOUNT -gt 0 ]; then VOLUMELEVEL="`amixer get Master | grep -m 1 -o '[0-9][0-9]*%'`" fi echo "V:$VOLUMELEVEL" } ## Script for printing out current time currenttime(){ echo "`date +'%a %b %e %I:%M %p'`" } ##---------## ## 3. Main ## ##---------## ## Make Caps Lock a Control key. See: http://www.emacswiki.org/emacs/MovingTheCtrlKey setxkbmap -option ctrl:nocaps ## Set pointer cursor and background color of the root window xsetroot -cursor_name $POINTER -solid $ROOTCOLOR ## Render image to X root window (i.e. set the wallpaper). ## Requires xloadimage. ## Other possible programs to render the background image of the X root window are: ## hsetroot (light) , nitrogen (heavier, but supports xinerama) and xli (light and like xloadimage) ## See also: http://urukrama.wordpress.com/2007/12/05/desktop-backgrounds-in-window-managers/ xloadimage -onroot -fullscreen $BACKGROUND ## Start the screensaver. Requires xscreensaver. ## An alternative is slock. See: http://tools.suckless.org/slock ## slock needs the suid bit set, the binary file should be owned by root:root and have permissions '-rwsr-xr-x'. (Use 'chmod +s' as root if necessary) xscreensaver & ## Write system info to X root window name, which dwm reads for its status bar input ## Edit the SYSINFO declaration as desired. The following functions are available: ## `debupdates` , `weather` , `cpuload` , `memoryuse` , `diskusage $DISKUSAGEMOUNTPOINTS` , `networkinfo` , `volume` , `batt` , `currenttime` while true do SYSINFO="`debupdates` `weather` `cpuload` `memoryuse` `diskusage $DISKUSAGEMOUNTPOINTS` `networkinfo` `volume` `batt` `currenttime`" xsetroot -name "$SYSINFO" sleep 1m ## Update every minute done & exec $DWMBIN ## Run dwm