Skip to content

Conversation

@x4lldux
Copy link
Contributor

@x4lldux x4lldux commented Jun 4, 2019

Runs *pre-exec-hook* & *post-exec-hook* functions before/after execution of a line. Can be used to time how long a command took:

(var *last-command-duration* 0)
(var last-command-start 0)

(var *pre-exec-hook* (fn [&] (set last-command-start (os/clock))))
(var *post-exec-hook* (fn [&]
                        (set *last-command-duration*
                             (- (os/clock) last-command-start))))

@andrewchambers
Copy link
Owner

I don't fully understand the use for this feature, if I want to time something usually I would just write a time function.

@x4lldux
Copy link
Contributor Author

x4lldux commented Jun 4, 2019

Borrowed the idea from ZSH. It's usually used to enhance prompt and timing is just an example (though I'm often wandering how long does something takes only after starting it ;) ). This is needed for another PR which allows cd - go to previous directory.

@andrewchambers
Copy link
Owner

I understand - I am still unsure, I will need to think about it and read the zsh documentation.

@andrewchambers
Copy link
Owner

It seems to me this patch breaks multi line input.

@x4lldux
Copy link
Contributor Author

x4lldux commented Jun 5, 2019

Should be easy to fix. Basically need to do the same thing you do in want-implicit-parens and detect that. I'll test it in few days.

@andrewchambers
Copy link
Owner

Right, I am leaning towards allowing the repl changes to hide the exit codes, in which case that fix may be able to go there.

@pauldub
Copy link

pauldub commented Jun 5, 2019

There is a kind of hook commonly found in shells which is executed right before showing the prompt (and sometimes also after showing it).

This is used by direnv integrations, which I must currently call in my prompt function.

For reference:

@x4lldux
Copy link
Contributor Author

x4lldux commented Jun 5, 2019

@pauldub You're right, equivalent of $PROMPT_COMMAND/precmd_function should be added. Calling direnv in *prompt* is kind a hackish and entangles concerns.

@x4lldux x4lldux changed the title Run hook functions before & after line execution WIP: Run hook functions before & after line execution Jun 5, 2019
@andrewchambers
Copy link
Owner

I like direnv, so that is a good argument for me.

@x4lldux
Copy link
Contributor Author

x4lldux commented Jun 6, 2019

Once changes to repl in #161 are done, I will update this & add precmd hook also.

@andrewchambers
Copy link
Owner

I would prefer on-crash be renamed to on-error or something else, it isn't necessarily a 'crash'. I know one use for this hook is what nixos does, which is to offer a list of packages for a user to install if a binary is missing.

@x4lldux
Copy link
Contributor Author

x4lldux commented Jun 6, 2019

Sure, so *post-crash-hook* -> *post-error-hook*?
Fefora has something similar. Use cases for those hooks are many! I saw a precmd hook function that changes terminal's profile so the background is red when you ssh to a remote server just to be extra alert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants