Debian Codegraph @

examples/synopsis

raw
1 #!/usr/bin/perl -w
2
3 # Example code from the module's POD to ensure that it actually works.
4 # Just three simple commands to show argument handling and completion.
5
6 # This file is released under the MIT license.
7
8 use strict;
9 use lib '../lib';
10
11
12 use Term::ShellUI;
13 my $term = new Term::ShellUI(
14 commands => {
15 "cd" => {
16 desc => "Change to directory DIR",
17 maxargs => 1, args => sub { shift->complete_onlydirs(@_); },
18 proc => sub { chdir($_[0] || $ENV{HOME} || $ENV{LOGDIR}); },
19 },
20 "pwd" => {
21 desc => "Print the current working directory",
22 maxargs => 0, proc => sub { system('pwd'); },
23 },
24 "quit" => {
25 desc => "Quit using Fileman", maxargs => 0,
26 method => sub { shift->exit_requested(1); },
27 }},
28 history_file => '~/.shellui-synopsis-history',
29 );
30
31 print 'Using '.$term->{term}->ReadLine."\n";
32 $term->run(@ARGV);
33