Last active
July 22, 2025 16:47
-
-
Save nopeless/f9af3c0b6a625e1de9ff767db8c6ff67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set +euo pipefail | |
| LANG="C.UTF-8" | |
| n() { | |
| (($1 >= ${#A[@]})) && return | |
| L=$(($1 + $2)) | |
| Q=$(($2 * 2)) | |
| V=${A[$1]} | |
| p="${V//?/ }" | |
| [[ ! $V || $z ]] && : "${z:=${p:- }}" && echo "$z" && echo "$z" && n $L $Q && return | |
| ((L >= ${#A[@]})) && echo "│$p" && echo "$V " && return | |
| mapfile -t J < <(n $L $Q) | |
| R=$((L + 1)) | |
| mapfile -t K < <(n $R $((Q + 1))) | |
| j=${J[0]//?/ } | |
| j=${j:1} | |
| k=${K[0]//?/ } | |
| k=${k:1} | |
| e="${p:${#j}}" | |
| if [[ -z ${A[$R]} ]]; then | |
| echo "│$p${j:${#V}}" | |
| echo "$V ${j:${#V}}" | |
| for ((i = 0; i < ${#J[@]}; i++)); do | |
| echo "${J[$i]}$e" | |
| done | |
| return | |
| fi | |
| echo "│$p ${j:${#V}}$k" | |
| d=${j//?/─} | |
| echo "$V${d:${#V}}─┐$k" | |
| for ((i = 0; i < ${#J[@]}; i++)); do | |
| echo "${J[$i]}$e${K[$i]}" | |
| done | |
| } | |
| 2tree() { | |
| local A=("$@") | |
| (n 0 1) | |
| } | |
| A=(nopeless $(seq 31) nopeless) | |
| 2tree "${A[@]}" | |
| # │ | |
| # nopeless─────────────────────────┐ | |
| # │ │ | |
| # 1────────────────────┐ 2───────────┐ | |
| # │ │ │ │ | |
| # 3──────────────┐ 4─────┐ 5─────┐ 6─────┐ | |
| # │ │ │ │ │ │ │ │ | |
| # 7───────────┐ 8──┐ 9──┐ 10─┐ 11─┐ 12─┐ 13─┐ 14─┐ | |
| # │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ | |
| # 15─┐ 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
| # │ │ | |
| # 31 nopeless |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment