debian/0000775000175000017500000000000013777135524012210 5ustar romualdromualddebian/patches/0000755000175000017500000000000013777127123013631 5ustar romualdromualddebian/patches/series0000644000175000017500000000001513422341743015033 0ustar romualdromualdshebang.diff debian/patches/shebang.diff0000644000175000017500000000023713777127123016074 0ustar romualdromualdReplace 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; debian/source/0000755000175000017500000000000013422341743013473 5ustar romualdromualddebian/source/format0000644000175000017500000000001413422341743014701 0ustar romualdromuald3.0 (quilt) debian/compat0000644000175000017500000000000313422341743013372 0ustar romualdromuald11 debian/copyright0000644000175000017500000000161613422341743014132 0ustar romualdromualdFormat: 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". debian/rules0000755000175000017500000000017513422341743013256 0ustar romualdromuald#!/usr/bin/make -f %: dh $@ override_dh_auto_build: # no build override_dh_auto_install: dh_auto_install -- prefix=/usr debian/watch0000644000175000017500000000021613422341743013223 0ustar romualdromualdversion=4 opts=filenamemangle=s/.+\/v?(\d\S+)\.tar\.gz/mypager-$1\.tar\.gz/ \ https://github.com/romuald/mypager/tags .*/v?(\d\S+)\.tar\.gz debian/control0000644000175000017500000000125613776022763013614 0ustar romualdromualdSource: mypager Maintainer: Romuald Brunet Section: misc Priority: optional Standards-Version: 4.5.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. debian/debhelper-build-stamp0000644000175000017500000000001013777131055016264 0ustar romualdromualdmypager debian/mypager/0000755000175000017500000000000013777131056013646 5ustar romualdromualddebian/mypager/usr/0000755000175000017500000000000013777131056014457 5ustar romualdromualddebian/mypager/usr/bin/0000755000175000017500000000000013777131056015227 5ustar romualdromualddebian/mypager/usr/bin/mypager0000755000175000017500000002611013777131056016621 0ustar romualdromuald#!/usr/bin/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() . "$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 exist, 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 = 1debian/mypager/usr/share/0000755000175000017500000000000013777131056015561 5ustar romualdromualddebian/mypager/usr/share/man/0000755000175000017500000000000013777131056016334 5ustar romualdromualddebian/mypager/usr/share/man/man1/0000755000175000017500000000000013777131056017170 5ustar romualdromualddebian/mypager/usr/share/man/man1/mypager.1.gz0000644000175000017500000000640313777131056021340 0ustar romualdromualdY[s~2AZ$DPvGa"O],XkJvC"\t' rX('-YtƔ/d&$bft`K*FO !RZ'Clq~1Ih7] __.y&}Rqqb/i- {a԰UW~j)\H…-&pL%rHuc^(:Vt4ć070}SpRţO;jt&:\ jo Zo˔} |;24&O AA"Qf3: vQD#FY9YPn R9v#Y[ǟ5jc4I'>">FINF gt*3 2ǿrN3Vyb xv>bO M͚F㯖y$Ƥl;;oc1l3P @|;9i?f$FY s%(wH |)^J9vE\:+b;%sVFmB-wL5u\r_xs cykQ*6JxZaYZow,'Z!\zt߱â}nZQw߷ ="L*U)qXF\|_G^vDY⮊֠:EװQS_p2*MO#}hry5ط;v_k(Q7Qa^ÆymjGk'neHmZޣ쁹=:=x|&ayd&a #Z:#"zŧ{ 4JtoČ7ړNΆ,~g^I3j/#vgF"/N+plYw"~*l8U{et:86.5JVB` +joH%t`QJ*"MA[QpQٱq}vV;dYUD)u/?t?6,qTJ[bhŶf, dҨ ^Q(e"YY.Ze(V3R"N b/O6HX1K7a|;o&ӆ0Y欬~%gdd$ydpd퓿x:U\S?%ڗ'ǯ ^p0oY͊ %iV@;Y(NIx%=Y,(Pyc$0}ڜ/)O> T phkMytJZԁMB>ǗgVN9DEk9OpÀek1L?L?N.lN3 a}'SυE/.hn'癤D{0ڿS+|Sn.LXxlG1(1PiHZD4, &19s M&РSeL<~:Y"d9 v1x"\ @Q[›րNERm,VӺ߇_0DZ o|՜3?'Z7qR>?NcʼnPt)$e˸6ժƮv %(L Kb|t2F^edJL}1v_j;}$E ðfhJL I'Q! [x3K.#n;{8PvLo0I@2@(ә~CSE%@ cRwbE-ΒrFU ˃:7+z2/JY=*R%6.ul)c!ѪmE*Ħۛ7o0멜IRr-ן\=yw|=z {[I3 ɿ`wX8&1L@~-2~pa2K(6imS~`!,91'{WA])56yz|}LR$5q5GĞ_fl(*5=Te]km4:~;hݑgTrJyP7J%!ku'7'IsbS`c9QE׺6$٥o?L+5Bښ#>@;!}:~y*RP. `4<hG)1牶 VR-ָvLWo2tv2;OpGX{׉Tubx-_>μuV}0vdQv?O켋$!( uZe+$hzdFcB"zFPPk^jC4*:r 9QrP UýHeEJb44i4WmrfS*.v* P8oj"'Zm3NEN~|6|?;"IY[}B|,׷%wII7{ml L7g)K U[SjHm.e3kPsڸ,H _|uО&>0psdIj'hN~ԉz2C#i\J2K`YDϭ׮mݍU wvmw[7JZ#`V,Kn!aǔsHL:\/Ĭ5D Q'̓L5(jI?gRwdebian/mypager/usr/share/doc/0000755000175000017500000000000013777131056016326 5ustar romualdromualddebian/mypager/usr/share/doc/mypager/0000755000175000017500000000000013777131056017772 5ustar romualdromualddebian/mypager/usr/share/doc/mypager/copyright0000644000175000017500000000161613422341743021722 0ustar romualdromualdFormat: 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". debian/mypager/usr/share/doc/mypager/changelog.Debian.gz0000644000175000017500000000034513777130755023453 0ustar romualdromualdKK1~/v$u@*x9Sy<,TP0c; kf^)Im ] -peiVp'#b ,RRx6+36dG MfXy7xT ^Bdg3VUG}3Ù/%b/VˁɝɒnٚrC*2ރw"{Edebian/mypager/DEBIAN/0000755000175000017500000000000013777131056014570 5ustar romualdromualddebian/mypager/DEBIAN/control0000644000175000017500000000100313777131056016165 0ustar romualdromualdPackage: mypager Version: 0.6.3-1 Architecture: all Maintainer: Romuald Brunet Installed-Size: 27 Depends: perl (>= 5.8.0), less, libterm-readkey-perl Section: misc Priority: optional Homepage: http://romuald.github.io/mypager/ 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. debian/mypager/DEBIAN/md5sums0000644000175000017500000000040213777131056016104 0ustar romualdromuald9b06dca8be7bdd6f87d2425b18809e8d usr/bin/mypager 00f59428beb76a790af2d48f0ad5cfad usr/share/doc/mypager/changelog.Debian.gz dcceb0a6227cf953c70925aa94e140f1 usr/share/doc/mypager/copyright b549f2682a7187c47e2940f29f40ac88 usr/share/man/man1/mypager.1.gz debian/mypager.debhelper.log0000644000175000017500000000005113777131056016276 0ustar romualdromualdoverride_dh_auto_install dh_auto_install debian/.debhelper/0000755000175000017500000000000013777131056014212 5ustar romualdromualddebian/.debhelper/generated/0000755000175000017500000000000013777131056016150 5ustar romualdromualddebian/.debhelper/generated/mypager/0000755000175000017500000000000013777131056017614 5ustar romualdromualddebian/.debhelper/generated/mypager/installed-by-dh_installdocs0000644000175000017500000000000013777131056025104 0ustar romualdromualddebian/.debhelper/generated/mypager/installed-by-dh_installman0000644000175000017500000000000013777131056024727 0ustar romualdromualddebian/mypager.substvars0000644000175000017500000000006613777131056015626 0ustar romualdromualdperl:Depends=perl:any misc:Depends= misc:Pre-Depends= debian/files0000644000175000017500000000012413777131056013224 0ustar romualdromualdmypager_0.6.3-1_all.deb misc optional mypager_0.6.3-1_amd64.buildinfo misc optional debian/changelog0000644000175000017500000000066613777135524014070 0ustar romualdromualdmypager (0.6.3-1) unstable; urgency=medium * New upstream release -- Romuald Brunet Mon, 11 Jan 2021 20:55:02 +0100 mypager (0.6.2-1) unstable; urgency=low * New upstream release -- Romuald Brunet Fri, 08 Jan 2021 10:39:06 +0100 mypager (0.6.1-1) unstable; urgency=low * Initial release (Closes: #908746) -- Romuald Brunet Wed, 17 Oct 2018 16:59:06 +0200 LICENSE0000644000175000017500000002167013422341743011764 0ustar romualdromualdApache 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 Makefile0000644000175000017500000000170313422341743012412 0ustar romualdromualdwhoami := $(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 MANUAL.pod0000644000175000017500000000570613422341743012442 0ustar romualdromuald=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 =backmypager0000755000175000017500000002611413777130615012356 0ustar romualdromuald#!/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() . "$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 exist, 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 = 1README.rst0000644000175000017500000000765013422341743012450 0ustar romualdromualdMy *(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 uuid.txt0000644000175000017500000000334413342265724012471 0ustar romualdromuald+----+--------------------------------------+--------------------------------------+---------------+-------+---------------+---------------------+ | id | uuid | sharing_id | name | ttl | primary_ns | created_at | +----+--------------------------------------+--------------------------------------+---------------+-------+---------------+---------------------+ | 9 | a08ec86d-422b-412a-98a2-8194f1a5a2ce | 2d550232-2e6c-4a8f-ae65-cf5d77b8bb22 | pouet | 10800 | ns1.gandi.net | 2015-10-06 16:43:13 | | 12 | a6d64a94-4e60-45c1-94bc-4d72c62d4c79 | 2d550232-2e6c-4a8f-ae65-cf5d77b8bb22 | pouet0 | 10800 | ns1.gandi.net | 2015-10-06 16:44:10 | | 28 | 3c11d91c-18eb-4aed-8bdf-fd1474b68b17 | 6302d4ea-2ef1-11e6-afc5-00163ec388ae | Monitoring re | 10800 | ns1.gandi.net | 2015-10-08 18:03:58 | | 31 | d70c9252-8f98-46bb-a34c-a3ee4f1a4730 | af67022f-456c-4b11-889b-f92d4242c439 | First zone | 10800 | ns1.gandi.net | 2015-10-08 22:26:12 | | 34 | 7e923131-b4a7-4ad7-8b5f-cd7f0d4e6bee | 65241051-88e7-450b-8d24-e28bfbdd2b48 | plokiploki.pw | 10800 | ns1.gandi.net | 2015-10-09 09:34:41 | | 37 | 76fa42d8-b3e7-43b4-82e1-b90d91c98a94 | caeb1ca0-5906-4960-ba2b-99cf55e08766 | First zone | 10800 | ns1.gandi.net | 2015-10-09 09:52:08 | | 40 | ffa2d49f-ed59-4450-b374-ec1954c18123 | caeb1ca0-5906-4960-ba2b-99cf55e08766 | Fesse zone | 10800 | ns1.gandi.net | 2015-10-09 09:55:12 | | 46 | 230d54fa-f267-4e3f-8269-e29dbd4a329d | 2dfb9769-764c-4322-a5bf-63685390410e | First zone | 10800 | ns1.gandi.net | 2015-10-09 14:34:22 | +----+--------------------------------------+--------------------------------------+---------------+-------+---------------+---------------------+