Created
January 24, 2017 03:22
-
-
Save Dobbie03/2c550b3333caca26cebdb065fb320185 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use autodie; | |
use POSIX qw(strftime); | |
use XML::Simple; | |
use Data::Dumper; | |
# Distro ------------------------------------------------------------------- | |
open (my $issue, "<", "/etc/issue"); | |
my $distro; | |
while (<$issue>) { | |
if (/^[^\s]/) { | |
$distro = (split / /, ((split /\\/)[0]))[0]; | |
last; | |
} | |
} | |
close $issue; | |
# Host --------------------------------------------------------------------- | |
my $host = `uname -n`; | |
chomp $host; | |
# Kernel ------------------------------------------------------------------- | |
my $kernel = `uname -r`; | |
chomp $kernel; | |
# Load --------------------------------------------------------------------- | |
my $load = (split ' ', (split ':', `uptime`)[4])[0]; | |
chop $load; | |
# Machine ------------------------------------------------------------------ | |
my $machine = `uname -m`; | |
chomp $machine; | |
# Memory (active) ---------------------------------------------------------- | |
open (my $meminfo, "<", "/proc/meminfo"); | |
my $mem_act; | |
while (<$meminfo>) { | |
chomp; | |
if (/^Active:/) { | |
$mem_act = int(((split)[-2])/1024); | |
last; | |
} | |
} | |
close $meminfo; | |
# Openbox theme ------------------------------------------------------------ | |
my $file = "$ENV{HOME}/.config/openbox/rc.xml"; | |
my $xs1 = XML::Simple->new(); | |
my $doc = $xs1->XMLin($file); | |
my $obtheme = $doc->{theme}->{'name'}; | |
# OS ----------------------------------------------------------------------- | |
my $os = `uname -o`; | |
chomp $os; | |
# Time --------------------------------------------------------------------- | |
my $time_date = strftime "%B, %d, %Y - %R", localtime; | |
# Uptime ------------------------------------------------------------------- | |
my $uptime = (split ' ', `uptime`)[0]; | |
# Writing the pipemenu ----------------------------------------------------- | |
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | |
. "<openbox_pipe_menu>\n" | |
. "<item label=\"+ $ENV{USER}\@$host +\" />\n" | |
. "<separator />" | |
. "<item label=\"OS: $distro $os $machine \" />\n" | |
. "<item label=\"Kernel: $kernel \" />\n" | |
. "<item label=\"Uptime: $uptime \" />\n" | |
. "<item label=\"Load: $load \" />\n" | |
. "<item label=\"Mem: $mem_act MB\" />\n" | |
. "<item label=\"Theme: $obtheme \" />\n" | |
. "<separator />" | |
. "<item label=\"+ $time_date +\" />\n" | |
. "</openbox_pipe_menu>\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Dynamic places menu generator for openbox | |
# Uses a list of parent directories to provide a menu of subdirectories | |
# After removing any entries found in an ignore list | |
# | |
# | |
# Originally created by: Kev at http://crunchbanglinux.org/forums/topic/373/dynamic-places-pipe-menu/ | |
# | |
# | |
# 1. Save this script to a place you prefer (mine is in ~/.config/openbox/scripts/) | |
# 2. Make it executable | |
# 3. Insert a line into your ~/.config/openbox/menu.xml like: | |
# <menu execute="perl ~/.config/openbox/scripts/places.py menu" id="pipe-places" label="Places"/> | |
# 4. Call the pipe-menu in your menu by adding the following line to the same file: | |
# <menu id="pipe-places"/> | |
# 5. Reconfigure OpenBox | |
# 6. You're done | |
# | |
# Important variables if you want to customise the generated menu: | |
# manager - File manager which you want to use (nautilus, thunar, pcmanfm, rox-filer, konqueror, dolphin, etc). | |
# dirs - The script lists and displays the subdirectories of these directories | |
# ignore - Any item exactly matching an entry in this list will not be displayed | |
# items - If you want to add a single directory entry to the menu you can do it here | |
# | |
import glob | |
import fnmatch | |
from os.path import expanduser | |
# File manager you want to use to open directories | |
manager = "pcmanfm" | |
# User home directory. If you hard code this location instead of relying on | |
# expanduser() then you can remove its import above | |
home = expanduser('~') | |
# List of directories whose subdirectories we want to display | |
dirs = [home, '/mnt/server/'] | |
# List of directories to ignore | |
# Shell-style wildcards as used by fnmatch are supported | |
ignore = ['/media/cdrom0'] | |
# Our list of menu items | |
# If you want to add single directories to the menu without including | |
# all of their subdirs then put them in here | |
items = [] | |
# Iterate through dirs | |
for dir in dirs: | |
# Get a list of subdirectories for each dir | |
subdirs = glob.glob(dir + '/*/') | |
# Alphabetise subdirs. Sorting here is less efficient but preserves | |
# directory order specified above. If this doesn't matter to you then | |
# remove this line and uncomment "items.sort(key=str.lower)" below | |
subdirs.sort(key=str.lower) | |
# Append each subdir to the items list | |
for sub in subdirs: | |
# Replace /home/user with ~ before appending to items (looks better) | |
sub = sub.replace(home, '~') | |
# Strip trailing / characters | |
sub = sub.rstrip('/') | |
items.append(sub) | |
# Iterate through ignore list and remove matches from items | |
for i in ignore: | |
matches = fnmatch.filter(items, i) | |
for m in matches: | |
try: | |
items.remove(m) | |
except ValueError: | |
pass | |
# Alphabetise directory list. Read comment for sort() above before uncommenting | |
#items.sort(key=str.lower) | |
# Output xml for the openbox menu | |
print('<openbox_pipe_menu>') | |
# Each item becomes a menu entry | |
for i in items: | |
print ('<item label="',i,'">') | |
print ('<action name="Execute">') | |
print ('<execute>') | |
print (manager,'" "',i) | |
print ('</execute>') | |
print ('</action>') | |
print ('</item>') | |
print ('</openbox_pipe_menu>') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment