Skip to content

Commit 1ab3c14

Browse files
author
梶塚太智
committed
become direction access file-system replace command shell
1 parent d97ab39 commit 1ab3c14

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ edition = "2021"
77

88
[dependencies]
99
opener = "0.6.1"
10-
powershell_script = "1.1.0"
1110
rand = "0.8"
1211
reqwest = { version = "0.11.0", features = ["blocking"] }

src/main.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use powershell_script::PsScriptBuilder;
1+
use opener;
22
use rand::seq::SliceRandom;
33
use std::collections::HashMap;
44
use std::env;
5-
use opener;
6-
use std::fs::File;
5+
use std::fs::{self, File};
76
use std::io::{self, Error, Read, Write};
87
use std::thread;
98
use std::thread::sleep;
@@ -870,32 +869,34 @@ impl Executor {
870869
let _result = opener::open(self.pop_stack().get_string());
871870
}
872871

873-
// シェルコマンドを実行
874-
"shell" => {
875-
let ps = PsScriptBuilder::new()
876-
.no_profile(true)
877-
.non_interactive(true)
878-
.hidden(false)
879-
.print_commands(false)
880-
.build();
881-
let _ = ps.run(
882-
"[Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding('utf-8')",
883-
);
884-
let result = ps.run(self.pop_stack().get_string().as_str());
885-
match result {
886-
Ok(i) => self.stack.push(Type::String(
887-
i.stdout()
888-
.unwrap_or("".to_string())
889-
.as_str()
890-
.trim()
891-
.to_string(),
892-
)),
893-
Err(_) => {
894-
self.log_print("エラー! シェルスクリプトの実行に失敗しました\n".to_string())
872+
//カレントディレクトリを変更
873+
"cd" => {
874+
if let Err(err) = std::env::set_current_dir(self.pop_stack().get_string()) {
875+
self.log_print(format!("エラー! {}", err));
876+
}
877+
}
878+
879+
// カレントディレクトリを表示
880+
"pwd" => {
881+
if let Ok(current_dir) = std::env::current_dir() {
882+
if let Some(path) = current_dir.to_str() {
883+
self.stack.push(Type::String(String::from(path)));
895884
}
896885
}
897886
}
898887

888+
// ファイル一覧のリスト
889+
"ls" => {
890+
if let Ok(entries) = fs::read_dir(".") {
891+
let value: Vec<Type> = entries
892+
.filter_map(|entry| {
893+
entry.ok().and_then(|e| e.file_name().into_string().ok()).map(|x| Type::String(x))
894+
})
895+
.collect();
896+
self.stack.push(Type::List(value));
897+
}
898+
}
899+
899900
// コマンドとして認識されない場合は文字列とする
900901
_ => self.stack.push(Type::String(command)),
901902
}

0 commit comments

Comments
 (0)