ao-mud is a spellbook of well-commented atomic bash scripts that each do one thing. we are building semantic building blocks for an autonomously-evolving digital spellcasting language.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
6.9 KiB

#!/bin/sh
# The Rosetta Stone Spell
#
# This spell is an immutable, self-describing teacher-script, designed to teach
# basic Unix commands to wizards studying magic.
# todo: this should allow colors
quest_text() {
foo=$1
for (( i=0; i<${#foo}; i++ )); do
echo -en "${foo:$i:1}"
sleep 0.01
if [ "${foo:$i:1}" = " " ]; then
# Add an extra pause between words
sleep "0.0$(echo $((RANDOM)))"
fi
done
echo -en "\n"
sleep 0.22
}
indent() { sed 's/^/ /'; }
this_spell="${GREEN}this spell${RESET}"
This_spell="${GREEN}This spell${RESET}"
# The rune for checking if a script file exists is -e
if [ -e "$0" ]; then
quest_text "This spell exists."
else
quest_text "The spell $0 does not exist."
fi
# The rune for checking if a script file is a regular file is -f
if [ -f "$0" ]; then
quest_text "The spell is a regular file."
else
quest_text "The spell is not a regular file."
fi
# The rune for checking if a script file is empty is -s
if [ -s "$0" ]; then
quest_text "The spell is not empty."
else
quest_text "The spell is empty."
fi
# The rune for revealing the name of this script is $0
quest_text "${This_spell} is named $0."
# The rune for determining the number of arguments passed to this script
quest_text "${This_spell} was passed $# arguments."
if [ $# -ge 1 ]; then
# The rune for revealing the first argument passed to this script
quest_text "The first argument passed to ${this_spell} is '$1'."
# The rune for revealing all of the arguments passed to this script
quest_text "All arguments passed to ${this_spell} are '$@'."
fi
# The rune for revealing the process ID of the current script
quest_text "The process ID of ${this_spell} is $$."
# The rune for revealing the exit status of the last executed command
quest_text "The exit status of the command ran previously to ${this_spell} was $?."
# todo: make sure -e is the right flag for checking that the string exists / is 1 or greater length
if [ -e "$!" ]; then
# The rune for revealing the process ID of the last backgrounded command
quest_text "The process ID of the last background command in this shell is $!."
fi
# The rune for revealing the current line number in the script
quest_text "The current line number in ${this_spell} is $LINENO."
# The spell for displaying the script's file type
quest_text "This spell is of type: "
quest_text "$(file $0 | indent)"
# The spell for displaying the script's permissions
quest_text "This spell has permissions $(ls -l $0 | awk '{print $1}')."
# The spell for displaying the script's owner and group
quest_text "This spell is owned by $(ls -l $0 | awk '{print $3}')."
quest_text "This spell belongs to group $(ls -l $0 | awk '{print $4}')."
# The spell for displaying the last time the script was modified
quest_text "This spell was last modified on $(ls -l --time-style=+"%D %T" $0 | awk '{print $6, $7}')."
# The spell for displaying the script's size
quest_text "This spell has a size of $(du -h $0 | awk '{print $1}')."
# The spell for displaying the number of lines in this script
quest_text "This spell has $(wc -l $0 | awk '{print $1}') lines."
# The spell for displaying the number of characters in this script
quest_text "This spell has $(wc -m $0 | awk '{print $1}') characters."
# The spell for displaying the number of words in this script
quest_text "This spell has $(wc -w $0 | awk '{print $1}') words."
# The spell for displaying the average line length of this script
quest_text "This script has an average line length of $(awk '{x += length; ++n} END {print x/n;}' $0)."
# The spell for displaying the top 10 most common words used in this script
quest_text "The top 10 most common words used in this spell are: "
quest_text "$(tr -cs "[:alpha:]" "\n" < $0 | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -n | tail -10 | indent)"
# The rune for revealing the current working directory
quest_text "The current working directory you are running ${this_spell} in is $(pwd)."
# The rune for revealing the current date and time
quest_text "The current date and time ${this_spell} is running is $(date)."
# The rune for revealing the current user's home directory
quest_text "The home directory of the user running ${this_spell} is $HOME."
# The rune for revealing the current shell
quest_text "The current shell is $SHELL."
# The rune for revealing the hostname of the system
quest_text "The hostname of the system ${this_spell} is on is $(hostname)."
# The rune for revealing the current user
quest_text "The current user is $(whoami)."
# The rune for revealing the current working directory's permissions
# quest_text
#!/bin/sh
# The rune for revealing the current PATH environment variable
quest_text "The current PATH env variable for the environment ${this_spell} is being run in is $PATH."
# The rune for revealing all the environment variables
quest_text "All environment variables are $ENV."
# The rune for revealing the number of seconds since the script was started
quest_text "Time since ${this_spell} started is $SECONDS."
# The spell for generating a hash of the script for integrity verification
quest_text "The SHA-256 hash of this spell is $(sha256sum $0)"
# The rune for revealing the system uptime
quest_text "Uptime since the system ${this_spell} is running on started is:"
quest_text "$(uptime | indent)"
printf "\n"
# The rune for revealing memory usage is free
quest_text "RAM memory usage is:"
quest_text "$(free -h | indent)."
printf "\n"
# The rune for revealing the total storage usage is df
quest_text "Hard disk storage usage is:"
quest_text "$(df -h | indent)"
printf "\n"
# The spell for revealing the total number of running processes is pgrep
#quest_text "Total number of running processes: $(pgrep -c | indent)"
#printf "\n"
# The spell for revealing all the running processes is ps
quest_text "All running processes on the shell ${this_spell} is running on are:"
quest_text "$(ps | indent)"
printf "\n"
# The spell for searching this script for a specific pattern or keyword
quest_text "Searching this spell for the word 'wizard':"
quest_text "$(grep -n "wizard" $0 | indent)"
printf "\n"
# The spell for performing text replacement within this script
#echo "Replacing all instances of 'spell' with 'incantation' in this script"
#sed -i "s/spell/incantation/g" $0
# The spell for extracting specific fields or information from this script
#echo "Extracting line numbers and line contents of all lines that contain the word 'spell':"
#awk '$0 ~ /spell/ {print NR,$0}' $0
# The spell for reading the content of the script file
quest_text "Complete contents of this spell are:"
cat $0 | indent
# The spell for copying the script file to a new location
quest_text "Copying this spell to rosetta-stone-backup.sh"
cp $0 rosetta-stone-backup.sh
# The spell for removing the script file
#quest_text "Deleting this script."
#rm $0
# The spell for making this script into an executable, self-destructing spell
echo "This script will now self-destruct."
chmod +x $0; rm $0