Add url command to {en,de}code text
This commit is contained in:
parent
1121b9a193
commit
e158d0f6d1
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
# Ignore all plugin files in subdirectories
|
# Ignore all plugin files in subdirectories
|
||||||
*/
|
zsh-*/
|
||||||
local
|
local
|
||||||
|
@ -86,6 +86,10 @@
|
|||||||
dest: ~/.local/bin/cmake-uninstall
|
dest: ~/.local/bin/cmake-uninstall
|
||||||
- src: ~/.config/zsh/$
|
- src: ~/.config/zsh/$
|
||||||
dest: ~/.local/bin/$
|
dest: ~/.local/bin/$
|
||||||
|
- src: ~/.config/zsh/url/url
|
||||||
|
dest: ~/.local/bin/url
|
||||||
|
- src: ~/.config/zsh/url/_url
|
||||||
|
dest: ~/.local/share/zsh/site-functions/_url
|
||||||
|
|
||||||
- name: zsh get absolute path
|
- name: zsh get absolute path
|
||||||
shell: command -v zsh
|
shell: command -v zsh
|
||||||
|
22
url/_url
Normal file
22
url/_url
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#compdef url
|
||||||
|
|
||||||
|
_url() {
|
||||||
|
local ret=1 context curcontext="$curcontext" state line
|
||||||
|
typeset -A opt_args
|
||||||
|
|
||||||
|
_arguments -C -w -s \
|
||||||
|
'(-h --help)'{-h,--help}'[show this help message and exit]' \
|
||||||
|
'1: :->command'
|
||||||
|
|
||||||
|
case $state in
|
||||||
|
(command)
|
||||||
|
declare -a commands
|
||||||
|
local commands=(
|
||||||
|
encode:'encode unencoded text'
|
||||||
|
decode:'decode encoded text'
|
||||||
|
)
|
||||||
|
_describe -t commands command commands && ret=0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
22
url/url
Executable file
22
url/url
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
from urllib import parse
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
cli = ArgumentParser(description=__doc__)
|
||||||
|
cli.add_argument('command', choices=['encode', 'decode'])
|
||||||
|
cli.add_argument('text')
|
||||||
|
args = cli.parse_args()
|
||||||
|
{
|
||||||
|
'encode': parse.quote,
|
||||||
|
'decode': parse.unquote,
|
||||||
|
}[args.command](args.text)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
exit(130)
|
Loading…
x
Reference in New Issue
Block a user