Here's a simple idea that others might find useful. Lately I've been playing around with Google Appengine. Like Catalyst and Ruby on Rails, you create directory for your project, and you often need to refer to this directory to access project specific scripts and files. The problem is that I often don't use a GUI editor for development, and so I navigate around my project files using cd and ls. Consequently, when it comes time to run a project-related command, my current working directory could be anywhere in my project tree.

A way I've found to mitigate this is to mark the project root by creating a special file there - like .appengine. Then I write a script that can be used with all AppEngine projects that goes something like this:

#!/usr/bin/perl use strict; use warnings; use Cwd; use File::Basename qw(dirname); sub app_directory { my $updir = getcwd; my $dir = ''; while ($updir ne $dir) { $dir = $updir; if (-f "$dir/.appengine") { return "$dir/app"; } $updir = dirname($dir); } die "not in an appengine workspace\n"; } sub sys { print "Executing: @_\n"; my $st = system {$_[0]} @_; if ($st == -1) { die "Exec failed: $!\n"; } } sub appdir { print app_directory(), "\n"; } sub server { my $appdir = app_directory(); sys("dev_appserver.py", "--address=0.0.0.0", $appdir, @_) } sub appcfg { my $appdir = app_directory(); my $cmd = shift; sys("appcfg.py", @_, $cmd, $appdir); } sub help { print <<END; Available appengine commands: help - list available commands appdir - print workspace directory server ... - start server update ... - perform update appcfg ... - invoke appcfg.py END } my $cmd = shift; if ($cmd eq "server") { server(@ARGV); } elsif ($cmd =~ m{\A(update|rollback|update_indexes|vacuum_indexes)\z}) { appcfg($cmd, @ARGV); } elsif ($cmd eq "appdir") { appdir(@ARGV); } elsif ($cmd eq "help") { help(@ARGV); } else { die "unknown command: $cmd -- use 'help' for a list of commands\n"; }

The way it works is this: after editing and viewing files I decide I want to upload the project to AppEngine. The command for that is:
appcfg.py update project_root
Instead of having to remember what my project root is, I can just type:
appeng update
and the appeng script will run the correct command for me.

Another example: using the appdir command you can quickly cd to your project's root with:

cd "$(appeng appdir)"
Of course, this can be made a shell alias or function.

This script also serves as a way of defining shortcuts for frequently run commands much like a Makefile. Indeed, I often write a make command for these kinds of scripts that will perform a cd and execute a top-level make.

Also, I've found this approach to be very helpful when working on multiple versions of a project each in their own directory.

I'm sure I'm not the first person to think of this idea, but I've found it very useful, so I thought I'd share it. And I decided to write it in perl.


In reply to poor man's IDE by pc88mxer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.