Обновление ohmyzsh
This commit is contained in:
@@ -2,41 +2,47 @@
|
||||
|
||||
Handy command line tools for dealing with json data.
|
||||
|
||||
## Tools
|
||||
To use it, add `jsontools` to the plugins array in your zshrc file:
|
||||
|
||||
- **pp_json** - pretty prints json
|
||||
- **is_json** - returns true if valid json; false otherwise
|
||||
- **urlencode_json** - returns a url encoded string for the given json
|
||||
- **urldecode_json** - returns decoded json for the given url encoded string
|
||||
```zsh
|
||||
plugins=(... jsontools)
|
||||
```
|
||||
|
||||
## Usage
|
||||
Usage is simple...just take your json data and pipe it into the appropriate jsontool.
|
||||
```sh
|
||||
<json data> | <jsontools tool>
|
||||
```
|
||||
## Examples
|
||||
|
||||
##### pp_json
|
||||
Usage is simple... just take your json data and pipe it into the appropriate jsontool:
|
||||
|
||||
- `pp_json`: pretty prints json.
|
||||
- `is_json`: returns true if valid json; false otherwise.
|
||||
- `urlencode_json`: returns a url encoded string for the given json.
|
||||
- `urldecode_json`: returns decoded json for the given url encoded string.
|
||||
|
||||
### Examples
|
||||
|
||||
- **pp_json**:
|
||||
|
||||
```sh
|
||||
# curl json data and pretty print the results
|
||||
curl https://coderwall.com/bobwilliams.json | pp_json
|
||||
```
|
||||
|
||||
##### is_json
|
||||
- **is_json**:
|
||||
|
||||
```sh
|
||||
# pretty print the contents of an existing json file
|
||||
# Validate if file's content conforms to a valid JSON schema
|
||||
less data.json | is_json
|
||||
```
|
||||
|
||||
##### urlencode_json
|
||||
- **urlencode_json**:
|
||||
|
||||
```sh
|
||||
# json data directly from the command line
|
||||
echo '{"b":2, "a":1}' | urlencode_json
|
||||
```
|
||||
|
||||
##### urldecode_json
|
||||
- **urldecode_json**:
|
||||
|
||||
```sh
|
||||
# url encoded string to decode
|
||||
echo '%7B%22b%22:2,%20%22a%22:1%7D%0A' | urldecode_json
|
||||
```
|
||||
```
|
||||
|
||||
@@ -11,9 +11,10 @@ if [[ $(whence node) != "" && ( "x$JSONTOOLS_METHOD" = "x" || "x$JSONTOOLS_METH
|
||||
alias urlencode_json='xargs -0 node -e "console.log(encodeURIComponent(process.argv[1]))"'
|
||||
alias urldecode_json='xargs -0 node -e "console.log(decodeURIComponent(process.argv[1]))"'
|
||||
elif [[ $(whence python) != "" && ( "x$JSONTOOLS_METHOD" = "x" || "x$JSONTOOLS_METHOD" = "xpython" ) ]]; then
|
||||
alias pp_json='python -mjson.tool'
|
||||
alias pp_json='python -c "import sys; del sys.path[0]; import runpy; runpy._run_module_as_main(\"json.tool\")"'
|
||||
alias is_json='python -c "
|
||||
import json, sys;
|
||||
import sys; del sys.path[0];
|
||||
import json;
|
||||
try:
|
||||
json.loads(sys.stdin.read())
|
||||
except ValueError, e:
|
||||
@@ -22,11 +23,13 @@ else:
|
||||
print True
|
||||
sys.exit(0)"'
|
||||
alias urlencode_json='python -c "
|
||||
import urllib, json, sys;
|
||||
import sys; del sys.path[0];
|
||||
import urllib, json;
|
||||
print urllib.quote_plus(sys.stdin.read())
|
||||
sys.exit(0)"'
|
||||
alias urldecode_json='python -c "
|
||||
import urllib, json, sys;
|
||||
import sys; del sys.path[0];
|
||||
import urllib, json;
|
||||
print urllib.unquote_plus(sys.stdin.read())
|
||||
sys.exit(0)"'
|
||||
elif [[ $(whence ruby) != "" && ( "x$JSONTOOLS_METHOD" = "x" || "x$JSONTOOLS_METHOD" = "xruby" ) ]]; then
|
||||
@@ -36,4 +39,4 @@ elif [[ $(whence ruby) != "" && ( "x$JSONTOOLS_METHOD" = "x" || "x$JSONTOOLS_MET
|
||||
alias urldecode_json='ruby -e "require \"uri\"; puts URI.unescape(STDIN.read)"'
|
||||
fi
|
||||
|
||||
unset JSONTOOLS_METHOD
|
||||
unset JSONTOOLS_METHOD
|
||||
|
||||
Reference in New Issue
Block a user