|
1 |
| -use powershell_script::PsScriptBuilder; |
| 1 | +use opener; |
2 | 2 | use rand::seq::SliceRandom;
|
3 | 3 | use std::collections::HashMap;
|
4 | 4 | use std::env;
|
5 |
| -use opener; |
6 |
| -use std::fs::File; |
| 5 | +use std::fs::{self, File}; |
7 | 6 | use std::io::{self, Error, Read, Write};
|
8 | 7 | use std::thread;
|
9 | 8 | use std::thread::sleep;
|
@@ -870,32 +869,34 @@ impl Executor {
|
870 | 869 | let _result = opener::open(self.pop_stack().get_string());
|
871 | 870 | }
|
872 | 871 |
|
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))); |
895 | 884 | }
|
896 | 885 | }
|
897 | 886 | }
|
898 | 887 |
|
| 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 | + |
899 | 900 | // コマンドとして認識されない場合は文字列とする
|
900 | 901 | _ => self.stack.push(Type::String(command)),
|
901 | 902 | }
|
|
0 commit comments