Skip to content

Commit

Permalink
fix misc arithmetic issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mitnk committed May 30, 2020
1 parent 0074d61 commit 8ebbf37
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 37 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Logs

## 0.9.12 - 2020-05-30

- show full datetime in output of `history -d`.
- Fixed divide by zero panic in arithmetic (e.g. `2 / 0`).
- Arithmetic commands change `previous status` too.

## 0.9.11 - 2020-04-26

- Upgraded some deps.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
edition = "2018"
build = "src/build.rs"
name = "cicada"
version = "0.9.11"
version = "0.9.12"
authors = ["Hugo Wang <w@mitnk.com>"]

description = "A simple Bash-like Unix shell."
Expand Down
11 changes: 0 additions & 11 deletions docs/envs.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,3 @@ default: `cicada_history`
Do not exit cicada on `Ctrl-D`, if this env is set to `1`.

default: `0`

## Other Built-in Variables

```
$ ls file-not-exist
$ echo $? # <-- print exit status of previous command
1
$ echo $$ # <-- print PID of current process (cicada)
2173
```
43 changes: 21 additions & 22 deletions docs/install.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## Install Cicada
# Install Cicada

There are a few ways to install cicada into your system.

### 1) Install via Pre-built Binaries
## 1) Install via Pre-built Binaries

First download the latest right binary for your system from
[Release Page](https://github.com/mitnk/cicada/releases).
Expand All @@ -23,9 +23,25 @@ $ cicada
(in-cicada) $ cinfo
```

You may want to [set cicada as the default shell](https://github.com/mitnk/cicada/blob/master/docs/install.md#user-content-set-cicada-as-your-login-shell).
### Set cicada as your login shell

**WARNING**: Please test cicada on your system before set it as default shell.

In file `/etc/shells`, append the following line:

```
/usr/local/bin/cicada
```

Then run

```
$ chsh -s /usr/local/bin/cicada
```

Next time you open a terminal window, cicada shell will be the default one.

### 2) Install via cargo crates
## 2) Install via cargo crates

If you already have [Rust environment](https://rustup.rs/), you can install
cicada with `cargo`:
Expand All @@ -41,7 +57,7 @@ $ mv ~/.cargo/bin/cicada /usr/local/bin/
$ cicada
```

### 3) Install via Source
## 3) Install via Source

Note: [Rust environment](https://rustup.rs/) (Rust stable or above) is required.

Expand All @@ -55,20 +71,3 @@ $ make install
$ cicada
```

### Set cicada as your login shell

**WARNING**: Please test cicada on your system before set it as default shell.

In file `/etc/shells`, append the following line:

```
/usr/local/bin/cicada
```

Then run

```
$ chsh -s /usr/local/bin/cicada
```

Next time you open a terminal window, cicada shell will be the default one.
10 changes: 9 additions & 1 deletion docs/rc-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ first existing file of below list:
Here is a sample RC file:

```
# handle envs
# customize my prompt on Mac
export PROMPT="${GITBR}${COLOR_STATUS} $CWD${RESET}$ "
# handle some envs
export RUST_BACKTRACE='full'
export COPYFILE_DISABLE=1
export PATH="/usr/local/bin:$PATH"
Expand All @@ -26,6 +29,11 @@ alias ls="ls -G"
alias ll="ls -lh"
alias foo='echo foo bar | wc'
# define functions
function foo-bar() {
echo foobar
}
# run regular commands
echo "cicada started at `date`" >> /tmp/some-random.log
touch /tmp/cicada-started
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn list_current_history(sh: &shell::Shell, conn: &Conn, opt: &OptMain) -> i32 {
}
};
let dt = NaiveDateTime::from_timestamp(tsb as i64, 0);
println!("{}: {}: {}", row_id, dt.date(), inp);
println!("{}: {}: {}", row_id, dt.format("%Y-%m-%d %H:%M:%S"), inp);
} else {
println!("{}: {}", row_id, inp);
}
Expand Down
8 changes: 7 additions & 1 deletion src/calculator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ pub fn eval_int(expression: Pairs<Rule>) -> i64 {
Rule::add => lhs + rhs,
Rule::subtract => lhs - rhs,
Rule::multiply => lhs * rhs,
Rule::divide => lhs / rhs,
Rule::divide => {
if rhs == 0 {
(lhs as f64 / 0.0) as i64
} else {
lhs / rhs
}
}
Rule::power => lhs.pow(rhs as u32),
_ => unreachable!(),
},
Expand Down
2 changes: 2 additions & 0 deletions src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn run_procs(sh: &mut shell::Shell,
} else {
println!("{}", result);
}
sh.previous_status = cr.status;
cr_list.push(cr);
return cr_list;
}
Expand All @@ -53,6 +54,7 @@ pub fn run_procs(sh: &mut shell::Shell,
} else {
println_stderr!("cicada: calculator: {}", e);
}
sh.previous_status = cr.status;
cr_list.push(cr);
return cr_list;
}
Expand Down

0 comments on commit 8ebbf37

Please sign in to comment.