Initial commit
This commit is contained in:
parent
9b126bfc6e
commit
87a295193a
30
README.md
30
README.md
@ -1 +1,31 @@
|
||||
# star_trek_date
|
||||
|
||||
## Installation
|
||||
|
||||
To install this on your system, the files need to go in certain places;
|
||||
|
||||
### bin/* (main script and config file)
|
||||
|
||||
Copy the files in bin/* to your $HOME/bin directory or /usr/local/bin or /usr/bin dir (or your chosen dir that's in the $PATH)
|
||||
|
||||
### bash.d/* (tab completion script)
|
||||
|
||||
Copy the file in bash.d/* to your $HOME/.bash.d directory, and make sure your $HOME/.bashrc sources all files in that dir
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
Usage: star_trek_date <language> [-d|--debug] [-l|--list]
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
'''bash
|
||||
$ star_trek_date klingon
|
||||
Today's date in Klingon is: wejleS jaj 19, jar jar
|
||||
```
|
||||
|
||||
```bash
|
||||
$ star_trek_date vulcan
|
||||
Today's date in Vulcan is: klosh wak 19, t'vash shen
|
||||
```
|
||||
|
17
bash.d/star_trek_date
Normal file
17
bash.d/star_trek_date
Normal file
@ -0,0 +1,17 @@
|
||||
_star_trek_date_complete()
|
||||
{
|
||||
local cur prev opts
|
||||
_get_comp_words_by_ref -n : cur
|
||||
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
opts="$(star_trek_date vulcan -l|grep -v '^Available languages')"
|
||||
|
||||
if [ ${COMP_CWORD} = 1 ]; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
__ltrim_colon_completions "$cur"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
complete -F _star_trek_date_complete star_trek_date
|
94
bin/star_trek_date
Executable file
94
bin/star_trek_date
Executable file
@ -0,0 +1,94 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration file path
|
||||
CONFIG_DIR="$(dirname $0)"
|
||||
CONFIG_FILE="${CONFIG_DIR}/star_trek_languages.conf"
|
||||
DEBUG=false
|
||||
|
||||
# Function to display debug messages
|
||||
debug() {
|
||||
if [ "$DEBUG" = true ]; then
|
||||
echo "DEBUG: $1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to list available languages
|
||||
list_languages() {
|
||||
echo "Available languages:"
|
||||
grep -E "^[a-zA-Z_]+ " "$CONFIG_FILE"|awk '{print $1}'|grep -v _|sort -u
|
||||
}
|
||||
|
||||
# Function to translate date to a fictional language
|
||||
translate_date() {
|
||||
local language=$1
|
||||
local day_label=""
|
||||
local month_label=""
|
||||
local day_of_week_label=""
|
||||
local month_of_year_label=""
|
||||
|
||||
# Get the current day, month, and day of week
|
||||
current_day=$(date +%d)
|
||||
current_month=$(date +%B)
|
||||
current_day_of_week=$(date +%u)
|
||||
|
||||
debug "Current day: $current_day"
|
||||
debug "Current month: $current_month"
|
||||
debug "Current day of week: $current_day_of_week"
|
||||
|
||||
# Read the configuration file and get the labels
|
||||
while IFS= read -r line; do
|
||||
if [[ $line == "$language "* ]]; then
|
||||
day_label=$(echo $line | awk '{print $2}')
|
||||
month_label=$(echo $line | awk '{print $3}')
|
||||
elif [[ $line == "${language}_day $current_day_of_week "* ]]; then
|
||||
day_of_week_label=$(echo $line | awk '{print $3}')
|
||||
elif [[ $line == "${language}_month $current_month "* ]]; then
|
||||
month_of_year_label=$(echo $line | awk '{print $3}')
|
||||
fi
|
||||
done < "$CONFIG_FILE"
|
||||
|
||||
debug "Day label: $day_label"
|
||||
debug "Month label: $month_label"
|
||||
debug "Day of week label: $day_of_week_label"
|
||||
debug "Month of year label: $month_of_year_label"
|
||||
|
||||
if [ -z "$day_label" ] || [ -z "$month_label" ] || [ -z "$day_of_week_label" ] || [ -z "$month_of_year_label" ]; then
|
||||
echo "Language not supported or not found in the configuration file."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Translate and display the date
|
||||
echo "Today's date in ${language^} is: $day_of_week_label $day_label $current_day, $month_of_year_label $month_label"
|
||||
}
|
||||
|
||||
# Check for command line arguments
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Usage: $(basename $0) <language> [-d|--debug] [-l|--list]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse command line arguments
|
||||
language=${1,,}
|
||||
shift
|
||||
args=${1,,}
|
||||
while [[ "$args" ]]; do
|
||||
case $args in
|
||||
-d|--debug)
|
||||
DEBUG=true
|
||||
;;
|
||||
-l|--list)
|
||||
list_languages
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
echo "Usage: $0 <language> [-d|--debug] [-l|--list]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Call the function with the provided language
|
||||
translate_date "$language"
|
||||
|
90
bin/star_trek_languages.conf
Normal file
90
bin/star_trek_languages.conf
Normal file
@ -0,0 +1,90 @@
|
||||
# star_trek_languages.conf
|
||||
# Format: <language> <day> <month> <day_of_week> <month_of_year>
|
||||
|
||||
# Klingon (example translations)
|
||||
klingon jaj jar
|
||||
klingon_day 1 wa'leS
|
||||
klingon_day 2 cha'leS
|
||||
klingon_day 3 wejleS
|
||||
klingon_day 4 loSleS
|
||||
klingon_day 5 vaghleS
|
||||
klingon_day 6 javleS
|
||||
klingon_day 7 SochleS
|
||||
klingon_month January jar wa'
|
||||
klingon_month February jar cha'
|
||||
klingon_month March jar wej
|
||||
klingon_month April jar loS
|
||||
klingon_month May jar vagh
|
||||
klingon_month June jar jav
|
||||
klingon_month July jar Soch
|
||||
klingon_month August jar chorgh
|
||||
klingon_month September jar Hut
|
||||
klingon_month October jar wa'maH
|
||||
klingon_month November jar wa'maH wa'
|
||||
klingon_month December jar wa'maH cha'
|
||||
|
||||
# Vulcan (example translations)
|
||||
vulcan wak shen
|
||||
vulcan_day 1 danik
|
||||
vulcan_day 2 t'khasi
|
||||
vulcan_day 3 klosh
|
||||
vulcan_day 4 hastek
|
||||
vulcan_day 5 p'pil'lay
|
||||
vulcan_day 6 t'plana
|
||||
vulcan_day 7 s'tar
|
||||
vulcan_month January shen t'Khasi
|
||||
vulcan_month February t'shen
|
||||
vulcan_month March t'ratikh
|
||||
vulcan_month April t'ke-tayek
|
||||
vulcan_month May t'khaf-spol
|
||||
vulcan_month June t'vash
|
||||
vulcan_month July t'masu
|
||||
vulcan_month August t'mekh
|
||||
vulcan_month September t'kor
|
||||
vulcan_month October t'klom
|
||||
vulcan_month November t'kuht
|
||||
vulcan_month December t'vakh
|
||||
|
||||
# Romulan (example translations)
|
||||
romulan daie muhr
|
||||
romulan_day 1 daehhae
|
||||
romulan_day 2 retor
|
||||
romulan_day 3 ssuaj
|
||||
romulan_day 4 mavj
|
||||
romulan_day 5 kra
|
||||
romulan_day 6 dhas
|
||||
romulan_day 7 llet
|
||||
romulan_month January muhr kaleh
|
||||
romulan_month February muhr fvai
|
||||
romulan_month March muhr ress
|
||||
romulan_month April muhr kuria
|
||||
romulan_month May muhr velk
|
||||
romulan_month June muhr jen
|
||||
romulan_month July muhr lal
|
||||
romulan_month August muhr huv
|
||||
romulan_month September muhr fvin
|
||||
romulan_month October muhr tasar
|
||||
romulan_month November muhr nev
|
||||
romulan_month December muhr nor
|
||||
|
||||
# Bajoran (example translations)
|
||||
bajoran ja kil
|
||||
bajoran_day 1 yot
|
||||
bajoran_day 2 ran
|
||||
bajoran_day 3 tre
|
||||
bajoran_day 4 ren
|
||||
bajoran_day 5 sen
|
||||
bajoran_day 6 lor
|
||||
bajoran_day 7 vor
|
||||
bajoran_month January kil yat
|
||||
bajoran_month February kil du
|
||||
bajoran_month March kil tse
|
||||
bajoran_month April kil var
|
||||
bajoran_month May kil lim
|
||||
bajoran_month June kil sen
|
||||
bajoran_month July kil sev
|
||||
bajoran_month August kil og
|
||||
bajoran_month September kil ren
|
||||
bajoran_month October kil tor
|
||||
bajoran_month November kil lat
|
||||
bajoran_month December kil bek
|
Loading…
x
Reference in New Issue
Block a user