App-BCVI

 view release on metacpan or  search on metacpan

bin/bcvi  view on Meta::CPAN

        summary     => 'port number for listener/port-forward',
        description => <<'END_POD'
When used with C<--listener>, this is the port the server process will listen
on.  When used with C<--wrap-ssh> this is the port number on the remote machine
that will be forwarded back to the listener process.  The default in both cases
is calculated using the user's numeric UID multiplied by 10 and added to 9.
The intent is to reduce the chance of collisions with other bcvi users.
END_POD
    );

    $class->register_option(
        name        => 'command',
        alias       => 'c',
        arg_spec    => '=s',
        arg_name    => '<cmnd>',
        summary     => 'command to send over back-channel',
        description => <<'END_POD'
Use C<cmnd> as the command to send over the back-channel (default: vi).
Recognised commands are described in L<COMMANDS> below.
END_POD
    );

    $class->register_option(
        name        => 'reuse-auth',
        summary     => "don't generate a new auth key on listener startup",
        description => <<'END_POD'
A new (random) authorisation key is generated when the listener process is
started - this will invalidate the keys in use by existing SSH sessions.
This option is for use when it is necessary to restart the listener process
without invalidating client keys.
END_POD
    );

    $class->register_option(
        name        => 'plugin-help',
        arg_spec    => '=s',
        arg_name    => '<plugin>',
        dispatch_to => 'plugin_help',
        summary     => "display documentation for <plugin>",
        description => <<'END_POD'
The --help output includes a list of installed plugins.  Use this option to
read the documentation for a named plugin.
END_POD
    );


    $class->register_command(
        name        => 'vi',
        description => <<'END_POD'
Invokes C<gvim> on the remote file - after translating the host+path to
an scp URI.  This is the default command if no C<--command> option is
specified.  If multiple filenames are supplied, the first will be opened
in gvim and you should use C<:n> to load the 'next' file.
END_POD
    );

    $class->register_command(
        name        => 'viwait',
        description => <<'END_POD'
This command works exactly the same as C<vi> above, except it waits for the
editor process to exit before bcvi exits on the remote machine.  This is
primarily for use with C<sudoedit>.  Note: when used with C<sudoedit>, the file
will not be updated on the remote machine until you exit the editor on your
workstation.
END_POD
    );

    $class->register_command(
        name        => 'scpd',
        description => <<'END_POD'
Uses C<scp> to copy the specified files or directories to the calling user's
F<~/Desktop>.`
END_POD
    );


    $class->add_home_bin();
    $class->register_aliases(
        'test -n "$(which bcvi)" && eval "$(bcvi --unpack-term)"',
        'test -n "${BCVI_CONF}"  && alias vi="bcvi"',
        'test -n "${BCVI_CONF}"  && alias suvi="EDITOR=\'bcvi -c viwait\' sudoedit"',
        'test -n "${BCVI_CONF}"  && alias bcp="bcvi -c scpd"',
    );

    $class->pod_class->init();

}


sub register_option {
    my $class = shift;
    my $opt   = { @_ };
    my $key   = $opt->{name};

    if(!defined $key or !length $key) {
        die "Can't register option without 'name'";
    }

    my($package, $filename, $line) = caller();
    $opt->{provider} = "$package at $filename line $line";
    my $taken = $options{$key};
    if($taken && !$opt->{force_override}) {
        warn "option '--$key' already registered by $taken->{provider}\n";
    }
    if($opt->{alias}) {
        foreach my $a (map { s/^-+//; $_ } split /\|/, $opt->{alias}) {
            if($option_name{$a} && !$opt->{force_override}) {
                if($taken = $options{$option_name{$a}}) {
                    warn "alias '$a' already registered for option "
                       . "'--$taken->{name}' by $taken->{provider}\n";
                }
            }
            $option_name{$a} = $key;
        }
    }
    $options{$key} = $opt;
}


sub register_command {
    my $class = shift;
    my $cmd   = { @_ };
    my $key   = $cmd->{name};

    if(!defined $key or !length $key) {
        die "Can't register command without 'name'";
    }

    $cmd->{dispatch_to} ||= "execute_$key";

    my($package, $filename, $line) = caller();
    $cmd->{provider} = "$package at $filename line $line";
    warn "option '$key' already registered by $commands{$key}->{provider}\n"
        if $commands{$key} && !$cmd->{force_override};
    $commands{$key} = $cmd;
}


sub each_option {
    my($class, $sub) = @_;

bin/bcvi  view on Meta::CPAN

        $parser->parse_file($path);
    }
    else {
        open my $pod_fh, '<', $path or die "open($path): $!";
        my $parser = Pod::Text->new (sentence => 1, width => 78);
        $parser->parse_from_filehandle($pod_fh, $pager);
    }
}


sub pager {
    my @commands = $ENV{PAGER} ? ( $ENV{PAGER} ) : qw(pager less more);
    foreach my $file (@commands) {
        foreach my $dir ( File::Spec->path() ) {
            my $exe_path = File::Spec->catfile($dir, $file);
            if(-x $exe_path) {
                open my $fh, '|-', $exe_path or next;
                return $fh;
            }
        }
    }
    return \*STDOUT;
}


1;

__DATA__

=head1 NAME

bcvi - Back-channel vi, a shell utility to proxy commands back over ssh

=head1 SYNOPSIS

  bcvi [options] [<files>]

  Options:

=for BCVI_OPTIONS_SUMMARY

=head1 DESCRIPTION

This utility works with SSH to allow commands issued on the SSH server host to
be 'proxied' back to the SSH client host.  For example:

=over 4

=item *

user F<sally> establishes an SSH connection from her workstation to a server
named F<pluto> and runs the command C<bcvi .bashrc>

=item *

bcvi tunnels the details back to sally's workstation which then invokes the
command C<gvim scp://pluto//home/sally/.bashrc>

=item *

the result is that sally gets a responsive GUI editor running on her local
machine, but editing a file on the remote machine

=back

See C<< perldoc App::BCVI >> for more examples and background information.

=head1 OPTIONS

=for BCVI_OPTIONS

=head1 COMMANDS

The following commands can be passed back to the listener process.

=for BCVI_COMMANDS

=head1 USING BCVI

You'll need to start a listener process on your workstation (perhaps from
your window manager session startup).

  bcvi -l &

To install the bcvi client to a remote machine:

  bcvi --install <hostname>

To ssh to a server with tunnelling enabled:

  bcvi --wrap-ssh -- hostname

To enable bcvi on all ssh connections:

  alias ssh="bcvi --wrap-ssh --"

On a target server, you'll need to unpack the overloaded TERM variable:

  test -n "$(which bcvi)" && eval "$(bcvi --unpack-term)"

To use vi over the back-channel:

  bcvi filename

The installation to a remote server should set up aliases, e.g.:

  test -n "${BCVI_CONF}"  && alias vi="bcvi"
  test -n "${BCVI_CONF}"  && alias bcp="bcvi -c scpd"

=head1 PLUGINS

=for BCVI_PLUGINS

=head1 COPYRIGHT

Copyright 2007-2012 Grant McLean E<lt>grantm@cpan.orgE<gt>

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut



( run in 0.908 second using v1.01-cache-2.11-cpan-39bf76dae61 )