pax_global_header00006660000000000000000000000064133616471520014522gustar00rootroot0000000000000052 comment=872df042712183aa7278b9fa1980476437748cf7 mypager-0.6.1/000077500000000000000000000000001336164715200131725ustar00rootroot00000000000000mypager-0.6.1/LICENSE000066400000000000000000000216701336164715200142050ustar00rootroot00000000000000Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS mypager-0.6.1/MANUAL.pod000066400000000000000000000057061336164715200146630ustar00rootroot00000000000000=head1 NAME mypager - add color to mysql/psql clients text output =head1 SYNOPSYS Pager tool that will add color to query results of MySQL or PostgreSQL command line clients. It will also automatically use less when terminal isn't able to display the full result in one page. mypager is meant to be used as a pager from the mysql or psql command line clients. To use it you must configure them properly. =head2 USAGE (MYSQL) Inside the mysql client, use the C command, then check using a simple select: pager mypager select 1; Alternatively, you can set mypager as the default pager in your client configuration. In F<$HOME/.my.cnf>: [mysql] pager = mypager =head2 USAGE (PSQL) Unlike the mysql client, there is no specific option in the psql client, you'll have to use the PAGER environment variable: PAGER=mypager psql --connect-options You may wish to add an alias in your preferred shell rc: alias psql="PAGER=mypager psql" Additionally, you'll need to change how query results are shown by editing your F<$HOME/.psqlrc> file: -- Headers and surrounding pipes for columns \pset border 2 -- mypager will decide when to switch to less, but will always add color \pset pager always -- You may want null to be NULL, at your discretion \pset null NULL =head2 CONFIGURATION Configuration is located in F<$HOME/.mypager.conf>, you can create a new configuration file with the current defaults by using C It is also found in the script itself in the __DATA__ section =head3 CONFIGURATION OPTIONS Possible styles documented in L, you may combine them, for example C is a valid style =over 3 =item C Text style for integer (or float) types. Default: green =item C Text style for the NULL value. Default: cyan =item C Text style for datetimes (and date) values. Default: yellow =item C Text style for row headers. Default: underline =item C Text style for row header when mysql is used with the C<\G> flag. Default: magenta =item C Defaults to 1. When 1: mypager will switch to less if it encounters any line longer than screen width (even if they fit within the height of the screen) When 0: it will only take the height as variable to switch to less. =item C Options passed on the the C executable, default to C<-S> (chop long lines) =item C Defaults to 0 If the C<$LESS> environment variable is already set, the default is to set our config options ("less-options") with a lower priority (in case of conflicts) Set to 1 to "override" the environment variable options =item use-less Determine when mypager will use the less executable Valid options: C, C, C, default is C =item fix-utf8 Use to "fix" broken MySQL client UTF-8 output. This bug was fixed a while ago, so this option is disabled by default =backmypager-0.6.1/Makefile000066400000000000000000000017031336164715200146330ustar00rootroot00000000000000whoami := $(shell whoami) MANBASE = /share/man # install to home dir if not root ifeq (root,$(whoami)) prefix := /usr/local else prefix := $(HOME) # Try to guess user local man path MANBASE = $(shell manpath | perl -ne 'chomp; s/^\Q$$ENV{HOME}\E// && print && exit for (split /:/)') # Not currently existing, try a lucky guess :/ MANBASE := /man endif MANUAL = MANUAL.pod INSTALL_BIN = $(DESTDIR)$(prefix)/bin INSTALL_MAN = $(DESTDIR)$(prefix)$(MANBASE)/man1 default: @echo Please use make install @echo Will install script in $(INSTALL_BIN) @echo Will install man page in $(INSTALL_MAN) install: install-bin install-doc install-bin: install -m 0755 -d $(INSTALL_BIN) install -m 0755 -c mypager $(INSTALL_BIN) install-doc: ifneq (,$(wildcard $(MANUAL))) # for future doc install -m 0755 -d $(INSTALL_MAN) pod2man -n 'MYPAGER' -r "" $(MANUAL) $(INSTALL_MAN)/mypager.1 endif uninstall: rm -f $(INSTALL_BIN)/mypager rm -f $(INSTALL_MAN)/mypager.1 mypager-0.6.1/README.rst000066400000000000000000000076501336164715200146710ustar00rootroot00000000000000My *(sql)* Pager ================== - `Usage, Mysql`_ - `Usage, PostgreSQL`_ - `Configuration`_ - `TODO`_ mypager is a tool meant to be used with the MySQL and PostgreSQL command line clients on unix platforms. Its goal is to ease the reading of resultsets, doing 2 things: - coloring data (numbers, dates, UUIDs and NULLs) - using the less command in case the output don't fit in the terminal Here is a sample output: .. image:: http://chivil.com/mysqlpager/sample-colored.png It currently requires perl 5.8, preferably with the `Term::ReadKey `_ module (should work without, using the ``stty`` command) Installation _________________ You can either simply copy the script to the location you wish, or use ``make install`` - when run as **user**, the script will be installed in ``~/bin/`` - when run as **root**, the script will be installed in ``/usr/local/bin/`` Usage, MySQL _________________ To use it you'll just have to tell your mysql client to use it as a pager:: mysql> pager /path/to/mypager or edit your ``~/.my.cnf`` file:: [mysql] pager = /path/to/mypager Usage, PostgreSQL ____________________ The script was originally designed to work with MySQL, but an option exists in PostgreSQL client that format output as mypager expects it. Unlike the mysql client, there is no specific option in the PostgreSQL client, you'll have to use the ``PAGER`` environment variable, for example:: export PAGER=/path/to/mypager psql --stuff Or in your ``.bashrc`` / ``.zshrc``:: alias psql="PAGER=/path/to/mypager psql" Then, you'll have to edit your ``.psqlrc`` file to set 2 default options:: -- Headers and surrounding pipes for columns \pset border 2 -- mypager will decide when to switch to less, but will always add color \pset pager always -- You may want null to be NULL, at your discretion -- \pset null NULL Configuration _________________ The configuration file is located in ``~/.mypager.conf``. A default configuration is present at the end of the script itself, should you wish to modify it instead. You can use ``mypager --installconf`` to write the default configuration to ``~/.mypager.conf``. Styles ------- Current available styles are ``style-int``, ``style-null``, ``style-date``, ``style-header``, ``style-row`` *header* and *row* styles are used for the ``\G`` option of the mysql client (vertically formated output) You can use any recognized value of the `Term::ANSIColor `_ module, and combine them as you please. Some valid examples: ``red``, ``bold blue``, or ``underline white on_black`` Other options -------------- long-lines-to-less 0/**1**, with this option set to 1, the pager will switch to less whenever it encounters a line longer than screen width (even if the screen has enough height available) less-options **-S**, these are the options sent to less (check out the *OPTIONS* section of the man page for a complete list). The default is to chop long lines, you can add your own choice here, like *-I* to make searches case insensitive. less-options-overrides-env **0**/1, the default behavior is to add *less-options* before your *$LESS* environment variable so that the options set by your environment take precedence over the script options. Set to *1* to reverse the behavior. use-less **auto**/always/never, will determine whenever or not to switch to less, should you wish to alway use it or just colorize the output fix-utf8 **0**/1, try to fix broken UTF-8 output of older (< 5.5 ?) MySQL clients. This option fixes unaligned columns when 2 bytes characters are present in a cell. uuid-color 0/**1**, colorize UUIDs. The UUIDs are colorized using a MD5 hash, to more easily identify 2 identical UUIDs in a list. This is especially useful when listing UUID1 created in short amount of time TODO __________ probably lots mypager-0.6.1/debian/000077500000000000000000000000001336164715200144145ustar00rootroot00000000000000mypager-0.6.1/debian/changelog000066400000000000000000000002311336164715200162620ustar00rootroot00000000000000mypager (0.6.1-1) unstable; urgency=low * Initial release (Closes: #908746) -- Romuald Brunet Wed, 17 Oct 2018 16:59:06 +0200 mypager-0.6.1/debian/compat000066400000000000000000000000031336164715200156130ustar00rootroot0000000000000011 mypager-0.6.1/debian/control000066400000000000000000000012561336164715200160230ustar00rootroot00000000000000Source: mypager Maintainer: Romuald Brunet Section: misc Priority: optional Standards-Version: 4.2.1 Build-Depends: debhelper (>= 11~), perl (>= 5.8.0) Vcs-Git: https://github.com/romuald/mypager.git Vcs-Browser: https://github.com/romuald/mypager Homepage: http://romuald.github.io/mypager/ Package: mypager Architecture: all Depends: perl (>= 5.8.0), less, libterm-readkey-perl, ${misc:Depends} Description: pager for MySQL/PostgreSQL command line clients Userfriendly pager that will add color to query results of MySQL or PostgreSQL command line clients. It will also automatically use less when terminal isn't able to display the full result in one page. mypager-0.6.1/debian/copyright000066400000000000000000000016161336164715200163530ustar00rootroot00000000000000Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: mypager Source: https://github.com/romuald/mypager Files: * Copyright: 2013 Romuald Brunet License: Apache-2.0 License: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at . http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. . On Debian systems, the complete text of the Apache version 2.0 license can be found in "/usr/share/common-licenses/Apache-2.0". mypager-0.6.1/debian/patches/000077500000000000000000000000001336164715200160435ustar00rootroot00000000000000mypager-0.6.1/debian/patches/series000066400000000000000000000000151336164715200172540ustar00rootroot00000000000000shebang.diff mypager-0.6.1/debian/patches/shebang.diff000066400000000000000000000002371336164715200203060ustar00rootroot00000000000000Replace default env shebang by the system perl --- a/mypager +++ b/mypager @@ -1,4 +1,4 @@ -#!/usr/bin/env perl +#!/usr/bin/perl package main; use strict; mypager-0.6.1/debian/rules000077500000000000000000000001751336164715200154770ustar00rootroot00000000000000#!/usr/bin/make -f %: dh $@ override_dh_auto_build: # no build override_dh_auto_install: dh_auto_install -- prefix=/usr mypager-0.6.1/debian/source/000077500000000000000000000000001336164715200157145ustar00rootroot00000000000000mypager-0.6.1/debian/source/format000066400000000000000000000000141336164715200171220ustar00rootroot000000000000003.0 (quilt) mypager-0.6.1/debian/watch000066400000000000000000000002161336164715200154440ustar00rootroot00000000000000version=4 opts=filenamemangle=s/.+\/v?(\d\S+)\.tar\.gz/mypager-$1\.tar\.gz/ \ https://github.com/romuald/mypager/tags .*/v?(\d\S+)\.tar\.gz mypager-0.6.1/mypager000077500000000000000000000261161336164715200145720ustar00rootroot00000000000000#!/usr/bin/env perl package main; use strict; use warnings; require 5.008_000; our $VERSION = '0.6.0'; use Module::Load; use POSIX ":sys_wait_h"; use Encode qw/encode_utf8 decode_utf8/; use Digest::MD5 qw/md5/; use Term::ANSIColor qw/color colored/; my $reset = color('reset'); # Different styles for different types # Try to determine the screen size from module or stty my ($term_cols, $term_lines) = (0, 0); eval { load Term::ReadKey; ($term_cols, $term_lines) = Term::ReadKey::GetTerminalSize(); } or eval { ($term_lines, $term_cols) = split /\s+/, `stty -F /dev/stderr size`; }; # Load (or install) configuration my %CONF; { no warnings qw/prototype/; if ( grep /^--installconf$/, @ARGV ) { MyPager::Config::write_defaults(); exit; } %CONF = %{ MyPager::Config::get_config() || {} }; } my $style_int = color($CONF{'style-int'}) || ''; my $style_null = color($CONF{'style-null'}) || ''; my $style_date = color($CONF{'style-date'}) || ''; # Column header in the \G style # TODO column headers too my $style_header = color($CONF{'style-header'}) || ''; # Row headers in the \G style my $style_row = color($CONF{'style-row'}) || ''; $ENV{LESS} ||= ""; $CONF{"less-options"} ||= ""; if ( $CONF{"less-options-overrides-env"} ) { $ENV{LESS} = $ENV{LESS} . $CONF{"less-options"}; } else { $ENV{LESS} = $CONF{"less-options"} . $ENV{LESS}; } # Global print "buffer" scalar and filehandle # Used to store data before sending it to `less` or stdout my $outhandle; my $outstring = ""; open($outhandle, "+>", \$outstring) or die("Can't create temporary buffer"); select($outhandle); END { # If less was used, then outstring will be empty print STDOUT $outstring if $outstring; } my $UUIDCOLORS = [ [map {color($_)} "rgb511", "rgb522", "rgb533", "rgb544"], # red [map {color($_)} "rgb151", "rgb252", "rgb353", "rgb454"], # green [map {color($_)} "rgb115", "rgb225", "rgb335", "rgb445"], # blue [map {color($_)} "rgb551", "rgb552", "rgb553", "rgb554"], # yellow [map {color($_)} "rgb515", "rgb525", "rgb535", "rgb545"], # magenta ]; sub uuid_color() { my $digest = md5("$1$2$3$4$5"); my @b = unpack('CCCCCC', $digest); my @colors = @{ $UUIDCOLORS->[$b[0] % @$UUIDCOLORS] }; return $colors[$b[1] % @colors] . "$1$reset-" . $colors[$b[2] % @colors] . "$2$reset-" . $colors[$b[3] % @colors] . "$3$reset-" . $colors[$b[4] % @colors] . "$4$reset-" . $colors[$b[5] % @colors] . "$5$reset"; } my $input_format = ""; # unknown by default; # Columns ("|") positions for standard input my @columns; # First line with +---+-----+ or ****** my $header = ; if ( $header =~ /^\+(?:-+\+)+$/ ) { $input_format = "std"; if ( $CONF{"fix-utf8"} ) { my $i = 0; for my $char ( split //, $header ) { push(@columns, $i) if $char eq "+"; $i++; } } print $header; } elsif ( $header =~ /^\*+/ ) { $input_format = "vertical"; print $style_row, $header, $reset; } else { # Unknown format, will proceed without coloring print $header; } my $date = '\d{4}-\d{2}-\d{2}'; my $time = '\d{2}:\d{2}:\d{2}(?:\.\d+)?'; my $uuid = '([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})'; # Quick max function :p sub max(@) { (sort @_)[-1] } =head2 fixutf8 Try to fix mysql utf8 buggy output by balancing n bytes characters with white spaces at the end of each column =cut sub fixutf8($) { my $line = $_[0]; my $uline; # decoded (unicode) version eval { $uline = decode_utf8($line, Encode::FB_CROAK); }; return $_[0] if ( $@ # decode error || length($uline) >= length($header) # no line change || length($_[0]) != length($header) # no line change || $uline !~ m/^\|.*\|$/ # probably multiline ); # $line was overwritten by decode $line = $_[0]; my @cells; my $i = 0; for (; $i < @columns-1; $i++) { # For each cell, try to determine if more bytes # than chars are used in output my $part = substr($line, $columns[$i], $columns[$i+1] - $columns[$i]); my $upart = decode_utf8($part); my $diff = length($part) - length($upart); if ($diff <= 0) { push @cells, $part; next; } # Append whitespaces corresponding to the additional bytes substr($upart, length($upart)-1, 0, " " x $diff); push @cells, encode_utf8($upart); } return join "", @cells, substr($line, $columns[$i]); } # If output to a non-terminal, don't bother sending data to less my $less; my $lesspid; my $useless; =head2 switch_to_less Open less in a subprocess, flush the current output buffer and set the standard output to it =cut sub switch_to_less() { $lesspid = open($less, '| less -R') or die("Can't open less"); select($less); print $outstring; close($outhandle); $outstring = ""; } =head2 less_no_more Called when sure we won't use less so we don't buffer output internally =cut sub less_no_more() { $useless = 0; select STDOUT; print $outstring; close($outhandle); $outstring = ""; } # Decide whenever to use less or not .. or maybe if ( !-t STDOUT ) { # Output is not a TTY: just colorize less_no_more(); } else { # Else determine behavior from configuration if ( $CONF{'use-less'} eq 'never' ) { less_no_more(); } elsif ( $CONF{'use-less'} eq 'always' ) { $useless = 1; switch_to_less(); } else { # auto, or any other setting $useless = 1; } } my $cur_cols = length($header); my $cur_lines = scalar(grep /\n/, $outstring); my $count = 0; while (my $line = ) { if ( !$less && $useless ) { $cur_lines++; $cur_cols = max($cur_cols, length($line)); # adding lines may lead to full terminal height # will lead to using less, which will wrap long lines if ( not $CONF{"long-lines-to-less"} ) { $cur_lines += int(length($line) / $term_cols); } if ( $cur_lines > $term_lines || ($CONF{"long-lines-to-less"} && $cur_cols - 1 > $term_cols) ) { switch_to_less(); } } elsif ( $lesspid && $count++ == 300 ) { # every 300 rows, check that less didn't exit # (don't hang CPU on large resultsets) $count = 0; if ( -1 == waitpid($lesspid, WNOHANG)) { last; } } if ( $input_format eq "std" ) { $line = fixutf8($line) if $CONF{"fix-utf8"}; $line =~ s/(\| +)(NULL +)(?=\|)/$1$style_null$2$reset/g; $line =~ s/(\| +)(-?\d+\.?\d*(?:e\+\d+)? )(?=\|)/$1$style_int$2$reset/g; $line =~ s/\| ((?:$date(?: $time)?|(?:$date )?$time) +)(?=\|)/| $style_date$1$reset/g; $line =~ s/\| $uuid( +)(?=\|)/"| " . uuid_color() . "$6$reset"/gie if $CONF{"uuid-color"}; } elsif ( $input_format eq "vertical" ) { $line =~ s/^((\*{27}) \d+\..*? \*{27})/$style_row$1$reset/; $line =~ s/^( *)(\S+)(?=: )/$1$style_header$2$reset/; $line =~ s/: (NULL)$/: $style_null$1$reset/ || $line =~ s/: (-?\d+\.?\d*)$/: $style_int$1$reset/ || $line =~ s/: ((?:$date(?: $time)?|(?:$date )?$time))$/: $style_date$1$reset/; $line =~ s/: $uuid$/": " . uuid_color() . "$6$reset"/ie if $CONF{"uuid-color"}; } print $line; } close($less) if $less; # this should be placed in another file, but I'd really # like to keep this utility in one script package MyPager::Config; use strict; use warnings; use Fcntl qw/SEEK_SET/; use constant CONFPATH => "~/.mypager.conf"; sub get_config() { my %return = (); my $config_file = CONFPATH; $config_file = glob($config_file); my @todo = strdata(); # Config file overwrites defaults if ( -f $config_file && -r _ ) { open CONF, $config_file; push @todo, join("", ); close CONF; } else { $return{'-defaults'} = 1; } for my $strconf (@todo) { # Remove inline comments $strconf =~ s/(?; seek(DATA, $origin, SEEK_SET); return $strconf; } =head2 write_defaults Try to write default configuration, may ask permission to overwrite =cut sub write_defaults() { my $config_file = CONFPATH; $config_file = glob($config_file); if ( -f $config_file ) { local $| = 1; # autoflush print STDERR "$config_file already exits, Overwrite? [y/N] "; my $response = ; exit unless $response =~ /^y/i; } my $ok = open(CONFWRITE, "> $config_file"); if ( !$ok ) { print STDERR "Unable to open $config_file for writing ($!)\n"; exit 1; } print CONFWRITE strdata(); close CONFWRITE; } 1; # Bellow is the default config, you can copy its contents to ~/.mypager.conf # if you wish to configure it. # Or simply change the values bellow :) __DATA__ # This is the default configuration file # Colors for each style # See Term::ANSIColor documentation for a complete list of available styles style-int = green style-null = cyan style-date = yellow # Column header in the \G style style-header = underline # Row headers in the \G style style-row = magenta # NOTE, you can combine multiple styles too, for example: # style-null = blink bold cyan # 1: mypager will switch to less if it encounters any line longer than screen # width (even if they fit within the height of the screen) # 0: it will only take the height as variable to switch to less. long-lines-to-less = 1 # Options passed on to less (as environment variable) # default: -S to chop long lines # you can add -I for case insensitive searches for example # `man less` for all options less-options = -S # If the $LESS environment variable is already set, the default is to set our # config options ("less-options") with a lower priority (in case of conflicts) # Set to 1 to "override" the environment variable options less-options-overrides-env = 0 # Use less .. or not. Valid values are: auto, always, never use-less = auto # Fix broken MySQL client output # Now useless with recent clients fix-utf8 = 0 # UUID colorization uuid-color = 1