Skip to content

Commit e4fd486

Browse files
fix @error2 on 6.2
1 parent 1e92409 commit e4fd486

File tree

18 files changed

+192
-127
lines changed

18 files changed

+192
-127
lines changed

Cargo.lock

Lines changed: 43 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,6 @@
33
欢迎使用 Tiks,一个简易的 Linux 终端命令行工具,类似于常见的 Linux 终端环境,提供了一系列常用的命令和功能。
44
#### 供参考,若有错误改进地方可push到main
55

6-
## 环境变量
7-
8-
如果想将其加入环境变量:
9-
10-
```bash
11-
Cargo build --release
12-
cp | copy ./target/release/tiks $HOME/.Tiks/bin
13-
或者下载 tiks / tiks.exe
14-
添加至.Tiks目录下的bin中
15-
```
16-
17-
- Windows: 执行./window/setup.bat -> setx PATH "%PATH%;%TIKS_DIR%\bin"
18-
- mac & Linux: 执行./mac_linux/setup.sh -> PATH=$PATH:/$HOME/.Tiks/bin
19-
20-
## 添加方法函数
21-
22-
如果想向其中添加其余函数:
23-
24-
- C\C++: [详见添加方法](./command/src/c_build/README.md)
25-
- rust: [详间rust添加方法](./command/src/commands/README.md)
26-
276
## 功能特点
287

298
- 提供常用的 Linux 命令,如 `pwd`, `ls`, `cd`, `rm`, `touch`, `cat`, `python` 等。
@@ -71,6 +50,17 @@ Commands:
7150

7251
[点击此处下载 Rust 工具链](https://www.rust-lang.org/tools/install)
7352

53+
## 添加方法函数
54+
55+
如果想向其中添加其余函数:
56+
57+
- C\C++: [详见添加方法](./command/src/c_build/README.md)
58+
- rust: [详间rust添加方法](./command/src/commands/README.md)
59+
60+
## 环境变量
61+
[点击此查看](./command/src/env/README.md)
62+
63+
7464
## 贡献
7565

7666
如果你希望贡献代码或改进本项目,请先进行以下操作:

command/bin/main.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@
99

1010
use command::env::init_env;
1111
use command::run::init_shell;
12-
use command::start_logo::start_logo;
13-
use command::root::new_session;
12+
use command::start::start_logo::start_logo;
13+
use command::root::SESSION;
1414

1515
fn main() {
1616
start_logo();
17-
18-
// new user
19-
let mut session_context = new_session();
2017

2118
// set os envirment path in Tiks
2219
init_env();
2320

2421
// init shell
25-
init_shell(&mut session_context)
22+
init_shell(&mut *SESSION.lock().unwrap())
2623
}

command/src/commands/apt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn update(version: &str) -> std::io::Result<()>{
7474
let _release_linux = format!("https://github.com/zhangzijie-pro/Tiks/releases/download/{}/tiks",version);
7575
let _release_window = format!("https://github.com/zhangzijie-pro/Tiks/releases/download/{}/tiks.exe",version);
7676

77-
if cfg!(target_os = "linux") | cfg!(target_os="mac"){
77+
if cfg!(target_os = "linux") | cfg!(target_os="macos"){
7878
let app_linux = get_linux_dir();
7979
task::block_on(async {
8080
update_to(&_release_linux, app_linux).await;
@@ -95,7 +95,7 @@ pub fn update(version: &str) -> std::io::Result<()>{
9595
pub async fn update_last() -> Result<(), Box<dyn std::error::Error>>{
9696
let client = Client::new();
9797

98-
if cfg!(target_os = "linux") | cfg!(target_os="mac"){
98+
if cfg!(target_os = "linux") | cfg!(target_os="macos"){
9999
let response = client.get(_GITHUB_RELEASE_LINUX).send().await.expect("Error: update error");
100100
let app = get_linux_dir();
101101
let mut file = File::create(app).expect("Can't create file : tiks");

command/src/commands/arg.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::set::set::get_similar;
22
use crate::root::{decryption, SessionContext};
33
use crate::set::version;
4-
use crate::state_code::{missing_pattern, not_found};
4+
use crate::start::state_code::{missing_pattern, not_found};
55

66
use super::code::*;
77
use super::command::*;
@@ -68,6 +68,13 @@ impl Commands {
6868
arg,
6969
}
7070
}
71+
72+
pub fn from_string<T: Into<String>>(arg: T) -> Commands {
73+
let arg_string = arg.into();
74+
let commands: Vec<&str> = arg_string.split_whitespace().collect();
75+
let commands_string: Vec<String> = commands.iter().map(|x| x.to_string()).collect();
76+
Commands::new(commands_string)
77+
}
7178

7279
}
7380

command/src/commands/code.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::process::Command;
22

3-
use crate::state_code::{run_code, run_code_er};
3+
use crate::start::state_code::{run_code, run_code_er};
44

55
// run code use python ...
66
pub fn python(file: Option<&str>) -> Result<(usize,String), std::io::Error> {

command/src/commands/command.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ use crate::commands::apt::{download_package, find_package};
314314
use crate::priority::get_priority;
315315
use crate::set::set::file_create_time;
316316
use crate::run::run;
317-
use crate::state_code::{empty_dir, empty_file, env, missing_pattern, STATUE_CODE};
317+
use crate::start::state_code::{empty_dir, empty_file, env, missing_pattern, STATUE_CODE};
318318
use super::apt::{update, update_last};
319319
use crate::root::SessionContext;
320320

@@ -538,16 +538,20 @@ pub fn pipe(command:Vec<String>) -> io::Result<(usize,String)>{
538538
}
539539

540540
// &&
541-
pub fn and(command:Vec<String>,session_context: &mut SessionContext){
541+
pub fn and(command:Vec<String>,session_context: &mut SessionContext) -> Vec<String>{
542+
let mut output:Vec<_> = Vec::new();
542543
let commands = command.split(|x| x=="&&");
543544
for c in commands{
544545
let v = c.to_vec();
545-
run(v, session_context)
546+
let r = run(v, session_context);
547+
output.push(r)
546548
}
549+
output
547550
}
548551

549552
// &
550-
pub fn priority_run(command:Vec<String>,session_context: &mut SessionContext){
553+
pub fn priority_run(command:Vec<String>,session_context: &mut SessionContext) -> Vec<String>{
554+
let mut output:Vec<_> = Vec::new();
551555
let commands = command.split(|x| x=="&");
552556
let mut save_command = Vec::new();
553557
for c in commands{
@@ -558,8 +562,10 @@ pub fn priority_run(command:Vec<String>,session_context: &mut SessionContext){
558562
save_command.sort_by_key(|c| -(get_priority(&c[0]).as_number() as i32));
559563

560564
for c in save_command{
561-
run(c, session_context)
565+
let r = run(c, session_context);
566+
output.push(r)
562567
}
568+
output
563569
}
564570

565571
fn get_env(id: String) -> String{

0 commit comments

Comments
 (0)