Skip to content
Browse files

working: ruby version of perl 'last two dirs' script

  • Loading branch information...
1 parent c6b932b commit ba799c6c8cec8538cb559af2e78ba554aaf5e978 @crux committed Apr 13, 2011
Showing with 33 additions and 27 deletions.
  1. +33 −27 scripts/c2prompt.rb
View
60 scripts/c2prompt.rb
@@ -1,27 +1,33 @@
-#!/usr/bin/env ruby
-
-puts ENV['PWD']
-
-__END__
-
-sub main {
-
- my @av = @_;
-
- $home = $ENV{HOME};
- $pwd = $ENV{PWD};
-#print "arg: $pwd\n";
- $pwd =~ s!($home)!~!;
- $npwd = $pwd;
-
- $pwd =~ m!([^/]*/[^/]*$)! and do {
- $npwd = $1;
-#print "1: '$1'\n";
- };
-
- print "$npwd";
-}
-
-main( @ARGV);
-
-#end of file
+#!/usr/bin/env ruby
+
+d = File.expand_path ENV['PWD']
+d.sub! /#{ENV['HOME']}/, '~'
+
+m = d.match %r[([^/]*/[^/]*$)]
+m && d = m[1]
+
+puts d
+
+__END__
+
+sub main {
+
+ my @av = @_;
+
+ $home = $ENV{HOME};
+ $pwd = $ENV{PWD};
+#print "arg: $pwd\n";
+ $pwd =~ s!($home)!~!;
+ $npwd = $pwd;
+
+ $pwd =~ m!([^/]*/[^/]*$)! and do {
+ $npwd = $1;
+#print "1: '$1'\n";
+ };
+
+ print "$npwd";
+}
+
+main( @ARGV);
+
+#end of file

0 comments on commit ba799c6

Please sign in to comment.
Something went wrong with that request. Please try again.