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.

86 lines
2.5 KiB

#!/bin/sh
# Initialize verbose flag to 0
verbose=0
# Parse options
while getopts "v" opt; do
case $opt in
v) verbose=1 ;; # If -v is passed, set verbose to 1
\?) echo "Invalid option: -$OPTARG" >&2 ;; # Invalid option
esac
done
shift $((OPTIND-1)) # Shift off the options and optional --.
# Function to display priorities
display_priorities() {
# Get directory
DIR="${PWD}"
# Get the current priorities of the directory
dir_priorities=$(read-magic "${DIR}" priorities)
# If there are no priorities, print an error message and exit
if [ -z "${dir_priorities}" ] || [ "$dir_priorities" = "Error: The attribute does not exist." ]; then
echo "No priorities set in the current folder. Try 'prioritize <filename>'."
exit 1
fi
# Initialize variables
highest_priority=""
line_added=false
menu_command="menu Priorities:"
# Loop through the priorities
dir_priorities=$(echo "${dir_priorities}" | tr ',' '\n')
for priority_hash in $dir_priorities; do
# Get the priority file
priority_file=$(get-card "${priority_hash}")
# Check if the file exists
if [ -n "${priority_file}" ]; then
# Get priority of the file
file_priority=$(read-magic "${priority_file}" priority 2>/dev/null)
# If the file does not have a priority, set it to 0
if [ -z "${file_priority}" ] || [ "$file_priority" = "Error: The attribute does not exist." ]; then
file_priority=0
fi
# If the priority of the file is a number
if [ "${file_priority}" -eq "${file_priority}" ] 2>/dev/null; then
# If the file's priority is not the highest priority, add a line
if [ -n "${highest_priority}" ] && [ "${file_priority}" -ne "${highest_priority}" ] && [ "${line_added}" = false ]; then
menu_command="${menu_command} \"─── %\""
line_added=true
fi
# Add the file to the menu command
menu_command="${menu_command} \""
if [ $verbose -eq 1 ]; then
menu_command="${menu_command}${file_priority} "
fi
item_name=$(basename "$priority_file")
menu_command="${menu_command}$item_name%priority-menu \\\"${priority_file}\\\"\""
# Update the highest priority
highest_priority="${file_priority}"
fi
fi
done
# Add exit command
menu_command="${menu_command} \"Exit%kill -2 $$\""
# Execute the constructed menu command
eval "${menu_command}"
}
# This script displays a list of the prioritized cards in the current directory.
# Catch Ctrl-C
trap "exit" INT
while true; do
display_priorities
done