#!/usr/bin/env python # Import libraries import subprocess, optparse from subprocess import Popen, PIPE from optparse import OptionParser # Array containing Values list = [] # Options if __name__=="__main__": parser = OptionParser("usage: %prog [-c COLOR]") parser.add_option("-c", action="store", default='blue', type="choice", dest="color", choices=('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'), help="choose a color: black, red, green, yellow, blue, magenta, cyan, white [Default: blue]") (options, args) = parser.parse_args() # Define colors colorscheme = "%s" % options.color colors = {'black': '0', 'red': '1', 'green': '2', 'yellow': '3', 'blue': '4', 'magenta': '5', 'cyan': '6', 'white': '7'} for key in colors.keys(): if key in colorscheme: colorcode = colors[key] color = '\x1b[1;3%sm' % colorcode color2 = '\x1b[0;3%sm' % colorcode clear = '\x1b[0m' # Display display = ['os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/' ] # Find running processes. p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') processes = [process.split()[3] for process in p1 if process] p1 = None # Print coloured key with normal value. def output(key, value): output = '%s%s:%s %s' % (color, key, clear, value) list.append(output) # Operating System Function def os_display(): arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') os = 'Arch Linux %s' % (arch) output('OS', os) # Kernel Function def kernel_display(): kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n') output ('Kernel', kernel) # Uptime Function def uptime_display(): fuptime = int(open('/proc/uptime').read().split('.')[0]) day = int(fuptime / 86400) fuptime = fuptime % 86400 hour = int(fuptime / 3600) fuptime = fuptime % 3600 minute = int(fuptime / 60) uptime = '' if day == 1: uptime += '%d day, ' % day if day > 1: uptime += '%d days, ' % day uptime += '%d:%02d' % (hour, minute) output('Uptime', uptime) # Battery Function [Requires: acpi] def battery_display(): p1 = Popen(['acpi'], stdout=PIPE).communicate()[0].lstrip() battery = p1.split(' ')[3].rstrip('\n') output ('Battery', battery) # Desktop Environment Function def de_display(): dict = {'gnome-session': 'GNOME', 'ksmserver': 'KDE', 'xfce-mcs-manager': 'Xfce'} de = 'None found' for key in dict.keys(): if key in processes: de = dict[key] output ('DE', de) # Window Manager Function def wm_display(): dict = {'awesome': 'Awesome', 'beryl': 'Beryl', 'blackbox': 'Blackbox', 'compiz': 'Compiz', 'dwm': 'DWM', 'enlightenment': 'Enlightenment', 'fluxbox': 'Fluxbox', 'fvwm': 'FVWM', 'icewm': 'icewm', 'kwin': 'kwin', 'metacity': 'Metacity', 'openbox': 'Openbox', 'wmaker': 'Window Maker', 'xfwm4': 'Xfwm', 'xmonad': 'Xmonad'} wm = 'None found' for key in dict.keys(): if key in processes: wm = dict[key] output ('WM', wm) # Packages Function def packages_display(): p1 = Popen(['pacman', '-Q'], stdout=PIPE) p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) packages = p2.communicate()[0].rstrip('\n') output ('Packages', packages) # File System Function def fs_display(mount=''): p1 = Popen(['df', '-Th', mount], stdout=PIPE).communicate()[0] part = [line for line in p1.split('\n') if line][1] part = part.split()[3] if mount == '/': mount = '/root' fs = mount.rpartition('/')[2].title() output (fs, part) # Run functions found in 'display' array. for x in display: call = [arg for arg in x.split(':') if arg] funcname=call[0] + "_display" func=locals()[funcname] if len(call) > 1: func(arg) else: func() # Array containing values. list.extend(['']*(13 - len(display))) ###### Result ####### print """%s %s + %s # %s ### %s %s ##### %s %s ###### %s %s ; #####; %s %s +##.##### %s %s +########## %s %s ######%s#####%s##; %s %s ###%s############%s+ %s %s #%s###### ####### %s %s .######; ;###;`\". %s %s .#######; ;#####. %s %s #########. .########` %s %s ######' '###### %s %s ;#### ####; %s ##' '## %s #' `# %s """ % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear)