Add terminal separator
This commit is contained in:
27
Cargo.lock
generated
27
Cargo.lock
generated
@@ -101,6 +101,19 @@ name = "quote"
|
|||||||
version = "0.3.15"
|
version = "0.3.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_syscall"
|
||||||
|
version = "0.1.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_termios"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
@@ -153,6 +166,16 @@ dependencies = [
|
|||||||
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termion"
|
||||||
|
version = "1.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thread_local"
|
name = "thread_local"
|
||||||
version = "0.3.5"
|
version = "0.3.5"
|
||||||
@@ -168,6 +191,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"os_type 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"os_type 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -242,12 +266,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
"checksum os_type 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "081f0539f57611638feee0d72fe98ad0b685e99da117be6b254bd1dfd7421609"
|
"checksum os_type 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "081f0539f57611638feee0d72fe98ad0b685e99da117be6b254bd1dfd7421609"
|
||||||
"checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f"
|
"checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f"
|
||||||
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||||
|
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
|
||||||
|
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
|
||||||
"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384"
|
"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384"
|
||||||
"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7"
|
"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7"
|
||||||
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
|
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
|
||||||
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
|
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
|
||||||
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
||||||
"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd"
|
"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd"
|
||||||
|
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
||||||
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
|
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
|
||||||
"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d"
|
"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d"
|
||||||
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
|
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
|
||||||
|
|||||||
@@ -7,3 +7,4 @@ authors = ["Roey Darwish Dror <roey.ghost@gmail.com>"]
|
|||||||
which = "2.0.0"
|
which = "2.0.0"
|
||||||
error-chain = "0.11.0"
|
error-chain = "0.11.0"
|
||||||
os_type = "2.0.0"
|
os_type = "2.0.0"
|
||||||
|
termion = "1.5.1"
|
||||||
|
|||||||
12
src/main.rs
12
src/main.rs
@@ -2,6 +2,7 @@ extern crate os_type;
|
|||||||
extern crate which;
|
extern crate which;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate error_chain;
|
extern crate error_chain;
|
||||||
|
extern crate termion;
|
||||||
|
|
||||||
mod error {
|
mod error {
|
||||||
error_chain!{
|
error_chain!{
|
||||||
@@ -13,6 +14,7 @@ mod error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod git;
|
mod git;
|
||||||
|
mod terminal;
|
||||||
|
|
||||||
use error::*;
|
use error::*;
|
||||||
use git::Git;
|
use git::Git;
|
||||||
@@ -21,6 +23,7 @@ use std::collections::HashSet;
|
|||||||
use std::env::home_dir;
|
use std::env::home_dir;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Command, ExitStatus};
|
use std::process::{Command, ExitStatus};
|
||||||
|
use terminal::Terminal;
|
||||||
use which::which;
|
use which::which;
|
||||||
|
|
||||||
trait Chain
|
trait Chain
|
||||||
@@ -65,6 +68,7 @@ fn tpm() -> Option<PathBuf> {
|
|||||||
fn run() -> Result<()> {
|
fn run() -> Result<()> {
|
||||||
let git = Git::new();
|
let git = Git::new();
|
||||||
let mut git_repos: HashSet<String> = HashSet::new();
|
let mut git_repos: HashSet<String> = HashSet::new();
|
||||||
|
let terminal = Terminal::new();
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut collect_repo = |path| {
|
let mut collect_repo = |path| {
|
||||||
@@ -83,12 +87,13 @@ fn run() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for repo in git_repos {
|
for repo in git_repos {
|
||||||
terminal.print_seperator(format!("Pulling {}", repo));
|
terminal.print_separator(format!("Pulling {}", repo));
|
||||||
git.pull(repo)?;
|
git.pull(repo)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg!(unix) {
|
if cfg!(unix) {
|
||||||
if let Ok(zsh) = which("zsh") {
|
if let Ok(zsh) = which("zsh") {
|
||||||
|
terminal.print_separator("zplug");
|
||||||
if home_path(".zplug").exists() {
|
if home_path(".zplug").exists() {
|
||||||
Command::new(&zsh)
|
Command::new(&zsh)
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
@@ -99,6 +104,7 @@ fn run() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(tpm) = tpm() {
|
if let Some(tpm) = tpm() {
|
||||||
|
terminal.print_separator("tmux plugins");
|
||||||
Command::new(&tpm).arg("all").spawn()?.wait()?;
|
Command::new(&tpm).arg("all").spawn()?.wait()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,6 +114,7 @@ fn run() -> Result<()> {
|
|||||||
|
|
||||||
match os_type::current_platform().os_type {
|
match os_type::current_platform().os_type {
|
||||||
OSType::Arch => {
|
OSType::Arch => {
|
||||||
|
terminal.print_separator("System update");
|
||||||
if let Ok(yay) = which("yay") {
|
if let Ok(yay) = which("yay") {
|
||||||
Command::new(yay).spawn()?.wait()?;
|
Command::new(yay).spawn()?.wait()?;
|
||||||
} else {
|
} else {
|
||||||
@@ -125,6 +132,7 @@ fn run() -> Result<()> {
|
|||||||
|
|
||||||
if let Ok(sudo) = &sudo {
|
if let Ok(sudo) = &sudo {
|
||||||
if let Ok(needrestart) = which("needrestart") {
|
if let Ok(needrestart) = which("needrestart") {
|
||||||
|
terminal.print_separator("Check for needed restarts");
|
||||||
Command::new(&sudo).arg(&needrestart).spawn()?.wait()?;
|
Command::new(&sudo).arg(&needrestart).spawn()?.wait()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,6 +140,7 @@ fn run() -> Result<()> {
|
|||||||
|
|
||||||
if cfg!(target_os = "macos") {
|
if cfg!(target_os = "macos") {
|
||||||
if let Ok(brew) = which("brew") {
|
if let Ok(brew) = which("brew") {
|
||||||
|
terminal.print_separator("Homebrew");
|
||||||
Command::new(&brew)
|
Command::new(&brew)
|
||||||
.arg("update")
|
.arg("update")
|
||||||
.spawn()?
|
.spawn()?
|
||||||
@@ -146,6 +155,7 @@ fn run() -> Result<()> {
|
|||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
terminal.print_separator("System update");
|
||||||
Command::new("softwareupdate")
|
Command::new("softwareupdate")
|
||||||
.arg("--install")
|
.arg("--install")
|
||||||
.arg("--all")
|
.arg("--all")
|
||||||
|
|||||||
29
src/terminal.rs
Normal file
29
src/terminal.rs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
use std::cmp::{max, min};
|
||||||
|
use termion;
|
||||||
|
use termion::color;
|
||||||
|
|
||||||
|
pub struct Terminal {
|
||||||
|
width: Option<u16>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Terminal {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
width: termion::terminal_size().map(|(w, _)| w).ok(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_separator<P: AsRef<str>>(&self, message: P) {
|
||||||
|
let message = message.as_ref();
|
||||||
|
if let Some(width) = self.width {
|
||||||
|
print!("\n{}―― {} ", color::Fg(color::LightWhite), message);
|
||||||
|
let border = max(2, min(80, width as usize) - 3 - message.len());
|
||||||
|
for _ in 0..border {
|
||||||
|
print!("―");
|
||||||
|
}
|
||||||
|
println!("{}", color::Fg(color::Reset));
|
||||||
|
} else {
|
||||||
|
println!("―― {} ――", message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user