lib/textbringer/commands/files.rb in textbringer-1.0.3 vs lib/textbringer/commands/files.rb in textbringer-1.0.4
- old
+ new
@@ -1,11 +1,11 @@
require "editorconfig"
module Textbringer
module Commands
define_command(:find_file, doc: "Open or create a file.") do
- |file_name = read_file_name("Find file: ")|
+ |file_name = read_file_name("Find file: ", default: (Buffer.current.file_name ? File.dirname(Buffer.current.file_name) : Dir.pwd) + "/")|
config = EditorConfig.load_file(file_name)
buffer = Buffer.find_file(file_name)
if buffer.new_file?
message("New file")
end
@@ -84,15 +84,16 @@
message("Wrote #{Buffer.current.file_name}")
end
define_command(:write_file,
doc: "Save the current buffer as the specified file.") do
- |file_name = read_file_name("Write file: ")|
+ |file_name = read_file_name("Write file: ",
+ default: Buffer.current.file_name)|
if File.directory?(file_name)
file_name = File.expand_path(Buffer.current.name, file_name)
end
if File.exist?(file_name)
- unless y_or_n?("File `#{file_name}' exists; overwrite?")
+ unless y_or_n?("File exists; overwrite?")
message("Cancelled")
next
end
end
Buffer.current.save(file_name)