zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
39.79k stars 2.08k forks source link

shebang task #13052

Open JustFrederik opened 3 weeks ago

JustFrederik commented 3 weeks ago

Check for existing issues

Describe the feature

it would be great if there could be auto task detection for shebangs. I listed some common file extensions for shebang below.

If applicable, add mockups / screenshots to help present your vision of the feature

check files with a function for shebang like this

fn get_shebang<'a>(s: &'a str) -> Option<&'a str> {
    let line = s.split_once("\n")?.0;
    line.strip_prefix("#!")
}

fn get_shebang_args(s: &str) -> (&str, Vec<&str>) {
    let mut parts = s.split(" ");
    let shebang = parts.next().unwrap();
    (shebang, parts.collect())
}

this could be for No extension, ".sh", ".bash", ".py", ".pl", ".rb",".php",".awk",".tcl",".r",".lua", ".groovy" and custom extensions from config.

EDIT: or executable text files(chmod +x)

the task would then execute something like Command::new(shebang).args(shebang_args).arg(absolute_path_to_file)

notpeter commented 3 weeks ago

Potentially instead of detecting purely based on filename it could also check the mode (+x) of the file.