Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

My everyday workstation runs GNOME and my editor of choice is gvim. This Perl script can integrate those two tools more tightly.

First of all, did you know that you can use gvim to edit files on remote servers over ssh like this:

gvim scp://servername//path/to/file

Second, did you know that the Nautilus file manager can browse filesystems on remote servers over ssh like this:

nautilus ssh://servername/path/to/dir

Browsing files like that is useful but when you want to edit them you discover that gvim doesn't understand the GNOME VFS URIs. With a little help from Perl, we can translate the ssh:... URIs from GNOME into scp:... URIs for gvim. Save the following script as ~/.gnome2/nautilus-scripts/Open with gvim.

#!/usr/bin/perl use strict; use warnings; my @files; foreach (split /\n/, $ENV{NAUTILUS_SCRIPT_SELECTED_URIS}) { if(s{^file://(/.*)$}{$1}) { push @files, unescape($_); } elsif(s{^ssh://([^/]+)/(.*)$}{scp://$1//$2}) { push @files, unescape($_); } else { system(qq{gdialog --infobox "Unknown URI type: '$_'"}); exit; } } my $msg = "Files:\n" . join("\n", @files); #system(qq{gdialog --infobox "$msg"}); system('gvim', @files); exit; sub unescape { my($data) = $_; $data =~ s/%([\da-f][\da-f])/chr(hex($1))/eg; return $data; }

Once you've saved the script and made it executable, if you right-click on a file in Nautilus, you'll find a 'Scripts' sub-menu with the 'Open with gvim' option. You'll find it works for local and remote files.

Both Nautilus and gvim support other protocols (such as ftp:...). You should find it pretty easy to hack in URI translations for those that you need.


In reply to Nautilus helper script to "Open in gvim" by grantm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2022-01-16 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (49 votes). Check out past polls.

    Notices?