Bash 从Shell输出生成文档
是否有一种方法/工具可以直接从我的Shell输出甚至保存的日志生成HTML文档(类似于doxygen所做的)?如果没有可用的工具,你们对如何使用现有的工具来实现这一点有什么创造性的想法吗 我认为在键入时,我可以放置某种标记或特殊字符,然后让工具将其作为注释的开头,而键入的其余内容是CLI和输出 例如:Bash 从Shell输出生成文档,bash,doxygen,documentation-generation,Bash,Doxygen,Documentation Generation,是否有一种方法/工具可以直接从我的Shell输出甚至保存的日志生成HTML文档(类似于doxygen所做的)?如果没有可用的工具,你们对如何使用现有的工具来实现这一点有什么创造性的想法吗 我认为在键入时,我可以放置某种标记或特殊字符,然后让工具将其作为注释的开头,而键入的其余内容是CLI和输出 例如: ubuntu@nso-172-73:~$ # This is a comment ubuntu@nso-172-73:~$ ping google.com PING google.com (172
ubuntu@nso-172-73:~$ # This is a comment
ubuntu@nso-172-73:~$ ping google.com
PING google.com (172.217.9.174) 56(84) bytes of data.
^C
--- google.com ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1008ms
ubuntu@nso-172-73:~$ # End of Comment
这并不能完全回答你的问题,但希望能给你一个开始
bash
有一个script
命令。这个名字够让人困惑的了,是吗?基本上,script
是一个交互式终端记录器。因为没有whatis
条目,这里是man
页面的开始:
$ man script | head -n 17 | sed '/^$/d'
SCRIPT(1) User Commands SCRIPT(1)
NAME
script - make typescript of terminal session
SYNOPSIS
script [options] [file]
DESCRIPTION
script makes a typescript of everything displayed on your terminal. It
is useful for students who need a hardcopy record of an interactive
session as proof of an assignment, as the typescript file can be
printed out later with lpr(1).
If the argument file is given, script saves the dialogue in this file.
If no filename is given, the dialogue is saved in the file typescript.
让我给你一个例子,然后我将向你展示我如何使用这个命令的细节,并给出如何使用它来实现acompl的想法。我在我的Cygwin终端上运行这个
$ script
Script started, file is typescript
$ pwd
/home/me
$ # This is a comment
$ ping google.com
PING google.com (172.217.12.206): 56 data bytes
64 bytes from 172.217.12.206: icmp_seq=0 ttl=51 time=68 ms
64 bytes from 172.217.12.206: icmp_seq=1 ttl=51 time=67 ms
64 bytes from 172.217.12.206: icmp_seq=2 ttl=51 time=67 ms
64 bytes from 172.217.12.206: icmp_seq=3 ttl=51 time=67 ms
64 bytes from 172.217.12.206: icmp_seq=4 ttl=51 time=68 ms
64 bytes from 172.217.12.206: icmp_seq=5 ttl=51 time=67 ms
----google.com PING Statistics----
6 packets transmitted, 6 packets received, 0.0% packet loss
round-trip (ms) min/avg/max/med = 67/67/68/67
$ # End of Comment
$ cd /
$ pwd
/
$ exit
exit
Script done, file is typescript
$ pwd
/home/me
现在我们来看看结果文件。不要尝试head
或cat
,因为您不会看到我们遇到的问题(或功能,如果您想要“^C”)
下面是vim typescript
您将看到逃逸和控制序列。这些可以删除(请参阅下面的“清理输出”部分。)
现在,您可以设置一个doxygen
过滤器,有点像前面描述的过滤器
(在这里,因为链接可能会消亡)
Doxygen不支持bash脚本文件。虽然这可能会
也就是说,不支持它们(根据
函数和变量),在
应该进入文档的源树
添加脚本文件而不更改它们是最简单的,因此
氧气输入过滤器。输入过滤器在命令行中工作得很好
sed或awk命令,因此我们将在这里执行一个简单的命令,允许您添加
Doxygen命令以##开头的输入行
在Doxyfile中编辑以下行:
FILE\u PATTERNS=*.sh*.awk
INPUT_FILTER=“sed-e's |#| |/!|””
FILTER\u SOURCE\u FILES=YES
在每个文件的顶部添加简要说明:
用于OpenEmbedded和Jenkins-*-shell脚本-*-的函数。
##@作者rickfoosusa
##@文件
一般来说,任何带有#
的注释都可以,但是对于语言来说就不行了
通过使用类似asm4doxy.pl的过滤器,您可以获得更多的文档
希望这能为你指明正确的方向。我希望能回来充实一下
清理输出
我使用以下两个文件来消除转义序列,一个perl
脚本
#!/usr/bin/perl
#
##############################################################################
# Takes escape and control sequences out of the `script` command's output
#
# @file output_scrubbed_script.pl
#
# Okay, I found this all over the internet, it's just my favorite.
# This removes all unwanted junk (control characters, etc) from the output
# of the Linux script command.
# It's imperfect. It struggles with vim, and it doesn't do too well with up
# arrows and tab completion, but I can usually at least see and understand
# what I did.
#
##############################################################################
while (<>)
{
s/ \e[ #%()*+\-.\/]. |
\r | # Remove extra carriage returns also
(?:\e\[|\x9b) [ -?]* [@-~] | # CSI ... Cmd
(?:\e\]|\x9d) .*? (?:\e\\|[\a\x9c]) | # OSC ... (ST|BEL)
(?:\e[P^_]|[\x90\x9e\x9f]) .*? (?:\e\\|\x9c) | # (DCS|PM|APC) ... ST
\e.|[\x80-\x9f] //xg;
1 while s/[^\b][\b]//g; #remove all non-backspace followed by backspace
print;
}
#!/bin/bash
#
##############################################################################
# Runs the clean-up
#
# @file script_scrubber.sh
# @author bballdave025
#
# See the usage variable
#
##############################################################################
usage="Usage is:\n > script_scrubber.sh <unscrubbed-file> "\
"[<alternate-filename>]\n"\
"If no <alternate-filename> argument is given, the <unscrubbed-file> \n"\
"will be cleaned in place.\n\n"\
"This script takes the output of the Linux script command and cleans"\
"control characters and other unwanted artifacts."\
"It uses output_scrubbed_text.pl\n"
scrubber_path="$HOME"
scrubber_location="${scrubber_path}/output_scrubbed_text.pl"
if [[ ! -f "${scrubber_location}" ]]; then
echo -e "Fatal error! ${scrubber_location} does not exist."
exit 1
fi #endof: if [[ -f "${location}/output_scrubbed_text.pl" ]]
if [[ ! -x "${scrubber_location}" ]]; then
chmod +x "${scrubber_location}"
fi #endof: if [[ ! -x "${scrubber_location}" ]]
if [[ $# -eq 0 ]]; then
echo "No argument given."
echo -e "${usage}"
exit 2
elif [[ $# -eq 1 ]]; then
if [[ $1 == "--help" ]]; then
echo -e "${usage}"
exit 0
else
"${scrubber_location}" $1 > tmp && mv tmp $1
fi #endof: if [[ $1 -eq "--help" ]]
elif [[ $# -eq 2 ]]; then
"${scrubber_location}" $1 > $2
else
echo "More than two arguments given."
echo -e "${usage}"
fi #endof: if [[ $# -eq <0,1,2,else> ]