aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2023-03-26 00:14:38 -0400
committerJesse Luehrs <doy@tozt.net>2023-03-26 00:14:38 -0400
commit6f19f96053db7475e2376c9dd3179c4dd2264df8 (patch)
treea6c3d3f02f7026b7e98a3e007ff6a37e2a77fd97
parent93e6a9a08aec3cbb8b847a815ad905aa0d0bffca (diff)
downloadfancy-prompt-6f19f96053db7475e2376c9dd3179c4dd2264df8.tar.gz
fancy-prompt-6f19f96053db7475e2376c9dd3179c4dd2264df8.zip
clippy
-rw-r--r--src/args.rs4
-rw-r--r--src/colors.rs13
-rw-r--r--src/power/mod.rs2
-rw-r--r--src/power/sys/linux.rs2
-rw-r--r--src/prompt.rs16
-rw-r--r--src/sys/unix.rs15
-rw-r--r--src/vcs/git.rs2
-rw-r--r--src/vcs/mod.rs2
8 files changed, 17 insertions, 39 deletions
diff --git a/src/args.rs b/src/args.rs
index 5186373..da1ff19 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -1,5 +1,3 @@
-use clap;
-
use crate::colors;
pub struct CommandLineOptions {
@@ -28,7 +26,7 @@ pub fn parse() -> CommandLineOptions {
let shell = matches
.value_of("prompt-escape")
- .map(|shell| colors::ShellType::from_str(shell))
+ .map(colors::ShellType::from_str)
.unwrap_or(colors::ShellType::Unknown);
let error_code = matches
.value_of("error-code")
diff --git a/src/colors.rs b/src/colors.rs
index 084e4f2..a28dfb5 100644
--- a/src/colors.rs
+++ b/src/colors.rs
@@ -1,6 +1,3 @@
-use std;
-use term;
-
#[derive(Debug, Clone)]
pub enum ShellType {
Unknown,
@@ -117,7 +114,7 @@ impl Colors {
&self,
t: &mut dyn term::Terminal<Output = W>,
) {
- write!(t, "{}", "\n").unwrap();
+ writeln!(t).unwrap();
}
pub fn print_host<W: std::io::Write>(
@@ -197,10 +194,10 @@ impl Colors {
{
match self.shell_type {
ShellType::Bash => {
- print!("{}", "\\[");
+ print!("\\[");
}
ShellType::Zsh => {
- print!("{}", "%{");
+ print!("%{{");
}
_ => {}
}
@@ -209,10 +206,10 @@ impl Colors {
match self.shell_type {
ShellType::Bash => {
- print!("{}", "\\]");
+ print!("\\]");
}
ShellType::Zsh => {
- print!("{}", "%}");
+ print!("%}}");
}
_ => {}
}
diff --git a/src/power/mod.rs b/src/power/mod.rs
index fb75499..25a7845 100644
--- a/src/power/mod.rs
+++ b/src/power/mod.rs
@@ -1,5 +1,3 @@
-use std;
-
use std::io::Read;
mod sys;
diff --git a/src/power/sys/linux.rs b/src/power/sys/linux.rs
index 90115a2..aee80d8 100644
--- a/src/power/sys/linux.rs
+++ b/src/power/sys/linux.rs
@@ -1,5 +1,3 @@
-use walkdir;
-
pub fn power_supplies() -> Vec<super::PowerSupplyInfo> {
let mut power_supplies = vec![];
for entry in walkdir::WalkDir::new("/sys/class/power_supply/")
diff --git a/src/prompt.rs b/src/prompt.rs
index a68b01e..1ab60d2 100644
--- a/src/prompt.rs
+++ b/src/prompt.rs
@@ -1,7 +1,3 @@
-use regex;
-use std;
-use term;
-
use std::fmt::Write;
use crate::colors;
@@ -219,11 +215,11 @@ impl Prompt {
}
fn format_vcs(&self) -> Option<String> {
- format_vcs(self.data.vcs_info.as_ref().map(|v| &**v))
+ format_vcs(self.data.vcs_info.as_deref())
}
fn vcs_color(&self) -> String {
- vcs_color(self.data.vcs_info.as_ref().map(|v| &**v))
+ vcs_color(self.data.vcs_info.as_deref())
}
fn print_host<W: std::io::Write>(
@@ -254,9 +250,7 @@ impl Prompt {
fn battery_discharge_color(usage: f64, charging: bool) -> &'static str {
if usage >= 0.8 {
"battery_full"
- } else if charging {
- "default"
- } else if usage >= 0.4 {
+ } else if charging || usage >= 0.4 {
"default"
} else if usage >= 0.15 {
"battery_warn"
@@ -309,7 +303,7 @@ fn format_vcs(vcs_info: Option<&dyn vcs::VcsInfo>) -> Option<String> {
}
})
.unwrap_or_else(|| String::from("???"));
- if branch != "" {
+ if !branch.is_empty() {
write!(vcs, ":").unwrap();
}
write!(vcs, "{}", branch).unwrap();
@@ -417,7 +411,7 @@ fn compress_vcs(vcs: &str, len: usize) -> String {
let branch_len = len - prefix_len - suffix_len;
let branch_re = regex::Regex::new(&format!(
r"(:[^:]{{{}}})[^:]*([^:]{{3}}:?)",
- (branch_len - 6).to_string()
+ (branch_len - 6)
))
.unwrap();
branch_re.replace(vcs, "$1...$2").into_owned()
diff --git a/src/sys/unix.rs b/src/sys/unix.rs
index 2d52627..e014b4c 100644
--- a/src/sys/unix.rs
+++ b/src/sys/unix.rs
@@ -1,6 +1,3 @@
-use std;
-use users;
-
use std::os::unix::fs::MetadataExt;
use std::os::unix::fs::PermissionsExt;
@@ -14,13 +11,11 @@ pub fn path_writable(path: &std::path::Path) -> super::PathWritability {
let file_gid = stat.gid();
let file_mode = stat.permissions().mode();
- if euid == 0 {
- super::PathWritability::Writable
- } else if (file_uid == euid) && (file_mode & 0o200 != 0) {
- super::PathWritability::Writable
- } else if (file_gid == egid) && (file_mode & 0o020 != 0) {
- super::PathWritability::Writable
- } else if file_mode & 0o002 != 0 {
+ if euid == 0
+ || ((file_uid == euid) && (file_mode & 0o200 != 0))
+ || ((file_gid == egid) && (file_mode & 0o020 != 0))
+ || (file_mode & 0o002 != 0)
+ {
super::PathWritability::Writable
} else {
super::PathWritability::NotWritable
diff --git a/src/vcs/git.rs b/src/vcs/git.rs
index 1a5b856..b2fd5b2 100644
--- a/src/vcs/git.rs
+++ b/src/vcs/git.rs
@@ -1,5 +1,3 @@
-use git2;
-
use std::fmt::Write;
#[derive(Debug)]
diff --git a/src/vcs/mod.rs b/src/vcs/mod.rs
index f033d2c..96340cb 100644
--- a/src/vcs/mod.rs
+++ b/src/vcs/mod.rs
@@ -30,7 +30,7 @@ pub trait VcsInfo {
self.has_modified_files()
|| self.has_staged_files()
|| self.has_new_files()
- || !diff.is_some()
+ || diff.is_none()
|| diff
.map(|(local, remote)| local > 0 || remote > 0)
.unwrap_or(false)