我想在终端树中打印出来,如下所示:
\n\n\n$ 树 -a\n。\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 .git\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\ x80 分支\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 配置\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 描述\n \xe2\x94 \x9c\xe2\x94\x80\xe2\x94\x80 HEAD\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 钩子\n \xe2\x94\x82\xc2\xa0\xc2 \xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 applypatch-msg.sample\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\ x94\x80\xe2\x94\x80 commit-msg.sample\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 fsmonitor- watchman.sample\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 更新后.sample\n \xe2\x94\x82 \xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 预应用补丁.sample\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\ x94\x9c\xe2\x94\x80\xe2\x94\x80 预提交.sample\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2 \x94\x80 准备提交消息.sample\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 预推送.sample \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 预变基.sample\n \xe2\x94\x82\xc2\ xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 预接收.sample\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94 \xe2\x94\x80\xe2\x94\x80 update.sample\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 信息\n \xe2\x94\x82\xc2\xa0\xc2 \xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 排除\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 对象\n \xe2\x94\x82 \xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 信息\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\ xe2\x94\x80\xe2\x94\x80 包\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 引用\n \xe2\x94\x9c\xe2\x94\x80\xe2\ x94\x80 头\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 标签\n\n\n\n
以图形方式呈现所有文件的内容,即它应该分别是什么样的?
\n\n\n.\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 .git\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 分支\n \xe2 \x94\x9c\xe2\x94\x80\xe2\x94\x80 配置\n |\n | [核心]\n | 存储库格式版本 = 0\n | 文件模式 = true\n | 裸=假\n | logallrefupdates = true\n |\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 描述\n |\n | 未命名存储库;编辑此文件“描述”以命名存储库。\n |\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 HEAD\n |\n | 参考:refs/heads/master\n |\n\n\n
有没有一种简单的方法可以达到这个目的?
\n我不知道有什么简单的方法可以做到这一点,但我编写了一个可以执行类似操作的脚本。我没有像tree那样使用花哨的树列表,而是将其扁平化,例如find。
输出(在像您的示例一样的空 git 存储库中):
.git/
.git/branches/
.git/config
==> start .git/config <==
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
==> end .git/config <==
.git/description
==> start .git/description <==
Unnamed repository; edit this file 'description' to name the repository.
==> end .git/description <==
.git/HEAD
==> start .git/HEAD <==
ref: refs/heads/master
==> end .git/HEAD <==
.git/hooks/
...
Run Code Online (Sandbox Code Playgroud)
(==> ... <==页眉/页脚的灵感来自tail)
这是脚本:
.git/
.git/branches/
.git/config
==> start .git/config <==
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
==> end .git/config <==
.git/description
==> start .git/description <==
Unnamed repository; edit this file 'description' to name the repository.
==> end .git/description <==
.git/HEAD
==> start .git/HEAD <==
ref: refs/heads/master
==> end .git/HEAD <==
.git/hooks/
...
Run Code Online (Sandbox Code Playgroud)
它不漂亮,但很有效。颜色至少让它变得漂亮:
#!/bin/bash
# Globs include hidden files, are null if no matches, recursive with **
shopt -s dotglob nullglob globstar
for file in **; do
# Print filename with an indicator suffix for filetype
ls --directory --classify -- "$file"
filetype="$(file --brief --mime-type -- "$file")"
# Only print text files
if [[ $filetype == text/* ]]; then
printf '==> %s %s <==\n' start "$file"
cat --show-nonprinting -- "$file"
printf '==> %s %s <==\n' end "$file"
echo
fi
done
Run Code Online (Sandbox Code Playgroud)
截屏: