也是老话题了,给出个我觉得实践下来比较好的, 详见该话题
无临时文件,但是过不了一些奇怪的manpage,(比如screen)
#!/bin/sh
# export PAGER='epager'
TTY="/dev/$(ps -o tty= -p $$)"
INPUT=$(cat)
ESCAPED_INPUT=$(printf '%s' "$INPUT" | sed 's/\\/\\\\/g; s/"/\\"/g')
emacsclient -nw -e "\
(let* ((name \"*pager*\")
(buffer (get-buffer-create name)))
(with-current-buffer buffer
(save-excursion
(delete-region (point-min) (point-max))
(insert \"$ESCAPED_INPUT\")
(require 'ansi-color)
(ansi-color-apply-on-region (point-min) (point-max)))
(read-only-mode 1))
(switch-to-buffer buffer))" < $TTY
大概效果: git log --oneline
→