Skip to content

Commit

Permalink
Fixes issues from #58 (Windows-specific)
Browse files Browse the repository at this point in the history
- Uses a more sensible default of notepad.exe on Windows
- Changes the tempfile name to have "renamer-" prefix and ".txt" suffix
  (the latter being a workaround for Windows which doesn't handle file
  names with a leading dot too well in Notepad)
- Updated README file to mention the new option
  • Loading branch information
assarbad committed Nov 4, 2022
1 parent 778b63f commit 1451a5b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,28 @@ USAGE:
ARGS:
<FILES>...
OPTIONS:
-c, --rename-command <RENAME_COMMAND> Optionally set a custom rename command, like 'git mv'
-f, --force Overwrite existing files
-h, --help Print help information
-p, --pretty-diff Prettify diffs
-V, --version Print version information
-y, --yes Answer all prompts with yes
-c, --rename-command <COMMAND>
Optionally set a custom rename command, like 'git mv'
-e, --editor <EDITOR>
Optionally set an editor, overriding EDITOR environment variable and default
-f, --force
Overwrite existing files
-h, --help
Print help information
-p, --pretty-diff
Prettify diffs
-V, --version
Print version information
-y, --yes
Answer all prompts with yes
```

## Contributors ✨
Expand Down
11 changes: 8 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ fn expand_dir(path: &str) -> anyhow::Result<Vec<String>, io::Error> {
}

fn open_editor(input_files: &[String], editor_string: &str) -> anyhow::Result<Vec<String>> {
let mut tmpfile = tempfile::NamedTempFile::new().context("Could not create temp file")?;
let mut tmpfile = tempfile::Builder::new()
.prefix("renamer-")
.suffix(".txt")
.tempfile()
.context("Could not create temp file")?;
write!(tmpfile, "{}", input_files.join("\n"))?;
let editor_parsed = shell_words::split(editor_string)
.expect("failed to parse command line flags in EDITOR command");
Expand Down Expand Up @@ -344,11 +348,12 @@ fn main() -> anyhow::Result<()> {

check_input_files(&input_files)?;

let default_editor = if cfg!(windows) { "notepad.exe" } else { "vim" };
let default_editor = default_editor.to_string();
let editor = opts.editor
.unwrap_or_else(
|| env::var("EDITOR")
.unwrap_or_else(
|_| "vim".to_string()));
.unwrap_or(default_editor));
let mut buffer = input_files.clone();

loop {
Expand Down

0 comments on commit 1451a5b

Please sign in to comment.