Skip to content

Instantly share code, notes, and snippets.

@mdriscoll93
Created October 26, 2024 14:10
Show Gist options
  • Select an option

  • Save mdriscoll93/c7ca6fcc88aab61c41e075b0d630e89f to your computer and use it in GitHub Desktop.

Select an option

Save mdriscoll93/c7ca6fcc88aab61c41e075b0d630e89f to your computer and use it in GitHub Desktop.

Revisions

  1. mdriscoll93 created this gist Oct 26, 2024.
    42 changes: 42 additions & 0 deletions tree.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/bin/env bash
    # just in case your default repositories don't contain `tree`

    trap "tput reset; tput cnorm; exit" 2

    # setup
    clear
    tput civis
    tree_height=20 # Set tree height
    col_center=$(($(tput cols) / 2)) # Center
    base_row=$(($(tput lines) / 2 + tree_height / 2)) # Position bottom tree

    # trunk
    tput sgr0; tput setaf 130
    for ((i=0; i<3; i++)); do
    tput cup $((base_row + i)) $col_center
    echo 'mWm'
    done

    # green
    draw_tree_row() {
    local row=$1
    local width=$2
    local start_col=$((col_center - width / 2)) # Center row
    tput setaf 2 # Set color to green
    tput bold
    tput cup $row $start_col
    for ((j=0; j<width; j++)); do
    echo -n "*"
    done
    tput sgr0
    }

    # draw tree
    for ((i=tree_height; i>=1; i--)); do
    width=$((2 * i - 1))
    row=$((base_row - (tree_height - i)))
    draw_tree_row $row $width
    sleep 0.1 # growing effect
    done

    tput cnorm