Skip to content

Commit 6648dda

Browse files
committed
Add build and homebrew formula
1 parent 74e26e2 commit 6648dda

7 files changed

Lines changed: 98 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/target
2+
*.tar.gz

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
[package]
22
name = "git-b"
3-
version = "0.1.0"
3+
version = "1.0.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
99
skim = "0.9.4"
10+
11+
[profile.release]
12+
lto = true
13+
codegen-units = 1
14+
opt-level = "z"
15+
strip = true

Formula/git_b.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
VERSION = '1.0.0'
3+
X86_64_SHA = '7c84096e7578411f9226e75a96df79c134eca2c8eddd7b452b609263cc6e243e'
4+
AARCH64_SHA = '191748a0e2f0d582d1f7c9c054b2a7a90daeb923ac9806df8e42d692b637adfa'
5+
6+
7+
class GitB < Formula
8+
desc "Git B"
9+
homepage "https://github.com/jharrilim/git-b"
10+
version VERSION
11+
12+
on_macos do
13+
if Hardware::CPU.intel?
14+
url "https://github.com/jharrilim/git-b/releases/download/v#{VERSION}/git-b-v#{VERSION}-x86_64-apple-darwin.tar.gz"
15+
sha256 X86_64_SHA
16+
else
17+
url "https://github.com/jharrilim/git-b/releases/download/v#{VERSION}/git-b-v#{VERSION}-aarch64-apple-darwin.tar.gz"
18+
sha256 AARCH64_SHA
19+
end
20+
end
21+
22+
def install
23+
bin.install "git-b"
24+
end
25+
26+
test do
27+
system bin / "git-b", "--version"
28+
end
29+
end

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
# git b
22

33
Fuzzy selector for git branches
4+
5+
## Install (Mac)
6+
7+
```sh
8+
brew tap jharrilim/git-b/git-b
9+
brew install git-b
10+
```
11+
12+
## Compiling from Mac to Linux
13+
14+
Due to [rust/issues/34282](https://github.com/rust-lang/rust/issues/34282), you'll need to run this
15+
before running the `build` script:
16+
17+
```sh
18+
brew tap SergioBenitez/osxct
19+
brew install x86_64-unknown-linux-gnu
20+
```

build

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
name="git-b"
6+
version="$1"
7+
8+
mac_intel="x86_64-apple-darwin"
9+
mac_silicon="aarch64-apple-darwin"
10+
linux_intel="x86_64-unknown-linux-gnu"
11+
12+
mac_intel_tar="$name-$version-$mac_intel.tar.gz"
13+
mac_silicon_tar="$name-v$version-$mac_silicon.tar.gz"
14+
linux_intel_tar="$name-v$version-$linux_intel.tar.gz"
15+
16+
cargo build --target=$mac_intel --release
17+
cargo build --target=$mac_silicon --release
18+
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc cargo build --target=$linux_intel --release
19+
20+
cd target/$mac_silicon/release
21+
tar -czvf "$mac_silicon_tar" $name
22+
silicon_sha=$(shasum -a 256 "$mac_silicon_tar" | cut -d ' ' -f 1)
23+
mv "$mac_silicon_tar" ../../../"$mac_silicon_tar"
24+
25+
cd ../../$mac_intel/release
26+
tar -czvf "$mac_intel_tar" $name
27+
intel_sha=$(shasum -a 256 "$mac_intel_tar" | cut -d ' ' -f 1)
28+
mv "$mac_intel_tar" ../../../"$mac_intel_tar"
29+
30+
cd ../../$linux_intel/release
31+
tar -czvf "$linux_intel_tar" $name
32+
mv "$linux_intel_tar" ../../../"$linux_intel_tar"
33+
34+
cd ../../../
35+
36+
sed -i '' -e "s|X86_64_SHA\ \=.*|X86_64_SHA = '$intel_sha'|" Formula/git_b.rb
37+
sed -i '' -e "s|AARCH64_SHA\ \=.*|AARCH64_SHA = '$silicon_sha'|" Formula/git_b.rb
38+
sed -i '' -e "s|VERSION\ \=.*|VERSION = '$version'|" Formula/git_b.rb

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ use skim::prelude::*;
22
use std::{io::BufReader, process::Command};
33

44
fn main() {
5+
if std::env::args().any(|arg| arg == "--version") {
6+
println!("git-b {}", env!("CARGO_PKG_VERSION"));
7+
return;
8+
}
9+
510
let branches = branch_names().join("\n");
611
let b = Box::leak(branches.into_boxed_str());
712
let reader = BufReader::new(b.as_bytes());

0 commit comments

Comments
 (0)