@@ -10,10 +10,9 @@ pub mod jobtable;
1010pub mod options;
1111
1212use crate :: { error, proc_ctrl, signal} ;
13- use crate :: error:: exec:: ExecError ;
1413use self :: database:: DataBase ;
1514use self :: options:: Options ;
16- use self :: completion:: CompletionInfo ;
15+ use self :: completion:: { Completion , CompletionEntry } ;
1716use std:: collections:: HashMap ;
1817use std:: os:: fd:: { FromRawFd , OwnedFd } ;
1918use std:: { io, env, path} ;
@@ -51,7 +50,6 @@ pub struct ShellCore {
5150 pub builtins : HashMap < String , fn ( & mut ShellCore , & mut Vec < String > ) -> i32 > ,
5251 pub sigint : Arc < AtomicBool > ,
5352 pub trapped : Vec < ( Arc < AtomicBool > , String ) > ,
54- pub read_stdin : bool ,
5553 pub is_subshell : bool ,
5654 pub source_function_level : i32 ,
5755 pub source_files : Vec < String > ,
@@ -65,10 +63,7 @@ pub struct ShellCore {
6563 pub job_table : Vec < JobEntry > ,
6664 pub job_table_priority : Vec < usize > ,
6765 current_dir : Option < path:: PathBuf > , // the_current_working_directory
68- pub completion_info : HashMap < String , CompletionInfo > ,
69- pub current_completion_info : CompletionInfo ,
70- pub completion_functions : HashMap < String , String > ,
71- pub default_completion_functions : String ,
66+ pub completion : Completion ,
7267 pub measured_time : MeasuredTime ,
7368 pub options : Options ,
7469 pub shopts : Options ,
@@ -83,7 +78,7 @@ impl ShellCore {
8378 let mut core = ShellCore {
8479 db : DataBase :: new ( ) ,
8580 sigint : Arc :: new ( AtomicBool :: new ( false ) ) ,
86- read_stdin : true ,
81+ // read_stdin: true,
8782 options : Options :: new_as_basic_opts ( ) ,
8883 shopts : Options :: new_as_shopts ( ) ,
8984 script_name : "-" . to_string ( ) ,
@@ -99,8 +94,8 @@ impl ShellCore {
9994 let _ = core. db . set_param ( "PS4" , "+ " , None ) ;
10095
10196 if unistd:: isatty ( 0 ) == Ok ( true ) {
102- core. db . flags += "im " ;
103- core. read_stdin = false ;
97+ core. db . flags += "imH " ;
98+ // core.read_stdin = false;
10499 let _ = core. db . set_param ( "PS1" , "🍣 " , None ) ;
105100 let _ = core. db . set_param ( "PS2" , "> " , None ) ;
106101 let fd = fcntl:: fcntl ( 0 , fcntl:: F_DUPFD_CLOEXEC ( 255 ) )
@@ -148,20 +143,20 @@ impl ShellCore {
148143 self . db . exit_status = if self . db . exit_status == 0 { 1 } else { 0 } ;
149144 }
150145
151- pub fn run_builtin ( & mut self , args : & mut Vec < String > , special_args : & mut Vec < String > )
152- -> Result < bool , ExecError > {
146+ pub fn run_builtin ( & mut self , args : & mut Vec < String > , special_args : & mut Vec < String > ) -> bool {
153147 if args. is_empty ( ) {
154- return Err ( ExecError :: Bug ( "ShellCore::run_builtin" . to_string ( ) ) ) ;
148+ eprintln ! ( "ShellCore::run_builtin" ) ;
149+ return false ;
155150 }
156151
157152 if self . builtins . contains_key ( & args[ 0 ] ) {
158153 let func = self . builtins [ & args[ 0 ] ] ;
159154 args. append ( special_args) ;
160155 self . db . exit_status = func ( self , args) ;
161- return Ok ( true ) ;
156+ return true ;
162157 }
163158
164- Ok ( false )
159+ false
165160 }
166161
167162 fn set_subshell_parameters ( & mut self ) -> Result < ( ) , String > {
@@ -233,12 +228,15 @@ impl ShellCore {
233228 }
234229
235230 fn replace_alias_core ( & self , word : & mut String ) -> bool {
236- if ! self . db . flags . contains ( 'i' ) {
237- return false ;
231+ if ! self . shopts . query ( "expand_aliases" ) {
232+ if ! self . db . flags . contains ( 'i' ) {
233+ return false ;
234+ }
238235 }
239236
240237 let mut ans = false ;
241238 let mut prev_head = "" . to_string ( ) ;
239+ let history = vec ! [ word. clone( ) ] ;
242240
243241 loop {
244242 let head = match word. replace ( "\n " , " " ) . split ( ' ' ) . nth ( 0 ) {
@@ -252,6 +250,9 @@ impl ShellCore {
252250
253251 if let Some ( value) = self . aliases . get ( & head) {
254252 * word = word. replacen ( & head, value, 1 ) ;
253+ if history. contains ( word) {
254+ return false ;
255+ }
255256 ans = true ;
256257 }
257258 prev_head = head;
0 commit comments