]> ruderich.org/simon Gitweb - fcscs/fcscs.git/blobdiff - bin/fcscs
add IP mode (mapped to i)
[fcscs/fcscs.git] / bin / fcscs
index 922d755330ae5d5cbbd56a8d10550ce76e849e3d..c06db37987e69e80cccb9d8c706eb4993a81a783 100755 (executable)
--- a/bin/fcscs
+++ b/bin/fcscs
@@ -716,6 +716,8 @@ The following normal modes are available:
 
 =item B<url mode>  select URLs
 
+=item B<ip mode>   select IPv4 and IPv6 addresses
+
 =back
 
 =cut
@@ -743,6 +745,19 @@ sub mapping_mode_url {
         handler => $config->{handler}{url},
     };
 }
+sub mapping_mode_ip {
+    my ($key, $screen, $config, $input) = @_;
+
+    $screen->debug('mapping_mode_ip', 'started');
+
+    my @ipv4 = get_regex_matches($input, $config->{regex}{ipv4});
+    my @ipv6 = get_regex_matches($input, $config->{regex}{ipv6});
+    return {
+        select  => 'ip select',
+        matches => [@ipv4, @ipv6],
+        handler => $config->{handler}{ip},
+    };
+}
 
 =head2 SEARCH MODE (AND EXTEND MODE)
 
@@ -1007,6 +1022,8 @@ them in parentheses):
 
 =item B<u> select URLs (C<\&mapping_mode_url>)
 
+=item B<i> select IPv4 and IPv6 addresses (C<\&mapping_mode_ip>)
+
 =item B</> search for regex to get selection (C<\&mapping_mode_search>)
 
 =item B<q> quit fcscs (C<\&mapping_quit>)
@@ -1052,6 +1069,7 @@ Example:
 my %mapping_mode = (
     f   => \&mapping_mode_path,
     u   => \&mapping_mode_url,
+    i   => \&mapping_mode_ip,
     '/' => \&mapping_mode_search,
     q   => \&mapping_quit,
 );
@@ -1152,6 +1170,10 @@ my %setting = (
 
 =item B<path> used by C<\&mapping_mode_path>
 
+=item B<ipv4> used by C<\&mapping_mode_ip>
+
+=item B<ipv6> used by C<\&mapping_mode_ip>
+
 =back
 
 Example:
@@ -1164,6 +1186,10 @@ my %regex = (
     # Taken from urlview's default configuration file, thanks.
     url  => qr{((?:(?:(?:http|https|ftp|gopher)|mailto):(?://)?[^ <>"\t]*|(?:www|ftp)[0-9]?\.[-a-z0-9.]+)[^ .,;\t\n\r<">\):]?[^, <>"\t]*[^ .,;\t\n\r<">\):])},
     path => qr{(~?[a-zA-Z0-9_./-]*/[a-zA-Z0-9_./-]+)},
+    # IP addresses with optional prefix. Not perfectly accurate but good
+    # enough.
+    ipv4 => qr!\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?:/\d{1,2})?)\b!,
+    ipv6 => qr!\b((?:[0-9a-fA-F]{1,4})?(?::+[0-9a-fA-F]{1,4})+(?:/\d{1,3})?)\b!,
 );
 
 =head2 HANDLERS
@@ -1180,6 +1206,8 @@ The following handlers are available, defaults in parentheses.
 
 =item B<url>   used to open URLs (e.g. in a browser) (C<\&handler_url>)
 
+=item B<ip>    used to handle IPs (C<\&handler_yank>)
+
 =back
 
 Example:
@@ -1203,6 +1231,7 @@ my %handler = (
     yank  => \&handler_yank,
     paste => \&handler_paste,
     url   => \&handler_url,
+    ip    => \&handler_yank,
 );
 
 my %state = (
@@ -1224,6 +1253,7 @@ Create a new Curses attribute with the given fore- and background color.
 
     mapping_mode_path()
     mapping_mode_url()
+    mapping_mode_ip()
     mapping_mode_search()
 
     mapping_paste()
@@ -1261,6 +1291,7 @@ package Fcscs {
 
     sub mapping_mode_path { return main::mapping_mode_path(@_); }
     sub mapping_mode_url { return main::mapping_mode_url(@_); }
+    sub mapping_mode_ip { return main::mapping_mode_ip(@_); }
     sub mapping_mode_search { return main::mapping_mode_search(@_); }
 
     sub mapping_paste { return main::mapping_paste(@_); }