From 734c18282ba37a059806988a2e5d232494b1dcbf Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Thu, 13 Apr 2023 19:03:13 +0800 Subject: [PATCH 01/13] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E4=BA=86?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8A=A0=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 3 +++ misc/Info.py | 4 ++-- ssr/config.ssr | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 ssr/config.ssr diff --git a/main.py b/main.py index 5971c68..d9941f0 100644 --- a/main.py +++ b/main.py @@ -9,6 +9,7 @@ from misc.Logo import Logo from tools.SelfCheck import SelfCheck from misc.Info import ProgramInfo +from misc.Info import SSR_Reader from misc.Error import Error from tools.Phraser import PS1 @@ -42,6 +43,8 @@ def IceShell(): # 程序从这里开始 SelfCheck.WelcomeStart() # 显示Logo SelfCheck.LibCheck() + ssr = SSR_Reader() + print(ssr.paraphraser()["version"]) print(Colors.BLUE + Logo.div_line_n_m + Colors.END + "\n") while True: try: diff --git a/misc/Info.py b/misc/Info.py index 88d57e4..77f88df 100644 --- a/misc/Info.py +++ b/misc/Info.py @@ -43,7 +43,7 @@ def __init__(self): # 读取配置文件 self.config = self.paraphraser(ProgramInfo.ssr_path + "config.ssr") # 更新配置 - self.update_config() + # self.update_config() # 解码器:将配置文件中的格式转化成字典 @@ -53,7 +53,7 @@ def __init__(self): # 请注意,“#”是注释符号,不会被解析,一般独占一行的开头 # 请注意,如果value中有“=”号,那么value中的“=”号不会被解析为=号而是作为普通字符 - def paraphraser(self, config_file: str): + def paraphraser(self, config_file: str = ProgramInfo.ssr_path + "config.ssr"): # 返回值:配置字典 # 读取文件 with open(config_file, "r") as f: diff --git a/ssr/config.ssr b/ssr/config.ssr new file mode 100644 index 0000000..4004119 --- /dev/null +++ b/ssr/config.ssr @@ -0,0 +1,7 @@ +version="v1.0.0-alphav1.2.1" +author="Lanbin" +using_libs=['os', 'sys'] +models_path="./models/" +registered_modules=['print', 'downlib', 'dellib', 'scan', 'models', 'shell', '*'] +debug_mode=True +ssr_path="./ssr/" From cf39f87c76187fbef787badcab596d020f2c250b Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Thu, 13 Apr 2023 19:04:57 +0800 Subject: [PATCH 02/13] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E4=BA=86man?= =?UTF-8?q?=E6=89=8B=E5=86=8C=E5=92=8Chelp=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86SSR=E9=85=8D=E7=BD=AE=E8=AF=BB?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 +- models/help/main.py | 30 +++++++++++++++++++++++++++++- models/man.conf | 6 ++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 models/man.conf diff --git a/main.py b/main.py index d9941f0..fc01d5e 100644 --- a/main.py +++ b/main.py @@ -44,7 +44,7 @@ def IceShell(): SelfCheck.WelcomeStart() # 显示Logo SelfCheck.LibCheck() ssr = SSR_Reader() - print(ssr.paraphraser()["version"]) + # print(ssr.paraphraser()["version"]) print(Colors.BLUE + Logo.div_line_n_m + Colors.END + "\n") while True: try: diff --git a/models/help/main.py b/models/help/main.py index 6d451d6..cc9acad 100644 --- a/models/help/main.py +++ b/models/help/main.py @@ -1,2 +1,30 @@ +import sys +sys.path.append("../../") + +from tools.iPrint import * + +# 读取配置文件 +# 格式:print=a function which print "helloworld" +def read_man_conf(): + with open("../man.conf", "r") as f: + conf = f.read() + + conf = conf.split("\n") + conf_dict = {} + author_dict = {} + for line in conf: + if line != "": + line = line.split("=") + aut = line[1].split("%%") + conf_dict[line[0]] = aut[0] + author_dict[line[0]] = aut[1] + return conf_dict, author_dict + +config, author = read_man_conf() + +# 打印帮助信息 +print("Man Help\tAuthor\tMan") +print('--------------------------------------') +for man in config: + print(f"{man}\t\t{author[man]}\t{config[man]}") -print("这是一个多文件模块的示例") diff --git a/models/man.conf b/models/man.conf new file mode 100644 index 0000000..9d148ea --- /dev/null +++ b/models/man.conf @@ -0,0 +1,6 @@ +print=A function which print "helloworld"%%Lanbin +dellib=A function which delete a library%%Lanbin +downlib=A function which download a library%%Lanbin +models=A function which show all models%%Lanbin +scan=A function which scan the network port%%Lanbin +shell=A function which open a shell%%Lanbin From e1fe35e6592d37acab0845ca8f20e699d69e0e44 Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Thu, 13 Apr 2023 21:33:24 +0800 Subject: [PATCH 03/13] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E4=BA=86print?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/print.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/models/print.py b/models/print.py index 5f73247..601c4fc 100644 --- a/models/print.py +++ b/models/print.py @@ -1 +1,6 @@ -print("Helloworld!") \ No newline at end of file +from argparse import ArgumentParser +parser = ArgumentParser() +parser.add_argument("echo", help="add some") +args = parser.parse_args() +echo = args.echo +print(echo) \ No newline at end of file From fa15c8329a36c1b3484865a79dfd4880de01dcb6 Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Thu, 13 Apr 2023 21:36:07 +0800 Subject: [PATCH 04/13] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BA=86?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E5=88=AB=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/alias.py | 23 +++++++++++++++++++++++ tools/alias.conf | 1 + 2 files changed, 24 insertions(+) create mode 100644 models/alias.py create mode 100644 tools/alias.conf diff --git a/models/alias.py b/models/alias.py new file mode 100644 index 0000000..4159c55 --- /dev/null +++ b/models/alias.py @@ -0,0 +1,23 @@ +import sys,os +from argparse import ArgumentParser +pa = os.getcwd() +sys.path.append("..") + +from tools.Phraser import alias + +os.chdir(pa+r"\..\tools") +ALIAS = alias("alias.conf") + +# parser = ArgumentParser() +# parser.add_argument("add", help="add some") +# args = parser.parse_args() +# ip = args.add +# start_port = int(args.sp) +# end_port = int(args.np) + +aliases = ALIAS.getAll() +print("Alias\tRunable") +print('----------------') +for i in aliases: + print(f"{i}\t-> {aliases[i]}") + diff --git a/tools/alias.conf b/tools/alias.conf new file mode 100644 index 0000000..4d16eda --- /dev/null +++ b/tools/alias.conf @@ -0,0 +1 @@ +sh=bash \ No newline at end of file From 528b58c503fc6ddf8b9701bc031a4220be4b1b0b Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Thu, 13 Apr 2023 21:36:23 +0800 Subject: [PATCH 05/13] =?UTF-8?q?feat:=20=E6=96=B0=E5=BB=BA=E4=BA=86Bash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/bash.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 models/bash.py diff --git a/models/bash.py b/models/bash.py new file mode 100644 index 0000000..7914471 --- /dev/null +++ b/models/bash.py @@ -0,0 +1 @@ +print("激活了Bash模块!") \ No newline at end of file From 34cf9ccea88d9e4b814263e98bd6cb8308ee7d72 Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Thu, 13 Apr 2023 21:37:34 +0800 Subject: [PATCH 06/13] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E5=88=AB=E5=90=8D=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/SelfCheck.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/SelfCheck.py b/tools/SelfCheck.py index 4206a50..569b47e 100644 --- a/tools/SelfCheck.py +++ b/tools/SelfCheck.py @@ -7,6 +7,7 @@ from misc.Color import Colors from misc.Logo import Logo from tools.iPrint import * +from tools.Phraser import alias import os class SelfCheck: @@ -61,11 +62,14 @@ def LibCheckNative(): def CheckModel(modelName): # iPrintLog("Checking model \""+modelName+"\"...", processName="SelfCheck", modelName="Models", typer="info") + ali = alias() if os.path.exists(ProgramInfo.models_path + modelName +".py"): # iPrintLog("Model \""+modelName+"\" is exists. ", processName="SelfCheck", modelName="Models", typer="success") return True elif os.path.exists(ProgramInfo.models_path + modelName + "/main.py"): return True + elif ali.exsist(modelName): + return True else: iPrintLog("Model \""+modelName+"\" is NOT exists! Please Check `main.py` and `"+ modelName +".py`", processName="SelfCheck", modelName="Models", typer="error") return False From 19653e010fa7f349a10066f74bb00ac8a0ee571a Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Thu, 13 Apr 2023 21:37:52 +0800 Subject: [PATCH 07/13] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=88=AB?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/Phraser.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/Phraser.py b/tools/Phraser.py index e9aec22..d914d7d 100644 --- a/tools/Phraser.py +++ b/tools/Phraser.py @@ -18,3 +18,27 @@ def paraphraser(prompt="[IShell] %u> "): prompt = prompt.replace("%u", "Lanbin") return prompt +class alias: + def __init__(self, path="tools/alias.conf"): + with open(path, "r") as f: + conf = f.read() + + conf = conf.split("\n") + self.conf_dict = {} + self.author_dict = {} + for line in conf: + if line != "": + line = line.split("=") + self.conf_dict[line[0]] = line[1] + + def get(self, key): + return self.conf_dict[key] + + def exsist(self, key): + if key in self.conf_dict: + return True + else: + return False + + def getAll(self): + return self.conf_dict \ No newline at end of file From c09a19d56ca794964200be7cc7c5f1aba751fc40 Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Thu, 13 Apr 2023 21:38:19 +0800 Subject: [PATCH 08/13] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86models?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/models.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/models/models.py b/models/models.py index cd42ecb..e8d64e0 100644 --- a/models/models.py +++ b/models/models.py @@ -12,6 +12,9 @@ lists = os.listdir(".") +# 剔除lists中所有后缀名非.py的文件并保持原格式 +lists = [i for i in lists if i.endswith(".py")] + total_model = len(lists) print("\nModels Found"+"\t\t"+"Author") @@ -26,11 +29,12 @@ print(Logo.div_line_n) for it in ProgramInfo.registered_modules: - print(it+" "+"\t\t"+"None") + if it != "*": + print(it+" "+"\t\t"+"None") print() -if len(ProgramInfo.registered_modules) == total_model: - iPrintLog(f"Found {total_model} models. And {len(ProgramInfo.registered_modules)} models were registered.", modelName="models", typer="success") +if len(ProgramInfo.registered_modules)-int("*" in ProgramInfo.registered_modules) == total_model: + iPrintLog(f"Found {total_model} models. And {len(ProgramInfo.registered_modules)-1} models were registered.", modelName="models", typer="success") else: iPrintLog(f"Found {total_model} models. But {len(ProgramInfo.registered_modules)} models were registered.", modelName="models", typer="warning") iPrintLog(f"Models end!", modelName="models", typer="info") From 4be2d52299dc696e9ddb4ee70520c24d493b0bbe Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Thu, 13 Apr 2023 21:39:30 +0800 Subject: [PATCH 09/13] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=88=AB?= =?UTF-8?q?=E5=90=8D=E7=9A=84=E4=B8=9C=E4=B8=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index fc01d5e..eca4ce0 100644 --- a/main.py +++ b/main.py @@ -12,17 +12,24 @@ from misc.Info import SSR_Reader from misc.Error import Error from tools.Phraser import PS1 +from tools.Phraser import alias + +ALIAS = alias() def ExecuteModel(args, moduleName): if not SelfCheck.CheckModel(moduleName): return os.chdir(r"./models") is_mutiple = False - if not os.path.exists(f"{moduleName}.py"): + if os.path.exists(f"{moduleName}.py"): + command = sys.executable + f" ./{moduleName}.py " + args + elif os.path.exists(f"./{moduleName}/main.py"): os.chdir(rf"./{moduleName}") command = sys.executable + f" ./main.py " + args is_mutiple = True else: - command = sys.executable + f" ./{moduleName}.py " + args + if ALIAS.exsist(moduleName): + command = ALIAS.get(moduleName) + command = sys.executable + f" ./{command}.py " + args os.system(command) if is_mutiple: os.chdir(r"..") os.chdir(r"..") From 6228059d4dda2e8a70ba20f4b03e7ef005f8f17a Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Thu, 13 Apr 2023 21:39:42 +0800 Subject: [PATCH 10/13] =?UTF-8?q?chore:=20=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- misc/Info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/Info.py b/misc/Info.py index 77f88df..9923b1b 100644 --- a/misc/Info.py +++ b/misc/Info.py @@ -12,7 +12,7 @@ class ProgramInfo: author = "Lanbin" using_libs = ["os", "sys"] models_path = r"./models/" - registered_modules = ["print", "downlib", "dellib", "scan", "models", "shell", "*"] + registered_modules = ["print", "downlib", "dellib", "scan", "models", "shell", "alias", "bash", "*"] debug_mode = True ssr_path = r"./ssr/" From 84ebc1e5bd66cea87ec0b5264858283be37e5d67 Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Fri, 14 Apr 2023 23:12:06 +0800 Subject: [PATCH 11/13] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E4=BA=86?= =?UTF-8?q?=E5=A4=9A=E9=87=8D=E5=88=AB=E5=90=8D=E5=92=8C=E5=88=AB=E5=90=8D?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/alias.py | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/Phraser.py | 15 +++++++- tools/alias.conf | 3 +- 3 files changed, 115 insertions(+), 2 deletions(-) diff --git a/models/alias.py b/models/alias.py index 4159c55..2dd5743 100644 --- a/models/alias.py +++ b/models/alias.py @@ -15,9 +15,108 @@ # start_port = int(args.sp) # end_port = int(args.np) +# 获取参数 +# 如果没有任何参数则输出所有别名 +# 参数有三种:add, set, del +# add: 添加别名 +# set: 修改别名 +# del: 删除别名 +# flu: 刷新别名配置文件 +# 创建一个类来实现 + +class Aliaser: + def __init__(self, path="alias.conf"): + self.path = path + self.alias = alias(path) + + def add(self, alias, command): + if self.alias.exsist(alias): + print(f"Alias {alias} already exsist!") + else: + with open(self.path, "a") as f: + f.write(f"\n{alias}={command}") + + def set(self, alias, command): + if self.alias.exsist(alias): # 别名存在 + config = self.alias.getAll() + config[alias] = command + with open(self.path, "w") as f: + for i in config: + f.write(f"{i}={config[i]}\n") + else: + print(f"Alias {alias} not exsist!") + + def delete(self, alias): + if self.alias.exsist(alias): + config = self.alias.getAll() + del config[alias] + with open(self.path, "w") as f: + for i in config: + f.write(f"{i}={config[i]}\n") + else: + print(f"Alias {alias} not exsist!") + + +# 获取参数 参数可能为空 + +parser = ArgumentParser() +parser.add_argument("-a", "--add", help="add some") +parser.add_argument("-s", "--set", help="set some") +parser.add_argument("-d", "--delete", help="delete some") +# -f 没有参数,加上即代表刷新 +# parser.add_argument("-f", "--flush", help="flush some") +parser.add_argument("-f", "--flush", action="store_true", help="flush some") + +args = parser.parse_args() +add = args.add +set = args.set +delete = args.delete +flush = args.flush + +# 如果参数为空则输出所有别名 +if add == None and set == None and delete == None and flush == False: + aliases = ALIAS.getAll() + print("Alias\tRunable") + print('----------------') + for i in aliases: + print(f"{i}\t-> {aliases[i]}") + exit() + +# 如果参数不为空则进行操作 +# 如果参数为add则添加别名 +# 如果参数为set则修改别名 +# 如果参数为del则删除别名 +# 如果参数为flu则刷新别名配置文件 + + +if flush: + ALIAS.reRead() + exit() + +# 如果参数为其他则报错 +if add != None: + add = add.split("=") + aliaser = Aliaser() + aliaser.add(add[0], add[1]) + ALIAS.reRead() +elif set != None: + set = set.split("=") + aliaser = Aliaser() + aliaser.set(set[0], set[1]) + ALIAS.reRead() +elif delete != None: + aliaser = Aliaser() + aliaser.delete(delete) + ALIAS.reRead() +else: + print("Wrong parameter!") + exit() + aliases = ALIAS.getAll() print("Alias\tRunable") print('----------------') for i in aliases: print(f"{i}\t-> {aliases[i]}") +exit() + diff --git a/tools/Phraser.py b/tools/Phraser.py index d914d7d..cc55a0c 100644 --- a/tools/Phraser.py +++ b/tools/Phraser.py @@ -41,4 +41,17 @@ def exsist(self, key): return False def getAll(self): - return self.conf_dict \ No newline at end of file + self.reRead() + return self.conf_dict + + def reRead(self, path="../tools/alias.conf"): + with open(path, "r") as f: + conf = f.read() + + conf = conf.split("\n") + self.conf_dict = {} + self.author_dict = {} + for line in conf: + if line != "": + line = line.split("=") + self.conf_dict[line[0]] = line[1] \ No newline at end of file diff --git a/tools/alias.conf b/tools/alias.conf index 4d16eda..0d0fa38 100644 --- a/tools/alias.conf +++ b/tools/alias.conf @@ -1 +1,2 @@ -sh=bash \ No newline at end of file +sh=bash +al=alias From 2f3e746eb7f452172f84a651256371316b9aa083 Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Fri, 14 Apr 2023 23:34:22 +0800 Subject: [PATCH 12/13] =?UTF-8?q?docs:=20=E6=96=B0=E5=A2=9E=E4=BA=86Ish?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=E8=A7=84=E5=88=99=EF=BC=88=E5=88=9D=E7=A8=BF?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "docs/ish\350\257\255\346\263\225.md" | 147 ++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 "docs/ish\350\257\255\346\263\225.md" diff --git "a/docs/ish\350\257\255\346\263\225.md" "b/docs/ish\350\257\255\346\263\225.md" new file mode 100644 index 0000000..9424a53 --- /dev/null +++ "b/docs/ish\350\257\255\346\263\225.md" @@ -0,0 +1,147 @@ +# Ish语法 + +ISH的语法与Bash的语法相似,但是有一些不同。 + +## 变量 + + +### 变量定义 +Bash中定义变量是: + +```bash +var="value" +``` + +而在ISH中定义变量是: + +```bash +$var="value" +``` + +### 变量调用 +Bash中调用变量和ISH中调用变量是一样的: + +```bash +echo $var +``` + +### 变量类型 +ISH中的变量类型支持Python中的所有类型,包括`int`、`float`、`str`、`bool`、`list`、`dict`、`tuple`、`set`、`None`。 + +### 变量赋值 +ISH中变量不仅支持赋值,也支持加减乘除等运算。具体如下: + +```bash +$a=1 +$b=$a+1 +$c=$a+$b +``` + +## 流程控制 + +### if语句 +Bash中的if语句是: + +```bash +if [ $a -eq 1 ]; then + echo "a=1" +elif [ $a -eq 2 ]; then + echo "a=2" +else + echo "a!=1 and a!=2" +fi +``` + +Ish沿袭了Bash的语法,但是增加了一些新的语法,如下: + +```cpp +!if ($a==1) +> echo "a=1" +> echo "This is more than one line" +!elseif ($a==2) +> echo "a=2" +!else +> echo "a!=1 and a!=2" +!endif +``` +您会发现,在Ish中,if语句的语法是以`!if`开始,以`!endif`结束,每一行的语句都必须以`>`开始,`!elseif`和`!else`也是以`>`开始。 + +也就是说,在ISH中的流程语句的关键字(条件语句)必须以`!`开头,如`!if`、`!else`、`!elseif`、`!endif`等。 + +### for语句 +Bash中的for语句是: + +```bash +for i in {1..10} +do + echo $i +done +``` + +基于上面提到的规则,Ish中的for语句是: + +```cpp +!for ($i;1,10,1) +> echo $i +!endfor +// 输出1-10 +``` + +我们不难发现,for循环的条件(括号内的内容)是以`;`分隔,分隔后的内容分别是变量名($i)、起始值、结束值、步长。 + +### while语句 +Bash中的while语句是: + +```bash +while [ $a -lt 10 ] +do + echo $a + a=$a+1 +done +``` + +Ish中的while语句是: + +```cpp +!while ($a<10) +> echo $a +> $a=$a+1 +!endwhile +// 输出1-10 +``` + +### 函数 +Bash中的函数是: + +```bash +function func() +{ + echo "This is a function" +} +``` + +Ish中的函数是: + +```cpp +!dec func() +> echo "This is a function" +!enddec +``` + +## 其他 + +### 注释 +Bash中的注释是: + +```bash +# This is a comment +``` + +Ish中的注释是: + +```txt +# This is a comment +或者 +; This is a comment +``` +中间都要有一个空格,且注释占一整行,注释标识符要放在第一位。 From eed2020171cbfd019fda26a1d970e8001dea52eb Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Fri, 14 Apr 2023 23:34:47 +0800 Subject: [PATCH 13/13] =?UTF-8?q?feat:=20=E5=B0=8F=E8=A7=84=E6=A8=A1?= =?UTF-8?q?=E9=87=8D=E5=86=99=E4=BA=86ish=E8=A7=A3=E6=9E=90=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/bash.py | 90 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/models/bash.py b/models/bash.py index 7914471..8e6d107 100644 --- a/models/bash.py +++ b/models/bash.py @@ -1 +1,89 @@ -print("激活了Bash模块!") \ No newline at end of file +# Ish 执行模块 +# 功能:执行一个.sh文件中的所有命令 +# 语法参见:ish语法.md + +import os +import sys +import time +import json +import random +import requests +import threading +import subprocess +from misc.Color import Colors +from misc.Logo import Logo +from misc.Info import ProgramInfo +from misc.Info import SSR_Reader +from misc.Error import Error +from tools.Phraser import PS1 +from tools.Phraser import alias +from tools.SelfCheck import SelfCheck + +ALIAS = alias() + +# 新建一个Class,每个运行的sh程序都是在这个对象里的 + +class Ish: + # 要预留程序定义变量的地方(可以用字典储存) + def __init__(self): + self.variables = {} + self.functions = {} + # 如 {"var1": "value1", "var2": 100} + + def run(self, path): + ... + + # 变量定义 + def var_define(self, var, value): + self.variables[var] = value + + # 变量调用 + def var_call(self, var): + return self.variables[var] + + # 变量赋值 + def var_assign(self, var, value): + self.variables[var] = value + + # 变量加减乘除 + def var_add(self, var, value): + self.variables[var] += value + + def var_sub(self, var, value): + self.variables[var] -= value + + def var_mul(self, var, value): + self.variables[var] *= value + + def var_div(self, var, value): + self.variables[var] /= value + + + # if语句 + def if_statement(self, condition, command): + if condition: + ... + + # for语句 + def for_statement(self, start, end, step, command): + for i in range(start, end, step): + ... + return i + + # while语句 + def while_statement(self, condition, command): + while condition: + ... + + # 函数定义 + def func_define(self, func_name, args, command): + self.functions[func_name] = {"args": args, "command": command} + ... + + # 函数调用 + def func_call(self, func_name, args): + ... + + # 函数删除 + def func_delete(self, func_name): + self.functions.pop(func_name)