You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/bin/bash ## name : ksd.sh# author : ChatGPT# date : 2024-10-28# version : 1.0.0## This script is a simple implementation of an interactive interface with `kd`,# the crystal clear command-line dictionaryinfo() {
echo"This script is used to interact with \`kd\`, the crystal clear command line dictionary. Every sequence you type down here will be passed to \`kd\`. Use '/help' for help message."
}
internal_commands_help() {
echo"Internal Commands: /clear to clear outputs /quit to quit /help to show this message "
}
print_help() {
echo"Usage: kds.sh [OPTIONS] Options:-h, --help Show this message -o, --options [OPTS] Specify options to be passed to the kd command-f, --file [FILE] Read queries from FILE "
info
}
process_input() {
local input="$1"if [[ "$input"=="/quit" ]];thenecho"Quit kd."return 1 # Return non-zero to indicate quitelif [[ "$input"=="/help" ]];then
info
echo
internal_commands_help
elif [[ "$input"=="/clear" ]];then
clear
else# Combine kd_options with the user_input and call kd
kd $kd_options"$input"fireturn 0 # Return zero to indicate continue
}
# Initialize kd_options
kd_options=""# Parse command line argumentswhile [[ "$#"-gt 0 ]];docase$1in
-h|--help)
print_help
exit 0
;;
-o|--options)
if [[ "$#"-gt 1 ]];then
kd_options="$kd_options$2"shift 2
elseecho"Error: --kd-options requires a value."exit 1
fi
;;
-f|--file)
if [[ "$#"-gt 1 ]];then
file_input="$2"shift 2
elseecho"Error: --file requires a filename."exit 1
fi
;;
*)
echo"Unknown option: $1"
print_help
exit 1
;;
esacdone
info
# If a file is specified, read from itif [[ -n"$file_input" ]];thenif [[ -f"$file_input" ]];thenwhile IFS= read -r line;doif! process_input "$line";thenbreakfidone<"$file_input"elseecho"Error: File '$file_input' not found."exit 1
fielsewhiletrue;doecho""# Always enter a space lineread -p "KD $kd_options >" user_input
if! process_input "$user_input";thenbreakfidonefi
The text was updated successfully, but these errors were encountered:
环境
描述
我在 Issue #30 中将问题描述为“从文件中读取单词通过标准输入输出流调用
kd
会导致单词查询失败,kd
似乎只接受用户从控制塔输入的字符,不接受从文件读取的字符”。但我在写 Issue 的时候,进行了新一轮的排查。经过排查之后发现导致这个问题的真正原因是kd
在 Windows 平台上无法处理文件中的 DOS 换行符。我不知道该 Bug 是否有修复的价值,但是以防万一我还是来反馈一下。
复现方法
可以首先使用
echo "abandon" > ./one_word.txt
命令将单词写入本地文件one_word.txt
使用:kd -t $(cat ./one_word.txt)
命令,会发现
kd
正确翻译了单纯abandon
;但是如果在 Windows 上使用任何文本编辑器编辑one_word.txt
。然后使用kd -t $(cat ./one_word.txt)
,就会发现kd
无法翻译单词。这个时候可以尝试命令dos2unix ./one_word.txt
,再尝试就没有问题了。我是在测试如下脚本的时候遇到问题的,该脚本也可用于反映问题。
The text was updated successfully, but these errors were encountered: