-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathanthy_create_aa_dic.sh
executable file
·83 lines (75 loc) · 2.53 KB
/
anthy_create_aa_dic.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
########################################################################
# anthy_create_aa_dic.sh: Create Anthy Dictionary for ASCII Art
#
# Description:
# This script creates a custom dictionary for Anthy, a Japanese input
# method, using ASCII art (AA) entries. It converts an MS-IME format
# dictionary to the Canna format using the convert_msime2cannna.rb script.
#
# Author: id774 (More info: http://id774.net)
# Source Code: https://github.com/id774/scripts
# License: LGPLv3 (Details: https://www.gnu.org/licenses/lgpl-3.0.html)
# Contact: [email protected]
#
# Version History:
# v1.2 2025-03-17
# Encapsulated all logic in functions and introduced main function.
# v1.1 2023-12-06
# Refactored for improved readability and added detailed comments.
# v1.0 2009-11-17
# Initial release.
#
# Usage:
# ./anthy_create_aa_dic.sh
#
########################################################################
# Check if the system is Linux
check_system() {
if [ "$(uname -s)" != "Linux" ]; then
echo "Error: This script is intended for Linux systems only." >&2
exit 1
fi
}
# Function to check if SCRIPTS variable is set
check_scripts() {
if [ -z "$SCRIPTS" ]; then
echo "Error: SCRIPTS environment variable is not set." >&2
echo "Please set the SCRIPTS variable to this script." >&2
exit 1
fi
}
# Function to check required commands
check_commands() {
for cmd in "$@"; do
cmd_path=$(command -v "$cmd" 2>/dev/null)
if [ -z "$cmd_path" ]; then
echo "Error: Command '$cmd' is not installed. Please install $cmd and try again." >&2
exit 127
elif [ ! -x "$cmd_path" ]; then
echo "Error: Command '$cmd' is not executable. Please check the permissions." >&2
exit 126
fi
done
}
# Function to check for required files and directories
check_files() {
test -f "$SCRIPTS/convert_msime2cannna.rb" || { echo "Error: Missing convert_msime2cannna.rb" >&2; exit 1; }
test -f "$SCRIPTS/etc/aa.txt" || { echo "Error: Missing aa.txt" >&2; exit 1; }
test -d "$HOME/.anthy" || mkdir -p "$HOME/.anthy"
}
# Function to create Anthy dictionary for ASCII Art
create_dictionary() {
ruby -Ku "$SCRIPTS/convert_msime2cannna.rb" < "$SCRIPTS/etc/aa.txt" > "$HOME/.anthy/private_words_default"
echo "Dictionary created."
}
# Main function to execute the script
main() {
check_system
check_scripts
check_commands ruby mkdir
check_files
create_dictionary
}
# Execute main function
main "$@"