Add dictionary system
This commit is contained in:
parent
f52954353d
commit
80f9164e85
3 changed files with 114 additions and 0 deletions
36
README.md
36
README.md
|
|
@ -610,6 +610,42 @@ The fonts are automatically installed and configured system-wide through the nix
|
||||||
|
|
||||||
## 🌟 Specialized Tools
|
## 🌟 Specialized Tools
|
||||||
|
|
||||||
|
### 📖 Offline Dictionary: sdcv
|
||||||
|
|
||||||
|
**Configuration**: `modules/dictionary.nix`
|
||||||
|
**Purpose**: Command-line offline dictionary system with English and Japanese dictionaries
|
||||||
|
|
||||||
|
A declarative offline dictionary system using sdcv (StarDict Console Version):
|
||||||
|
|
||||||
|
#### Key Features:
|
||||||
|
- **Complete Offline Access**: No internet required for dictionary lookups
|
||||||
|
- **Multiple Dictionary Types**: English-English, Japanese-English, and English-Japanese
|
||||||
|
- **Declarative Downloads**: Dictionary files automatically downloaded and configured
|
||||||
|
- **Shell Integration**: Convenient aliases for different dictionary types
|
||||||
|
- **Reproducible Setup**: Dictionary configuration managed through Nix
|
||||||
|
|
||||||
|
#### Available Dictionary Aliases:
|
||||||
|
```bash
|
||||||
|
# English-English dictionary (primary)
|
||||||
|
def word # Look up English word
|
||||||
|
define word # Same as def
|
||||||
|
|
||||||
|
# Japanese-English dictionary
|
||||||
|
j2e 単語 # Short alias for Japanese-English
|
||||||
|
e2j word # English to Japanese lookup
|
||||||
|
|
||||||
|
# Utility commands
|
||||||
|
dict-list # List all available dictionaries
|
||||||
|
dict-setup # Manually download/setup dictionary files
|
||||||
|
dict-disable-auto-setup # Disable automatic dictionary setup
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Features:
|
||||||
|
- **Automatic Download**: Dictionary files downloaded from archive.org sources
|
||||||
|
- **Smart Caching**: Files only downloaded once, marked as extracted
|
||||||
|
- **Environment Integration**: `STARDICT_DATA_DIR` configured automatically
|
||||||
|
- **Multiple Formats**: Supports .ifo, .dict, and .idx StarDict format files
|
||||||
|
|
||||||
### 📚 Reference Management: papis
|
### 📚 Reference Management: papis
|
||||||
|
|
||||||
**Purpose**: Command-line reference manager for academic papers and documents
|
**Purpose**: Command-line reference manager for academic papers and documents
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
../../modules/firefox.nix
|
../../modules/firefox.nix
|
||||||
../../modules/ghostty.nix
|
../../modules/ghostty.nix
|
||||||
../../modules/syncthing.nix
|
../../modules/syncthing.nix
|
||||||
|
../../modules/dictionary.nix
|
||||||
../../config/fonts.nix
|
../../config/fonts.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -39,6 +40,7 @@
|
||||||
git-credential-oauth
|
git-credential-oauth
|
||||||
zoxide
|
zoxide
|
||||||
delta
|
delta
|
||||||
|
fastfetch
|
||||||
|
|
||||||
# macOS-specific GUI applications
|
# macOS-specific GUI applications
|
||||||
maccy # Clipboard manager (macOS-only)
|
maccy # Clipboard manager (macOS-only)
|
||||||
|
|
|
||||||
76
modules/dictionary.nix
Normal file
76
modules/dictionary.nix
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
# Create dictionary setup script that downloads and extracts dictionaries
|
||||||
|
setupDictionaries = pkgs.writeShellScript "setup-dictionaries" ''
|
||||||
|
# Create dictionary directory
|
||||||
|
mkdir -p "$HOME/.stardict/dic"
|
||||||
|
|
||||||
|
# Function to download and extract dictionary
|
||||||
|
download_dict() {
|
||||||
|
local url="$1"
|
||||||
|
local filename="$2"
|
||||||
|
local extract_dir="$HOME/.stardict/dic"
|
||||||
|
|
||||||
|
if [ ! -f "$extract_dir/.$(basename $filename)-extracted" ]; then
|
||||||
|
echo "Downloading $filename..."
|
||||||
|
if ${pkgs.curl}/bin/curl -L -o "/tmp/$filename" "$url"; then
|
||||||
|
echo "Extracting $filename..."
|
||||||
|
${pkgs.gnutar}/bin/tar -xf "/tmp/$filename" -C "$extract_dir" --strip-components=1 2>/dev/null || \
|
||||||
|
${pkgs.gnutar}/bin/tar -xf "/tmp/$filename" -C "$extract_dir" 2>/dev/null || true
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
rm -f "/tmp/$filename"
|
||||||
|
touch "$extract_dir/.$(basename $filename)-extracted"
|
||||||
|
echo "$filename setup complete!"
|
||||||
|
else
|
||||||
|
echo "Failed to download $filename"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download dictionaries (using working URLs)
|
||||||
|
download_dict "https://web.archive.org/web/20200702203642/http://download.huzheng.org/dict.org/stardict-dictd_www.dict.org_gcide-2.4.2.tar.bz2" "gcide-dict.tar.bz2"
|
||||||
|
download_dict "https://cyphar.github.io/jpn-stardicts/JMdict-ja-en.tar.gz" "jmdict-ja-en.tar.gz"
|
||||||
|
|
||||||
|
echo "Dictionary setup process completed!"
|
||||||
|
'';
|
||||||
|
|
||||||
|
in
|
||||||
|
{
|
||||||
|
home.packages = with pkgs; [
|
||||||
|
sdcv
|
||||||
|
curl # For downloading dictionaries
|
||||||
|
gnutar # For extracting dictionaries
|
||||||
|
];
|
||||||
|
|
||||||
|
# Environment variable for dictionary location
|
||||||
|
home.sessionVariables = {
|
||||||
|
STARDICT_DATA_DIR = "$HOME/.stardict/dic";
|
||||||
|
};
|
||||||
|
|
||||||
|
# Note: Dictionary files will be downloaded automatically when you first run 'dict-setup'
|
||||||
|
# or you can run the setup manually at any time
|
||||||
|
|
||||||
|
# Shell aliases for different dictionary types
|
||||||
|
programs.zsh.shellAliases = {
|
||||||
|
# English-English dictionary
|
||||||
|
"def" = "sdcv";
|
||||||
|
"define" = "sdcv";
|
||||||
|
|
||||||
|
# Japanese-English dictionary
|
||||||
|
"j2e" = "sdcv -u JMdict-ja-en";
|
||||||
|
|
||||||
|
# English-Japanese dictionary (same as Japanese-English - JMdict is bidirectional)
|
||||||
|
"e2j" = "sdcv -u JMdict-ja-en";
|
||||||
|
|
||||||
|
# List available dictionaries
|
||||||
|
"dict-list" = "sdcv -l";
|
||||||
|
|
||||||
|
# Manual dictionary setup
|
||||||
|
"dict-setup" = toString setupDictionaries;
|
||||||
|
|
||||||
|
# Disable auto-setup for future activations
|
||||||
|
"dict-disable-auto-setup" = "touch $HOME/.stardict/.skip-auto-setup";
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue