从 Shell 输出生成文档

2023-12-27

有没有一种方法/工具可以直接从我的 Shell 输出甚至保存的日志生成 HTML 文档(类似于 doxygen 的作用)?如果没有可用的东西,你们对如何使用现有工具做到这一点有什么创意吗?

我想,在打字时,我可以放置某种标记或特殊字符,然后让一个工具将其拾取作为注释的开头,而输入的其余内容是 CLI 和输出。

例子 :

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 has a script命令。这是一个足够令人困惑的名字,是吗?基本上,script是一个交互式终端记录器。既然没有whatis它的入口,这里是开始man page:

$ 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.

让我给您举一个例子,然后我将向您展示我使用此命令执行的操作的详细信息,并介绍如何使用此命令来完成任务。我从我的 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 or cat,因为您不会看到我们遇到的问题(或功能,如果您想要“^C”)。

这是前几行vim typescript

您将看到转义和控制序列。这些可以删除(参见清理输出下面的部分。)

现在,您可以设置一个doxygen过滤器,有点像描述的那样here http://rickfoosusa.blogspot.com/2011/08/howto-have-doxygen-support-bash-script.html

(就在这里,因为链接可能会失效)

Doxygen 不支持 bash 脚本文件。虽然这可能会让 感觉,不支持它们(定义一个 bash 脚本文件 函数和变量),总是有一些在一个 应该进入文档的源代码树。

添加脚本文件而不更改它们是最简单的,因此 doxygen 输入过滤器。输入过滤器与命令行配合得很好 sed 或 awk 命令,所以我们将在这里做一个简单的命令,让您添加 Doxygen 命令以 ## 开头的行。

在 Doxyfile 中编辑这些行:

FILE_PATTERNS = *.sh *.awk

INPUT_FILTER = "sed -e 's|##|//!|'"

FILTER_SOURCE_FILES = YES

在每个文件的顶部添加简短说明:

## functions for OpenEmbedded, and Jenkins -*- shell-script -*-.

## @author rickfoosusa

## @file

一般来说,任何与#评论可以,但对于语言 通过使用像 asm4doxy.pl 这样的过滤器,你可以获得更多的文档http://rudy.mif.pg.gda.pl/~bogdro/inne/asm4doxy.txt http://rudy.mif.pg.gda.pl/~bogdro/inne/asm4doxy.txt

希望这能为您指明正确的方向。我希望能回来并充实一下它。

清理输出

我使用以下两个文件来摆脱转义序列,一个perl script

#!/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;
}

and a bash script

#!/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> ]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 Shell 输出生成文档 的相关文章

