Skip to content
Snippets Groups Projects
Commit fe7d3e0b authored by nimrod's avatar nimrod
Browse files

Some Python3 work.

- Replace urlencode/ urldecode with Python3 instead of Perl.
- A little cleaner json_tool usage.
- A Python3 only (no Python2) AWS region deducation.
parent c1888248
No related branches found
No related tags found
No related merge requests found
...@@ -80,8 +80,6 @@ alias tolower='awk "{print tolower(\$0)}"' ...@@ -80,8 +80,6 @@ alias tolower='awk "{print tolower(\$0)}"'
# shellcheck disable=SC2142 # shellcheck disable=SC2142
alias toupper='awk "{print toupper(\$0)}"' alias toupper='awk "{print toupper(\$0)}"'
alias wifi-portal='curl --silent --fail --write-out "%{redirect_url}" --output /dev/null http://detectportal.firefox.com/success.txt' alias wifi-portal='curl --silent --fail --write-out "%{redirect_url}" --output /dev/null http://detectportal.firefox.com/success.txt'
alias urlencode='perl -MURI::Escape -ne "chomp;print uri_escape(\$_), \"\n\""'
alias urldecode='perl -MURI::Escape -ne "chomp;print uri_unescape(\$_), \"\n\""'
alias transmission-remote='ssh -fNo ExitOnForwardFailure=yes xbmc.shore.co.il && transmission-remote' alias transmission-remote='ssh -fNo ExitOnForwardFailure=yes xbmc.shore.co.il && transmission-remote'
alias kpcli='kpcli --kdb ~/Documents/Database.kdbx' alias kpcli='kpcli --kdb ~/Documents/Database.kdbx'
alias gen-mac="hexdump -n5 -e '\"02\" 5/1 \":%02X\" \"\\n\"' /dev/urandom" alias gen-mac="hexdump -n5 -e '\"02\" 5/1 \":%02X\" \"\\n\"' /dev/urandom"
...@@ -98,6 +96,34 @@ alias screenshot-cleanup='find "$HOME/Pictures" -name "Screenshot from *.png" -d ...@@ -98,6 +96,34 @@ alias screenshot-cleanup='find "$HOME/Pictures" -name "Screenshot from *.png" -d
alias bell='printf \a' alias bell='printf \a'
command -v notify-send > /dev/null || alias notify-send='bell' command -v notify-send > /dev/null || alias notify-send='bell'
urlencode () {
if [ -t 0 ]
then
echo "$@" | urlencode
else
python3 -c '
from sys import stdin
from urllib.parse import quote_plus
for line in stdin.readlines():
print(quote_plus(line.strip()))
'
fi
}
urldecode () {
if [ -t 0 ]
then
echo "$@" | urldecode
else
python3 -c '
from sys import stdin
from urllib.parse import unquote_plus
for line in stdin.readlines():
print(unquote_plus(line.strip()))
'
fi
}
monitor () { monitor () {
if eval "$@" if eval "$@"
then then
...@@ -110,7 +136,7 @@ monitor () { ...@@ -110,7 +136,7 @@ monitor () {
json_tool () { json_tool () {
if [ -t 0 ] if [ -t 0 ]
then then
echo "$@" | python3 -m json.tool | pygmentize -l javascript echo "$@" | json_tool
else else
python3 -m json.tool | pygmentize -l javascript python3 -m json.tool | pygmentize -l javascript
fi fi
...@@ -168,11 +194,7 @@ cyan () { ...@@ -168,11 +194,7 @@ cyan () {
} }
deduce_aws_region () { deduce_aws_region () {
AWS_DEFAULT_REGION="$(python << EOF AWS_DEFAULT_REGION="$(python3 << EOF
from __future__ import print_function
try:
from urllib import urlopen
except ImportError:
from urllib.request import urlopen from urllib.request import urlopen
import json import json
print(json.load(urlopen('http://169.254.169.254/latest/dynamic/instance-identity/document'))['region']) print(json.load(urlopen('http://169.254.169.254/latest/dynamic/instance-identity/document'))['region'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment