summaryrefslogtreecommitdiffstats
path: root/cmd.c
diff options
context:
space:
mode:
authornicm <nicm>2016-10-13 10:01:49 +0000
committernicm <nicm>2016-10-13 10:01:49 +0000
commit4d9e6ea3106ea06afa4583254549d525b31ed277 (patch)
tree8532ce29088d6b65b9615271dd6b5fdaa9984ca2 /cmd.c
parent05dac2e42c257c87d1fdbc70d0d976f918d77cfd (diff)
Some improvements and bug fixes for hooks:
- Prepare the state again before the "after" hooks are run, because the command may have killed or moved windows. - Use the hooks list from the newly prepared target, not the old hooks list (only matters for new-session really). - Correctly detect an invalid current state and ignore it in cmd_find_target ("killw; swapw"). - Change neww, new, killp, killw, splitw, swapp, swapw to update the current state (used if no explicit target is given) to something more useful after they have finished. For example, neww changes it to the newly created window. Hooks are still relatively new and primitive so there are likely to be more changes to come. Parts based on bug reports from Uwe Werler and Iblis Lin.
Diffstat (limited to 'cmd.c')
-rw-r--r--cmd.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/cmd.c b/cmd.c
index f5889a7e..7964f654 100644
--- a/cmd.c
+++ b/cmd.c
@@ -456,12 +456,15 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
current = &parent->state.tflag;
else if (c == 's')
current = &parent->state.sflag;
- } else {
+ }
+ if (current == NULL || !cmd_find_valid_state(current)) {
error = cmd_find_current(&tmp, cmdq, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET)
return (-1);
current = &tmp;
}
+ if (!cmd_find_empty_state(current) && !cmd_find_valid_state(current))
+ fatalx("invalid current state");
switch (flag) {
case CMD_NONE:
@@ -558,6 +561,13 @@ cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq, struct cmd_q *parent)
if (error != 0)
return (error);
+ if (!cmd_find_empty_state(&state->tflag) &&
+ !cmd_find_valid_state(&state->tflag))
+ fatalx("invalid -t state");
+ if (!cmd_find_empty_state(&state->sflag) &&
+ !cmd_find_valid_state(&state->sflag))
+ fatalx("invalid -s state");
+
return (0);
}