Sublime Forum

Double quotes?

#1

How to use double quotes with ST3? This will not work. And the second one just escapes the quotes.

[
  {
    "keys": ["ctrl+shift+j"],
    "command": "shell_command",
    "args": {
    "command": "xargs -n 1 -L 1 -P 16 -I {} curl -sL -o /dev/null -m 2 -w """{} {size: %{size_download} code: %{http_code}}\n""" {}",
      "region": "stdin",
      "panel": true
    }
  }
]

[
  {
    "keys": ["ctrl+shift+j"],
    "command": "shell_command",
    "args": {
    "command": "xargs -n 1 -L 1 -P 16 -I {} curl -sL -o /dev/null -m 2 -w \"{} {size: %{size_download} code: %{http_code}}\n\" {}",
      "region": "stdin",
      "panel": true
    }
  }
]
0 Likes

#2

–>

"xargs -n 1 -L 1 -P 16 -I {} curl -sL -o /dev/null -m 2 -w \"{} {size: %{size_download} code: %{http_code}}\n\" {}",
0 Likes

#3

Right…

What about this?

rg -N -v "\{([^}]+)\}" --replace "" --mmap --threads 4

Is there an online website to convert strings to compatible JSON? Or a plugin for ST3?
Jsonify? :smiley:

0 Likes

#4

Actually that should be pretty easy just open Tools > Developer > New Plugin… and paste:

import json

import sublime_plugin


class JsonDumpsCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        view = self.view
        indent = view.settings().get("tab_size", 4)
        for sel in view.sel():
            if sel.empty():
                continue
            origin = view.substr(sel)
            try:
                # just format valid json
                json_content = json.loads(origin)
            except:
                # load normal content as string
                json_content = origin
            new_content = json.dumps(
                json_content,
                sort_keys=True,
                indent=indent
            )
            view.replace(edit, sel, new_content)

The reate a keybinding/command/whatever

    {
        "keys": ["ctrl+k", "j"],
        "command": "json_dumps",
    },

Select your text, press the keybinding and get:

"rg -N -v \"\\{([^}]+)\\}\" --replace \"\" --mmap --threads 4"
4 Likes