@@ -10,10 +10,9 @@ pub mod jobtable;
10
10
pub mod options;
11
11
12
12
use crate :: { error, proc_ctrl, signal} ;
13
- use crate :: error:: exec:: ExecError ;
14
13
use self :: database:: DataBase ;
15
14
use self :: options:: Options ;
16
- use self :: completion:: CompletionInfo ;
15
+ use self :: completion:: { Completion , CompletionEntry } ;
17
16
use std:: collections:: HashMap ;
18
17
use std:: os:: fd:: { FromRawFd , OwnedFd } ;
19
18
use std:: { io, env, path} ;
@@ -51,7 +50,6 @@ pub struct ShellCore {
51
50
pub builtins : HashMap < String , fn ( & mut ShellCore , & mut Vec < String > ) -> i32 > ,
52
51
pub sigint : Arc < AtomicBool > ,
53
52
pub trapped : Vec < ( Arc < AtomicBool > , String ) > ,
54
- pub read_stdin : bool ,
55
53
pub is_subshell : bool ,
56
54
pub source_function_level : i32 ,
57
55
pub source_files : Vec < String > ,
@@ -65,10 +63,7 @@ pub struct ShellCore {
65
63
pub job_table : Vec < JobEntry > ,
66
64
pub job_table_priority : Vec < usize > ,
67
65
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 ,
72
67
pub measured_time : MeasuredTime ,
73
68
pub options : Options ,
74
69
pub shopts : Options ,
@@ -83,7 +78,7 @@ impl ShellCore {
83
78
let mut core = ShellCore {
84
79
db : DataBase :: new ( ) ,
85
80
sigint : Arc :: new ( AtomicBool :: new ( false ) ) ,
86
- read_stdin : true ,
81
+ // read_stdin: true,
87
82
options : Options :: new_as_basic_opts ( ) ,
88
83
shopts : Options :: new_as_shopts ( ) ,
89
84
script_name : "-" . to_string ( ) ,
@@ -99,8 +94,8 @@ impl ShellCore {
99
94
let _ = core. db . set_param ( "PS4" , "+ " , None ) ;
100
95
101
96
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;
104
99
let _ = core. db . set_param ( "PS1" , "🍣 " , None ) ;
105
100
let _ = core. db . set_param ( "PS2" , "> " , None ) ;
106
101
let fd = fcntl:: fcntl ( 0 , fcntl:: F_DUPFD_CLOEXEC ( 255 ) )
@@ -148,20 +143,20 @@ impl ShellCore {
148
143
self . db . exit_status = if self . db . exit_status == 0 { 1 } else { 0 } ;
149
144
}
150
145
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 {
153
147
if args. is_empty ( ) {
154
- return Err ( ExecError :: Bug ( "ShellCore::run_builtin" . to_string ( ) ) ) ;
148
+ eprintln ! ( "ShellCore::run_builtin" ) ;
149
+ return false ;
155
150
}
156
151
157
152
if self . builtins . contains_key ( & args[ 0 ] ) {
158
153
let func = self . builtins [ & args[ 0 ] ] ;
159
154
args. append ( special_args) ;
160
155
self . db . exit_status = func ( self , args) ;
161
- return Ok ( true ) ;
156
+ return true ;
162
157
}
163
158
164
- Ok ( false )
159
+ false
165
160
}
166
161
167
162
fn set_subshell_parameters ( & mut self ) -> Result < ( ) , String > {
@@ -233,12 +228,15 @@ impl ShellCore {
233
228
}
234
229
235
230
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
+ }
238
235
}
239
236
240
237
let mut ans = false ;
241
238
let mut prev_head = "" . to_string ( ) ;
239
+ let history = vec ! [ word. clone( ) ] ;
242
240
243
241
loop {
244
242
let head = match word. replace ( "\n " , " " ) . split ( ' ' ) . nth ( 0 ) {
@@ -252,6 +250,9 @@ impl ShellCore {
252
250
253
251
if let Some ( value) = self . aliases . get ( & head) {
254
252
* word = word. replacen ( & head, value, 1 ) ;
253
+ if history. contains ( word) {
254
+ return false ;
255
+ }
255
256
ans = true ;
256
257
}
257
258
prev_head = head;
0 commit comments