# SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie # # SPDX-License-Identifier: MIT # Completion for zig65, a 6502 processor and Apple II emulator. # # Install it by copying this file to # /usr/share/bash-completion/completions/zig65, or to # ~/.local/share/bash-completion/completions/zig65, or by sourcing it from # ~/.bashrc. A package should put it in share/bash-completion/completions, # which `zig build` already does. # # It stands on its own and does not need the bash-completion package: the # helpers that would come from it are the only thing it would want, and file # name matching is done here instead. # Offers file names, kept to the given patterns if there are any. Directories # are always offered so that a path can be walked into whatever is being asked # for. _zig65_files() { local current=$1 shift local IFS=$'\n' local names=() if (($# == 0)); then # Everything, directories included: -f does not leave them out. names+=($(compgen -f -- "$current")) else # The patterns leave directories out, so they are asked for # separately. names+=($(compgen -d -- "$current")) local pattern for pattern in "$@"; do names+=($(compgen -f -X "!$pattern" -- "$current")) done fi COMPREPLY=("${names[@]}") # Left to itself bash would treat these as words rather than paths, and # neither escape the awkward characters in them nor mark the directories. compopt -o filenames 2>/dev/null } _zig65() { local current=${COMP_WORDS[COMP_CWORD]} local previous=${COMP_WORDS[COMP_CWORD - 1]} # What the flag before the cursor is waiting for, if it is waiting for # anything. A ROM is just a file; a disk has to be one of the three sector # orders, matched without regard to case, since an image is as likely to # arrive named .DSK as .dsk. The patterns are spelled out a letter at a # time rather than with extglob, which is not on unless something has # turned it on. case $previous in --slot) COMPREPLY=($(compgen -W "\ 1=disk 1=parallel 1=serial 2=serial 2=passport 2=videx 3=videx \ 3=ultraterm 3=uthernet 3=uthernet1 4=mouse 4=mockingboard 4=phasor 4=soundspeech 5=clock 5=ramfactor 6=disk 7=block \ 7=transporter" -- "$current")) return ;; --config | --rom | --disk-rom | --aci-rom | --serial-rom | --videx-rom | --videx-charset | --videx-alternate | --ultraterm-rom | --ultraterm-charset | --ramfactor-rom | --ramcharger | --hard-disk | --scsi-rom | --scsi | --screenshot | --snapshot | --audio | --cassette-in | --cassette-out | --serial-in | --serial-out | --imagewriter | --midi-in | --midi-out | --printer-out | --parallel-out | --localtalk-log | --localtalk-interface | --battery-ram) _zig65_files "$current" return ;; --disk1 | --disk2 | --unidisk | --unidisk2) _zig65_files "$current" '*.[dD][sS][kK]' '*.[dD][oO]' '*.[pP][oO]' \ '*.2[mM][gG]' '*.[sS][hH][kK]' '*.[sS][dD][kK]' '*.[nN][iI][bB]' '*.[wW][oO][zZ]' return ;; --drives) COMPREPLY=($(compgen -W '0 1 2' -- "$current")) return ;; --machine) COMPREPLY=($(compgen -W 'flat i ii ii+ iie iic iii iii+ iigs' -- "$current")) return ;; --video-rom) COMPREPLY=($(compgen -W 'original enhanced' -- "$current")) return ;; --memory) COMPREPLY=($(compgen -W '256K 512K 1M 2M 4M 8M' -- "$current")) return ;; --ramfactor) COMPREPLY=($(compgen -W '256K 512K 768K 1024K' -- "$current")) return ;; --memory-expansion) COMPREPLY=($(compgen -W '256K 512K 768K 1M' -- "$current")) return ;; --processor) COMPREPLY=($(compgen -W '6502 RP2A03 65C02 R65C02 W65C02' -- "$current")) return ;; esac # Otherwise a flag. None of them can be given twice, so one already on the # line is not offered again. The word under the cursor does not count as # already given: finishing off a flag that is spelled out in full would # otherwise offer nothing at all. local flags='id --config --machine --processor --memory --revision --rom --video-rom --disk-rom --aci-rom --slot --drives --disk1 --disk2 --unidisk --unidisk2 --hard-disk --scsi-rom --scsi --screenshot --snapshot --monitor --text --halted --audio --no-audio --volume --mute --cassette-in --cassette-out --parallel-out --serial-rom --serial-in --serial-out --imagewriter --modem --modem-answer --printer-out --localtalk --localtalk-log --localtalk-interface --appletalk --battery-ram --videx-rom --videx-charset --videx-alternate --ultraterm-rom --ultraterm-charset --mouse --mockingboard --mockingboard-speech --phasor --sound-speech --passport --uthernet --uthernet1 --ethernet-interface --mac --midi-in --midi-out --clock --clock-offset --ramfactor-rom --ramfactor --ramcharger --memory-expansion --writable --help' local offered=() flag index seen for flag in $flags; do seen= for index in "${!COMP_WORDS[@]}"; do ((index == COMP_CWORD)) && continue if [[ ${COMP_WORDS[index]} == "$flag" ]]; then seen=yes break fi done [[ -z $seen ]] && offered+=("$flag") done COMPREPLY=($(compgen -W "${offered[*]}" -- "$current")) } complete -F _zig65 zig65