Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can change the action that is performed when you execute a line to alter the command that will be executed. This can be done by defining a function which you then bind to the enter key.</p> <p>Lets first define a function that can add the '> file.txt | cat' ending to any command:</p> <pre><code>function log_and_accept { BUFFER="$BUFFER &gt; file.txt | cat" zle accept-line } </code></pre> <p>The next part is to actually replace the default enter key behaviour with your new function. The default behaviour we are replacing is the accept-line function, and if we look at the <a href="http://www.cs.elte.hu/zsh-manual/zsh_14.html">zle documentation</a>, you will see that accept-line is bound to ^J and ^M.</p> <p>To bind this function to those letters you first need to turn it into a widget:</p> <pre><code>zle -N log_and_accept_widget log_and_accept </code></pre> <p>Then you can bind it, replacing the old behaviour:</p> <pre><code>bindkey '^J' log_and_accept_widget bindkey '^M' log_and_accept_widget </code></pre> <p>Now you will be expanding that command for every single command you do. Every cd, ls, vim etc etc. As such I recommend that you define a couple more functions that actually turn this on and off:</p> <pre><code>function turn_on_logging { bindkey '^J' log_and_accept_widget bindkey '^M' log_and_accept_widget } function turn_off_logging { bindkey '^J' accept-line bindkey '^M' accept-line } zle -N turn_on_logging_widget turn_on_logging zle -N turn_off_logging_widget turn_off_logging bindkey '^P' turn_on_logging_widget bindkey '^O' turn_off_logging_widget </code></pre> <p>I think you should be careful with this. After testing it a little, I quickly grew to dislike it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload