From: Simon Ruderich Date: Mon, 1 Feb 2016 07:55:02 +0000 (+0100) Subject: multiple documentation improvements X-Git-Url: https://ruderich.org/simon/gitweb/?p=fcscs%2Ffcscs.git;a=commitdiff_plain;h=1beed87f2aa993a61aff87793fc4e5f32ea3369d multiple documentation improvements --- diff --git a/bin/fcscs b/bin/fcscs index 27c133a..6741a91 100755 --- a/bin/fcscs +++ b/bin/fcscs @@ -62,6 +62,7 @@ Short overview of the general usage, details below: - ... - select mode (optional, URL mode is used on startup): - f: file paths + - i: IPs - u: URLs - ... - /: search mode @@ -989,15 +990,18 @@ settings see below): # Draw matches in blue. $config{attribute}{match_string} = color_pair(COLOR_BLUE, -1); - # Enable Vim-like 'smartcase', ignore case until an upper character is + # Draw numbers in bold yellow. + $config{attribute}{match_id} = color_pair(COLOR_YELLOW, -1) + | A_BOLD; + # Disable Vim-like 'smartcase', ignore case until an upper character is # searched. - $config{setting}{smartcase} = 1; + $config{setting}{smartcase} = 0; # Use chromium to open URLs if running under X, elinks otherwise. if (defined $ENV{DISPLAY}) { $config{setting}{browser} = ['chromium']; } else { - $config{setting}{browser} = ['elinks']; + $config{setting}{browser} = ['elinks', '-remote']; } # Let fcscs know the file was loaded successfully. @@ -1034,7 +1038,7 @@ local $SIG{__WARN__} = sub { I: Mappings are split in two categories: Mode mappings which change the selection and may receive additional input (e.g. a search string) and simple -mappings which only change some value. Mode mappings are configured via +mappings which only change some config value. Mode mappings are configured via C<$config{mapping}{mode}>, simple mappings via C<$config{mapping}{simple}>. The following mode mappings are available by default (the function to remap @@ -1297,7 +1301,6 @@ Used as mappings, see L above. Used as handler to yank, paste selection or open URL in browser. - debug() get_regex_matches() select_match() run_command() @@ -1307,7 +1310,47 @@ Helper functions when writing custom mappings, see the source for details. Example: - TODO + # Enhance URL mode by updating the mapping. + $config{mapping}{mode}{u} = sub { + my ($key, $screen, $config, $input) = @_; + + # First get matches of normal URL mode. + my $result = mapping_mode_url(@_); + + # Add all strings matching "CVE-1234-1234" with URLs pointing to the + # Debian security tracker. "->{value}" is the string which is used as + # result of the match (e.g. the URL in this case). + my @matches = get_regex_matches($input, qr/\b(CVE-\d+-\d+)\b/); + foreach (@matches) { + $_->{value} = "https://security-tracker.debian.org/$_->{string}"; + } + push @{$result->{matches}}, @matches; + + # Change all YouTube links to use the custom "youtube" handler (see + # below). This will allow us to automatically open YouTube URLs with a + # custom program, like `youtube-dl` or `mpv`. + foreach (@{$result->{matches}}) { + if ($_->{string} =~ m{^https://www.youtube.com/}) { + $_->{handler} = $config{handler}{youtube}; + } + } + + return $result; + } + # Also update initial mode to use our new "URL mode". + $config{setting}{initial_mode} = $config{mapping}{mode}{u}; + + # Special handler to download YouTube URLs with `youtube-dl`. You could + # also use `mpv` here to immediately play them. + $config{handler}{youtube} = sub { + my ($screen, $config, $match) = @_; + + return run_in_background($screen, sub { + run_command($screen, ['youtube-dl', $match->{value}]); + }); + }; + + =cut