From 7f1c10a5a855543eeaffe41867328d65867d7558 Mon Sep 17 00:00:00 2001 From: Hugh Ratsch Date: Sun, 9 Feb 2025 03:46:16 -0600 Subject: [PATCH] updated project 2 --- projects/02-command-line-mastery/play.sh | 61 ++++++++++++++---------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/projects/02-command-line-mastery/play.sh b/projects/02-command-line-mastery/play.sh index e7cd4e4..8449ad3 100644 --- a/projects/02-command-line-mastery/play.sh +++ b/projects/02-command-line-mastery/play.sh @@ -261,28 +261,29 @@ setup_challenge_env() { local challenge_id=$1 echo -e "${BLUE}Setting up challenge files...${NC}" - # Source the setup script instead of executing it - if ! source "$CHALLENGE_DIR/.tracking/level1-setup.sh"; then - echo -e "${RED}Error: Failed to setup challenge environment${NC}" - echo -e "${YELLOW}Try running: $0 clean && $0 setup${NC}" - return 1 - fi + # Create necessary directories + mkdir -p "$CHALLENGE_DIR/files" - # Run the setup function from the sourced script - if ! init_environment; then - echo -e "${RED}Error: Failed to initialize environment${NC}" - return 1 - fi - - if ! setup_file_challenges; then - echo -e "${RED}Error: Failed to setup file challenges${NC}" - return 1 - fi - - if ! setup_permission_challenges; then - echo -e "${RED}Error: Failed to setup permission challenges${NC}" - return 1 - fi + # Setup files for the challenge + case "$challenge_id" in + "1.1") + # Create some .conf files with different timestamps + for i in {1..15}; do + echo "config$i=value$i" > "$CHALLENGE_DIR/files/config$i.conf" + # Set random timestamps within the last 48 hours + touch -d "@$(($(date +%s) - RANDOM % 172800))" "$CHALLENGE_DIR/files/config$i.conf" + done + ;; + "1.2") + # Create various file types + for ext in txt conf log py js json yml; do + for i in {1..5}; do + echo "content" > "$CHALLENGE_DIR/files/file$i.$ext" + done + done + ;; + # Add more challenge setups as needed + esac echo -e "${GREEN}Challenge environment ready!${NC}" return 0 @@ -346,7 +347,9 @@ start_challenge() { bind 'set show-all-if-ambiguous on' 2>/dev/null || true echo -e "\n${YELLOW}Your challenge environment is ready!${NC}" - echo -e "You can use the following commands:" + echo -e "${BLUE}Current working directory: $CHALLENGE_DIR${NC}" + echo -e "${BLUE}Challenge: $(get_challenge_description "$challenge_id")${NC}" + echo -e "\nAvailable commands:" print_help_menu # Start command loop with improved prompt @@ -354,8 +357,18 @@ start_challenge() { while true; do cmd_count=$((cmd_count + 1)) echo -ne "\n${GREEN}challenge${BLUE}[$challenge_id]${GREEN}>${NC} " - read -e -r cmd args # -e enables readline for command history - history -s "$cmd $args" # Add command to history + read -e -r cmd args || true # Add || true to prevent exit on Ctrl+D + + # Handle Ctrl+D (EOF) + if [ $? -ne 0 ]; then + echo -e "\n${YELLOW}Use 'exit' or 'q' to quit${NC}" + continue + fi + + # Add command to history + history -s "$cmd $args" + + # Handle the command if ! handle_command "$cmd" $args; then break fi