same but a single parameter is user defined.
.TP
.BI "shortcut-add " "SHORTCUT" "=" "URI"
-Adds a shortcut with the \fISHORTCUT\fP and search \fIURI\fP. The \fIURI\fP
+Adds a shortcut with the \fISHORTCUT\fP and \fIURI\fP template. The \fIURI\fP
can contain multiple placeholders $0-$9 that will be filled by the parameters
-given when the shortcut is called. The $0 placeholder will be filled with all
-given parameters (this is useful for search engines), all other placeholders $1
-to $9 will be replaced by the numbered argument.
+given when the shortcut is called. The parameters given when the shortcut is
+called will be split into as many parameters like the highest used
+placeholder.
Example 1: shortcut-add dl=https://duckduckgo.com/lite/?q=$0 to setup a
search engine. Can be called by `:open dl my search phrase'.
-Example 2: shortcut-add gh=https://github.com/$1/$2 to build urls from given
+Example 2: shortcut-add gh=https://github.com/$0/$1 to build urls from given
parameters. Can be called `:open gh fanglingsu vimb'.
.TP
.BI "shortcut-remove " "SHORTCUT"
char *shortcut_get_uri(const char *string)
{
const char *tmpl, *query = NULL;
+ char *uri, **parts, ph[3] = "$0";
+ unsigned int len;
+ int max;
tmpl = shortcut_lookup(string, &query);
if (!tmpl) {
return NULL;
}
- char *qs, *uri, **parts, ph[3] = "$0";
- unsigned int len;
-
- /* replace $0 with all parameters */
- qs = soup_uri_encode(query, "&");
- uri = util_str_replace(ph, qs, tmpl);
- g_free(qs);
-
- int max = get_max_placeholder(tmpl);
+ uri = g_strdup(tmpl);
+ max = get_max_placeholder(tmpl);
/* skip if no placeholders found */
if (max < 0) {
return uri;
len = g_strv_length(parts);
for (unsigned int n = 0; n < len; n++) {
- char *new;
- ph[1] = n + '1';
+ char *new, *qs;
+ ph[1] = n + '0';
qs = soup_uri_encode(parts[n], "&");
new = util_str_replace(ph, qs, uri);
g_free(qs);