Allow special history also for :open and :tabopen commands.
This file holds the history of commands and search queries performed via input
box.
.RE
+.I $XDG_CONFIG_HOME/PROJECT/search
+.RS
+This file holds the history of search queries.
+box.
+.RE
.I $XDG_CONFIG_HOME/PROJECT/scripts.js
.RS
This file can be used to run user scripts, that are injected into every paged
gboolean command_history(const Arg* arg)
{
- const int count = vb.state.count ? vb.state.count : 1;
- const gint step = count * arg->i;
- const char* entry = history_get(HISTORY_COMMAND, step);
+ const char* input = GET_TEXT();
+ int step = vb.state.count ? vb.state.count * arg->i : arg->i;
+ const char* entry;
+ char* prefix = NULL;
+
+ /* use the right history type according to current input text */
+ if (!strncmp(input, ":open ", 6)) {
+ entry = history_get(HISTORY_URL, step, input + 6);
+ prefix = ":open ";
+ } else if (!strncmp(input, ":tabopen ", 9)) {
+ entry = history_get(HISTORY_URL, step, input + 9);
+ prefix = ":tabopen ";
+ } else if (*input == ':') {
+ entry = history_get(HISTORY_COMMAND, step, input + 1);
+ prefix = ":";
+ } else if (*input == '/' || *input == '?') {
+ entry = history_get(HISTORY_SEARCH, step, input + 1);
+ prefix = *input == '/' ? "/" : "?";
+ }
if (!entry) {
return FALSE;
}
- command_write_input(entry);
+
+ char* value = g_strconcat(prefix, entry, NULL);
+ command_write_input(value);
+ g_free(value);
return TRUE;
}
/* map history types to files */
static const VbFile file_map[HISTORY_LAST] = {
FILES_COMMAND,
+ FILES_SEARCH,
FILES_HISTORY
};
return history_load(history_get_file_by_type(type));
}
-const char* history_get(HistoryType type, int step)
+const char* history_get(HistoryType type, int step, const char* query)
{
const char* command;
/* get the search prefix only on start of history search */
if (!vb.state.history_active) {
- OVERWRITE_STRING(vb.state.history_prefix, GET_TEXT());
+ OVERWRITE_STRING(vb.state.history_prefix, query);
GList* src = history_load(history_get_file_by_type(type));
typedef enum {
HISTORY_FIRST = 0,
HISTORY_COMMAND = 0,
+ HISTORY_SEARCH,
HISTORY_URL,
HISTORY_LAST
} HistoryType;
void history_cleanup(void);
void history_add(HistoryType type, const char* value);
GList* history_get_all(HistoryType type);
-const char* history_get(HistoryType type, int step);
+const char* history_get(HistoryType type, int step, const char* query);
void history_rewind(void);
void history_list_free(GList** list);
static void vb_inputbox_activate_cb(GtkEntry *entry)
{
const char* text;
- gboolean hist_save = FALSE;
char* command = NULL;
guint16 length = gtk_entry_get_text_length(entry);
a.i = *text == '/' ? VB_SEARCH_FORWARD : VB_SEARCH_BACKWARD;
a.s = (command + 1);
command_search(&a);
- hist_save = TRUE;
+ history_add(HISTORY_SEARCH, command + 1);
break;
case ':':
completion_clean();
vb_process_input((command + 1));
- hist_save = TRUE;
+ history_add(HISTORY_COMMAND, command + 1);
break;
}
- if (hist_save) {
- /* save the command in history */
- history_add(HISTORY_COMMAND, command);
- }
g_free(command);
}
vb.files[FILES_COMMAND] = g_build_filename(path, "command", NULL);
util_create_file_if_not_exists(vb.files[FILES_COMMAND]);
+ vb.files[FILES_SEARCH] = g_build_filename(path, "search", NULL);
+ util_create_file_if_not_exists(vb.files[FILES_SEARCH]);
+
vb.files[FILES_SCRIPT] = g_build_filename(path, "scripts.js", NULL);
vb.files[FILES_USER_STYLE] = g_build_filename(path, "style.css", NULL);
FILES_SCRIPT,
FILES_HISTORY,
FILES_COMMAND,
+ FILES_SEARCH,
FILES_USER_STYLE,
FILES_LAST
} VbFile;