#!/bin/sh # shellcheck disable=SC2086 # pingo - POSIX-compliant shell script to help running pingo through Wine # # Written in 2016-2017 by Daniel Bermond < yahoo.com: danielbermond > # # To the extent possible under law, the author(s) have dedicated all # copyright and related and neighboring rights to this software to the # public domain worldwide. This software is distributed without any # warranty. # # You should have received a copy of the CC0 Public Domain Dedication # along with this software. If not, see # . pingo_dir='/usr/share/pingo' pingo_file='pingo.exe' # cd_error function: print a message indicating a failed cd command and exit # arguments: $1 - the directory that failed to cd into # return value: none # return code (status): not relevant, will exit the program cd_error() { printf '%s\n' "error: could not cd into '${1%/}/' directory" >&2 exit 1 } # enable some options if the executing shell is zsh if [ -n "$ZSH_VERSION" ] then command -v setopt >/dev/null 2>&1 || { printf '%s\n' 'script appears to be running in zsh but setopt was not found'; exit 1; } setopt SH_WORD_SPLIT # enable variable word splitting fi # check if requirements are installed (wine and pingo.exe) command -v wine >/dev/null 2>&1 || { printf '%s\n' 'error: wine not found' >&2; printf '%s\n' ' please install wine' >&2; exit 1; } test -f "${pingo_dir}/${pingo_file}" || { printf '%s\n' "error: '${pingo_file}' not found" >&2; printf '%s\n' " please copy it to '${pingo_dir}/'" >&2; exit 1; } # Parse command line arguments and build a string with options # and PNG/JPG files to be passed to pingo. We cannot simply # pass the untouched command line arguments to pingo because # it's necessary to map paths for wine. for arg in "$@" do # test if command line argument is a valid file if [ -f "$arg" ] then # map path for wine using default WINEPREFIX fullpath="$(printf '%s' "$(cd "$(dirname "$arg")" || cd_error "$(dirname "$arg")"; pwd)/$(basename "$arg")")" imgfiles="${imgfiles} ${HOME}/.wine/dosdevices/z:${fullpath} " else # if not a valid file, just store it (should be an option) pingo_opts="${pingo_opts} ${arg}" fi done # delete the first character of strings (a blank character) imgfiles="$(printf '%s' "$imgfiles" | sed 's/.//')" pingo_opts="$(printf '%s' "$pingo_opts" | sed 's/.//')" # execute pingo through wine cd "$pingo_dir" || cd_error "$pingo_dir" IFS=' ' wine ./"$pingo_file" $pingo_opts $imgfiles