Skip to content

Commit

Permalink
🐧first bonk
Browse files Browse the repository at this point in the history
  • Loading branch information
elliot40404 committed Sep 23, 2022
0 parents commit 5111df5
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
.dccache
7 changes: 7 additions & 0 deletions Cargo.lock

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

14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "bonk"
version = "0.1.0"
edition = "2021"

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

[dependencies]

[profile.release]
strip = true
opt-level = "s"
lto = true
codegen-units = 1
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# BONK

The blazingly fast touch alternative written in rust. Made for the sole purpose to create files.

![Bonky bonk](./bonk.png)

## USAGE

Create a file

```bash
bonk main.rs
```

Create a nested file

```bash
bonk src/main.rs
```
Binary file added bonk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::fs::File;
use std::path::Path;
use std::{env, fs};

fn check_if_dir(dir: &str) -> bool {
if dir.contains('/') || dir.contains('\\') {
return true;
} else {
return false;
}
}

fn main() {
let mut input: Vec<String> = env::args().collect();
input.remove(0);
input.iter().for_each(|x| {
if check_if_dir(x) {
let sep = if x.contains('/') { '/' } else { '\\' };
let mut dir = x.split(sep).collect::<Vec<&str>>();
if Path::new(dir[0]).exists() {
return println!("{}: A file with same name already exists", dir[0]);
}
dir.pop();
let dir = dir.join(&sep.to_string());
fs::create_dir_all(&dir).expect("Directory already exists");
if !Path::new(x).exists() {
File::create(String::from(x)).expect("Unable to create file in directory");
}
} else {
if !Path::new(x).exists() {
File::create(String::from(x)).expect("Unable to create file");
}
}
});
}

0 comments on commit 5111df5

Please sign in to comment.