Created
October 6, 2024 16:21
-
-
Save taiar/69d64e64a412c563128e81239ca5ff72 to your computer and use it in GitHub Desktop.
csv to where sublime plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
[ | |
{"caption": "CSV to Where", "command": "format_as_where"} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime | |
import sublime_plugin | |
class FormatAsWhereCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
# return a list with all lines of the current file | |
lines = self.view.lines(sublime.Region(0, self.view.size())) | |
# join lines as strings with comma and space | |
text = "IN ('" + "', '".join([self.view.substr(line) for line in lines]) + "')" | |
# replace the content of the current file with the formatted text | |
self.view.replace(edit, sublime.Region(0, self.view.size()), text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment