Compare commits
No commits in common. "main" and "v0.2.4" have entirely different histories.
13
CHANGELOG.md
13
CHANGELOG.md
@ -6,19 +6,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
## [0.4.0] - 2024-12-22
|
|
||||||
|
|
||||||
### Added
|
|
||||||
- make init zsh
|
|
||||||
|
|
||||||
### Other
|
|
||||||
- make variant for the other shell commands
|
|
||||||
|
|
||||||
## [0.3.0] - 2024-12-22
|
|
||||||
|
|
||||||
### Added
|
|
||||||
- make cli look nice
|
|
||||||
|
|
||||||
## [0.2.4] - 2024-12-22
|
## [0.2.4] - 2024-12-22
|
||||||
|
|
||||||
### Other
|
### Other
|
||||||
|
102
Cargo.lock
generated
102
Cargo.lock
generated
@ -60,12 +60,6 @@ dependencies = [
|
|||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitflags"
|
|
||||||
version = "2.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
@ -74,18 +68,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.27"
|
version = "4.5.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796"
|
checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_builder"
|
name = "clap_builder"
|
||||||
version = "4.5.27"
|
version = "4.5.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7"
|
checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
@ -129,27 +123,6 @@ dependencies = [
|
|||||||
"powerfmt",
|
"powerfmt",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dirs"
|
|
||||||
version = "6.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
|
|
||||||
dependencies = [
|
|
||||||
"dirs-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dirs-sys"
|
|
||||||
version = "0.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"option-ext",
|
|
||||||
"redox_users",
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "encode_unicode"
|
name = "encode_unicode"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
@ -166,17 +139,6 @@ dependencies = [
|
|||||||
"once_cell",
|
"once_cell",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "getrandom"
|
|
||||||
version = "0.2.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"libc",
|
|
||||||
"wasi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indenter"
|
name = "indenter"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
@ -197,11 +159,10 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kignore"
|
name = "kignore"
|
||||||
version = "0.4.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"console",
|
"console",
|
||||||
"dirs",
|
|
||||||
"eyre",
|
"eyre",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
@ -219,16 +180,6 @@ version = "0.2.169"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libredox"
|
|
||||||
version = "0.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.22"
|
version = "0.4.22"
|
||||||
@ -281,12 +232,6 @@ version = "1.20.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "option-ext"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "overload"
|
name = "overload"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@ -323,17 +268,6 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "redox_users"
|
|
||||||
version = "0.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b"
|
|
||||||
dependencies = [
|
|
||||||
"getrandom",
|
|
||||||
"libredox",
|
|
||||||
"thiserror",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.11.1"
|
version = "1.11.1"
|
||||||
@ -430,26 +364,6 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "thiserror"
|
|
||||||
version = "2.0.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc"
|
|
||||||
dependencies = [
|
|
||||||
"thiserror-impl",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "thiserror-impl"
|
|
||||||
version = "2.0.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thread_local"
|
name = "thread_local"
|
||||||
version = "1.1.8"
|
version = "1.1.8"
|
||||||
@ -586,12 +500,6 @@ version = "0.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasi"
|
|
||||||
version = "0.11.0+wasi-snapshot-preview1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
11
Cargo.toml
11
Cargo.toml
@ -3,13 +3,4 @@ members = ["crates/*"]
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.4.0"
|
version = "0.2.4"
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
opt-level = "z"
|
|
||||||
lto = true
|
|
||||||
codegen-units = 1
|
|
||||||
debug = false
|
|
||||||
panic = "abort"
|
|
||||||
overflow-checks = false
|
|
||||||
strip = true
|
|
||||||
|
24
README.md
24
README.md
@ -27,22 +27,24 @@ Cargo will only pull the `kignore` command and won't add a subcommand to `git.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo install kignore
|
$ cargo install kignore
|
||||||
$ cargo binstall kignore # binstall will warn that git.front.kjuulh.io isn't a valid repo, it is still installable though
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Post install
|
#### Post install
|
||||||
|
|
||||||
To get the `git ignore` subcommand working you will need to have the file
|
To get the `git ignore` subcommand working you will need to have the file
|
||||||
git-ignore available on your path
|
git-ignore available on your path, either add it yourself using
|
||||||
|
`git-alias/git-ignore` as a template or:
|
||||||
|
|
||||||
```
|
```
|
||||||
# zsh
|
git clone https://github.com/kjuulh/gitignore
|
||||||
eval "kignore init zsh"
|
./scripts/install-git-alias.sh # only tested on mac and linux
|
||||||
|
```
|
||||||
# shell
|
|
||||||
eval "kignore init sh"
|
### Homebrew
|
||||||
|
|
||||||
# bash
|
Added in HomebrewFormula
|
||||||
eval "kignore init bash"
|
|
||||||
|
```bash
|
||||||
|
$ brew tap kjuulh/gitignore https://github.com/kjuulh/gitignore
|
||||||
|
$ brew install kjuulh/gitignore/kignore-bin
|
||||||
```
|
```
|
||||||
|
@ -15,11 +15,9 @@ edition = "2021"
|
|||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.4", features = ["env", "unicode", "string"] }
|
clap = { version = "4.5.4", features = ["env", "unicode", "string"] }
|
||||||
console = "0.15.8"
|
console = "0.15.8"
|
||||||
dirs = "6.0.0"
|
|
||||||
eyre = "0.6.12"
|
eyre = "0.6.12"
|
||||||
tracing = { version = "0.1.40", features = ["log"] }
|
tracing = { version = "0.1.40", features = ["log"] }
|
||||||
tracing-subscriber = { version = "0.3.18", features = [
|
tracing-subscriber = { version = "0.3.18", features = [
|
||||||
|
@ -1,76 +1,28 @@
|
|||||||
use clap::{Arg, Command};
|
use clap::{Arg, Command};
|
||||||
use console::style;
|
use eyre::{Context, ContextCompat};
|
||||||
use eyre::{Context, ContextCompat, OptionExt};
|
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::os::unix::fs::PermissionsExt;
|
|
||||||
use std::{env::current_dir, io::Read, path::PathBuf};
|
use std::{env::current_dir, io::Read, path::PathBuf};
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
use tracing_subscriber::util::SubscriberInitExt;
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
|
|
||||||
const ZSH_FILE_CONTENTS: &[u8] = b"#!/usr/bin/env zsh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
kignore $@
|
|
||||||
";
|
|
||||||
|
|
||||||
const SH_FILE_CONTENTS: &[u8] = b"#!/usr/bin/env sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
kignore $@
|
|
||||||
";
|
|
||||||
|
|
||||||
const BASH_FILE_CONTENTS: &[u8] = b"#!/usr/bin/env bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
kignore $@
|
|
||||||
";
|
|
||||||
|
|
||||||
pub fn main() -> eyre::Result<()> {
|
pub fn main() -> eyre::Result<()> {
|
||||||
let matches = Command::new("gitignore")
|
let matches = Command::new("gitignore")
|
||||||
.version("0.1")
|
.version("0.1")
|
||||||
.author("Kasper J. Hermansen <contact@kjuulh.io>")
|
.author("Kasper J. Hermansen <contact@kjuulh.io>")
|
||||||
.about("Easily ignore items and remove from git state")
|
.about("Easily ignore items and remove from git state")
|
||||||
.long_about(
|
.long_about("git ignore is a utility tool for easily adding patterns to your .gitignore file.
|
||||||
"git ignore is a utility tool for easily adding patterns to your .gitignore file.
|
Easily add patterns using `git ignore <pattern>` this will by default also help you remove committed code violating these patterns
|
||||||
Easily add patterns using `git ignore <pattern>` this will by default
|
")
|
||||||
also help you remove committed code violating these patterns
|
|
||||||
",
|
|
||||||
)
|
|
||||||
.propagate_version(true)
|
.propagate_version(true)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("pattern")
|
Arg::new("pattern")
|
||||||
.help("the pattern you want to ignore")
|
.help("the pattern you want to ignore")
|
||||||
.long_help("the pattern you want to ignore in the nearest .gitignore file"),
|
.long_help("the pattern you want to ignore in the nearest .gitignore file")
|
||||||
)
|
.required(true),
|
||||||
.arg(
|
).arg(
|
||||||
Arg::new("log-level")
|
Arg::new("log-level").long("log-level").help("choose a log level and get more messages").long_help("Choose a log level and get more message, defaults to [fatal]"))
|
||||||
.long("log-level")
|
|
||||||
.default_value("warn")
|
|
||||||
.help("choose a log level and get more messages")
|
|
||||||
.long_help("Choose a log level and get more message, defaults to [warn]"),
|
|
||||||
)
|
|
||||||
.subcommand(
|
|
||||||
clap::Command::new("init")
|
|
||||||
.subcommand_required(true)
|
|
||||||
.subcommand(Command::new("zsh"))
|
|
||||||
.subcommand(Command::new("sh"))
|
|
||||||
.subcommand(Command::new("bash")),
|
|
||||||
)
|
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
match matches.subcommand() {
|
|
||||||
Some(("init", args)) => match args
|
|
||||||
.subcommand()
|
|
||||||
.expect("should never be able to call on init")
|
|
||||||
{
|
|
||||||
("zsh", _) => init_script(ShellType::Zsh),
|
|
||||||
("bash", _) => init_script(ShellType::Bash),
|
|
||||||
("sh", _) => init_script(ShellType::Shell),
|
|
||||||
(subcommand, _) => {
|
|
||||||
panic!("cannot call on subcommand: {}", subcommand);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
let log_level = match matches.get_one::<String>("log-level").map(|f| f.as_str()) {
|
let log_level = match matches.get_one::<String>("log-level").map(|f| f.as_str()) {
|
||||||
Some("off") => "off",
|
Some("off") => "off",
|
||||||
Some("info") => "info",
|
Some("info") => "info",
|
||||||
@ -96,8 +48,6 @@ also help you remove committed code violating these patterns
|
|||||||
|
|
||||||
add_gitignore_pattern(term, pattern)
|
add_gitignore_pattern(term, pattern)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum GitActions {
|
enum GitActions {
|
||||||
AddPattern { gitignore_path: PathBuf },
|
AddPattern { gitignore_path: PathBuf },
|
||||||
@ -105,7 +55,7 @@ enum GitActions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<()> {
|
fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<()> {
|
||||||
println!("git ignore: Add pattern");
|
term.write_line("git ignore: Add pattern")?;
|
||||||
let curdir = current_dir().context(
|
let curdir = current_dir().context(
|
||||||
"could not find current_dir, you may not have permission to access that directory",
|
"could not find current_dir, you may not have permission to access that directory",
|
||||||
)?;
|
)?;
|
||||||
@ -125,7 +75,7 @@ fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<
|
|||||||
|
|
||||||
match actions {
|
match actions {
|
||||||
GitActions::AddPattern { gitignore_path } => {
|
GitActions::AddPattern { gitignore_path } => {
|
||||||
println!("Found existing {}", style(".gitignore").green());
|
term.write_line("Found existing .gitignore")?;
|
||||||
let mut gitignore_file = open_gitignore_file(&gitignore_path)?;
|
let mut gitignore_file = open_gitignore_file(&gitignore_path)?;
|
||||||
let mut gitignore_content = String::new();
|
let mut gitignore_content = String::new();
|
||||||
gitignore_file
|
gitignore_file
|
||||||
@ -135,26 +85,22 @@ fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<
|
|||||||
gitignore_path.to_string_lossy()
|
gitignore_path.to_string_lossy()
|
||||||
))?;
|
))?;
|
||||||
if gitignore_content.contains(pattern) {
|
if gitignore_content.contains(pattern) {
|
||||||
println!(
|
term.write_line(".gitignore already contains pattern, skipping")?;
|
||||||
".gitignore already contains pattern, {}",
|
|
||||||
style("skipping...").blue()
|
|
||||||
);
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("adding pattern to file");
|
term.write_line("adding pattern to file")?;
|
||||||
writeln!(gitignore_file, "{}", pattern).context("could not write contents to file")?;
|
writeln!(gitignore_file, "{}", pattern).context("could not write contents to file")?;
|
||||||
gitignore_file
|
gitignore_file
|
||||||
.sync_all()
|
.sync_all()
|
||||||
.context("failed to write data to disk")?;
|
.context("failed to write data to disk")?;
|
||||||
}
|
}
|
||||||
GitActions::CreateIgnoreAndAddPattern { git_path } => {
|
GitActions::CreateIgnoreAndAddPattern { git_path } => {
|
||||||
println!(
|
term.write_line(
|
||||||
"could not find {} file, creating one in the root of the git repository",
|
"could not find .gitignore file, creating one in the root of the git repository",
|
||||||
style(".gitignore").yellow()
|
)?;
|
||||||
);
|
|
||||||
let mut gitignore_file = create_gitignore_file(git_path)?;
|
let mut gitignore_file = create_gitignore_file(git_path)?;
|
||||||
println!("adding pattern to file");
|
term.write_line("adding pattern to file")?;
|
||||||
writeln!(gitignore_file, "{}", pattern).context("could not write contents to file")?;
|
writeln!(gitignore_file, "{}", pattern).context("could not write contents to file")?;
|
||||||
gitignore_file
|
gitignore_file
|
||||||
.sync_all()
|
.sync_all()
|
||||||
@ -175,19 +121,8 @@ fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result<
|
|||||||
String::from_utf8(output.stdout)?
|
String::from_utf8(output.stdout)?
|
||||||
.lines()
|
.lines()
|
||||||
.chain(String::from_utf8(output.stderr)?.lines())
|
.chain(String::from_utf8(output.stderr)?.lines())
|
||||||
.map(|l| {
|
.try_for_each(|l| term.write_line(l))
|
||||||
// make rm 'path' look nice
|
.context("could not print all output to terminal")?;
|
||||||
if l.contains("rm") {
|
|
||||||
if let Some((_, pruned_first)) = l.split_once("'") {
|
|
||||||
if let Some((content, _)) = pruned_first.rsplit_once("'") {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
l
|
|
||||||
})
|
|
||||||
.for_each(|l| println!("removed from git history: {}", style(l).yellow()));
|
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
return Err(eyre::anyhow!("failed to run git index command"));
|
return Err(eyre::anyhow!("failed to run git index command"));
|
||||||
@ -300,50 +235,3 @@ fn search_for_dotgitignore(path: &PathBuf) -> eyre::Result<GitSearchResult> {
|
|||||||
|
|
||||||
search_for_dotgitignore(&upwards_par)
|
search_for_dotgitignore(&upwards_par)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ShellType {
|
|
||||||
Bash,
|
|
||||||
Shell,
|
|
||||||
Zsh,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn init_script(shell: ShellType) -> eyre::Result<()> {
|
|
||||||
let bin_dir = dirs::executable_dir().ok_or_eyre("failed to find executable dir")?;
|
|
||||||
|
|
||||||
let script = match shell {
|
|
||||||
ShellType::Bash => BASH_FILE_CONTENTS,
|
|
||||||
ShellType::Shell => SH_FILE_CONTENTS,
|
|
||||||
ShellType::Zsh => ZSH_FILE_CONTENTS,
|
|
||||||
};
|
|
||||||
|
|
||||||
let alias_script = bin_dir.join("git-ignore");
|
|
||||||
if let Ok(existing_file) = std::fs::read(&alias_script) {
|
|
||||||
if existing_file == script {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
std::fs::create_dir_all(&bin_dir).context("failed to create bin dir")?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut file = std::fs::OpenOptions::new()
|
|
||||||
.write(true)
|
|
||||||
.create(true)
|
|
||||||
.truncate(true)
|
|
||||||
.open(&alias_script)?;
|
|
||||||
|
|
||||||
file.write_all(script)?;
|
|
||||||
file.flush()?;
|
|
||||||
|
|
||||||
// Set the file to be executable
|
|
||||||
let metadata = file.metadata()?;
|
|
||||||
let mut permissions = metadata.permissions();
|
|
||||||
permissions.set_mode(0o755); // rwxr-xr-x
|
|
||||||
file.set_permissions(permissions)?;
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"successfully wrote alias to {}",
|
|
||||||
style(alias_script.display()).green()
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
@ -6,9 +6,6 @@ vars:
|
|||||||
service: "kignore"
|
service: "kignore"
|
||||||
registry: kasperhermansen
|
registry: kasperhermansen
|
||||||
|
|
||||||
rust:
|
|
||||||
publish: {}
|
|
||||||
|
|
||||||
please:
|
please:
|
||||||
project:
|
project:
|
||||||
owner: kjuulh
|
owner: kjuulh
|
||||||
|
Loading…
Reference in New Issue
Block a user