text
stringlengths
0
834k
}
sub dictsort(@) {
my $o = shift if eval { $_[0]->isa(""PPMShell"") };
my $filt = ref($_[0]) eq 'CODE' ? shift @_ : undef;
return map { $_->[0] }
sort { lc $a->[1] cmp lc $b->[1] }
map { [ $_, $filt ? $filt->($_) : $_ ] } @_;
}
sub path_under {
my $path = shift;
my $cmp = shift;
if ($^O eq 'MSWin32') {
$path =~ s#\\#/#g;
$cmp =~ s#\\#/#g;
return $path =~ /^\Q$cmp\E/i;
}
else {
return $path =~ /^\Q$cmp\E/;
}
}
sub prompt_str {
my $o = shift;
# Hack: set the pager here, instead of in settings_setkey()
$o->{API}{pager} = $o->conf('pager');
my @search_results = $o->cache_sets('search');
my $search_result_current = $o->cache_set_current('search');
my $search_result_index = $o->cache_set_index('search');
my @query_results = $o->cache_sets('query');
my $query_result_current = $o->cache_set_current('query');
my $query_result_index = $o->cache_set_index('query');
# Make sure a profile is selected if they turned tracking on.
my $profile_track = $o->conf('profile-track');
my $profile = PPM::UI::profile_get()->result;
$o->setup_profile()
if $profile_track and not $profile and $o->mode eq 'SHELL';
my @targs = PPM::UI::target_list()->result_l;
if (@targs and not find_index($o->conf('target'), 1, @targs)) {
$o->conf('target', $targs[0]);
}
if ($o->conf('prompt-context')) {
my ($targ, $rep, $s, $sp, $q, $qp);
if ($o->conf('prompt-verbose')) {
my $sz = $o->conf('prompt-slotsize');
$targ = substr($o->conf('target'), 0, $sz);
$rep = substr($o->conf('repository'), 0, $sz);
my $sq_tmp = $o->cache_set('search', undef, 'query');
my $ss_tmp = $o->cache_set('search');
my $sp_tmp = $o->cache_entry('search');
$s = (defined $sq_tmp)
? "":"" . substr($sq_tmp, 0, $sz)
: """";
$sp = ($s and defined $sp_tmp and
bounded(0, $search_result_index, $#$ss_tmp))
? "":"" . substr($sp_tmp->name, 0, $sz)
: """";
my $qq_tmp = $o->cache_set('query', undef, 'query');
my $qs_tmp = $o->cache_set('query');
my $qp_tmp = $o->cache_entry('query');
$q = (defined $qq_tmp)
? "":"" . substr($qq_tmp, 0, $sz)
: """";
$qp = ($q and defined $qp_tmp and
bounded(0, $query_result_index, $#$qs_tmp))
? "":"" . substr($qp_tmp->name, 0, $sz)
: """";
}
else {
# Target and Repository:
$targ = find_index($o->conf('target'), 1, @targs);
$targ = '?' if $targ == 0;
# Search number & package:
$s = @search_results ? "":s"".($search_result_current + 1) : """";
my $sp_tmp = $o->cache_set('search');
$sp = ($s and defined $sp_tmp and
bounded(0, $search_result_index, $#$sp_tmp))
? "":sp"".($search_result_index + 1)
: """";
# Query number & package:
$q = @query_results ? "":q"".($query_result_current + 1) : """";
my $qp_tmp = $o->cache_set('query');
$qp = ($q and defined $qp_tmp and
bounded(0, $query_result_index, $#$qp_tmp))
? "":qp"".($query_result_index + 1)
: """";
}
return ""ppm:$targ$s$sp$q$qp> "";
}