diff --git a/CHANGELOG.md b/CHANGELOG.md index fa16f99..2236dea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/Cargo.toml b/Cargo.toml index 2013747..966c979 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ edition = "2018" build = "src/build.rs" name = "cicada" -version = "0.9.11" +version = "0.9.12" authors = ["Hugo Wang "] description = "A simple Bash-like Unix shell." diff --git a/docs/envs.md b/docs/envs.md index 2014892..0de2894 100644 --- a/docs/envs.md +++ b/docs/envs.md @@ -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 -``` diff --git a/docs/install.md b/docs/install.md index ccff8f9..8e3a6fb 100644 --- a/docs/install.md +++ b/docs/install.md @@ -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). @@ -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`: @@ -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. @@ -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. diff --git a/docs/rc-file.md b/docs/rc-file.md index 773f6bd..256a3bb 100644 --- a/docs/rc-file.md +++ b/docs/rc-file.md @@ -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" @@ -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 diff --git a/src/builtins/history.rs b/src/builtins/history.rs index 269b6c0..d150c3b 100644 --- a/src/builtins/history.rs +++ b/src/builtins/history.rs @@ -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); } diff --git a/src/calculator/mod.rs b/src/calculator/mod.rs index cb69580..b46ef5c 100644 --- a/src/calculator/mod.rs +++ b/src/calculator/mod.rs @@ -31,7 +31,13 @@ pub fn eval_int(expression: Pairs) -> 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!(), }, diff --git a/src/execute.rs b/src/execute.rs index 5cb65ef..f18c23e 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -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; } @@ -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; }