Compare commits
1 Commits
v0.1.1
...
3895791138
Author | SHA1 | Date | |
---|---|---|---|
|
3895791138 |
@@ -6,16 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.1.1] - 2025-08-04
|
||||
|
||||
### Fixed
|
||||
- if path is empty default to `.`
|
||||
|
||||
## [0.1.0] - 2025-08-03
|
||||
|
||||
### Added
|
||||
- add open command
|
||||
- noil now handles open, and open in non-terminals via. /dev/tty
|
||||
- add file opener with chooser
|
||||
- update demo
|
||||
- add help text for preview
|
||||
|
93
Cargo.lock
generated
93
Cargo.lock
generated
@@ -257,44 +257,12 @@ version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
||||
|
||||
[[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 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dotenvy"
|
||||
version = "0.15.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi 0.11.1+wasi-snapshot-preview1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.3.3"
|
||||
@@ -377,16 +345,6 @@ version = "0.2.174"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
|
||||
|
||||
[[package]]
|
||||
name = "libredox"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.13"
|
||||
@@ -431,7 +389,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "noil"
|
||||
version = "0.1.0"
|
||||
version = "0.0.5"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"anyhow",
|
||||
@@ -441,7 +399,6 @@ dependencies = [
|
||||
"ignore",
|
||||
"pretty_assertions",
|
||||
"rand",
|
||||
"shellexpand",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
@@ -479,12 +436,6 @@ version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||
|
||||
[[package]]
|
||||
name = "option-ext"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
||||
|
||||
[[package]]
|
||||
name = "overload"
|
||||
version = "0.1.1"
|
||||
@@ -589,7 +540,7 @@ version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||
dependencies = [
|
||||
"getrandom 0.3.3",
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -601,17 +552,6 @@ dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac"
|
||||
dependencies = [
|
||||
"getrandom 0.2.16",
|
||||
"libredox",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.9"
|
||||
@@ -679,15 +619,6 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shellexpand"
|
||||
version = "3.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b1fdf65dd6331831494dd616b30351c38e96e45921a27745cf98490458b90bb"
|
||||
dependencies = [
|
||||
"dirs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
@@ -742,26 +673,6 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.9"
|
||||
|
@@ -3,7 +3,7 @@ members = ["crates/*"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.1"
|
||||
version = "0.1.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
noil = { path = "crates/noil" }
|
||||
|
73
README.md
73
README.md
@@ -1,11 +1,8 @@
|
||||
# noil
|
||||
|
||||
**noil** is a structured, text-buffer-based file operation tool – think of it
|
||||
like [`oil.nvim`](https://github.com/stevearc/oil.nvim), but for any editor,
|
||||
terminal, or automated process.
|
||||
**noil** is a structured, text-buffer-based file operation tool – think of it like [`oil.nvim`](https://github.com/stevearc/oil.nvim), but for any editor, terminal, or automated process.
|
||||
|
||||
Edit filesystem operations like it's plain text, and then apply them in a
|
||||
controlled, explicit way.
|
||||
Edit filesystem operations like it's plain text, and then apply them in a controlled, explicit way.
|
||||
|
||||

|
||||
|
||||
@@ -13,19 +10,17 @@ controlled, explicit way.
|
||||
|
||||
## Interactive Mode (TBA)
|
||||
|
||||
I am planning an interactive TUI mode, where you don't have to care about tags,
|
||||
like in `oil`. For now the normal editor is quite useful though, and allows all
|
||||
types of editors to easily move, edit files and so on.
|
||||
I am planning an interactive TUI mode, where you don't have to care about tags, like in `oil`. For now the normal editor is quite useful though, and allows all types of editors to easily move, edit files and so on.
|
||||
|
||||
---
|
||||
|
||||
## ✨ Features
|
||||
|
||||
- Edit your file tree like a normal buffer
|
||||
- Preview, format, and apply changes
|
||||
- Integrates with `$EDITOR`
|
||||
- CLI first, editor agnostic
|
||||
- No surprises: nothing is applied until you say so
|
||||
* Edit your file tree like a normal buffer
|
||||
* Preview, format, and apply changes
|
||||
* Integrates with `$EDITOR`
|
||||
* CLI first, editor agnostic
|
||||
* No surprises: nothing is applied until you say so
|
||||
|
||||
---
|
||||
|
||||
@@ -47,7 +42,7 @@ cat something.noil | noil fmt > something.noil
|
||||
cat something.noil | noil apply
|
||||
```
|
||||
|
||||
noil will ask you if you want to apply your changes before doing any operations.
|
||||
noil will always ask you if you want to apply your changes before doing any operations.
|
||||
|
||||
---
|
||||
|
||||
@@ -61,14 +56,13 @@ Each line follows this format:
|
||||
|
||||
### Supported operations:
|
||||
|
||||
| Operation | Meaning | Tag Required? |
|
||||
| --------: | ------------------------------------------------------ | ------------- |
|
||||
| `ADD` | Add new file | ❌ No |
|
||||
| `COPY` | Copy file with given tag | ✅ Yes |
|
||||
| `DELETE` | Delete file with given tag | ✅ Yes |
|
||||
| `MOVE` | Move file with given tag | ✅ Yes |
|
||||
| `OPEN` | Open a file with a given tag (requires --chooser-file) | ❌ No |
|
||||
| _(blank)_ | Reference existing file (default) | ✅ Yes |
|
||||
| Operation | Meaning | Tag Required? |
|
||||
| --------: | --------------------------------- | ------------- |
|
||||
| `ADD` | Add new file | ❌ No |
|
||||
| `COPY` | Copy file with given tag | ✅ Yes |
|
||||
| `DELETE` | Delete file with given tag | ✅ Yes |
|
||||
| `MOVE` | Move file with given tag | ✅ Yes |
|
||||
| *(blank)* | Reference existing file (default) | ✅ Yes |
|
||||
|
||||
---
|
||||
|
||||
@@ -79,11 +73,9 @@ Each line follows this format:
|
||||
COPY abc : /tmp/nginx-copy
|
||||
DELETE 123 : /etc/nginx
|
||||
ADD : /new/file.txt
|
||||
OPEN : /new/file.txt
|
||||
```
|
||||
|
||||
You can use short, unique tags (like `abc`, `ng1`, etc.) to refer to files.
|
||||
`noil` will generate these tags when you run `noil .`.
|
||||
You can use short, unique tags (like `abc`, `ng1`, etc.) to refer to files. `noil` will generate these tags when you run `noil .`.
|
||||
|
||||
---
|
||||
|
||||
@@ -95,11 +87,9 @@ Want to clean up alignment and spacing?
|
||||
cat my-buffer.noil | noil fmt
|
||||
```
|
||||
|
||||
Or automatically format inside your editor with the following config for
|
||||
[Helix](https://helix-editor.com):
|
||||
Or automatically format inside your editor with the following config for [Helix](https://helix-editor.com):
|
||||
|
||||
```toml
|
||||
# .config/helix/languages.toml
|
||||
[[language]]
|
||||
name = "noil"
|
||||
scope = "source.noil"
|
||||
@@ -112,30 +102,8 @@ formatter = { command = "noil", args = ["fmt"] }
|
||||
[[grammar]]
|
||||
name = "noil"
|
||||
source = { git = "https://git.kjuulh.io/kjuulh/tree-sitter-noil.git", rev = "2f295629439881d0b9e89108a1296881d0daf7b9" }
|
||||
|
||||
# .config/helix/config.toml
|
||||
# Optional extra command Space + o will open noil allowing edits and the OPEN command
|
||||
[keys.normal.space]
|
||||
o = [
|
||||
":sh rm -f /tmp/unique-file-kjuulh",
|
||||
# DISCLAIMER: Until noil has a proper interactive mode, we cannot ask for confirmation, as such we always commit changes, you don't get to have a preview unlike the normal cli option
|
||||
":insert-output noil edit '%{buffer_name}' --chooser-file=/tmp/unique-file-kjuulh --commit --quiet < /dev/tty",
|
||||
":insert-output echo \"x1b[?1049h\" > /dev/tty",
|
||||
":open %sh{cat /tmp/unique-file-kjuulh}",
|
||||
":redraw",
|
||||
]
|
||||
```
|
||||
|
||||
### Edit options
|
||||
|
||||
When using `noil edit .` a few additional options are available
|
||||
|
||||
- `--chooser-file`: A chooser file is a newline delimited file where each line
|
||||
corresponds to a relative file to be opened or manipulated by the user. Only
|
||||
items with `OPEN` command will be added to the file
|
||||
- `--commit`: commit files without asking for confirmation
|
||||
- `--quiet`: don't print results
|
||||
|
||||
---
|
||||
|
||||
## 🔒 Safety First
|
||||
@@ -155,9 +123,7 @@ You will be prompted before anything is modified.
|
||||
|
||||
## 🧠 Philosophy
|
||||
|
||||
noil gives you full control over file operations in a composable and
|
||||
editor-friendly way. Think Git index, but for actual file moves and deletions —
|
||||
human-editable, patchable, and grep-able.
|
||||
noil gives you full control over file operations in a composable and editor-friendly way. Think Git index, but for actual file moves and deletions — human-editable, patchable, and grep-able.
|
||||
|
||||
---
|
||||
|
||||
@@ -169,6 +135,7 @@ human-editable, patchable, and grep-able.
|
||||
cargo install noil
|
||||
```
|
||||
|
||||
|
||||
**Build from source**:
|
||||
|
||||
```bash
|
||||
|
@@ -21,7 +21,6 @@ ignore = "0.4.23"
|
||||
blake3 = "1.8.2"
|
||||
rand = "0.9.2"
|
||||
ansi_term = "0.12.1"
|
||||
shellexpand = "3.1.1"
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "1.4.1"
|
||||
|
@@ -34,7 +34,6 @@ impl ApplyCommand {
|
||||
&original,
|
||||
ApplyOptions {
|
||||
chooser_file: self.chooser_file.clone(),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
@@ -50,7 +49,6 @@ impl ApplyCommand {
|
||||
&input,
|
||||
ApplyOptions {
|
||||
chooser_file: self.chooser_file.clone(),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
@@ -1,17 +1,13 @@
|
||||
use std::{
|
||||
env::temp_dir,
|
||||
io::{IsTerminal, Write},
|
||||
io::Write,
|
||||
path::{Path, PathBuf},
|
||||
process::Stdio,
|
||||
};
|
||||
|
||||
use ansi_term::Color;
|
||||
use anyhow::{Context, bail};
|
||||
use clap::Parser;
|
||||
use tokio::{
|
||||
fs::OpenOptions,
|
||||
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
|
||||
};
|
||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
|
||||
|
||||
use crate::{
|
||||
commit::{Action, print_changes},
|
||||
@@ -30,12 +26,6 @@ pub struct EditCommand {
|
||||
|
||||
#[arg(long = "chooser-file", env = "NOIL_CHOOSER_FILE")]
|
||||
chooser_file: Option<PathBuf>,
|
||||
|
||||
#[arg(long = "commit")]
|
||||
commit: bool,
|
||||
|
||||
#[arg(long = "quiet")]
|
||||
quiet: bool,
|
||||
}
|
||||
|
||||
impl EditCommand {
|
||||
@@ -62,14 +52,9 @@ impl EditCommand {
|
||||
.await
|
||||
.context("create temp file for noil")?;
|
||||
|
||||
let path = &self.get_path().await.context("get path")?;
|
||||
let output = get_outputs(path, true)
|
||||
.await
|
||||
.context(format!("get output: {}", path.display()))?;
|
||||
file.write_all(output.as_bytes())
|
||||
.await
|
||||
.context("write contents for edit")?;
|
||||
file.flush().await.context("flush contents for edit")?;
|
||||
let output = get_outputs(&self.path, true).await?;
|
||||
file.write_all(output.as_bytes()).await?;
|
||||
file.flush().await?;
|
||||
|
||||
let editor = std::env::var("EDITOR").context("EDITOR not found in env")?;
|
||||
|
||||
@@ -77,22 +62,7 @@ impl EditCommand {
|
||||
let mut cmd = tokio::process::Command::new(editor.trim());
|
||||
cmd.arg(&file_path);
|
||||
|
||||
if !std::io::stdout().is_terminal() {
|
||||
let tty = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open("/dev/tty")
|
||||
.await
|
||||
.context("open tty")?;
|
||||
let tty_in = tty.try_clone().await.context("clone ttyin")?;
|
||||
let tty_out = tty.try_clone().await.context("clone ttyout")?;
|
||||
|
||||
cmd.stdin(Stdio::from(tty_in.into_std().await))
|
||||
.stdout(Stdio::from(tty_out.into_std().await))
|
||||
.stderr(Stdio::from(tty.into_std().await));
|
||||
}
|
||||
|
||||
let mut process = cmd.spawn().context("command not found")?;
|
||||
let mut process = cmd.spawn()?;
|
||||
let status = process.wait().await.context("editor closed prematurely")?;
|
||||
if !status.success() {
|
||||
let code = status.code().unwrap_or(-1);
|
||||
@@ -103,13 +73,7 @@ impl EditCommand {
|
||||
.await
|
||||
.context("read noil file")?;
|
||||
|
||||
let res = if !self.commit {
|
||||
print_changes(&noil_content, PREVIEW).await
|
||||
} else {
|
||||
Ok(Action::Apply {
|
||||
original: noil_content,
|
||||
})
|
||||
};
|
||||
let res = print_changes(&noil_content, PREVIEW).await;
|
||||
|
||||
let action = match res {
|
||||
Ok(a) => a,
|
||||
@@ -119,7 +83,7 @@ impl EditCommand {
|
||||
Color::Red.normal().paint(format!("{e:?}"))
|
||||
);
|
||||
|
||||
wait_user().await.context("user finished prematurely")?;
|
||||
wait_user().await?;
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -132,7 +96,6 @@ impl EditCommand {
|
||||
&original,
|
||||
ApplyOptions {
|
||||
chooser_file: self.chooser_file.clone(),
|
||||
quiet: self.quiet,
|
||||
},
|
||||
)
|
||||
.await;
|
||||
@@ -141,31 +104,6 @@ impl EditCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_path(&self) -> anyhow::Result<PathBuf> {
|
||||
let path_str = self.path.display().to_string();
|
||||
let expanded_path = shellexpand::full(&path_str)?;
|
||||
let path = PathBuf::from(expanded_path.to_string());
|
||||
|
||||
if !path.exists() {
|
||||
anyhow::bail!("path: {} does not exist", self.path.display());
|
||||
}
|
||||
|
||||
if path.is_file() {
|
||||
let parent_path = path
|
||||
.parent()
|
||||
.map(|p| p.to_path_buf())
|
||||
.ok_or(anyhow::anyhow!("parent doesn't exist for file"))?;
|
||||
|
||||
if parent_path.display().to_string() == "" {
|
||||
return Ok(PathBuf::from("."));
|
||||
}
|
||||
|
||||
return Ok(parent_path);
|
||||
}
|
||||
|
||||
Ok(path.clone())
|
||||
}
|
||||
}
|
||||
|
||||
async fn wait_user() -> Result<(), anyhow::Error> {
|
||||
@@ -174,17 +112,13 @@ async fn wait_user() -> Result<(), anyhow::Error> {
|
||||
let stdin = tokio::io::stdin();
|
||||
let mut reader = BufReader::new(stdin);
|
||||
let mut input_buf = String::new();
|
||||
reader
|
||||
.read_line(&mut input_buf)
|
||||
.await
|
||||
.context("failed to read stdin")?;
|
||||
reader.read_line(&mut input_buf).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct ApplyOptions {
|
||||
pub chooser_file: Option<PathBuf>,
|
||||
pub quiet: bool,
|
||||
}
|
||||
|
||||
/// the philosphy behind apply is that we try unlike normal file system operations to be idempotent.
|
||||
@@ -195,9 +129,7 @@ pub struct ApplyOptions {
|
||||
///
|
||||
/// All in all apply is mostly idempotent, and won't override files, it tries to be as non destructive as possible. For example move will only throw a warning if the source file doesn't exists, but the destination does
|
||||
pub async fn apply(input: &str, options: ApplyOptions) -> anyhow::Result<()> {
|
||||
if !options.quiet {
|
||||
eprintln!("applying changes");
|
||||
}
|
||||
eprintln!("applying changes");
|
||||
|
||||
let noil_index = parse::parse_input(input).context("parse input")?;
|
||||
|
||||
|
Reference in New Issue
Block a user