Browse Source

Add urle() for urlencode encoding/decoding

Alois Mahdal 3 years ago
parent
commit
0ac602f1e2
1 changed files with 12 additions and 0 deletions
  1. 12
    0
      dotfiles/bash/main.bashrc

+ 12
- 0
dotfiles/bash/main.bashrc View File

@@ -390,6 +390,18 @@ nljoin() {
390 390
       | fixnl -c
391 391
 }
392 392
 
393
+urle() {
394
+    #
395
+    # Encode or decode (if $1 is '-d') message on stdin as URL encode
396
+    #
397
+    local fn=quote
398
+    case $1 in
399
+        -d) fn=unquote ;;
400
+        -*) echo 'usage: urle [-d] <text' >&2; return 2 ;;
401
+    esac
402
+    python3 -c "import sys; from urllib.parse import $fn; print($fn(sys.stdin.read()));"
403
+}
404
+
393 405
 qpr() {
394 406
     #
395 407
     # Encode or decode (if $1 is '-d') message on stdin as Quoted Printable