Because I really miss being able to gnuclient +23 foo (for which there at least is mate --line 23 foo) or vim +/pat bar (which mate can't do) I whipped this up. Maybe someone will find it useful.
##
## ma -- textmate launcher that works like 'vi +line file' or 'vi +/re file'
##
ma () {
emulate -L zsh
setopt extended_glob
local line="" column="" url="txmt://open?url=" term=""
local usage="usage: ma [+line[:col]] file"
if (( # == 0 )) ; then
print "$usage"
return 1
fi
if [[ "$1" = (#b)+([0-9]##)(:([0-9]##)#)# ]] ; then
shift ## eat $1
line="$match[1]"
[[ -n "$match[3]" ]] && column="$match[3]"
elif [[ "$1" = (#b)+/(*) ]] ; then
shift
local term="$match[1]"
fi
if [[ -z "$1" ]] ; then
print "$usage"
return 1
fi
file="$1" ; shift
[[ "$file" !=/* ]] && file="${PWD}/$file"
if [[ -n "$term" ]] ; then
local -a maybe_line
maybe_line=( "${(s,:,)$(perl -lne 'BEGIN{$p=shift;$p=qr/($p)/}if(/$p/ ){$c=$-[1]+1;print "$.:$c";exit 0}END{exit 1;}' -- "$term" "$file")}" )
if [[ -z "$maybe_line" ]] ; then
print "No match for '$term' found in '$file'"
return 1
else
line="$maybe_line[1]"
column="$maybe_line[2]"
fi
fi
url="${url}file:///$file"
[[ -n "$line" ]] && url="${url}&line=$line"
[[ -n "$column" ]] && url="${url}&column=$column"
open "$url"
}
ma "$@"
Give or take, as the rough DateTime::Duration calculation flies.
Long time, no post.
So . . . here's a post.
This will let Class::DBI::Pg deal with tables which have a primary key consisting of more than one column (e.g. CREATE TABLE foo ( a integer, b integer, PRIMARY KEY ( a, b ) ))
Patch sent to author as well, but just in case anyone else is interested . . .
---
/usr/lib/perl5/site_perl/5.8.0/Class/DBI/Pg.pm 2003-09-10 03:59:40.000000000 -0400
+++ Class/DBI/Pg.pm 2004-05-05 13:53:57.000000000 -0400
@@ -23,7 +23,7 @@
WHERE relname = ?)
SQL
$sth->execute($table);
- my $prinum = $sth->fetchrow_array;
+ my @prinums = split(/\s+/, ( $sth->fetchrow_array )[0] );
$sth->finish;
# find all columns
@@ -50,17 +50,17 @@
$sth->finish;
my($sequence) = $nextval_str =~ m/^nextval\('"?([^"']+)"?'::text\)/;
- my(@cols, $primary);
+ my(@cols, @primary);
foreach my $col(@$columns) {
# skip dropped column.
next if $col->[0] =~/^\.+pg\.dropped\.\d+\.+$/;
push @cols, $col->[0];
- next unless $prinum && $col->[1] eq $prinum;
- $primary = $col->[0];
+ next unless @prinums && grep $col->[1] eq $_, @prinums;
+ push @primary, $col->[0];
}
- _croak("$table has no primary key") unless $primary;
+ _croak("$table has no primary key") unless @primary;
$class->table($table);
- $class->columns(Primary => $primary);
+ $class->columns(Primary => @primary);
$class->columns(All => @cols);
$class->sequence($sequence) if $sequence;
}
Found out about scselect yesterday from here. A couple of minutes effort on the train and I now can change from a shell without having to mouse up to the apple menu.
zsh ++
##
## _scselect -- Completion for OS X Network Location utility
##
_scselect () {
local locs
locs=( $( scselect |& \
perl -lne 'next if/^\S/;/\(([^)]+)\)/&&print qq{"$1"}' ) )
_arguments -C "*:Network Location Set:($locs)"
}
Just to save some other person some googling:
Memo to myself: Next OS release bring chair. Mall tile floor is not the most comfortable.
Or at least until that long running wget completes. This will temporarily set the OS X energy saver sleep timer to `never', run the specified command, and then restore the sleep time.
#!/usr/bin/perl
##
## nosleep -- Disable sleep while command runs (OS X)
##
use warnings;
use strict;
my @pm_set_cmd = qw( pmset sleep );
unshift @pm_set_cmd, 'sudo' unless $> == 0; ## Setting needs root privs
## Figure out what sleep's set to
my $old_sleep = undef;
open( GET, "pmset -g live |" ) or die "Can't open pipe from pmset -g: $!\n";
while( <GET> ) {
if(/sleep\s+(\d+)/ ) {
$old_sleep = $1;
last;
}
}
close( GET );
die "Couldn't determine current sleep setting.\n" unless defined $old_sleep;
my $ret;
## Set sleep to 0 (never)
$ret = system( @pm_set_cmd, 0 );
die "Problem setting sleep: @{[ $? >> 8 ]}\n" unless $ret == 0;
## Run command passed as argument
$ret = system( @ARGV );
warn "Problem running command: @{[ $? >> 8 ]}\n" unless $ret == 0;
## Revert to old sleep value
$ret = system( @pm_set_cmd, $old_sleep );
die "Problem setting sleep: @{[ $? >> 8 ]}\n" unless $ret == 0;
exit 0;
__END__
You may wish to add something along these lines to your/etc/sudoers:
Cmnd_Alias PMSET =/usr/bin/pmset sleep [0-9]*
%admin ALL=(ALL) ALL, NOPASSWD: PMSET
Two handy ORA onlamp.com articles you may not have seen:
Now I don't have to remember what box I book marked those on . . .
Last night I bought some socks at a warehouse store because the wife has been complaining about the lack of structural integrity of my present hosiery.
At any rate; 12 pair, 9$US, in a plastic bag. A plastic bag with a recloseable zipper seal.
Socks. In a ziplock bag. This means something. Possibly that ziplock bags are available off the shelf and were the most convenient way to package 12 socks. Or that I should be keeping my socks in the vegetable crisper in the fridge.