diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e73bfc..3c05c3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## 0.3.1 + +### Changes + +* Update temp snippet TOML file to include instructions for escaping quotes in commands and documentation + +### Bugfixes + +* Escape quotes in commands, documentation, and snippet name when editing a snippet +* Remove debug output after saving an edited snippet +* Always create a new temp snippet file even when it exists to prevent editing the wrong snippet + ## 0.3.0 ### Features diff --git a/Makefile b/Makefile index 45a7ca0..c1ca92f 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,10 @@ install: build | $(INSTALL_DIR) @rm -f $(SNIPCLI_SYSTEM) @cp $(SNIPCLI) $(SNIPCLI_SYSTEM) +cp: + @rm -f $(SNIPCLI_SYSTEM) + @cp $(SNIPCLI) $(SNIPCLI_SYSTEM) + link: build | $(INSTALL_DIR) @echo "Symlinking $(SNIPCLI) to $(SNIPCLI_SYSTEM)" @ln -s $(SNIPCLI) $(SNIPCLI_SYSTEM) @@ -39,4 +43,4 @@ clean: rm -rf $(SNIPCLI) distclean: - rm -rf $(SNIPCLI) .crystal .shards libs lib \ No newline at end of file + rm -rf $(SNIPCLI) .crystal .shards libs lib diff --git a/shard.yml b/shard.yml index 07327d8..32b95cc 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: cli -version: 0.3.0 +version: 0.3.1 authors: - Mitchell Stanley diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 531b14d..7792aa4 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: snipcli -version: 0.3.0 +version: 0.3.1 summary: Shell Snippet organiser description: > Snipcli is a commandline interface for managing shell commands. Sync commands with your Snipline account or use in guest mode. Snipline lets you dynamically change command parameters easily so you never have to remember how to build a command. diff --git a/spec/services/migrator_spec.cr b/spec/services/migrator_spec.cr index 64f2945..634c8b8 100644 --- a/spec/services/migrator_spec.cr +++ b/spec/services/migrator_spec.cr @@ -1,5 +1,4 @@ describe SniplineCli::Services::Migrator do - it "should create and migrate a DB from scratch" do File.exists?("./test.db").should eq(false) SniplineCli::Services::Migrator.run diff --git a/src/snipline_cli.cr b/src/snipline_cli.cr index 979d0a9..b66fcda 100644 --- a/src/snipline_cli.cr +++ b/src/snipline_cli.cr @@ -26,7 +26,7 @@ module Repo end module SniplineCli - VERSION = "0.3.0" + VERSION = "0.3.1" def self.config Config.config diff --git a/src/snipline_cli/services/edit_snippet.cr b/src/snipline_cli/services/edit_snippet.cr index 066c7b3..f9a446f 100644 --- a/src/snipline_cli/services/edit_snippet.cr +++ b/src/snipline_cli/services/edit_snippet.cr @@ -16,7 +16,9 @@ module SniplineCli system("#{ENV["EDITOR"]} #{File.expand_path("#{config.get("general.temp_dir")}/temp.toml")}") snippet_attributes = temp_file.read snippet.name = snippet_attributes.name - snippet.real_command = snippet_attributes.real_command + snippet.real_command = snippet_attributes.real_command.strip + log.info(snippet.real_command.not_nil!) + log.info(snippet_attributes.real_command.not_nil!) snippet.documentation = snippet_attributes.documentation snippet.tags = (snippet_attributes.tags.nil?) ? nil : snippet_attributes.tags.not_nil!.join(",") snippet.snippet_alias = snippet_attributes.snippet_alias diff --git a/src/snipline_cli/services/snipline_api.cr b/src/snipline_cli/services/snipline_api.cr index f7de554..e2386d1 100644 --- a/src/snipline_cli/services/snipline_api.cr +++ b/src/snipline_cli/services/snipline_api.cr @@ -76,14 +76,9 @@ module SniplineCli::Services "%F %T", Time::Location::UTC ) - puts "cloud #{cloud_updated_at}" - local_snippet = Repo.get_by(Snippet, cloud_id: response.id.not_nil!) - if local_snippet - puts "local #{local_snippet.updated_at}" - end + Repo.get_by(Snippet, cloud_id: response.id.not_nil!) - q = Repo.raw_exec("UPDATE snippets SET updated_at=? WHERE cloud_id=?", cloud_updated_at, response.id) - puts q.inspect + Repo.raw_exec("UPDATE snippets SET updated_at=? WHERE cloud_id=?", cloud_updated_at, response.id) end def delete(snippet) diff --git a/src/snipline_cli/services/temp_snippet_editor_file.cr b/src/snipline_cli/services/temp_snippet_editor_file.cr index dda4d18..732b78b 100644 --- a/src/snipline_cli/services/temp_snippet_editor_file.cr +++ b/src/snipline_cli/services/temp_snippet_editor_file.cr @@ -9,8 +9,9 @@ module SniplineCli::Services # This file uses TOML syntax and will be processed after the file is saved and closed # Fill in the below options and save+quit to continue name = "" +# Tip: When working with quotes make sure to escape doubles with \\ or switch to ''' real_command = """ -echo 'hello, world' +echo 'hello, World' """ documentation = """ This section supports **Markdown** @@ -26,12 +27,13 @@ sync_to_cloud = #{SniplineCli.config.get("api.token") == "" ? "false" : "true"} @template = %<# Welcome to the terminal-based snippet editor # This file uses TOML syntax and will be processed after the file is saved and closed # Fill in the below options and save+quit to continue -name = "#{snippet.name}" +name = "#{snippet.name ? snippet.name.not_nil!.gsub("\"", "\\\"") : ""}" +# Tip: When working with quotes make sure to escape doubles with \\ or switch to ''' real_command = """ -#{snippet.real_command} +#{snippet.real_command ? snippet.real_command.not_nil!.gsub("\"", "\\\"") : ""} """ documentation = """ -#{snippet.documentation} +#{snippet.documentation ? snippet.documentation.not_nil!.gsub("\"", "\\\"") : ""} """ is_pinned = #{snippet.is_pinned} snippet_alias = "#{snippet.snippet_alias}" @@ -42,9 +44,7 @@ sync_to_cloud = #{SniplineCli.config.get("api.token") == "" ? "false" : "true"} def create config = SniplineCli.config - unless File.exists?(File.expand_path("#{config.get("general.temp_dir")}/temp.toml")) - File.write(File.expand_path("#{config.get("general.temp_dir")}/temp.toml"), @template) - end + File.write(File.expand_path("#{config.get("general.temp_dir")}/temp.toml"), @template) end def read