]> code.delx.au - monosys/commitdiff
Added other cool things
authorJames Bunton <jamesbunton@fastmail.fm>
Fri, 21 Sep 2007 02:17:45 +0000 (12:17 +1000)
committerJames Bunton <jamesbunton@fastmail.fm>
Fri, 21 Sep 2007 02:17:45 +0000 (12:17 +1000)
scripts/dos2unix [new file with mode: 0755]
scripts/osx_ps [new file with mode: 0755]
scripts/osx_top [new file with mode: 0755]
scripts/powerbook_battery [new file with mode: 0755]

diff --git a/scripts/dos2unix b/scripts/dos2unix
new file mode 100755 (executable)
index 0000000..762f90b
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+while [ "$1" != "" ]; do
+       dosunix "$1" /tmp/outfile
+       mv /tmp/outfile "$1"
+       shift
+done
+
diff --git a/scripts/osx_ps b/scripts/osx_ps
new file mode 100755 (executable)
index 0000000..ce49a64
--- /dev/null
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+if test '!' -c /dev/fd/1; then
+       /bin/ps "$@" -ww
+else
+       /bin/ps "$@"
+fi
diff --git a/scripts/osx_top b/scripts/osx_top
new file mode 100755 (executable)
index 0000000..ba66e04
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+exec /usr/bin/top -ocpu -Otime "$@"
diff --git a/scripts/powerbook_battery b/scripts/powerbook_battery
new file mode 100755 (executable)
index 0000000..871f017
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+import subprocess, re, sys
+
+# Run ioreg to get the battery status line
+p = subprocess.Popen(args=["ioreg", "-w0", "-l"], stdout=subprocess.PIPE)
+for line in p.stdout.xreadlines():
+       if line.find("IOBatteryInfo") >= 0:
+               p.stdout.close()
+               break
+else:
+       print "IOBatteryInfo not found!"
+       sys.exit(1)
+
+
+# Parse the line to a dict & calculate the percentage
+line = line.strip()
+m = re.compile('^.*"IOBatteryInfo" = ').match(line)
+line = line[m.end()+1:-1].replace("=", ":")
+exec "fields = " + line
+fields["Capacity%"] = int(100.0 * float(fields["Capacity"]) / float(fields["AbsoluteMaxCapacity"]))
+
+
+# Print to screen
+for field in ("Current", "Capacity", "Capacity%", "Cycle Count"):
+       print "%s:\t%d" % (field, fields[field])
+
+