From 0f1df0db903ba576fd17b08197d3066af7a61e5f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 18 Nov 2023 23:23:40 +0100 Subject: A lot of changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- man/Makefile | 18 ++++++++++++++++++ man/colourised-less-for-man | 22 ++++++++++++++++++++++ man/man | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 man/Makefile create mode 100755 man/colourised-less-for-man create mode 100755 man/man (limited to 'man') diff --git a/man/Makefile b/man/Makefile new file mode 100644 index 0000000..726047c --- /dev/null +++ b/man/Makefile @@ -0,0 +1,18 @@ +.POSIX: + +install: + ../check-installed-shebang colourised-less-for-man + ../check-installed-shebang man + ../check-in-path dmenu + ../check-in-path sed + ../check-in-path isfg + ../check-in-path less + mkdir -p -- ~/.local/bin + ln -sf -- ~/.dotfiles/man/man ~/.local/bin/ + ln -sf -- ~/.dotfiles/man/colourised-less-for-man ~/.local/bin/ + +uninstall: + +! ../check-installed man + +! ../check-installed man-db + -unlink -- ~/.local/bin/man + -unlink -- ~/.local/bin/colourised-less-for-man diff --git a/man/colourised-less-for-man b/man/colourised-less-for-man new file mode 100755 index 0000000..e57fa18 --- /dev/null +++ b/man/colourised-less-for-man @@ -0,0 +1,22 @@ +#!/bin/dash + +colourise () { + if test -n "$2"; then + from="$(printf "$1"'\n' | sed 's/\[/\\[/g')" + to="$(printf '%s\n' "$2" | sed 's/\[/\\[/g')" + shift 2 + sed "s/$from/$to/g" | "$@" + else + shift 2 + "$@" + fi +} + +sed 's/\x1B\[\(.\)m\x1B\[2\(.\)m/\x1B\[2\2m\x1B\[\1m/g' | \ +colourise "\033[4m" "${LESS_TERMCAP_us}" \ +colourise "\033[24m" "${LESS_TERMCAP_ue}" \ +colourise "\033[1m" "${LESS_TERMCAP_md}" \ +colourise "\033[22m" "${LESS_TERMCAP_me}" \ +colourise "\033[7m" "${LESS_TERMCAP_so}" \ +colourise "\033[27m" "${LESS_TERMCAP_se}" \ +less "$@" diff --git a/man/man b/man/man new file mode 100755 index 0000000..bcd9481 --- /dev/null +++ b/man/man @@ -0,0 +1,44 @@ +#!/bin/dash + +# Browse with dmenu if no page has been specified +if test $# = 0; then + manpage="$(/usr/bin/man -k '' | dmenu -l 40 | sed 's/^\([^ ]*\) (\([^)]*\)).*$/\2 \1/')" + if test -z "$manpage"; then + exit 1 + fi + set $manpage +fi + + +# Bold +export LESS_TERMCAP_md="$(printf '\033[01;34m')" +export LESS_TERMCAP_me="$(printf '\033[0m')" + +# Italic +export LESS_TERMCAP_us="$(printf '\033[01;04;32m')" +export LESS_TERMCAP_ue="$(printf '\033[0m')" + +# Reverse video +if test "$TERM" = linux; then + export LESS_TERMCAP_so="$(printf '\033[07m')" +else + export LESS_TERMCAP_so="$(printf '\033[07;01m')" +fi +export LESS_TERMCAP_se="$(printf '\033[0m')" + +# The above stopped working +if test -z "$MANPAGER"; then + export MANPAGER=colourised-less-for-man +fi + + +# Display, open new terminal if in the background +if isfg; then + exec /usr/bin/man "$@" +elif test -x /usr/bin/terminator; then + exec terminator -e "/usr/bin/man $*" +elif test -x /usr/bin/st; then + exec st -e /usr/bin/man "$@" +else + exec xterm -e /usr/bin/man "$@" +fi -- cgit v1.2.3-70-g09d2