-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from lanbinshijie/dev
Alpha 1.3.0开发
- Loading branch information
Showing
13 changed files
with
471 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` | ||
中间都要有一个空格,且注释占一整行,注释标识符要放在第一位。 |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
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) | ||
|
||
# 获取参数 | ||
# 如果没有任何参数则输出所有别名 | ||
# 参数有三种: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() | ||
|
||
|
Oops, something went wrong.