#!/bin/bash # Title......: g # Description: A menu for games # Author.....: Mitchell Johnston - uid 0 # Contact....: mitch@crn.hopto.org # Updated....: Fri 03 May 2024 06:11:51 AM CDT #---------------------------------- # Sections: Changes variables functions setup main # use '#' in vi/vim to jump to word under cursor : ' Changes Fri Apr 05 2024 Added window title to playing games Fri Apr 05 2024 Changed Solitaire and added back in klondike2 as well Thu Mar 14 2024 Added -l option to list menu options Thu Feb 15 2024 Added version() to display version and changes ' trap "continue" 2 # allows you to break a bad connection # variables #---------------------------------- [ "$1" == "-D" ] && DEBUG=1 && shift 1 # -D to turn on debug mode DATE=$(date +"%a %b %d") # sets up the date display PS4='$SECONDS $LINENO: ' # debug prompt OS=$(uname -s) # OS type: SunOS Linux NAME=${0##*/} # name of the script TMOUT=15 # time before screen saver kicks in export PATH=/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:$PATH # color setup R=$(tput setaf 1) # red G=$(tput setaf 2) # green Y=$(tput setaf 3) # yellow B=$(tput setaf 4) # blue BC=$(tput setaf 6; tput bold) # bold cyan M=$(tput setaf 5) # magenta C=$(tput setaf 6) # cyan L=$(tput setaf 7) # light grey N=$(tput sgr0) # normal # functions #---------------------------------- html(){ ## mark up code vim -f +"syn on" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1 } pause(){ ## Simple routine to stop execution echo " " echo -n "Hit any key to continue: " read -n 1 x } xtitle(){ ## set window title [ "$DEBUG" == "1" ] && set -x printf "\033]0;${*}🌀${HOSTNAME}\007" } log(){ ## creates a basic log entry $LOG must be defined # Use: log {entry} [ "$DEBUG" == "1" ] && set -x logger -i -t "$NAME" "$*" } version(){ ## display version and change history grep -E '^# Updated' $0 echo " " sed -n "/' Changes/,/^ *$/p" <$0 |grep -E -v 'sed -n|exit 0|}' exit 0 } # setup #---------------------------------- # this provides a quick way to edit all my scripts on the fly if [ "$1" == "-E" ] then vim $0 sed -i -e "7s/.*/# Updated....: $(date)/" $0 log "Updated $0" html $0 cp $0 /var/www/unix mv $0.html /var/www/unix cp $0 /var/gopher/scripts log "Updated $0" exit fi # display version and change history if [ "$1" == "-v" ] || [ "$1" == "--version" ] then version fi # install checks #--------------------------- command -v ppt >/dev/null || sudo apt install bsdgames -yyq command -v klondike2 >/dev/null || wget http://crn.hopto.org/unix/klondike2 command -v boxes >/dev/null || sudo apt install boxes -yy command -v rogue >/dev/null || sudo apt install bsdgames-nonfree -yy command -v nettoe >/dev/null || sudo apt install nettoe -yy command -v freesweep >/dev/null || sudo apt install freesweep -yy command -v vitetris >/dev/null || sudo apt install vitetris -yy command -v ninvaders >/dev/null || sudo apt install ninvaders # main #--------------------------- [ "$DEBUG" == "1" ] && set -x while : do if [ $# -lt 1 ] # check to see if a command line argument is passed then clear xtitle "Games" echo ",----[${BC}Games${N}]" echo " $(fclock) ${N} 2. 🎴 Blackjack b. 🟠 Backgammon h. 🤓 Hangman i. 👾 Invaders k. 🎴 Klondike m. 🚦 Milleborn M. 💣 Minesweeper p. 🎴 Poker r. 🏹 Rogue s. 🎴 Solitaire t. 🔳 Tetris T. 🔖 Tic-Tac-Toe y. 🎲 Yahtzee w. 🔍 Word Search ${Y}-----------------------${N} ${BR}q. Quit${N} "|boxes -d boxquote |grep -v '\,' read -p Selection: -n 1 CHOICE else CHOICE=$(echo "$1" |cut -d'-' -f2) [ "$1" == "-E" ] && CHOICE=E fi case $CHOICE in b) # backgammon xtitle "🟠 Backgammon" clear echo $BC /usr/games/backgammon -n -w echo ${N} ;; 2) # blackjack xtitle "🎴 21" clear bj pause ;; h) # hangman xtitle "🤓 Hangman" clear echo "${Y}" /usr/games/hangman -d ~/etc/words.txt # my custom word list, with Bibles words added echo ${N} ;; i) # ninvaders xtitle "👾 Ninvaders" ninvaders ;; k) # klondike xitle "🎴 Klondike" klondike2 ;; l) # list games grep ') #' $0| sed 's/^[ \t]*//' |grep -v grep ;; m) # milleborn xtitle "🚦 Milleborn" clear echo "${Y}" /usr/games/mille echo ${N} ;; M) # minesweeper xtitle "💣 Minesweeper" freesweep -m 5 ;; p) # poker xtitle "🎴 Poker" poker ;; r) # rogue xtitle "🏹 Rogue" clear echo "$BC" cd ~ if [ -f ~/etc/rogue_vim.save ] then vim -c ':RogueRestore' -c ':q!' else vim -c ':Rogue' -c ':q!' fi [ -f ~/etc/rogue_vim.save ] && ft "Game saved!" || ft "RIP fallen hero!" cd - ;; s) # ttysolitaire #ttysolitaire --passes 4 --no-background-color xtitle "🎴 Solitaire" cd ~/bin/csol-master && ./csol 2>/dev/null cd - >/dev/null ;; t) # tetris xtitle "🔳 Tetris" clear vitetris pause ;; T) # tic-tac-toe xtitle "🔖 tic-tac-toe" clear nettoe clear ;; y) # yahtzee xtitle "🎲 Yahtzee" clear;echo ${BC} yaht1 pause ;; q) # quit clear echo ${G}Bye${N} exit ;; w) # wordsearch xtitle "🔍 Word Search" clear cd ~/bin/wordsearch-master ./wordsearch cd - ;; !) # run command clear echo "${C}Hit return with no command to end.${N}" while : do echo -n "[menu] $PWD $ " read EXEC [ -z "$EXEC" ] && break eval "$EXEC" done pause ;; =) # reset term and restart script reset exec $0 ;; *) # screen saver xtitle "🌘 Screen saver" btop ;; esac [ $# -eq 1 ] && exit done