File: pyfiglet_example

package info (click to toggle)
pyfiglet 0.7.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 308 kB
  • ctags: 268
  • sloc: python: 724; sh: 76; makefile: 8
file content (61 lines) | stat: -rwxr-xr-x 1,235 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
PYFIGLET='./pyfiglet'
OUTPUT='/tmp/pyfiglet_example.log'
TEXT='pyfiglet'
LOG=0

cd "$(dirname "$0")"
if [ ! -f "$PYFIGLET" ]; then
    echo "Error ! can't find $PYFIGLET!"
fi

print_samples() {
    if [ "$LOG" -eq 1 ]; then
        output="$OUTPUT"
        rm "$output" 2>/dev/null
    else
        output='/dev/null'
    fi

    #. strip \' \, \[ \] from font lists of pyfiglet.
    fonts="$("$PYFIGLET" -l | sed -e "s/[',]//g" -e 's/^\[//g' -e 's/\]$//g')"

    for font in $fonts; do
        echo "$font" | tee -a "$output"
        "$PYFIGLET" "$TEXT" -f "$font" | tee -a "$output"
    done
}

useage() {
    echo "Useage: $0 [options] [text ...]\n"
    echo "Options:"
    echo "-l\t\t\tcreate log file."
    echo "-o [path_to_file]\tspecify the path of log file,\n\t\t\tdefault is $OUTPUT."
    echo "-h\t\t\tshow help messages."
    exit 0
}

#. parse apts & args
while getopts ":lo:h" opt; do
    case "$opt" in
        l)
            LOG=1
            ;;
        o)
            if [ -n $OPTARG ]; then
                OUTPUT="$OPTARG"
            fi
            ;;
        h|\?)
            useage
            ;;
    esac
done
shift `expr $OPTIND - 1`
if [ ! -z "$1" ]; then
    TEXT="$@"
fi

#. main 
print_samples