如何像打开x-man-page://链接一样打开本地文本文件
在MacOS黄色手册页阅读器中打开自定义文本
MacOS定义了一套x-man-page://command格式的URL,不管是通过浏览器访问,还是在Terminal里执行open x-man-page://command,都能唤起那个带黄色背景的手册页阅读器。实际上这个阅读器就是采用「Man Page」配置文件的Terminal窗口。
如果你想要实现打开指定配置文件的Terminal窗口,向其中写入文本并保持窗口打开(和打开手册页的效果一致),目前你可以用groff -man -Tps filename.txt | open -f -a Preview在Preview中打开文本,但更推荐用下面的方案直接使用黄色终端阅读器:
借助@Philippe提供的AppleScript,你可以定义以下shell函数,用它在该阅读器中打开大多数文本文件:
function reader { if [[ "$1" = /* ]]; then osascript ~/Code/scripts/xman_window.scpt "cat $1" elif [[ "$1" = ~/* ]]; then osascript ~/Code/scripts/xman_window.scpt "cat ${1/#\~/$HOME}" else osascript ~/Code/scripts/xman_window.scpt "cat $(pwd)/$1" fi }
内容的提问来源于stack exchange,提问作者Hugo Schongin
相关产品推荐
相关产品推荐

