Skip to content

Commit

Permalink
Rename .crs to .ers
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Oct 28, 2020
1 parent 7cd6461 commit 225c0aa
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ jobs:
- name: Install file association
run: ./target/debug/rust-script.exe --install-file-association
- name: Run example script with file extension
run: cmd.exe /C .\examples\hello.crs
run: cmd.exe /C .\examples\hello.ers
- name: Run example script without file extension
run: cmd.exe /C hello
working-directory: examples
continue-on-error: true
- name: Uninstall file association
run: ./target/debug/rust-script.exe --uninstall-file-association
- name: Run example script with file extension
run: cmd.exe /C .\examples\hello.crs
run: cmd.exe /C .\examples\hello.ers
continue-on-error: true
- name: Run example script without file extension
run: cmd.exe /C hello
Expand Down
12 changes: 6 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ Useful command-line arguments:

## Executable Scripts

On Unix systems, you can use `#!/usr/bin/env rust-script` as a shebang line in a Rust script. This will allow you to execute a script file directly.
On Unix systems, you can use `#!/usr/bin/env rust-script` as a shebang line in a Rust script. This will allow you to execute a script files (which don't need to have the `.rs` file extension) directly.

If you are using Windows, you can associate the `.crs` extension (which is simply a renamed `.rs` file) with `rust-script`. This allows you to execute Rust scripts simply by naming them like any other executable or script.
If you are using Windows, you can associate the `.ers` extension (executable Rust - a renamed `.rs` file) with `rust-script`. This allows you to execute Rust scripts simply by naming them like any other executable or script.

This can be done using the `rust-script --install-file-association` command. It will also allow you to execute `.crs` scripts *without* having to specify the file extension, in the same way that `.exe` and `.bat` files can be used.
This can be done using the `rust-script --install-file-association` command. It will also allow you to execute `.ers` scripts *without* having to specify the file extension, in the same way that `.exe` and `.bat` files can be used.

Uninstall the file association with `rust-script --uninstall-file-association`.

If you want to make a script usable across platforms, use *both* a hashbang line *and* give the file a `.crs` file extension.
If you want to make a script usable across platforms, use *both* a hashbang line *and* give the file a `.ers` file extension.

## Expressions

Expand All @@ -127,7 +127,7 @@ The code given is embedded into a block expression, evaluated, and printed out u
You can use `rust-script` to write a quick filter, by specifying a closure to be called for each line read from stdin, like so:

```sh
$ cat now.crs | rust-script --loop \
$ cat now.ers | rust-script --loop \
"let mut n=0; move |l| {n+=1; println!(\"{:>6}: {}\",n,l.trim_right())}"
1: // cargo-deps: time="0.1.25"
3: fn main() {
Expand All @@ -138,7 +138,7 @@ $ cat now.crs | rust-script --loop \
You can achieve a similar effect to the above by using the `--count` flag, which causes the line number to be passed as a second argument to your closure:
```sh
$ cat now.crs | rust-script --count --loop \
$ cat now.ers | rust-script --count --loop \
"|l,n| println!(\"{:>6}: {}\", n, l.trim_right())"
1: // cargo-deps: time="0.1.25"
2: fn main() {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub const METADATA_FILE: &str = "metadata.json";
/**
Extensions to check when trying to find script input by name.
*/
pub const SEARCH_EXTS: &[&str] = &["crs", "rs"];
pub const SEARCH_EXTS: &[&str] = &["ers", "rs"];

/**
When generating a package's unique ID, how many hex nibbles of the digest should be used *at most*?
Expand Down
30 changes: 15 additions & 15 deletions src/file_assoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ pub fn install_file_association() -> Result<()> {

let res = (|| -> io::Result<()> {
let hlcr = RegKey::predef(wre::HKEY_CLASSES_ROOT);
let dot_crs = hlcr.create_subkey(".crs")?;
dot_crs.set_value("", &"CargoScript.Crs")?;
let dot_ers = hlcr.create_subkey(".ers")?;
dot_ers.set_value("", &"RustScript.Ers")?;

let cs_crs = hlcr.create_subkey("CargoScript.Crs")?;
cs_crs.set_value("", &"Cargo Script")?;
let cs_ers = hlcr.create_subkey("RustScript.Ers")?;
cs_ers.set_value("", &"Rust Script")?;

let sh_o_c = cs_crs.create_subkey(r#"shell\open\command"#)?;
let sh_o_c = cs_ers.create_subkey(r#"shell\open\command"#)?;
sh_o_c.set_value("", &format!(r#""{}" "%1" %*"#, rcs_path))?;
Ok(())
})();
Expand All @@ -67,12 +67,12 @@ pub fn install_file_association() -> Result<()> {
hklm.open_subkey(r#"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"#)?;

let pathext: String = env.get_value("PATHEXT")?;
if !pathext.split(';').any(|e| e.eq_ignore_ascii_case(".crs")) {
let pathext = pathext.split(';').chain(Some(".CRS")).join(";");
if !pathext.split(';').any(|e| e.eq_ignore_ascii_case(".ers")) {
let pathext = pathext.split(';').chain(Some(".ERS")).join(";");
env.set_value("PATHEXT", &pathext)?;
}

println!("Added `.crs` to PATHEXT. You may need to log out for the change to take effect.");
println!("Added `.ers` to PATHEXT. You may need to log out for the change to take effect.");

Ok(())
}
Expand All @@ -86,13 +86,13 @@ pub fn uninstall_file_association() -> Result<()> {
let mut notify = || ignored_missing = true;

let hlcr = RegKey::predef(wre::HKEY_CLASSES_ROOT);
hlcr.delete_subkey(r#"CargoScript.Crs\shell\open\command"#)
hlcr.delete_subkey(r#"RustScript.Ers\shell\open\command"#)
.ignore_missing_and(&mut notify)?;
hlcr.delete_subkey(r#"CargoScript.Crs\shell\open"#)
hlcr.delete_subkey(r#"RustScript.Ers\shell\open"#)
.ignore_missing_and(&mut notify)?;
hlcr.delete_subkey(r#"CargoScript.Crs\shell"#)
hlcr.delete_subkey(r#"RustScript.Ers\shell"#)
.ignore_missing_and(&mut notify)?;
hlcr.delete_subkey(r#"CargoScript.Crs"#)
hlcr.delete_subkey(r#"RustScript.Ers"#)
.ignore_missing_and(&mut notify)?;
}

Expand All @@ -107,13 +107,13 @@ pub fn uninstall_file_association() -> Result<()> {
hklm.open_subkey(r#"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"#)?;

let pathext: String = env.get_value("PATHEXT")?;
if pathext.split(';').any(|e| e.eq_ignore_ascii_case(".crs")) {
if pathext.split(';').any(|e| e.eq_ignore_ascii_case(".ers")) {
let pathext = pathext
.split(';')
.filter(|e| !e.eq_ignore_ascii_case(".crs"))
.filter(|e| !e.eq_ignore_ascii_case(".ers"))
.join(";");
env.set_value("PATHEXT", &pathext)?;
println!("Removed `.crs` from PATHEXT. You may need to log out for the change to take effect.");
println!("Removed `.ers` from PATHEXT. You may need to log out for the change to take effect.");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ fn parse_args() -> Args {
let app = app
.arg(
Arg::with_name("install-file-association")
.help("Install a file association so that rust-script executes .crs files.")
.help("Install a file association so that rust-script executes .ers files.")
.long("install-file-association"),
)
.arg(
Arg::with_name("uninstall-file-association")
.help("Uninstall the file association that makes rust-script execute .crs files.")
.help("Uninstall the file association that makes rust-script execute .ers files.")
.long("uninstall-file-association"),
)
.group(
Expand Down

0 comments on commit 225c0aa

Please sign in to comment.