-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding xtask for setting up dotfiles
- Loading branch information
Showing
5 changed files
with
156 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ in place, so the recommended way to try out `ad` is to clone this repo and compi | |
$ git clone [email protected]:sminez/ad.git | ||
$ cd ad | ||
$ cargo install --path . | ||
$ make setup-dotfiles | ||
$ cargo xtask setup-dotfiles | ||
``` | ||
|
||
From there you should be able to open `ad` and run the `:help` command to view the built-in help. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use crate::{dist_dir, project_root, DynResult}; | ||
use man::prelude::*; | ||
use std::{fs, path::PathBuf}; | ||
|
||
const DESCRIPTION: &str = "\ | ||
ad is a text editor and command line stream editor. The text editor interface for | ||
ad is inspired by the likes of vim and kakoune, along with the acme and sam editors | ||
from plan9. ad aims to provide an 'integrating development environment' as opposed | ||
to an 'integrated' one: leveraging the surrounding system for the majority of | ||
functionality outisde of the core text editing actions. | ||
"; | ||
|
||
const DOTFILE_DIR: &str = ".ad"; | ||
|
||
pub fn generate_manpage() -> DynResult { | ||
eprintln!(">> Generating man page"); | ||
let dir = dist_dir(); | ||
fs::create_dir_all(&dir)?; | ||
|
||
let content = Manual::new("ad") | ||
.about("An adaptable text editor") | ||
.author(Author::new("Innes Anderson-Morrison")) | ||
.description(DESCRIPTION) | ||
.option( | ||
Opt::new("script") | ||
.short("-e") | ||
.help("Execute an edit script on file(s)"), | ||
) | ||
.option( | ||
Opt::new("script-file") | ||
.short("-f") | ||
.help("Execute an edit script loaded from a script-file on file(s)"), | ||
) | ||
.arg(Arg::new("[file...]")) | ||
.flag( | ||
Flag::new() | ||
.short("-h") | ||
.long("--help") | ||
.help("Print command line help and exit"), | ||
) | ||
.flag( | ||
Flag::new() | ||
.short("-v") | ||
.long("--version") | ||
.help("Print version information and exit"), | ||
) | ||
.render(); | ||
|
||
let p = dir.join("ad.1"); | ||
eprintln!(" [ ] writing manpage to {}", p.display()); | ||
fs::write(p, content)?; | ||
eprintln!(" [ ] done"); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn setup_dotfiles() -> DynResult { | ||
eprintln!(">> Setting up dotfile directory"); | ||
let data_dir = project_root().join("data"); | ||
let dot_dir = PathBuf::from(env!("HOME")).join(DOTFILE_DIR); | ||
|
||
eprintln!(" [ ] creating dotfile directory: {}", dot_dir.display()); | ||
fs::create_dir_all(dot_dir.join("mnt"))?; | ||
|
||
let cp = |path: &str| fs::copy(data_dir.join(path), dot_dir.join(path)); | ||
|
||
eprintln!(" [ ] copying default config file"); | ||
cp("config.toml")?; | ||
eprintln!(" [ ] copying default plumbing rules"); | ||
cp("plumbing.rules")?; | ||
eprintln!(" [ ] copying data/bin..."); | ||
fs::create_dir_all(dot_dir.join("bin"))?; | ||
for entry in fs::read_dir(data_dir.join("bin"))? { | ||
let path = entry?.path(); | ||
let fname = path.file_name().unwrap().to_string_lossy(); | ||
cp(&format!("bin/{fname}"))?; | ||
} | ||
eprintln!(" [ ] copying data/lib..."); | ||
fs::create_dir_all(dot_dir.join("lib"))?; | ||
for entry in fs::read_dir(data_dir.join("lib"))? { | ||
let path = entry?.path(); | ||
let fname = path.file_name().unwrap().to_string_lossy(); | ||
cp(&format!("lib/{fname}"))?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::{err, project_root, DynResult}; | ||
use std::fs; | ||
|
||
pub fn lint_ts_queries() -> DynResult { | ||
let unsupported_predicates = [ | ||
// neovim | ||
"any-contains?", | ||
"any-lua-match?", | ||
"any-vim-match?", | ||
"contains?", | ||
"has-ancestor?", | ||
"has-parent?", | ||
"lua-match?", | ||
"vim-match?", | ||
]; | ||
let mut valid = true; | ||
eprintln!(">> Linting tree-sitter queries"); | ||
|
||
let query_root = project_root().join("data/tree-sitter/queries"); | ||
for entry in fs::read_dir(query_root)? { | ||
let path = entry?.path(); | ||
if path.is_file() { | ||
eprintln!( | ||
"[x] unexpected file in data/tree-sitter/queries:\n{}", | ||
path.display() | ||
); | ||
valid = false; | ||
} | ||
|
||
let lang = path.file_name().unwrap().to_string_lossy(); | ||
let highlights = path.join("highlights.scm"); | ||
eprintln!("[ ] checking highlights for {lang}..."); | ||
|
||
if !highlights.exists() { | ||
eprintln!(" [x] no highlights.scm found for {lang}"); | ||
valid = false; | ||
continue; | ||
} | ||
|
||
let query = fs::read_to_string(highlights)?; | ||
for p in unsupported_predicates { | ||
if query.contains(p) { | ||
eprintln!(" [x] highlights for {lang} contain an unsupported predicate: {p}"); | ||
valid = false; | ||
} | ||
} | ||
if query.contains("@spell") { | ||
eprintln!(" [x] highlights for {lang} contain '@spell' which needs to be removed"); | ||
valid = false; | ||
} | ||
} | ||
|
||
if !valid { | ||
return err!("validation failed: see logs for details"); | ||
} | ||
|
||
eprintln!("\ntree-sitter queries linted successfully"); | ||
|
||
Ok(()) | ||
} |