#!/usr/bin/perl -w # # perl script to extract a shell command from the NEdit configuration. # # Copyright (c) 2000 Joor Loohuis and Philippe Couton. All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # Based on nxlang from Joor Loohuis (joor@nl.linux.org), which do the same for # a language mode. # # revision history: # date author/comment # 2000/10/31 v0.10, Philippe Couton (philippe.couton@sercel.fr) # original version: # rewrite of nxlang to extract shell commands rather than a # language mode. # use strict; use NEdit::Config; use Getopt::Long; use vars qw( $comment $list $version $infile $outfile $cmd $VERSION $version_string $instructions $usage %export $out ); $VERSION = 0.10; my($tool) = /\// ? ($0 =~ m/\/([^\/]+)$/) : $0; $version_string = sprintf "%s %.2f", $tool, $VERSION; $instructions =< ! ! Then, check that the shell command is loaded correctly, and choose Save ! Defaults from the Preferences menu. The new shell command will now be ! incorporated into your own .nedit file, so the next time you start NEdit, ! you will no longer need to use -import. ! ! These comments will not appear in your ~/.nedit ! EOF # extracted using 'pod2usage -v 1' $usage =<<'EOF'; Usage: nxshell [-c] [-l] [-V] [-i file] [-o file] shell_command Options: -c, --comment Prepend a comment area with import instructions to the output. -l, --list List all available shell commands and exit. -V, --version Write the version and exit. -i file, --input file Read the configuration from a file other than $HOME/.nedit. -o file, --output file Write the output to the specified file. Writes to STDOUT by default. EOF $infile = "$ENV{HOME}/.nedit"; # default input $outfile = "-"; # default output GetOptions("c|comment" => \$comment, # prepend instructions "l|list" => \$list, # list shell command names and exit "V|version" => \$version, # print version number and exit "i|input=s" => \$infile, # provide input filename "o|output=s" => \$outfile # provide output filename ); # send output to STDOUT unless a file is specified die "$version_string\n" if (defined $version); # get the language data tie my %config, "Tie::IxHash", read_config($infile) or die "failed to open $infile: $!\n"; tie my %commands, "Tie::IxHash", %{$config{'shellCommands'}}; if ($list) { die "available shell commands:\n\t", join("\n\t", keys %commands), "\n"; } # get the shell command, and add it to the output $cmd = shift or die $usage; exists $commands{$cmd} or die "unknown shell command '$cmd'\n"; $export{'shellCommands'}->{$cmd} = $commands{$cmd}; # add the NEdit version for the configuration, if it exists $export{'fileVersion'} = $config{'fileVersion'} if $config{'fileVersion'}; # write the output open(STDOUT, "> $outfile") or die "can't write to $outfile: $!\n"; print STDOUT "! Shell command for $cmd\n!\n"; print STDOUT $instructions if (defined $comment); print STDOUT format_config(\%export); print STDOUT "\n! generated with $version_string\n"; close STDOUT; =pod =head1 NAME nxshell - extract a shell command from the NEdit configuration =head1 SYNOPSIS nxshell [-c] [-l] [-V] [-i file] [-o file] shell_command =head1 DESCRIPTION nxshell reads C<$HOME/.nedit> and extracts the requested shell command. The output is a file that can be used with the C<-import> option that NEdit provides. =head1 OPTIONS =over 4 =item -c, --comment Prepend a comment area with import instructions to the output. =item -l, --list List all available shell commands and exit. =item -V, --version Write the version and exit. =item -i file, --input file Read the configuration from a file other than $HOME/.nedit. =item -o file, --output file Write the output to the specified file. Writes to STDOUT by default. =back =head1 AUTHOR Joor Loohuis, joor@nl.linux.org and Philippe Couton, philippe.couton@sercel.fr Copyright (c) 2000 Joor Loohuis and Philippe Couton. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO perl(1), nxlang(1), nxmacs(1), NEdit::Config(3). =cut