随机推荐

  • 并发修改异常? [复制]

    这个问题在这里已经有答案了 我试图按开始时间对时间跨度列表 表示为具有开始时间和结束时间的 Time 数组 进行排序 我正在尝试使用以下嵌套循环来执行此操作 for Time span workingList Time compareTo
  • 配置 cobertura 以忽略某些代码块

    是否可以使用 Cobertura 告诉它忽略由开始和结束注释标识的某些代码位 例如 public class Foo public void static doSomething Cobertura Ignore Start Cobertu
  • 0x80020101代表什么?

    一个简单的问题 我在微软的错误查找或轻松使用谷歌中找不到答案 HRESULT 0x80020101 代表什么 http support microsoft com kb 247784 http support microsoft com k
  • 从scala并行收集到常规收集的转换

    我正在尝试从并行集合转换回常规地图 根据 api 如果我在任何适当定义的并行集合上调用 toMap 它应该返回一个标准 Map 但它会通过可迭代的扁平集合返回 ParMap I have a val task Stream Future I
  • 在哪里存储密码?

    我正在编写一个 Android 密码管理器应用程序 我想将主密码存储在某个地方 但我不知道在哪里 我是否应该使用我选择的硬编码密码对用户提供的主密码进行加密 然后将其存储到数据库中 或者我应该做点别的什么 您永远不应该存储未加密的密码 对于
  • 默认加载哪些 ruby​​ 模块?

    直到最近 我还认为所有标准模块 那些可以在http ruby doc org stdlib http ruby doc org stdlib 默认情况下不加载 也就是说 您必须要求您将要使用的每一个 但从内容来看 确实有一些是被加载的 LO
  • 删除网格视图选项

    如何删除 显示分组依据框 和 删除此列 GridView菜单 当我去参加活动时 没有 ShowGridMenu 事件 所以对我不起作用 Use the GridView PopupMenuShowing http documentation
  • Powershell:无法与 .Net 程序集中存储的表单交互

    我只是想学习这个东西 并且将来想在我的一个项目中使用它 我有一个带有简单文本框的小表单 存储在 Net dll C 中 这是我在这个 dll 中的类 其中包含与此表单交互的方法 using System using System Colle
  • 按 HSV/HSB 对颜色列表进行排序

    我希望按 HSV HSB 值对很长的颜色列表进行排序 我想按色调 周六 亮度对它们进行排序 实际上 我需要的是一种方法来根据 HSV 的顺序判断一种颜色是出现在 之前 还是 之后 因为我只是要在 Java 中创建一个compareTo 并使
  • 将内容部署到多个服务器 (EC2)

    我一直在开发基于云 AWS EC2 的 PHP Web 应用程序 当涉及到使用多个服务器 全部在 AWS 弹性负载均衡器下 时 我遇到了一个问题 在一台服务器上 当我上传最新文件时 它们会立即在整个应用程序中投入使用 但当使用多个服务器时
  • django.core.exceptions.ImproperlyConfigured:加载 MySQLdb 模块时出错:

    我正在关注 django 教程 很多人都问过这个问题 但我认为我的情况有点独特 因为安装 python mysql 后 当我尝试执行 python manage pysyncdb 时 我仍然收到此错误 我在 virtualenv 中 因为我
  • 从数组中选取随机字符串

    我如何从数组中随机选择一个字符串 但不选择相同的字符串两次 string names image1 png image2 png image3 png image4 png image5 png 这可能吗 我正在考虑使用 return st
  • 从指向某个成员的指针获取指向对象的指针

    假设有一个结构 struct Thing int a bool b 我得到一个指向成员的指针b该结构的 例如某个函数的参数 void some function bool ptr Thing thing 如何获得指向包含对象的指针 最重要的
  • grunt 任务完成后运行命令?

    我想要运行命令 https stackoverflow com questions 10456865 running a command in a grunt task but after任务在咕噜声中完成 uglify compile o
  • 如果实现 __getattribute__ 有没有办法访问形式参数

    好像 getattribute 只有 2 个参数 self name 然而 在实际的代码中 我拦截的方法实际上带有参数 无论如何可以访问这些参数吗 Thanks Charlie 获取属性 只是返回所请求的属性 如果是方法 则返回 call
  • 从其他进程读取和写入

    我希望能够从另一个进程的内存中读取和写入 我调用了这些函数Readprocessmemory and WriteProcessmemory from Kernel32 dll我用了GetProcessByName 函数来查找进程 这样就成功
  • 如何从 Rails 控制台使用 Devise 登录用户?

    加载Rails控制台后 我应该如何登录用户 Devise 提供了一个可以在测试中使用的测试助手 我尝试在控制台中使用 gt gt include Devise TestHelpers gt gt helper sign in User fi
  • 如何将异常从一个进程传递到另一个进程?

    如果停止函数中的运行状态为 停止 我想在上传函数中引发异常 这似乎不起作用 我正在使用 Pipe 来传递异常 怎么了 def upload instances u1 for instance in instance try u1 recv
  • iOS/Android 检测和重定向

    js新手 慢慢来 D 需要根据用户使用的操作系统进行重定向 如果ios重定向到x 如果android重定向到y 否则 留在原来的地址 我的问题 这些片段够了吗
  • 从 Shell 输出生成文档

    有没有一种方法 工具可以直接从我的 Shell 输出甚至保存的日志生成 HTML 文档 类似于 doxygen 的作用 如果没有可用的东西 你们对如何使用现有工具做到这一点有什么创意吗 我想 在打字时 我可以放置某种标记或特殊字符 然后让一