summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard R. Link <brlink@debian.org>2008-06-10 14:24:05 +0200
committerShawn <sabetts@juicebox.(none)>2008-10-22 14:18:41 -0700
commitd11f0735321bc725441fbc1dec04e363d07c987a (patch)
treefa0e3a3383e92ced6d719b52952fa0bb591e0232
parentd801644502adf42570e9a5b75fcaa013f613fc5a (diff)
downloadratpoison-d11f0735321bc725441fbc1dec04e363d07c987a.zip
SHELLCMD history only shows execute arguments, things to execute are stored as in history as execute commands
-rw-r--r--src/actions.c36
-rw-r--r--src/history.c32
2 files changed, 55 insertions, 13 deletions
diff --git a/src/actions.c b/src/actions.c
index df075d9..221c1cd 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -1676,9 +1676,21 @@ exec_completions (char *str)
}
static cmdret *
-read_shellcmd (struct argspec *spec, struct sbuf *s, struct cmdarg **arg)
+read_shellcmd (struct argspec *spec, struct sbuf *s, struct cmdarg **arg, const char *command_name)
{
- return read_string (spec, s, hist_SHELLCMD, exec_completions, arg);
+ cmdret *ret;
+
+ ret = read_string (spec, s, hist_SHELLCMD, exec_completions, arg);
+#ifdef HAVE_HISTORY
+ if (command_name && !ret) {
+ /* store for command history */
+ char *s = xmalloc (strlen(command_name) + strlen((*arg)->string) + 2);
+ sprintf (s, "%s %s", command_name, (*arg)->string);
+ history_add (hist_COMMAND, s);
+ free(s);
+ }
+#endif
+ return ret;
}
/* Return NULL on abort/failure. */
@@ -2101,7 +2113,7 @@ read_number (struct argspec *spec, struct sbuf *s, struct cmdarg **arg)
}
static cmdret *
-read_arg (struct argspec *spec, struct sbuf *s, struct cmdarg **arg)
+read_arg (struct argspec *spec, struct sbuf *s, struct cmdarg **arg, const char *command_name)
{
cmdret *ret = NULL;
@@ -2128,7 +2140,7 @@ read_arg (struct argspec *spec, struct sbuf *s, struct cmdarg **arg)
ret = read_command (spec, s, arg);
break;
case arg_SHELLCMD:
- ret = read_shellcmd (spec, s, arg);
+ ret = read_shellcmd (spec, s, arg, command_name);
break;
case arg_WINDOW:
ret = read_window (spec, s, arg);
@@ -2153,7 +2165,7 @@ read_arg (struct argspec *spec, struct sbuf *s, struct cmdarg **arg)
/* Return -1 on failure. Return the number of args on success. */
static cmdret *
parsed_input_to_args (int num_args, struct argspec *argspec, struct list_head *list,
- struct list_head *args, int *parsed_args)
+ struct list_head *args, int *parsed_args, const char *command_name)
{
struct sbuf *s;
struct cmdarg *arg;
@@ -2167,7 +2179,7 @@ parsed_input_to_args (int num_args, struct argspec *argspec, struct list_head *l
list_for_each_entry (s, list, node)
{
if (*parsed_args >= num_args) break;
- ret = read_arg (&argspec[*parsed_args], s, &arg);
+ ret = read_arg (&argspec[*parsed_args], s, &arg, command_name);
/* If there was an error, then abort. */
if (ret)
return ret;
@@ -2182,20 +2194,20 @@ parsed_input_to_args (int num_args, struct argspec *argspec, struct list_head *l
/* Prompt the user for missing arguments. Returns non-zero on
failure. 0 on success. */
static cmdret *
-fill_in_missing_args (struct user_command *cmd, struct list_head *list, struct list_head *args)
+fill_in_missing_args (struct user_command *cmd, struct list_head *list, struct list_head *args, const char *command_name)
{
cmdret *ret;
struct cmdarg *arg;
int i = 0;
- ret = parsed_input_to_args (cmd->num_args, cmd->args, list, args, &i);
+ ret = parsed_input_to_args (cmd->num_args, cmd->args, list, args, &i, command_name);
if (ret)
return ret;
/* Fill in the rest of the required arguments. */
for(; i < cmd->i_required_args; i++)
{
- ret = read_arg (&cmd->args[i], NULL, &arg);
+ ret = read_arg (&cmd->args[i], NULL, &arg, command_name);
if (ret)
return ret;
list_add_tail (&arg->node, args);
@@ -2468,11 +2480,11 @@ command (int interactive, char *data)
/* Interactive commands prompt the user for missing args. */
if (interactive)
- result = fill_in_missing_args (uc, &head, &args);
+ result = fill_in_missing_args (uc, &head, &args, uc->name);
else
{
int parsed_args;
- result = parsed_input_to_args (uc->num_args, uc->args, &head, &args, &parsed_args);
+ result = parsed_input_to_args (uc->num_args, uc->args, &head, &args, &parsed_args, uc->name);
}
if (result == NULL)
@@ -5222,7 +5234,7 @@ cmd_set (int interactive, struct cmdarg **args)
if (result)
goto failed;
result = parsed_input_to_args (ARG(0,variable)->nargs, ARG(0,variable)->args,
- &head, &arglist, &parsed_args);
+ &head, &arglist, &parsed_args, NULL);
if (result)
goto failed;
/* 0 or nargs is acceptable */
diff --git a/src/history.c b/src/history.c
index 28292f6..4178cf9 100644
--- a/src/history.c
+++ b/src/history.c
@@ -86,7 +86,7 @@ history_add (int history_id, char *item)
{
HIST_ENTRY *h;
- if (history_id == hist_NONE)
+ if (history_id == hist_NONE || history_id == hist_SHELLCMD)
return;
h = history_get (history_length);
@@ -98,16 +98,39 @@ history_add (int history_id, char *item)
add_history (item);
}
+static const char *
+extract_shell_part (const char *p)
+{
+ if (strncmp(p, "exec", 4) &&
+ strncmp(p, "verbexec", 8))
+ return NULL;
+ while( *p && !isspace(*p) )
+ p++;
+ while( *p && isspace(*p) )
+ p++;
+ if (*p)
+ return p;
+ return NULL;
+}
+
const char *
history_previous (int history_id)
{
HIST_ENTRY *h = NULL;
+ const char *p;
if (history_id == hist_NONE)
return NULL;
h = previous_history();
+ if (history_id == hist_SHELLCMD) {
+ p = NULL;
+ while( h && h->line && !(p = extract_shell_part(h->line)))
+ h = previous_history();
+ return p;
+ }
+
return h ? h->line : NULL;
}
@@ -115,12 +138,19 @@ const char *
history_next (int history_id)
{
HIST_ENTRY *h = NULL;
+ const char *p;
if (history_id == hist_NONE)
return NULL;
h = next_history();
+ if (history_id == hist_SHELLCMD) {
+ p = NULL;
+ while( h && h->line && !(p = extract_shell_part(h->line)))
+ h = next_history();
+ return p;
+ }
return h ? h->line : NULL;
}