forked from erlehmann/uii
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uiipager
executable file
·24 lines (24 loc) · 1.06 KB
/
uiipager
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh
# read <http://www.gnu.org/software/termutils/manual/termutils-2.0/html_chapter/tput_1.html#SEC8>
echo "USAGE: $0 OUTFILE INFILE HIGHLIGHT PROMPT"
test -n "$1" && test -n "$2" && test -e "$1" && test -e "$2" || exit 1;
trap "kill 0" 0 1 2 5 15
BOLD=`tput bold`; RESET=`tput sgr0`; BANNED=`printf "\001-\011\013-\037"`
init () {
COLS=`tput cols`; LINES=`tput lines`; TAILLINES=`expr $LINES - 2`
TAILAREA=`expr "$COLS" \* "$TAILLINES"`; FOOTER=`tput rev; \
printf "%${COLS}s"; tput cr; tput sgr0`
}; init; tput clear; tput cup "$LINES" 0
tput hs && echo `tput tsl`"$5"`tput fsl`;
redraw() {
tput sc; tput home; printf "%${TAILAREA}s"; tput home;
tail -n "$TAILLINES" "$1" | tr -d "$BANNED" | fold -sw "$COLS" | \
sed -e "$ s/\(^\|\s\|\$\)\($3\)/\1$BOLD\2\a$RESET/gi" \
-e "s/\(^\|\s\|\$\)\($3\)/\1$BOLD\2$RESET/gi" | \
tail -n "$TAILLINES"
echo "$FOOTER"; tput rc;
}
(while true; do
trap 'init' 28; redraw "$1" "$2" "$3"; inotifywait "$1" -e MODIFY -qq;
done) &
rlwrap -i -p'0;37' -r -S "$4 " cat >> "$2" 2>/dev/null