From 3f2841d1092b4efc9fc8d5b814d04563c9c88696 Mon Sep 17 00:00:00 2001 From: TheSecEng Date: Fri, 17 Apr 2020 22:43:01 -0400 Subject: [PATCH] implement: jq path setting --- Pretty JSON.sublime-settings | 3 ++- PrettyJson.py | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Pretty JSON.sublime-settings b/Pretty JSON.sublime-settings index 5b8e124..37ffa1d 100644 --- a/Pretty JSON.sublime-settings +++ b/Pretty JSON.sublime-settings @@ -8,5 +8,6 @@ "keep_arrays_single_line": false, "max_arrays_line_length": 120, "pretty_on_save": false, - "validate_on_save": true + "validate_on_save": true, + "jq_binary": "jq" } \ No newline at end of file diff --git a/PrettyJson.py b/PrettyJson.py index b8067f0..bae45d2 100644 --- a/PrettyJson.py +++ b/PrettyJson.py @@ -27,7 +27,7 @@ SUBLIME_MAJOR_VERSION = int(sublime.version()) / 1000 jq_exits = False jq_init = False - +jq_path = str() """ for OSX we need to manually add brew bin path so jq can be found """ if sys.platform != "win32" and "/usr/local/bin" not in os.environ["PATH"]: @@ -38,20 +38,20 @@ if sys.platform != "win32" and "/usr/local/bin" not in os.environ["PATH"]: def check_jq(): - global jq_exits - global jq_init + global jq_exits, jq_init, jq_path if not jq_init: jq_init = True + jq_path = s.get("jq_binary", "jq") try: # checking if ./jq tool is available so we can use it - s = subprocess.Popen( - ["jq", "--version"], + jq = subprocess.Popen( + [jq_path, "--version"], stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, ) - out, err = s.communicate() + out, err = jq.communicate() jq_exits = True except OSError: os_exception = sys.exc_info()[1] @@ -334,7 +334,7 @@ class JqPrettyJson(sublime_plugin.WindowCommand): def done(self, query): try: p = subprocess.Popen( - ["jq", query], + [jq_path, query], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE,