gboolean command_open(const Arg* arg)
{
- char* uri = NULL;
- gboolean result;
-
- if (!arg->s || arg->s[0] == '\0') {
- Arg a = {arg->i, vb.config.home_page};
- return vb_load_uri(&a);
- }
- /* check for searchengine handles */
- /* split into handle and searchterms */
- char **string = g_strsplit(arg->s, " ", 2);
- if (g_strv_length(string) == 2
- && (uri = searchengine_get_uri(string[0]))
- ) {
- char* term = soup_uri_encode(string[1], "&");
- Arg a = {arg->i, g_strdup_printf(uri, term)};
- result = vb_load_uri(&a);
- g_free(term);
- g_free(a.s);
- } else {
- result = vb_load_uri(arg);
- }
- g_strfreev(string);
-
- return result;
+ return vb_load_uri(arg);
}
/**
gboolean vb_load_uri(const Arg* arg)
{
char* uri;
+ char* part;
char* path = arg->s;
struct stat st;
if (!path) {
- return FALSE;
+ path = vb.config.home_page;
}
g_strstrip(path);
if (!strlen(path)) {
- return FALSE;
+ path = vb.config.home_page;
}
/* check if the path is a file path */
if (stat(path, &st) == 0) {
char* rp = realpath(path, NULL);
uri = g_strdup_printf("file://%s", rp);
+ } else if (!strchr(path, '.') && (part = strchr(path, ' '))) {
+ /* look up for a searchengine */
+ *part = '\0';
+ char* search_uri = searchengine_get_uri(path);
+ char* term = soup_uri_encode(part + 1, "&");
+
+ if (search_uri) {
+ uri = g_strdup_printf(search_uri, term);
+ } else {
+ uri = g_strrstr(path, "://") ? g_strdup(path) : g_strdup_printf("http://%s", path);
+ }
+ g_free(term);
} else {
uri = g_strrstr(path, "://") ? g_strdup(path) : g_strdup_printf("http://%s", path);
}