Shell-NLS Tool
1. Introduction
This is a simple tool for convert a long english sentence format to a nls key.
2. Install
$ ./install.sh
Open the git bash under the tool directory and run ./install.sh,
Then you should restart the git bash shell to make the installation avaliable.
3. unInstall
$ ./unInstall.sh
run ./unInstall.sh under the git bash
4. Useage sample
Usage 1: f
$ f "test the nls tool to format your nls sentence"
$ F_TEST_THE_NLS_TOOL_TO_FORMAT_YOUR_NLS : test the nls tool to format your nls sentence
Usage 2: F
$ F "test the nls tool to format your nls sentence"
$ mc.inbox_F_TEST_THE_NLS_TOOL_TO_FORMAT_YOUR_NLS : test the nls tool to format your nls sentence
Usage 3: m
$ m "test the nls tool to format your nls sentence"
$ mc_test_the_nls_tool_to_format_your_nls : test the nls tool to format your nls sentence
Usage 4: M
$ M "test the nls tool to format your nls sentence"
$ mc.test_the_nls_tool_to_format_your_nls : test the nls tool to format your nls sentence
5. Define the slice words number
Usage 1: f -2
$ f -2 "test the nls tool to format your nls sentence"
$ F_TEST_THE : test the nls tool to format your nls sentence
Usage 2: F -3
$ F -3 "test the nls tool to format your nls sentence"
$ mc.inbox_F_TEST_THE_NLS : test the nls tool to format your nls sentence
Usage 3: m -4
$ m -4 "test the nls tool to format your nls sentence"
$ mc_test_the_nls_tool : test the nls tool to format your nls sentence
Usage 4: M -5
$ M -5 "test the nls tool to format your nls sentence"
$ mc.test_the_nls_tool_to : test the nls tool to format your nls sentence
6. set default slice words number
Useage: setn 5
$ setn 5
$ Default slice words number is 5 now!
Notice: You have get the format nls key in clicp board, So you just can paste the nls key handle result
to the place where you needed.
config.sh
#!/usr/bin/bash
# config file for Shell-NLS tool
installFile=~/.bashrc
lockFile=~/nls.lock
shellFileName=nls.sh
utils.sh
#!/usr/bin/bash
function echoError {
echo -e "\033[31m $1 \033[0m"
}
function echoSuccess {
echo -e "\033[32m $1 \033[0m"
}
function echoNotice {
echo -e "\033[33m $1 \033[0m"
}
install.sh
#!/usr/bin/bash
# install Shell-NLS tool
# import config file
. ./config.sh
. ./utils.sh
sucess="Install Shell-NLS Tool Success!"
notice="Note: You should restart the bash shell before using this tool!"
error="Shell-NLS Tool have Installed, please unInstall it before you install it again!"
# check lockfile
if [ -f $lockFile ]
then
echoError "$error"
exit 1
fi
cp ./$shellFileName ~/$shellFileName
if [ -f $installFile ]
then
echo ". ~/$shellFileName" >> $installFile
else
touch $installFile
echo ". ~/$shellFileName" > $installFile
fi
touch $lockFile && echo '8' > $lockFile
echoSuccess "$sucess"
echoNotice "$notice"
unInstall.sh
#!/usr/bin/bash
# unInstall nls tool shell
. ./config.sh
. ./utils.sh
sucess="UnInstall Shell-NLS Tool Success! "
notice="Error: Shell-NLS Tool have not installed! "
if [ -f $lockFile ] && [ -f $installFile ]
then
sed -i '/nls.sh/d' $installFile
rm $lockFile ~/$shellFileName
echoSuccess "$sucess"
else
echoNotice "$notice"
fi
update.sh
#!/usr/bin/bash
# update Shell-NLS tool
# import config file
. ./config.sh
. ./utils.sh
success="Shell-NLS Tool updated success!"
error="Shell-NLS Tool have not installed, you can not update it!"
# check lockfile
if [ -f $lockFile ]
then
cp ./$shellFileName ~/$shellFileName
echoSuccess "$success"
else
echoError "$error"
fi
menu.sh
#!/usr/bin/bash
# create menu for this tool
function install {
. ./install.sh
}
function unInstall {
. ./unInstall.sh
}
function update {
. ./update.sh
}
PS3="Enter option: "
select option in "Install" "Update" "UnInstall" "Exit"
do
case $option in
"Exit")
break;;
"Install")
install ;;
"Update")
update ;;
"UnInstall")
unInstall ;;
*)
echo "Sorry, wrong selection";;
esac
done
clear
nls.sh
#!/usr/bin/bash
# nls key generate shell function
function format_F {
# default words count is 8
defaultLen=$(cat ~/nls.lock)
# prefix string
formatStr=$1
# when no the third param set the defaultLen to sliceLen
sliceLen=${3:-$defaultLen}
count=0
for word in $2
do
if [ $count -ge $sliceLen ]
then
break
fi
formatStr="$formatStr${word^^}_"
count=$[ $count + 1]
done
len=$[ ${#formatStr} - 1 ]
echo ${formatStr:0:$len}
}
function format_M {
# default words count is 8
defaultLen=$(cat ~/nls.lock)
# prefix string
formatStr=$1
# when no the third param set the defaultLen to sliceLen
sliceLen=${3:-$defaultLen}
count=0
for word in $2
do
if [ $count -ge $sliceLen ]
then
break
fi
# convert word to lowercase and concat prefix string
formatStr="$formatStr${word,,}_"
# increse the count indicator
count=$[ $count + 1]
done
# calculate the length of formatStr and minus 1
len=$[ ${#formatStr} - 1 ]
echo ${formatStr:0:$len}
}
function formatEcho_F {
if [ $# -lt 2 ]
then
str=$(format_F "$prefix" "$@")
echo "$str : $@"
else
sliceLen="$1"
str=$(format_F "$prefix" "$2", ${sliceLen:1})
echo "$str : $2"
fi
echo $str | clip
}
function formatEcho_M {
if [ $# -lt 2 ]
then
str=$(format_M "$prefix" "$@")
echo "$str : $@"
else
sliceLen="$1"
str=$(format_M "$prefix" "$2", ${sliceLen:1})
echo "$str : $2"
fi
# set the string to clipborad
echo $str | clip
}
function f {
prefix="F_"
# $@ is all the parameter list
formatEcho_F "$@"
}
function F {
prefix="mc.inbox_F_"
formatEcho_F "$@"
}
function m {
prefix="mc_"
formatEcho_M "$@"
}
function M {
prefix="mc."
formatEcho_M "$@"
}
function setn {
echo $1 > ~/nls.lock
echo -e "#\033[31m Default slice words number is $1 now!\033[0m#"
}
# Sample
#===============================================================
# F "You Need to enter the number"
# F -9 "You Need to enter the number"
# f "You Need to enter the number"
# f -4 "You Need to enter the number"
# m -3 "You Need to enter the number"
# M -1 "You Need to enter the number"
# setn 5
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战