Я хотел бы распечатать в терминальном дереве как одно ниже:
$ tree -a . └── .git ├── branches ├── config ├── description ├── HEAD ├── hooks │ ├── applypatch-msg.sample │ ├── commit-msg.sample │ ├── fsmonitor-watchman.sample │ ├── post-update.sample │ ├── pre-applypatch.sample │ ├── pre-commit.sample │ ├── prepare-commit-msg.sample │ ├── pre-push.sample │ ├── pre-rebase.sample │ ├── pre-receive.sample │ └── update.sample ├── info │ └── exclude ├── objects │ ├── info │ └── pack └── refs ├── heads └── tags
С графически представленным содержанием всех файлов т.е. это хотело бы соответственно?
. └── .git ├── branches ├── config | | [core] | repositoryformatversion = 0 | filemode = true | bare = false | logallrefupdates = true | ├── description | | Unnamed repository; edit this file 'description' to name the repository. | ├── HEAD | | ref: refs/heads/master |
Существует ли простой способ достигнуть этого?
Я не знаю о простом способе сделать это, но я записал сценарий, который делает что-то подобное. Вместо необычного дерева, перечисляющего как tree
делает, я сделал это плоским, как find
.
Вывод (в пустом мерзавце repo как Ваш пример):
.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/
...
( ==> ... <==
заголовок/нижний колонтитул вдохновлен tail
)
Вот сценарий:
#!/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
Это не симпатично, но это работает. Цвет делает его, довольно по крайней мере:
#!/bin/bash
shopt -s dotglob nullglob globstar
for file in **; do
ls --directory --classify --color=yes -- "$file"
filetype="$(file --brief --mime-type -- "$file")"
# Only print text files
if [[ $filetype == text/* ]]; then
printf '\e[32m==> %s %s <==\e[m\n' start "$file"
cat --show-nonprinting -- "$file"
printf '\e[31m==> %s %s <==\e[m\n' end "$file"
echo
fi
done
Снимок экрана: