User:Baavgai

From Openbox

Revision as of 14:20, 14 May 2008 by Baavgai (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

The User Page

Greetings from Jersey ( be afraid ). Do folks have user pages on this wiki? I'm like the third. Seems kind of lonely.

I'm enjoying open box, though haven't taken the plunge to go stand alone; gnome has me by a toe or two.

I love the pipemenus, brilliant idea. I've thrown some stuff up on the page. I'm curious as to the etiquette of the source posting. Everyone seems to host their own, but wikis seem made of code collecting. Also, if the host should go away, it would be nice to have a reference in the main project. With that in mind, I'm going to put some scripts on this page and see if the powers that be are cool with it.

If they aren't, this stuff can also be found at [1].

I can be contacted at "baavgai at chaingang.org".

Scripts

Any script should be considered GPLv3. ( I'm leaving the slug off here for brevity. ) Please use them and let me know if I need to fix anything.

bbgnomepipe.py

There's a lot of cool stuff for the Debian menu, but Gnome also has a menu. So, if you need it, use this.

#!/usr/bin/env python

import gmenu

menuCount = 0

def EscText(text):
	return text.replace(u"&", u"&").replace(u"<", u"<").replace(u"'", u"'")


def WalkTreeBranch(node):
	for child in node.contents:
		if isinstance (child, gmenu.Directory):
			WalkTree(child)

		if not isinstance (child, gmenu.Entry):
			continue

		if child.type == gmenu.TYPE_ENTRY:
			print '<item label="%s">' % EscText(child.name)
			print '<action name="Execute"><execute>%s</execute></action>' % EscText(child.get_exec())
			print '</item>'


def WalkTree(node):
	global menuCount
		
	menuCount = menuCount + 1

	print '<menu id="%s" label="%s">' % ('gnome_menu_%s' % (menuCount), EscText(node.name))
	WalkTreeBranch(node)
	print '</menu>'


if __name__ == "__main__":
	print '<openbox_pipe_menu>'
	WalkTreeBranch(gmenu.lookup_tree("applications.menu", gmenu.FLAGS_INCLUDE_EXCLUDED).root)
	print '</openbox_pipe_menu>'

diskspace.sh

I think I do a "df -h" at least once a day, sometimes many if iso are on the download. I originally wrote this is python too, but felt bad about it. This is a job for awk! Does anyone use awk anymore? It's actually kind of fun.

#!/bin/sh

df -kT | awk 'BEGIN { print "<openbox_pipe_menu>"; 
		itemFmt="<item label=\"%s: %s\"><action name=\"Execute\"><command>true</command></action></item>\n";
		itemFmt2="<item label=\"%s: %dKB\"><action name=\"Execute\"><command>true</command></action></item>\n";
		menuFmt="<menu id=\"fs_menu_%s\" label=\"%7.2fGB %s\">\n";
		menuNum=0;
		}
	$0 ~ "dev" { 
		menuNum = menuNum + 1;
		printf(menuFmt, menuNum, $5 / 1048576, $7);
		printf(itemFmt, "Filesystem", $1);
		printf(itemFmt, "Type", $2);
		printf(itemFmt2, "Size", $3/1024);
		printf(itemFmt2, "Used", $4/1024);
		printf(itemFmt2, "Avail", $5/1024);
		printf(itemFmt, "Use%", $6);
		printf(itemFmt, "Mounted on", $7);
		print "</menu>";
	}
	END { print "</openbox_pipe_menu>" }
	'