combine the two files into one and create a directory with languages
This commit is contained in:
parent
bfea545af6
commit
02eb365650
6 changed files with 184 additions and 143 deletions
|
@ -1,5 +1,7 @@
|
|||
FROM alpine:latest
|
||||
COPY tree-EN.sh /tree-EN.sh
|
||||
RUN apk add --update ncurses bash
|
||||
RUN mkdir /langs
|
||||
COPY langs /langs
|
||||
COPY tree.sh /tree.sh
|
||||
RUN apk add --update ncurses grep bash
|
||||
ENV TERM=xterm-256color
|
||||
CMD ["bash","/tree-EN.sh"]
|
||||
CMD ["bash","/tree.sh"]
|
||||
|
|
5
langs/en
Normal file
5
langs/en
Normal file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
MERRY_CHRISTMAS='MERRY CHRISTMAS'
|
||||
AND_LOTS_OF_CODE_IN_NEW_YEAR="And lots of CODE in $(($(date +'%Y')+1))"
|
||||
CODE='CODE'
|
5
langs/es
Normal file
5
langs/es
Normal file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
MERRY_CHRISTMAS='FELICES FIESTAS'
|
||||
AND_LOTS_OF_CODE_IN_NEW_YEAR="Y mucho CODIGO en $(($(date +'%Y')+1))"
|
||||
CODE='CODIGO'
|
70
tree-EN.sh
70
tree-EN.sh
|
@ -1,70 +0,0 @@
|
|||
#!/bin/bash
|
||||
trap "tput reset; tput cnorm; exit" 2
|
||||
clear
|
||||
tput civis
|
||||
lin=2
|
||||
col=$(($(tput cols) / 2))
|
||||
c=$((col-1))
|
||||
est=$((c-2))
|
||||
color=0
|
||||
tput setaf 2; tput bold
|
||||
|
||||
# Tree
|
||||
for ((i=1; i<20; i+=2))
|
||||
{
|
||||
tput cup $lin $col
|
||||
for ((j=1; j<=i; j++))
|
||||
{
|
||||
echo -n \*
|
||||
}
|
||||
let lin++
|
||||
let col--
|
||||
}
|
||||
|
||||
tput sgr0; tput setaf 3
|
||||
|
||||
# Trunk
|
||||
for ((i=1; i<=2; i++))
|
||||
{
|
||||
tput cup $((lin++)) $c
|
||||
echo 'mWm'
|
||||
}
|
||||
new_year=$(date +'%Y')
|
||||
let new_year++
|
||||
tput setaf 1; tput bold
|
||||
tput cup $lin $((c - 6)); echo MERRY CHRISTMAS
|
||||
tput cup $((lin + 1)) $((c - 10)); echo And lots of CODE in $new_year
|
||||
let c++
|
||||
k=1
|
||||
|
||||
# Lights and decorations
|
||||
while true; do
|
||||
for ((i=1; i<=35; i++)) {
|
||||
# Turn off the lights
|
||||
[ $k -gt 1 ] && {
|
||||
tput setaf 2; tput bold
|
||||
tput cup ${line[$[k-1]$i]} ${column[$[k-1]$i]}; echo \*
|
||||
unset line[$[k-1]$i]; unset column[$[k-1]$i] # Array cleanup
|
||||
}
|
||||
|
||||
li=$((RANDOM % 9 + 3))
|
||||
start=$((c-li+2))
|
||||
co=$((RANDOM % (li-2) * 2 + 1 + start))
|
||||
tput setaf $color; tput bold # Switch colors
|
||||
tput cup $li $co
|
||||
echo o
|
||||
line[$k$i]=$li
|
||||
column[$k$i]=$co
|
||||
color=$(((color+1)%8))
|
||||
# Flashing text
|
||||
sh=1
|
||||
for l in C O D E
|
||||
do
|
||||
tput cup $((lin+1)) $((c+sh))
|
||||
echo $l
|
||||
let sh++
|
||||
sleep 0.01
|
||||
done
|
||||
}
|
||||
k=$((k % 2 + 1))
|
||||
done
|
70
tree-ES.sh
70
tree-ES.sh
|
@ -1,70 +0,0 @@
|
|||
#!/bin/bash
|
||||
trap "tput reset; tput cnorm; exit" 2
|
||||
clear
|
||||
tput civis
|
||||
lin=2
|
||||
col=$(($(tput cols) / 2))
|
||||
c=$((col-1))
|
||||
est=$((c-2))
|
||||
color=0
|
||||
tput setaf 2; tput bold
|
||||
|
||||
# Tree
|
||||
for ((i=1; i<20; i+=2))
|
||||
{
|
||||
tput cup $lin $col
|
||||
for ((j=1; j<=i; j++))
|
||||
{
|
||||
echo -n \*
|
||||
}
|
||||
let lin++
|
||||
let col--
|
||||
}
|
||||
|
||||
tput sgr0; tput setaf 3
|
||||
|
||||
# Trunk
|
||||
for ((i=1; i<=2; i++))
|
||||
{
|
||||
tput cup $((lin++)) $c
|
||||
echo 'mWm'
|
||||
}
|
||||
new_year=$(date +'%Y')
|
||||
let new_year++
|
||||
tput setaf 1; tput bold
|
||||
tput cup $lin $((c - 6)); echo FELICES FIESTAS
|
||||
tput cup $((lin + 1)) $((c - 9)); echo Y mucho CODIGO en $new_year
|
||||
let c++
|
||||
k=1
|
||||
|
||||
# Lights and decorations
|
||||
while true; do
|
||||
for ((i=1; i<=35; i++)) {
|
||||
# Turn off the lights
|
||||
[ $k -gt 1 ] && {
|
||||
tput setaf 2; tput bold
|
||||
tput cup ${line[$[k-1]$i]} ${column[$[k-1]$i]}; echo \*
|
||||
unset line[$[k-1]$i]; unset column[$[k-1]$i] # Array cleanup
|
||||
}
|
||||
|
||||
li=$((RANDOM % 9 + 3))
|
||||
start=$((c-li+2))
|
||||
co=$((RANDOM % (li-2) * 2 + 1 + start))
|
||||
tput setaf $color; tput bold # Switch colors
|
||||
tput cup $li $co
|
||||
echo o
|
||||
line[$k$i]=$li
|
||||
column[$k$i]=$co
|
||||
color=$(((color+1)%8))
|
||||
# Flashing text
|
||||
sh=1
|
||||
for l in C O D I G O
|
||||
do
|
||||
tput cup $((lin+1)) $((c-3+sh))
|
||||
echo $l
|
||||
let sh++
|
||||
sleep 0.01
|
||||
done
|
||||
}
|
||||
k=$((k % 2 + 1))
|
||||
done
|
169
tree.sh
Executable file
169
tree.sh
Executable file
|
@ -0,0 +1,169 @@
|
|||
#!/bin/bash
|
||||
|
||||
trap onexit 2
|
||||
|
||||
START_LINE=2
|
||||
CROWN_HEIGHT=10
|
||||
TRUNK_HEIGHT=2
|
||||
MSG_LANG=en
|
||||
|
||||
CENTER=$(($(tput cols)/2))
|
||||
|
||||
function main() {
|
||||
|
||||
parsed_args=$(getopt -o l:Lh -l language,list-languages,help -n 'tree.sh' -- "$@")
|
||||
getopt_exit_code=$?
|
||||
|
||||
if [ $getopt_exit_code -ne 0 ] ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
eval set -- "$parsed_args"
|
||||
|
||||
while :; do
|
||||
case "$1" in
|
||||
-h | --help ) show_help; exit 1 ;;
|
||||
-L | --list-languages ) listlangs; exit ;;
|
||||
-l | --language ) MSG_LANG="$2"; shift 2 ;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
validate_language && source ./langs/$MSG_LANG
|
||||
empty_screen
|
||||
|
||||
show_tree_crown
|
||||
show_tree_trunk
|
||||
show_messages
|
||||
|
||||
animate
|
||||
|
||||
}
|
||||
|
||||
function listlangs() {
|
||||
cat << EOF
|
||||
Code Language
|
||||
---- --------
|
||||
es English (default)
|
||||
en Spanish
|
||||
EOF
|
||||
}
|
||||
|
||||
function validate_language() {
|
||||
if [ $(echo -n "$MSG_LANG" | wc -c) -ne 2 ] || [ ! -f "./langs/$MSG_LANG" ] ; then
|
||||
err "language code $MSG_LANG isnt supported"
|
||||
fi
|
||||
}
|
||||
|
||||
function empty_screen() {
|
||||
clear
|
||||
tput civis
|
||||
}
|
||||
|
||||
function show_tree_crown() {
|
||||
tput setaf 2
|
||||
tput bold
|
||||
|
||||
for i in $(seq 1 $CROWN_HEIGHT); do
|
||||
tput cup $((START_LINE + i - 1)) $((CENTER - i + 1))
|
||||
for j in $(seq 1 $(((i-1)*2 + 1))); do
|
||||
echo -n '*'
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
function show_tree_trunk() {
|
||||
tput sgr0
|
||||
tput setaf 3
|
||||
|
||||
for i in $(seq 1 $TRUNK_HEIGHT); do
|
||||
tput cup $((START_LINE + CROWN_HEIGHT + i - 1)) $((CENTER - 1))
|
||||
echo 'mWm'
|
||||
done
|
||||
}
|
||||
|
||||
function show_messages() {
|
||||
tput setaf 1
|
||||
tput bold
|
||||
|
||||
mc_length=$(echo -n "$MERRY_CHRISTMAS" | wc -c)
|
||||
loc_length=$(echo -n "$AND_LOTS_OF_CODE_IN_NEW_YEAR" | wc -c)
|
||||
|
||||
tput cup $((START_LINE + CROWN_HEIGHT + TRUNK_HEIGHT)) $((CENTER - mc_length / 2))
|
||||
echo $MERRY_CHRISTMAS
|
||||
|
||||
tput cup $((START_LINE + CROWN_HEIGHT + TRUNK_HEIGHT + 1)) $((CENTER - loc_length / 2))
|
||||
echo $AND_LOTS_OF_CODE_IN_NEW_YEAR
|
||||
}
|
||||
|
||||
function animate() {
|
||||
|
||||
color=0
|
||||
turn_off=false
|
||||
code_index=$(echo "$AND_LOTS_OF_CODE_IN_NEW_YEAR" | grep "$CODE" -bo | cut -d ':' -f1)
|
||||
loc_length=$(echo -n "$AND_LOTS_OF_CODE_IN_NEW_YEAR" | wc -c)
|
||||
xmem=()
|
||||
ymem=()
|
||||
|
||||
# lights and decorations
|
||||
while :; do
|
||||
for i in $(seq 1 36); do
|
||||
|
||||
if $turn_off ; then
|
||||
tput setaf 2
|
||||
tput bold
|
||||
tput cup ${ymem[$i]} ${xmem[$i]}
|
||||
unset xmem[$i]
|
||||
unset ymem[$i]
|
||||
echo -n '*'
|
||||
fi
|
||||
|
||||
y=$(((RANDOM % (CROWN_HEIGHT - 1)) + 1))
|
||||
x=$((((RANDOM % y) + 1) * 2 - 1))
|
||||
|
||||
ymem[$i]=$((START_LINE + y))
|
||||
xmem[$i]=$((CENTER - y + x))
|
||||
|
||||
tput setaf $color
|
||||
tput bold
|
||||
tput cup ${ymem[$i]} ${xmem[$i]}
|
||||
echo o
|
||||
|
||||
color=$(((color + 1) % 8))
|
||||
cpos=0
|
||||
|
||||
for c in $(echo -n "$CODE" | grep -o .); do
|
||||
tput cup $((START_LINE + CROWN_HEIGHT + TRUNK_HEIGHT + 1)) $(((CENTER - loc_length / 2) + code_index + cpos))
|
||||
echo -n $c
|
||||
cpos=$((cpos + 1))
|
||||
sleep 0.01
|
||||
done
|
||||
done
|
||||
|
||||
$turn_off &&
|
||||
turn_off=false ||
|
||||
turn_off=true
|
||||
done
|
||||
}
|
||||
|
||||
function err() {
|
||||
printf "tree.sh: %s\n" "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
function show_help() {
|
||||
echo Usage: tree.sh [ -hL ] [ -l language_code ]
|
||||
echo Options are:
|
||||
echo ' -l | --language uses the specified language (english default)'
|
||||
echo ' -L | --list-languages list all supported languages'
|
||||
echo ' -h | --help display this message and exit'
|
||||
}
|
||||
|
||||
function onexit() {
|
||||
tput reset
|
||||
tput cnorm
|
||||
exit
|
||||
}
|
||||
|
||||
main "$@"
|
Loading…
Reference in a new issue