diff --git a/LICENSE.md b/LICENSE.md index 3957dce..f493383 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -© Головин Г.Г., 2021-2024 +© Головин Г.Г., 2021-2025 Опубликовано под [Открытой лицензией 1.1](OPEN_LICENSE.txt) @@ -8,7 +8,7 @@ --- -© Golovin G.G., translation from Russian, 2021-2024 +© Golovin G.G., translation from Russian, 2021-2025 Published under the [Open License 1.1](OPEN_LICENSE.txt) diff --git a/WIKI.md b/WIKI.md index 791aa77..9d10601 100644 --- a/WIKI.md +++ b/WIKI.md @@ -1,7 +1,5 @@ -
-
-

Оглавление

+Оглавление / Contents
@@ -11,13 +9,6 @@ - [График функции в консоли](https://pomodoro5.mircloud.ru/ru/2023/02/05/function-graph-in-console.html) — 05.02.2023. - [Рисуем простую капчу](https://pomodoro5.mircloud.ru/ru/2023/01/03/drawing-simple-captcha.html) — 03.01.2023. -
- -
- -
-

Contents

-
- [Directory tree with links](https://pomodoro5.mircloud.ru/en/2023/08/04/directory-tree.html) — 04.08.2023. @@ -27,5 +18,3 @@ - [Drawing simple captcha](https://pomodoro5.mircloud.ru/en/2023/01/04/drawing-simple-captcha.html) — 04.01.2023.
- -
diff --git a/jekyll_site/_config_color.yml b/jekyll_site/_config_color.yml index 52e598c..60cee56 100644 --- a/jekyll_site/_config_color.yml +++ b/jekyll_site/_config_color.yml @@ -7,9 +7,9 @@ url: "https://pomodoro5.mircloud.ru" # подпапка этой сборки для относительных URL-ов baseurl: "/color" # ссылка в верхнем левом углу заглавных страниц -homepage_url: "https://gitea.com/pomodoro/5" +homepage_url: "https://codeberg.org/pomodoro/5" # представление ссылки -homepage_name: "GITEA" +homepage_name: "CODEBERG" # подпапка альтернативной сборки older_tomato_baseurl: "" # часовой пояс для формата даты ISO-8601 diff --git a/jekyll_site/_config_older.yml b/jekyll_site/_config_older.yml index 3f0d71f..9864a9d 100644 --- a/jekyll_site/_config_older.yml +++ b/jekyll_site/_config_older.yml @@ -7,9 +7,9 @@ url: "https://pomodoro5.mircloud.ru" # подпапка этой сборки для относительных URL-ов baseurl: "" # ссылка в верхнем левом углу заглавных страниц -homepage_url: "https://gitea.com/pomodoro/5" +homepage_url: "https://codeberg.org/pomodoro/5" # представление ссылки -homepage_name: "GITEA" +homepage_name: "CODEBERG" # подпапка альтернативной сборки color_tomato_baseurl: "/color" # часовой пояс для формата даты ISO-8601 diff --git a/jekyll_site/en/2023/08/04/directory-tree.md b/jekyll_site/en/2023/08/04/directory-tree.md index 9264475..3d803fd 100644 --- a/jekyll_site/en/2023/08/04/directory-tree.md +++ b/jekyll_site/en/2023/08/04/directory-tree.md @@ -1,6 +1,6 @@ --- title: Directory tree with links -description: We write a Bash script for building a directory tree for a repository in the Markdown file. We use only Bash tools and basic Linux software without additional. +description: We write a Bash script for building a directory tree for a repository in the Markdown file. We use only Bash builtin tools and basic Linux software without... sections: [Recursion,File processing,Web-navigation] tags: [linux,bash,markdown,html,structure,folders,files,references,sorting] canonical_url: /en/2023/08/04/directory-tree.html @@ -10,11 +10,11 @@ date: 2023.08.04 lang: en --- -We write a Bash script for building a directory tree for a repository in -the Markdown file. We use only Bash tools and basic Linux software — `ls`, -`sed`, `tr` and `echo` — without additional programs. The obtained file +We write a Bash script for building a directory tree for a repository in the +Markdown file. We use only Bash builtin tools and basic Linux software — `ls`, +`sed`, `tr` and `printf` — without additional programs. The obtained file [`DIRECTORY_TREE.md`]({{ site.homepage_url }} "{{ site.homepage_name }}") -will be used in the web interface to navigate through the objects of the repository. +is useful in the web-interface to navigate through the objects of the repository. We create a recursive function and use it to bypass all files and directories of the repository, excluding the list from `.gitignore` — we build a directory structure in the form of a tree. We @@ -24,31 +24,32 @@ concise Markdown file with links. ```bash #!/bin/bash -# sorted list of files and directories -function list_directory_contents { - # first uppercase letters, then lowercase, first directories, then files - eval "LC_COLLATE=C ls -A --group-directories-first $exclusions $1" -} # directory tree with links function directory_tree { # arguments local path="$1" local head="$2" local tail="$3" - # prefix for current element - [ "one" == "$4" ] && printf '%s' "/" || printf '\n%s' "$head" - # current element of the tree + # get directory contents + if [ -d "$path" ]; then + # first uppercase letters, then lowercase, first directories, then files + ls_sorted="LC_COLLATE=C ls -A --group-directories-first $exclusions $path" + # sorted array of files and directories + local list && readarray -t list < <(eval "$ls_sorted") + # length of array + local size=${#list[@]} + # skip empty directory + [ "$size" == 0 ] && return + fi + # prefix of current element, collapse singletons into one line + [ "$4" == "one" ] && printf '%s' "/" || printf '\n%s' "$head" + # current element of the tree — relative hyperlink printf '%s' "${path##*/}" # recursive calls for subdirectories if [ -d "$path" ]; then - local list # array of files and directories - readarray -t list < <(list_directory_contents "$path") - local size=${#list[@]} # length of array local i # counter for ((i = 0; i < size; i++)); do - if [ -z "${list[$i]}" ]; then - continue # skip empty directory - elif ((size == 1)); then + if ((size == 1)); then directory_tree "$path/${list[$i]}" "$tail" "$tail" "one" elif ((i < size - 1)); then directory_tree "$path/${list[$i]}" "$tail├─ " "$tail│ " diff --git a/jekyll_site/en/index.md b/jekyll_site/en/index.md index f4d4abe..2c3d779 100644 --- a/jekyll_site/en/index.md +++ b/jekyll_site/en/index.md @@ -12,10 +12,10 @@ lang: en {%- assign articles = "" | split: "" %} {%- assign articles = articles | push: "Directory tree with links" %} {%- capture article_brief %} -We write a Bash script for building a directory tree for a repository in the Markdown file. -We use only Bash tools and basic Linux software — `ls`, `sed`, `tr` and `echo` — without -additional programs. The obtained file `DIRECTORY_TREE.md` will be used in the web interface -to navigate through the objects of the repository. +We write a Bash script for building a directory tree for a repository in the Markdown file. We +use only Bash builtin tools and basic Linux software — `ls`, `sed`, `tr` and `printf` — without +additional programs. The obtained file `DIRECTORY_TREE.md` is useful in the web-interface to +navigate through the objects of the repository. We create a recursive function and use it to bypass all files and directories of the repository, excluding the list from `.gitignore` — we build a directory structure in the form of a tree. We diff --git a/jekyll_site/ru/2023/08/03/directory-tree.md b/jekyll_site/ru/2023/08/03/directory-tree.md index 2d09901..44e1b22 100644 --- a/jekyll_site/ru/2023/08/03/directory-tree.md +++ b/jekyll_site/ru/2023/08/03/directory-tree.md @@ -1,6 +1,6 @@ --- title: Дерево каталогов со ссылками -description: Напишем скрипт Bash для построения дерева каталогов для репозитория в файле Markdown. Будем использовать только средства Bash и базовое ПО Linux без... +description: Напишем скрипт Bash для построения дерева каталогов для репозитория в файле Markdown. Будем использовать только встроенные средства Bash и базовое ПО Linux... sections: [Рекурсия,Обработка файлов,Вёб-навигация] tags: [linux,bash,markdown,html,структура,каталоги,файлы,ссылки,сортировка] canonical_url: /ru/2023/08/03/directory-tree.html @@ -9,11 +9,11 @@ title_translated: Directory tree with links date: 2023.08.03 --- -Напишем скрипт Bash для построения дерева каталогов для репозитория в -файле Markdown. Будем использовать только средства Bash и базовое ПО Linux -— `ls`, `sed`, `tr` и `echo` — без дополнительных программ. Полученный файл +Напишем скрипт Bash для построения дерева каталогов для репозитория в файле +Markdown. Будем использовать только встроенные средства Bash и базовое ПО Linux +— `ls`, `sed`, `tr` и `printf` — без дополнительных программ. Полученный файл [`DIRECTORY_TREE.md`]({{ site.homepage_url }} "{{ site.homepage_name }}") -будем использовать в вёб-интерфейсе для навигации по объектам репозитория. +пригодится в вёб-интерфейсе для навигации по объектам репозитория. Создаём рекурсивную функцию и с её помощью обходим все файлы и каталоги репозитория, за исключением списка из `.gitignore` — строим структуру каталогов в форме дерева. Выводим @@ -23,31 +23,32 @@ date: 2023.08.03 ```bash #!/bin/bash -# отсортированный список файлов и каталогов -function list_directory_contents { - # сначала заглавные буквы, потом строчные, сначала каталоги, потом файлы - eval "LC_COLLATE=C ls -A --group-directories-first $exclusions $1" -} # дерево каталогов со ссылками function directory_tree { # аргументы local path="$1" local head="$2" local tail="$3" - # префикс для текущего элемента - [ "one" == "$4" ] && printf '%s' "/" || printf '\n%s' "$head" - # текущий элемент дерева + # получить содержимое каталога + if [ -d "$path" ]; then + # сначала заглавные буквы, потом строчные, сначала каталоги, потом файлы + ls_sorted="LC_COLLATE=C ls -A --group-directories-first $exclusions $path" + # отсортированный массив файлов и каталогов + local list && readarray -t list < <(eval "$ls_sorted") + # длина массива + local size=${#list[@]} + # пропустить пустой каталог + [ "$size" == 0 ] && return + fi + # префикс текущего элемента, сворачивать синглтоны в одну строку + [ "$4" == "one" ] && printf '%s' "/" || printf '\n%s' "$head" + # текущий элемент дерева — относительная гиперссылка printf '%s' "${path##*/}" # рекурсивные вызовы для подкаталогов if [ -d "$path" ]; then - local list # массив файлов и каталогов - readarray -t list < <(list_directory_contents "$path") - local size=${#list[@]} # длина массива local i # счётчик for ((i = 0; i < size; i++)); do - if [ -z "${list[$i]}" ]; then - continue # пропустить пустой каталог - elif ((size == 1)); then + if ((size == 1)); then directory_tree "$path/${list[$i]}" "$tail" "$tail" "one" elif ((i < size - 1)); then directory_tree "$path/${list[$i]}" "$tail├─ " "$tail│ " diff --git a/jekyll_site/ru/index.md b/jekyll_site/ru/index.md index dca52a5..17a3d75 100644 --- a/jekyll_site/ru/index.md +++ b/jekyll_site/ru/index.md @@ -11,10 +11,10 @@ title_translated: Code with comments {%- assign articles = "" | split: "" %} {%- assign articles = articles | push: "Дерево каталогов со ссылками" %} {%- capture article_brief %} -Напишем скрипт Bash для построения дерева каталогов для репозитория в файле Markdown. -Будем использовать только средства Bash и базовое ПО Linux — `ls`, `sed`, `tr` и `echo` -— без дополнительных программ. Полученный файл `DIRECTORY_TREE.md` будем использовать -в вёб-интерфейсе для навигации по объектам репозитория. +Напишем скрипт Bash для построения дерева каталогов для репозитория в файле Markdown. Будем +использовать только встроенные средства Bash и базовое ПО Linux — `ls`, `sed`, `tr` и `printf` +— без дополнительных программ. Полученный файл `DIRECTORY_TREE.md` пригодится в вёб-интерфейсе +для навигации по объектам репозитория. Создаём рекурсивную функцию и с её помощью обходим все файлы и каталоги репозитория, за исключением списка из `.gitignore` — строим структуру каталогов в форме дерева. Выводим