Last active
August 29, 2015 14:01
-
-
Save unhammer/f5ade1c20f0f5d653b8c to your computer and use it in GitHub Desktop.
source this file; cd to apertium language pair / language dir by saying "ca some pair" or "ca somelang"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Save this file to e.g. ~/src/apertium-ca.sh, then put "source | |
# ~/src/apertium-ca.sh" in ~/.bashrc Now you can type "ca nno" to go | |
# to languages/apertium-nno and "ca kir kaz" to go to | |
# nursery/apertium-kaz-kir – even though it's in the other order | |
export APERTIUM_SVNROOT=$HOME/src/apertium | |
ca () { | |
declare -a modes dirs | |
declare -A pairsdirs langsdirs | |
modes=( "${APERTIUM_SVNROOT}"/{trunk,incubator,nursery,staging,languages}/apertium-*/modes.xml ) | |
dirs=( ${modes[@]%/modes.xml} ) | |
add_langsdir () { | |
if [[ ${langsdirs[$1]+isset} ]]; then | |
langsdirs[$1]="$2\n${langsdirs[$1]}" | |
else | |
langsdirs[$1]=$2 | |
fi | |
} | |
for dir in "${dirs[@]}"; do | |
pair=${dir##*apertium-} | |
if [[ ${pair} = *-* ]]; then | |
from=${pair%%-*} | |
to=${pair##*-} | |
pairsdirs[${from}-${to}]=${dir} | |
pairsdirs[${to}-${from}]=${dir} | |
add_langsdir ${from} ${dir} | |
add_langsdir ${to} ${dir} | |
# interpret nor as both nob and nno: | |
if [[ ${from} = nor ]]; then | |
pairsdirs[nno-${to}]=${dir} | |
add_langsdir nno ${dir} | |
pairsdirs[nob-${to}]=${dir} | |
add_langsdir nob ${dir} | |
elif [[ ${to} = nor ]]; then | |
pairsdirs[${from}-nno]=${dir} | |
add_langsdir nno ${dir} | |
pairsdirs[${from}-nob]=${dir} | |
add_langsdir nob ${dir} | |
fi | |
else | |
pairsdirs[${pair}]=$dir | |
add_langsdir ${pair} ${dir} | |
fi | |
done | |
case $# in | |
1) cd "${pairsdirs[$1]}";; | |
2) | |
if [[ $1 = -l ]]; then | |
if [[ ${langsdirs[$2]+isset} ]]; then | |
echo -e "${langsdirs[$2]}" | |
else | |
echo "No directories found for language code $2" | |
return 1 | |
fi | |
else | |
cd "${pairsdirs[$1-$2]}" | |
fi | |
;; | |
*) | |
echo "Usage: " | |
echo "$0 nob nno cd to the directory containing a pair of nob and nno (even though it's named apertium-nno-nob)" | |
echo "$0 nno cd to the directory containing apertium-nno" | |
echo "$0 -l nno list all apertium directories with nno in the name" | |
return 2 | |
;; | |
esac | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment