summaryrefslogtreecommitdiffstats
path: root/src/modules/battery.rs
diff options
context:
space:
mode:
authorTsubasaKawajiri <39114857+TsubasaKawajiri@users.noreply.github.com>2019-08-26 10:52:44 +0900
committerMatan Kushner <hello@matchai.me>2019-08-25 21:52:44 -0400
commit08aef016cdb1dbf53fc50b6e31ab0add2f40856b (patch)
tree24d6a0de4a720c0da922e496912cf3537dcd622a /src/modules/battery.rs
parentfeb737190eccc9f9b3e8f27dd3c3de8ad201cecd (diff)
fix: battery percentage character on Zsh. #226 (#237)
on Zsh, battery percentage character would print % this PR fixes print %{ -> %
Diffstat (limited to 'src/modules/battery.rs')
-rw-r--r--src/modules/battery.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/modules/battery.rs b/src/modules/battery.rs
index 78ea1813d..800fb6d23 100644
--- a/src/modules/battery.rs
+++ b/src/modules/battery.rs
@@ -8,6 +8,13 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
const BATTERY_CHARGING: &str = "⇡";
const BATTERY_DISCHARGING: &str = "⇣";
const BATTERY_THRESHOLD: f32 = 10.0;
+ // TODO: Update when v1.0 printing refactor is implemented to only
+ // print escapes in a prompt context.
+ let shell = std::env::var("STARSHIP_SHELL").unwrap_or_default();
+ let percentage_char = match shell.as_str() {
+ "zsh" => "%%", // % is an escape in zsh, see PROMPT in `man zshmisc`
+ _ => "%",
+ };
let battery_status = get_battery_status()?;
let BatteryStatus { state, percentage } = battery_status;
@@ -42,7 +49,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut percent_string = Vec::<String>::with_capacity(2);
// Round the percentage to a whole number
percent_string.push(percentage.round().to_string());
- percent_string.push("%".to_string());
+ percent_string.push(percentage_char.to_string());
module.new_segment("percentage", percent_string.join("").as_ref());
Some(module)