-
Notifications
You must be signed in to change notification settings - Fork 357
Expand file tree
/
Copy path_pb
More file actions
93 lines (81 loc) · 3.17 KB
/
Copy path_pb
File metadata and controls
93 lines (81 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#compdef pb
__pb_hist_names() {
local hist_file="${XDG_CONFIG_DIR:-$HOME/.config}/pb_hist"
[[ -r "$hist_file" ]] || return
local -a names
# strip ":passwd", drop empties, reverse (latest first), then dedup keeping first
names=(${${(f)"$(<$hist_file)"}%%:*})
names=(${names:#})
compadd -- ${(u)${(Oa)names}}
}
# Flags accepted at any position (before OR after the action).
local -a common_args=(
'(-h --help)'{-h,--help}'[print help]'
'(-d --dry)'{-d,--dry}'[dry run]'
'(-v --verbose)'{-v,--verbose}'[verbose]'
'--base-url[Base URL (overrides $PB_DOMAIN)]:url'
)
local -a root_args=(
$common_args
'1:command:->commands'
'*::arguments:->arguments'
)
_arguments -s $root_args && return 0
case "$state" in
(commands)
cmdlist=(
{p,post}":Post paste"
{u,update}":Update paste"
{d,delete}":Delete paste"
{g,get}":Get paste"
)
_describe -t pb-commands 'pb.sh command' cmdlist
;;
(arguments)
case ${line[1]} in
(p|post)
local -a args=(
'(-c --content -)'{-c,--content}'[Content of paste]'
'(-c --content -)-[Read the paste from stdin]'
'(-c --content -)*:paste from file:_files'
'(-e --expire)'{-e,--expire}'[Expiration time]:expiration'
'(-n --name)'{-n,--name}'[Name]:Name of paste'
'(-s --passwd)'{-s,--passwd}'[Password]:Password of paste'
'(-p --private)'{-p,--private}'[Make generated paste name longer for privacy]'
'(-x --clip)'{-x,--clip}'[Clip the url to the clipboard]'
'(-E --encrypt)'{-E,--encrypt}'[Client-side AES-GCM encryption]'
'(-F --filename)'{-F,--filename}'[Filename to store with paste]:filename'
)
_arguments -s $args $common_args
;;
(u|update)
local -a args=(
'(-f -c --file --content -)'{-c,--content}'[Read the paste from file]'
'(-f -c --file --content -)'{-f,--file}'[Content of the paste]:paste from file:_files'
'*:paste name'
'(-e --expire)'{-e,--expire}'[Expiration time]:expiration'
'(-s --passwd)'{-s,--passwd}'[Password]:Password of paste'
'(-x --clip)'{-x,--clip}'[Clip the url to the clipboard]'
'(-E --encrypt)'{-E,--encrypt}'[Client-side AES-GCM encryption]'
'(-F --filename)'{-F,--filename}'[Filename to store with paste]:filename'
)
_arguments -s $args $common_args
;;
(g|get)
local -a args=(
'*:paste name:__pb_hist_names'
'(-o --output)'{-o,--output}'[Output the paste in file]:file:_files'
'(-u --url --meta)'{-u,--url}'[Make a 302 redirection]'
'(-u --url --meta)--meta[Fetch /m/<name> metadata as JSON]'
'(-K --key)'{-K,--key}'[Decryption key (overrides history)]:key'
'--no-decrypt[Do not decrypt encrypted pastes]'
'--save[Save under DIR using server filename]::dir:_files -/'
'(-f --force)'{-f,--force}'[Overwrite existing file without prompting]'
)
_arguments -s $args $common_args
;;
(d|delete)
_arguments -s $common_args
;;
esac
esac