Commits

Randy Stauner committed 8bd83d0

Modify python's json.tool to change the indent to 2

Comments (0)

Files changed (2)

home/.bashrc.d/python.bashrc

 
 export PIP_DOWNLOAD_CACHE=$HOME/python/pip-downloads
 
-alias json_tool='python -m json.tool'
+[[ -f ~/bin/contrib/json_tool ]] || alias json_tool='python -m json.tool'
 
 export VIRTUAL_ENV_DISABLE_PROMPT=1
 source_rc_files ~/python/venv/local/bin/activate

scripts/contrib.sh

 dl_bin  hub     http://defunkt.io/hub/standalone
 dl_bin  viack   https://github.com/tsibley/viack/raw/master/viack
 
+# python
+
 pipc="$completion/pip.bashrc"
 test -s "$pipc" || pip completion --bash > "$pipc"
+
+json_tool="$bin/json_tool"
+if ! [[ -f "$json_tool" ]]; then
+  # Use pydoc to find the file.
+  jtpy="`pydoc json.tool | awk '{ if( found ){ print $1; exit } } /FILE/ { found=1 }'`"
+  if [[ -f "$jtpy" ]]; then
+    # Insert a shebang and change the indent level.
+    sed -e '1 i #!/usr/bin/env python' -e 's/indent=4/indent=2/' "$jtpy" > "$json_tool"
+    # Set exec bit.
+    chmod 0755 "$json_tool"
+  fi
+fi