generated from nvim-lua/nvim-lua-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlorem.sh
executable file
·60 lines (52 loc) · 1.51 KB
/
lorem.sh
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
#!/bin/sh
# Function to display the help menu with evenly spaced text
show_help() {
printf "Usage: %s [OPTION] AMOUNT\n\n" "$0"
printf "Generate lorem ipsum text.\n\n"
printf "%-25s %-40s\n" "Options:" ""
printf " %-20s %s\n" "-w, --words" "Generate a specified amount of words"
printf " %-20s %s\n" "-p, --paragraphs" "Generate a specified amount of paragraphs"
printf " %-20s %s\n" "-h, --help" "Display this help menu"
printf "\n"
printf "%-25s %-40s\n" "Example:" ""
printf " %-20s %s\n" "$0 -w 100" "Generate 100 words"
printf " %-20s %s\n" "$0 -p 3" "Generate 3 paragraphs"
exit 0
}
# Default values
FORMAT=""
AMOUNT=""
# Parse options using case
while [ "$#" -gt 0 ]; do
case "$1" in
-w|--words)
FORMAT="words"
AMOUNT="$2"
shift 2
;;
-p|--paragraphs)
FORMAT="paragraphs"
AMOUNT="$2"
shift 2
;;
-h|--help)
show_help
;;
-*)
echo "Error: Invalid option $1" >&2
show_help
;;
*)
echo "Error: Unexpected argument $1" >&2
show_help
;;
esac
done
# Ensure required arguments are provided
if [ -z "$FORMAT" ] || [ -z "$AMOUNT" ]; then
echo "Error: Missing required arguments." >&2
show_help
fi
# Generate the lorem ipsum text
TEXT=$(nvim --headless -c "lua print(require('lorem').$FORMAT($AMOUNT))" +qall | tail -n +1)
echo "$TEXT"