File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,19 @@ snippets accessible by the token at the project on the standard out.
141
141
This command takes the identifier of an existing snippet as an argument and will
142
142
print out its raw content on the standard out.
143
143
144
+ #### ` search `
145
+
146
+ This command searches for snippets matching the extended regular expressions
147
+ passed through the options and prints their identifiers. Recognised options are:
148
+
149
+ + ` -t ` or ` --title ` is the regex to match against the title of the snippet.
150
+ + ` -d ` or ` --description ` is the regex to match against the description of the
151
+ snippet.
152
+ + ` -f ` or ` --filename ` is the regex to match against the filename of the
153
+ snippet.
154
+ + ` -v ` or ` --visibility ` is the regex to match against the visibility of the
155
+ snippet.
156
+
144
157
#### ` details `
145
158
146
159
This command takes the identifier of an existing snippet and prints out the
Original file line number Diff line number Diff line change @@ -40,4 +40,58 @@ snippet_details() {
40
40
snippet_curl " ${1} " | yush_json
41
41
fi
42
42
fi
43
+ }
44
+
45
+ _snippet_value () {
46
+ printf %s\\ n " $1 " | grep -E " ^/${2} " | cut -d " " -f 3-
47
+ }
48
+
49
+ snippet_search () {
50
+ _title=" .*"
51
+ _description=" .*"
52
+ _filename=" .*"
53
+ _visibility=" .*"
54
+ while [ $# -gt 0 ]; do
55
+ case " $1 " in
56
+ -t | --title)
57
+ _title=$2 ; shift 2;;
58
+ --title=* )
59
+ _title=" ${1#* =} " ; shift 1;;
60
+
61
+ -d | --description)
62
+ _description=$2 ; shift 2;;
63
+ --description=* )
64
+ _description=" ${1#* =} " ; shift 1;;
65
+
66
+ -f | --filename)
67
+ _filename=$2 ; shift 2;;
68
+ --filename=* )
69
+ _filename=" ${1#* =} " ; shift 1;;
70
+
71
+ -v | --visibility)
72
+ _visibility=$2 ; shift 2;;
73
+ --visibility=* )
74
+ _visibility=" ${1#* =} " ; shift 1;;
75
+
76
+ -h | --help)
77
+ usage " " 0;;
78
+
79
+ --)
80
+ shift ; break ;;
81
+ -* )
82
+ usage " Unknown option: $1 !" ;;
83
+ * )
84
+ break ;;
85
+ esac
86
+ done
87
+
88
+ for _s in $( snippet_list) ; do
89
+ _json=$( snippet_details " $_s " )
90
+ if _snippet_value " $_json " " title" | grep -Eq " $_title " \
91
+ && _snippet_value " $_json " " description" | grep -Eq " $_description " \
92
+ && _snippet_value " $_json " " file_name" | grep -Eq " $_filename " \
93
+ && _snippet_value " $_json " " visibility" | grep -Eq " $_visibility " ; then
94
+ printf %d\\ n " $_s "
95
+ fi
96
+ done
43
97
}
Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ Commands:
69
69
specified)
70
70
get|read Get raw content of snippet
71
71
details Get JSON or parsed JSON content of snippet
72
+ search Search for matching snippet
72
73
add|create Create new snippet
73
74
update|change Change existing snippet
74
75
delete|remove Delete existing snippet
@@ -196,6 +197,8 @@ case "$cmd" in
196
197
snippet_get " $@ " ;;
197
198
details)
198
199
snippet_details " $@ " ;;
200
+ search)
201
+ snippet_search " $@ " ;;
199
202
create|add)
200
203
snippet_create " $@ " ;;
201
204
update|change)
You can’t perform that action at this time.
0 commit comments