summaryrefslogtreecommitdiff
path: root/include/genzshrc
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2008-12-06 12:08:11 +0100
committerDaniel Friesel <derf@derf.homelinux.org>2008-12-06 12:08:11 +0100
commit6a2ab0571f690acab50a7559071c7cdcc4aea27b (patch)
treebfcdf63f023832015127047d1d4c9488dd0a7947 /include/genzshrc
parent0b5b3e2d788b6c6f8819181d20f47165004ec3b6 (diff)
Added include/genzshrc (Maybe for future optimization tests or so)
Diffstat (limited to 'include/genzshrc')
-rwxr-xr-xinclude/genzshrc52
1 files changed, 52 insertions, 0 deletions
diff --git a/include/genzshrc b/include/genzshrc
new file mode 100755
index 0000000..21a022a
--- /dev/null
+++ b/include/genzshrc
@@ -0,0 +1,52 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+my $zshrc = "$ENV{HOME}/.zshrc";
+my $zsource = "$ENV{HOME}/packages/zsh/etc/rc";
+my %subst = (
+ ZDIR => "$ENV{HOME}/packages/zsh/etc",
+ HOME => $ENV{HOME},
+);
+my ($command, $args);
+
+sub substitute($) {
+ my $string = shift;
+ my ($param, $value);
+ while (($param, $value) = each(%subst)) {
+ $string =~ s/\$($param|\{$param\})/$value/g;
+ }
+ return($string);
+}
+
+sub parse($) {
+ my $file = shift;
+ my $fh;
+ open($fh, '<', $file) or die("Can't open $file: $!");
+ while(<$fh>) {
+ chomp;
+ s/^\s*//;
+ if (/^#/ or $_ eq '') {
+ next
+ }
+ if (/^(\S+)(?:\s+(.+))?$/ and deploy($1, $2)) {
+ next;
+ }
+ print;
+ print "\n";
+ }
+ close($fh);
+}
+
+sub deploy($;$) {
+ my ($command, $args) = @_;
+ my $plain_args = substitute($args || '');
+ if ($command =~ /^x?source$/ and -r $plain_args) {
+ print "## source $plain_args\n";
+ parse($plain_args);
+ return(1);
+ }
+ return(0);
+}
+
+parse($zsource);