Skip to content

Commit

Permalink
Change styling
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquan committed Jun 8, 2023
1 parent fa84b9d commit d3603a8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 42 deletions.
72 changes: 35 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "git-del-branches"
version = "0.1.0"
version = "0.2.0"
authors = ["Nguyễn Hồng Quân <ng.hong.quan@gmail.com>"]
license = "GPL-3.0-or-later"
edition = "2021"
Expand Down
19 changes: 15 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use eyre::Context;
use git2::{Branch, BranchType, Repository, Remote, RemoteCallbacks, PushOptions};
use inquire::error::InquireError;
use inquire::{Confirm, MultiSelect};
use inquire::ui::{RenderConfig, Styled};
use git2_credentials::CredentialHandler;

const EXCLUDES: &[&str] = &["master", "main", "develop", "development"];
Expand Down Expand Up @@ -56,17 +57,27 @@ fn delete_upstream_branch(mut branch: Branch, origin: &mut Remote, opts: &mut Pu
branch.delete().ok()
}

fn get_render_config() -> RenderConfig {
let mut config = RenderConfig::default();
config.scroll_down_prefix = Styled::new("▼");
config.scroll_up_prefix = Styled::new("▲");
config
}

fn main() -> Result<()> {
color_eyre::install()?;
Cli::parse();
inquire::set_global_render_config(get_render_config());
let repo = Repository::discover(".").wrap_err("Not a Git working folder")?;
let branches = repo.branches(Some(BranchType::Local))?;
let staying_in_branch = repo.head().ok().map(|r| r.is_branch()).unwrap_or(false);
let names: Vec<String> = branches
.filter_map(|b| {
let branch = b.ok().map(|x| x.0)?;
let names: Vec<String> = branches.flat_map(|b| b)
.filter_map(|(branch, _type)| {
if branch.is_head() {
return None;
}
let n = branch.name().ok()??;
if branch.is_head() || EXCLUDES.contains(&n) {
if EXCLUDES.contains(&n) {
None
} else {
Some(n.to_string())
Expand Down

0 comments on commit d3603a8

Please sign in to comment.