Skip to content

Commit

Permalink
make source can load env without export; fix path completion
Browse files Browse the repository at this point in the history
  • Loading branch information
mitnk committed Mar 22, 2019
1 parent 3165323 commit e96effa
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Change Logs

## 0.9.3 - master
## 0.9.3

- Made brace expansion behavior align with bash.
- Fixed an issue of path completion in middle of input.
- Implemented builtin command `source`
- Two more issues fixes on path completion.
- Partly implemented builtin command `source`.

## 0.9.2

Expand Down
6 changes: 2 additions & 4 deletions src/builtins/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ use crate::tools;
use crate::types::Tokens;

pub fn run(_sh: &shell::Shell, tokens: &Tokens) -> i32 {
let mut i = 0;
for (_, text) in tokens.iter() {
if i == 0 {
i += 1;
if text == "export" {
continue;
}

if !tools::is_env(text) {
println!("export: invalid command");
println!("usage: export XXX=YYY");
Expand All @@ -38,7 +37,6 @@ pub fn run(_sh: &shell::Shell, tokens: &Tokens) -> i32 {
println_stderr!("cicada: re new error");
return 2;
}
i += 1;
}
0
}
3 changes: 2 additions & 1 deletion src/builtins/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ pub fn run(sh: &mut shell::Shell, tokens: &Tokens) -> i32 {
println_stderr!("cicada: source: no file specified");
return 1;
}
if !args[1].ends_with("cicadarc") {
if !args[1].ends_with("rc") {
println_stderr!("cicada: source command only supports cicadarc files");
println_stderr!("cicada: try rename the target file to end with 'rc'");
println_stderr!("scripting in cicada is still a work in progress");
return 1;
}
Expand Down
7 changes: 3 additions & 4 deletions src/completers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ pub fn escaped_word_start(line: &str) -> usize {
if bytes_c > 1 {
extra_bytes += bytes_c - 1;
}
if found_space {
found_space = false;
start_position = i + extra_bytes;
}
found_bs = false;
}
if found_space {
start_position = line.len();
Expand Down Expand Up @@ -182,6 +179,8 @@ mod tests {
assert_eq!(escaped_word_start("ls a\\ b"), 3);
assert_eq!(escaped_word_start("ls a\\ b\\ c"), 3);
assert_eq!(escaped_word_start(" ls a\\ b\\ c"), 7);
assert_eq!(escaped_word_start("mv foo\\ bar abc"), 12);
assert_eq!(escaped_word_start("mv føo\\ bar abc"), 13);

assert_eq!(escaped_word_start("ls a\\'"), 3);
assert_eq!(escaped_word_start("ls a\\'b"), 3);
Expand Down
3 changes: 2 additions & 1 deletion src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ pub fn unquote(s: &str) -> String {
}

pub fn is_export_env(line: &str) -> bool {
re_contains(line, r"^ *export +[a-zA-Z0-9_]+=.*$")
re_contains(line, r"^ *export +[a-zA-Z0-9_]+=.*$") ||
re_contains(line, r"^ *[a-zA-Z0-9_]+=.*$")
}

pub fn is_env(line: &str) -> bool {
Expand Down

0 comments on commit e96effa

Please sign in to comment.