Something went wrong. Try again.
a less like pager but for fun
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305#!/usr/bin/env bash
# Copyright (c) 2026 codie.# Permission is granted to copy, distribute and/or modify this document# under the terms of the GNU Free Documentation License, Version 1.3# or any later version published by the Free Software Foundation;# with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.# A copy of the license is included in the section entitled "GNU# Free Documentation License".
VERSION=`git describe`NAME="kk"SECTION="1"DATE=$(printf '%(%b %Y)T\n' "-1")
# Disable unicode.LC_ALL=CLANG=C
# ///////////////////////////// HELPER FUNCTIONS ///////////////////////////// #
debug() { printf $@ >&2 echo >&2}
# ///////////////////////////////// SECTIONS ///////////////////////////////// #
section_name() { printf ".SH NAME\n" printf ".B kk\n" printf "\- stupid pager\n" printf "\n"}
section_synopsis() { printf ".SH SYNOPSIS\n" printf ".B kk\n" printf ".RI [\| "OPTIONS" \|]\n" printf "[\|\-\-\|]\n" printf ".RI [\| "FILE" \|]\n" printf "\n"}
section_description() { printf ".SH DESCRIPTION\n" printf ".B kk\n" printf "is a hobbiest pager which aims to be a small but reliable programm.\n" printf "It uses\n" printf ".B ncurses(3)\n" printf "to display content and colors.\n"
printf "\n"}
section_options() { printf ".SH OPTIONS\n" printf "Arguments are also taken from the enviroment via the\n" printf ".RB $ KKOPTS\n" printf "variable. For example, to avoid using \n" printf ".RB ' kk\n" printf ".B -r\n" printf ".IR ... '\n" printf "each time to enable ansi color parsing, you might want to set\n" printf ".RB $ KKOPTS\n" printf "to '-r'\n\n"
printf "Options that are duplicated either on the command line, in\n" printf ".RB $ KKOPTS\n" printf "or both, are not harmful but the latest of which will override previous ones.\n\n"
printf "Options of which that include\n" printf ".RI ' [no-] '\n" printf "in their long options, can be appended thus and revert the changes described.\n" printf "Alike duplicate options, latest of which will override previous ones,\n" printf "therefore\n" printf ".RI ' --no- '\n" printf "options can be used instead of\n" printf ".B -D\n" printf "to surgically disable options set in\n" printf ".RB $ KKOPTS .\n\n"
printf "Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.\n"
printf ".IP \\\"" printf "\\\fB\\--separator=\\\fISEP\\\fP or \\\fB--sep=\\\fISEP\n" printf "Specifies the separator which will be used to split lines on.\n" printf "Currently does not support control characters.\n"
printf ".IP \\\"" printf "\\\fB\\-z\\\fP or \\\fB--zero-terminated\n" printf "Changes the line separator to a null character, instead of a new line.\n" printf "This can be useful for displaying output from other programs that use\n" printf "null as means of indicating fields.\n"
printf ".IP \\\"" printf "\\\fB\\-f\\\fP or \\\fB--[no-]force\n" printf "Normaly,\n" printf ".B kk\n" printf "will refuse to open non-regular files.\n" printf "(A non-regular file is a directory or a device special file.)\n" printf "Setting this option will override this check.\n"
printf ".IP \\\"" printf "\\\fB\\-g\\\fP or \\\fB--[no-]git\n" printf "Enables\n" printf ".B git(1)\n" printf "support. Currently only implies --parse-ansi.\n" printf "This option is useful to be set in\n" printf ".RB $ GIT_PAGER .\n"
printf ".IP \\\"" printf "\\\fB\\-l\\\fP or \\\fB--[no-]line-number\n" printf "Displays line numbers at the begining of each line.\n" printf "Unlike\n" printf ".BR less(1) ,\n" printf ".B kk\n" printf "calculates maximum line number at the start, so enabling this option\n" printf "doesn't have performance implications beyond which is already present.\n"
printf ".IP \\\"" printf "\\\fB\\-r\\\fP or \\\fB--[no-]parse-ansi\n" printf "Enables parsing of ANSI color escape sequences.\n" printf "ANSI color escape sequences are of the form;\n\n" printf " ESC [ ... m\n\n" printf "where \"...\" is zero or more color spesification characters.\n" printf "(Of which there is a hard limit of 4 characters. This is subject to change)\n" printf "Color escape sequences are only support of which change color only on one line,\n" printf "and all color formating is reset between each line.\n"
printf ".IP \\\"" printf "\\\fB\\-s\\\fP or \\\fB--[no-]small-paging\n" printf "Tells\n" printf ".B kk\n" printf "to start paging for inputs that can fit in one screen window.\n" printf "This option uses ioctl TIOCWINSZ ,\n" printf ".RB $ KK_SHELL_LINES\n" printf "and\n" printf ".RB $ KK_LINES\n" printf "to determine the size of the console instead of using ncurses idea of screen height.\n"
printf ".IP \\\"" printf "\\\fB--line-num-padding=\\\fIBEFORE\\\fB|\\\fIAFTER\\n" printf "Sets the style of padding used by\n" printf ".BR -l .\n"
printf ".IP \\\"" printf "\\\fB\\-t\\\fP or \\\fB--tabsize=\\\fISIZE\n" printf "Sets the tabstop period to determine how to display tab chacacters.\n" printf "Cannot be less than or equal to 1\n"
printf ".IP \\\"" printf "\\\fB\\-D\\\fP or \\\fB--defaults\n" printf "Resets all options as if they were never passed.\n" printf "May be useful for reseting options set in\n" printf ".RB $ KKOPTS .\n"
printf ".IP \\\"" printf "\\\fB\\-h\\\fP or \\\fB--help\n" printf "Displays help and exits.\n"
printf ".IP \\\"" printf "\\\fB\\-V\\\fP or \\\fB--version\n" printf "Displays version and build info and exits.\n"}
# TODO: get current build options and display thatsection_enviroment() { printf ".SH ENVIROMENT\n"
printf ".TP\n" printf ".B KKOPTS\n" printf "Extra arguments passed to the program, parsed prior to \n" printf ".BR kk 's\n" printf "own command line. Style of these arguments are expected to be of a similar format.\n" printf "Options requiring an argument will be overridden by the same option found on the command line.\n" printf "\n" printf "\n\n" printf "To reset all of the options set in\n" printf ".RB $ KKOPTS ,\n" printf ".B -D\n" printf "can be passed as the initial command line option\n"
printf ".TP\n" printf ".B KK_SHELL_LINES\n" printf "When -s option is not set,\n" printf ".B kk\n" printf "exits automaticly when input lines are less than or equal to screen height minus\n" printf ".RB $ KK_SHELL_LINES .\n" printf "Thus, if you use a shell prompt which occupies more than one screen line,\n" printf "this variable can be set to the number of lines used by your prompt, to ensure\n" printf "that the entire file can be seen. If not set,\n" printf ".RB $ KK_SHELL_LINES\n" printf "is assumed to be 1.\n"
printf ".TP\n" printf ".B KK_COLUMNS\n" printf "Sets the number of columns on the screen. Overrides\n" printf ".RB $ COLUMNS\n" printf "and/or what ncurses idea of the screen size is,\n" printf "so it can be used to make\n" printf ".B kk\n" printf "use less than the full screen width.\n"
printf ".TP\n" printf ".B KK_LINES\n" printf "Sets the number of lines on the screen. Overrides\n" printf ".RB $ LINES\n" printf "and/or what ncurses idea of the screen size is,\n" printf "so it can be used to make\n" printf ".B kk\n" printf "use less than the full screen height.\n"
printf ".TP\n" printf ".B KK_TMP_DIR\n" printf "If set, its value is used to create tmp inodes in.\n" printf " default: /tmp\n"
printf ".TP\n" printf ".B KK_HELP_FILE\n" printf "If set, its value is used to read display help.txt.\n" printf " default: /usr/share/kk/help.txt\n"
printf "\n"}
# section_files() {# printf ".SH FILES\n"# printf ".TP\n"# printf ".I ...\n"# printf "configuration file.\n"# printf ".TP\n"# printf ".B /tmp\n"# printf "Directory for creating unnamed inodes to store stdin as a stream. All data will be lost when\n"# printf ".B kk\n"# printf "exits.\n"# printf "\n"# }
# section_notes() {# printf ".SH NOTES\n"# printf "\n"# }
# section_bugs() {# printf ".SH KNOWN BUGS\n"# printf "\n"# }
# section_examples() {# printf ".SH EXAMPLES\n"# printf ".TP\n"# printf ".B kk \\\fIfile\n"# printf "Open\n"# printf ".I file\n"# printf "in\n"# printf ".BR kk .\n"# }
section_authors() { printf ".SH AUTHOR\n" printf "Written by codie <codieuwu@gmail.com>\n" printf "(author info pending change)\n" printf "\n"}
section_see_also() { printf ".SH SEE ALSO\n" printf ".BR less(1),\n" printf ".BR more(1)\n" # printf ".PP\n" # printf "also checkout the tangled.org page" printf "\n"}
main() {
printf ".\\\ Copyright (c) 2026 codie." printf ".\\\ Permission is granted to copy, distribute and/or modify this document" printf ".\\\ under the terms of the GNU Free Documentation License, Version 1.3" printf ".\\\ or any later version published by the Free Software Foundation;" printf ".\\\ with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts." printf ".\\\ A copy of the license is included in the section entitled \"GNU" printf ".\\\ Free Documentation License\"."
printf ".\\\"Man page for kk.\n" printf ".\\\" Open an issue at https://tangled.sh/codieuwu.bsky.social/kk for typos and corrections.\n\n"
printf ".TH kk \"$SECTION\" \"$DATE\" \"$VERSION\" \"\"\n\n"
section_name section_synopsis section_description section_options section_enviroment # section_files # section_notes # section_bugs # section_examples section_authors section_see_also}
main $@