diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-25 13:08:33 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-25 13:08:33 +0100 |
commit | d7ce2174f12d1b7730a015100ca0fef457ad4d72 (patch) | |
tree | bbd7bc1a76689bdb0c0e1b731db7834520d58ac4 /src/ips | |
parent | 22abd1b12b66e75f75fe01dc33abaa7d74597b3c (diff) | |
download | chawan-d7ce2174f12d1b7730a015100ca0fef457ad4d72.tar.gz |
ips/editor: don't write file for empty input, check for conflicting files
Diffstat (limited to 'src/ips')
-rw-r--r-- | src/ips/editor.nim | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/ips/editor.nim b/src/ips/editor.nim index bfa88cb5..4361c39f 100644 --- a/src/ips/editor.nim +++ b/src/ips/editor.nim @@ -24,8 +24,6 @@ func formatEditorName(editor, file: string, line: int): string = continue result &= editor[i] inc i - if editor.len == 0: - result = "vi" if not filefound: if result[^1] != ' ': result &= ' ' @@ -48,12 +46,19 @@ proc openInEditor*(term: Terminal, config: Config, input: var string): bool = let tmpdir = config.tmpdir if not dirExists(tmpdir): createDir(tmpdir) - let tmpf = tmpdir / "chatmp" & $tmpf_seq + var tmpf = tmpdir / "chatmp" & $tmpf_seq + while fileExists(tmpf): + inc tmpf_seq + tmpf = tmpdir / "chatmp" & $tmpf_seq inc tmpf_seq - writeFile(tmpf, input) + if input != "": + writeFile(tmpf, input) if openEditor(term, config, tmpf): - input = readFile(tmpf) - removeFile(tmpf) - return true + if fileExists(tmpf): + input = readFile(tmpf) + removeFile(tmpf) + return true + else: + return false except IOError: discard |