package Psh
::Builtins
::Firsttime
;
firsttime is a setup utility which should be used by first-time
psh users. It will parse existing shell rc files and try to
convert as much settings as possible and generate a .pshrc
file. It currently can only convert aliases, bash completions
and environment variables.
my (%aliases,$env,$complete);
Welcome to the Firsttime Setup Utility!
This utility will try to setup an initial .pshrc file for you.
You can interrupt the process anytime using ^C
my $home=Psh
::OS
::get_home_dir
();
You unfortunately do not have a home directory where the .pshrc file could
be stored. Please set the environment variable HOME to a sensible value.
$tmp= Psh
::OS
::catfile
($home,'.pshrc');
$line=Psh
::Util
::prompt
('yn',
"Warning - you already have a .pshrc file!!!!\n".
"Do you really want to continue (y/n)? ");
return (0,undef) if $line eq 'n';
my $text= "# This file was autogenerated by psh firsttime\n\n";
print "Please press ENTER to start...\n";
my @sh_files=qw(.bashrc .bash_login .login);
my @csh_files=qw(.cshrc);
# .alias files usually _only_ contain aliases and functions
# so we offer to source them
$tmp= Psh
::OS
::catfile
($home,'.alias');
$line=Psh
::Util
::prompt
('ics',
"We have found a .alias file. Do you want to\n".
"(c)all it from your .pshrc file\n".
"(i)nsert it into your .pshrc file\n".
$text.="source ~/.alias\n";
$line=Psh
::Util
::prompt
('cs',"Parse (s) bash/sh files or\n (c) csh files? ");
foreach my $file (@sh_files) {
$tmp= Psh
::OS
::catfile
($home,$file);
$line=Psh
::Util
::prompt
('yn',
"Found file $file - parse it (y/n)? ");
foreach my $file (@csh_files) {
$tmp= Psh
::OS
::catfile
($home,$file);
$line=Psh
::Util
::prompt
('yn',
"Found file $file - parse it (y/n)? ");
$text.=_generate_stuff
();
print "The setup process is finished now.\n";
print "Press ENTER to save to $home/.pshrc now or ^C to stop.\n";
open(FILE
,"> $home/.pshrc");
print "$home/.pshrc saved\n";
while ( ($key,$value)= each %aliases) {
$text.="alias $key=$value\n";
if ($line=~/^\s*alias (\S+)\=(.+)$/) {
if (exists $aliases{$key}) {
print STDERR
"Warning: alias $key redefined.\n";
} elsif ($line=~/^\s*function (\S+) \{/) {
while (Psh
::Parser
::incomplete_expr
($tmp)>0 && <FILE
>) {
} elsif ($line=~/^\s*(\S+)\=(.*)$/) {
my $value= _change_env_value
($2);
$env.="setenv $key=$value\n";
} elsif ($line=~/^\s*export (\S+)\=(.+)$/) {
my $value= _change_env_value
($2);
$env.="setenv $key=$value\n";
if ($line=~/^\s*alias (\S+)\s+(.+)$/) {
if (exists $aliases{$key}) {
print STDERR
"Warning: alias $key redefined.\n";
} elsif ($line=~/^\s*setenv\s+(\S+)\s+(.+)$/) {
my $value= _change_env_value
($2);
$env.="setenv $key=\"$value\"\n";
} elsif ($line=~/^\s*set\s+(\S+)\=\s*["]([^\"]+)["]\s*$/ ||
$line=~/^\s*set\s+(\S+)\=\s*[']([^\']+)[']\s*$/ ||
$line=~/^\s*set\s+(\S+)\=\s*(\([^\']+\))\s*$/ ||
$line=~/^\s*set\s+(\S+)\=([^#\s]+)\s*/) {
my $value= _change_env_value
($2);
$env.="setenv $key=$value\n";
return $val if ($val=~/^\'(.*)\'$/); # do not modify if single quotes
$val=~s/\$([a-zA-Z0-9_]+)/\$ENV\{$1\}/g;
return "\"$val\"" if ($val !~ /^\"(.*)\"$/);