Add an option to specify where to wrap the message

The option is:
  -w, --word-wrap COLUMN
    Specify roughly where messages should be wrapped.
This commit is contained in:
Lucas Possatti
2015-06-23 15:47:35 -03:00
parent a59f1b32e6
commit 1fc82b622d

View File

@@ -4,13 +4,15 @@ usage() {
echo echo
echo " Description: Pokemonsay makes a pokémon say something to you." echo " Description: Pokemonsay makes a pokémon say something to you."
echo echo
echo " Usage: $(basename $0) [-p POKEMON_NAME] [-f COW_FILE] [-l] [-n] [-h] [MESSAGE]" echo " Usage: $(basename $0) [-p POKEMON_NAME] [-f COW_FILE] [-w COLUMN] [-l] [-n] [-h] [MESSAGE]"
echo echo
echo " Options:" echo " Options:"
echo " -p, --pokemon POKEMON_NAME" echo " -p, --pokemon POKEMON_NAME"
echo " Choose what pokemon will be used by its name." echo " Choose what pokemon will be used by its name."
echo " -f, --file COW_FILE" echo " -f, --file COW_FILE"
echo " Specify which .cow file should be used." echo " Specify which .cow file should be used."
echo " -w, --word-wrap COLUMN"
echo " Specify roughly where messages should be wrapped."
echo " -l, --list" echo " -l, --list"
echo " List all the pokémon available." echo " List all the pokémon available."
echo " -n, --no-name" echo " -n, --no-name"
@@ -58,6 +60,14 @@ case $key in
COW_FILE="${1#*=}" COW_FILE="${1#*=}"
shift shift
;; ;;
-w|--word-wrap)
WORD_WRAP="$2"
shift; shift
;;
-w=*|--word-wrap=*)
WORD_WRAP="${1#*=}"
shift
;;
-l|--list) -l|--list)
list_pokemon list_pokemon
;; ;;
@@ -80,6 +90,11 @@ case $key in
esac esac
done done
# Define where to wrap the message.
if [ -n "$WORD_WRAP" ]; then
word_wrap="-W $WORD_WRAP"
fi
# Define which pokemon should be displayed. # Define which pokemon should be displayed.
if [ -n "$POKEMON_NAME" ]; then if [ -n "$POKEMON_NAME" ]; then
pokemon_cow=$(find $pokemon_path -name "$POKEMON_NAME.cow") pokemon_cow=$(find $pokemon_path -name "$POKEMON_NAME.cow")
@@ -94,7 +109,7 @@ filename=$(basename "$pokemon_cow")
pokemon_name="${filename%.*}" pokemon_name="${filename%.*}"
# Call cowsay. # Call cowsay.
cowsay -f "$pokemon_cow" "$MESSAGE" cowsay -f "$pokemon_cow" "$word_wrap" "$MESSAGE"
# Write the pokemon name, unless requested otherwise. # Write the pokemon name, unless requested otherwise.
if [ -z "$DISPLAY_NAME" ]; then if [ -z "$DISPLAY_NAME" ]; then