def gzipOA(directory=None, cmdverbose : int =0, add_check : bool =  True, unzip_text : bool = False):
    """ Create script to compress all oa files in a directory with gzip """ 
    if directory is not None:
        cmd = 'cd %s\n' % directory
    else:
        cmd = ''

    if cmdverbose>=2:
            cmd += 'echo "Running script generated by gzipOA"\n'

    if unzip_text:
        cmd += '# check for accidentially zipped text files\n'
        cmd += 'gzoafiles=$(ls *.oa.gz 2> /dev/null)\n'
        cmd += 'for f in $gzoafiles\ndo\n'
        cmd += 'format=$(oainfo -v 0 -f $f)\n'
        if cmdverbose>=3:
            cmd += 'echo "unzip? $f, format is $format"\n'
        cmd += 'if [ "$format" == 5 ]; then\n'
        if cmdverbose:
            cmd += 'echo "unzip $f, format is $format"\n'
        cmd += '   gzip -d -q -f $f; \n'
        cmd += 'fi\n'
        cmd += 'done\n'
        
        cmd += '\n'
    cmd += 'oafiles=$(ls *.oa 2> /dev/null)\n'
    cmd += 'noafiles=$(ls *.oa 2> /dev/null | wc -l)\n'
    cmd += '# echo "oafiles $oafiles\n'

    cmd += 'if [ "$noafiles" != "0" ]; then\n'

    if cmdverbose:
        cmd += 'echo "doing zip of $noafiles file(s)..."\n'
    if add_check:
        # bash only...
        cmd += 'for f in $oafiles\ndo\n'
        cmd += 'format=$(oainfo -v 0 -f $f)\n'
        cmd += 'if [ "$format" != 0 ]; then\n'
        if cmdverbose:
            cmd += 'echo "zip $f, format is $format"\n'
        cmd += '   gzip -q -f $f; \n'
        cmd += 'fi\n'
        cmd += 'done\n'
    else:
        cmd += '   gzip -q -f *.oa; \n'
    cmd += 'fi\n'
    return cmd