Skip to content

πŸ™Š Zsh Zle plugin to quietly run a command 🀫

License

Notifications You must be signed in to change notification settings

AdrieanKhisbe/zsh-quiet-accept-line

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

55 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Zsh Quiet-Accept-Line

Tag Version Build Status License: MIT

This Zsh plugin enables you to run typed zsh command without triggering new prompt, history entry, or having output being outputed.

Here is a (now a outdated πŸ“œ)_) preview 🎬:

asciicast

Usage

This plugins define several zle widgets to run commands from the shell as variant of classic accept-line:

  • quiet-accept-line: run the current typed command, without output a new prompt (it removes and rewrite command)

    • bound to C-x RET/C-x C-m, ESC ENTER, (this is Alt enter on macos). Configurable with ZLE_QAL_QUIET_KEY
    • output can be piped to a custom program/function with ZLE_QAL_COMMAND
  • pager-accept-line: run the current typed command outputing output in pager, preserve(restore) existing prompt

    • bound to both C-x C-RET/C-x C-m, ESC CTRL-ENTER AND A-C-m, CTRL-ALT-ENTER (overridable with ZLE_QAL_PAGER_KEY and ZLE_QAL_PAGER_KEY2)
    • pager configurable with ZLE_QAL_PAGER, default to less
  • compact-accept-line: run the current typed command persisting a more compact prompt

    • bound to \C-N/C-n,(overridable with ZLE_QAL_COMPACT_KEY)
    • compact prompt default to $ bold, configurable with ZLE_QAL_COMPACT_PROMPT
  • silent-accept-line: run the current typed command, without output a new prompt. output wil be suppressed

    • bound to ^X^\C-N aka ESC C-N (overridable with ZLE_QAL_SILENT_KEY)
    • content is dump in a temporary file (/tmp/zsh-quiet-accept-line-silent-$$.log pattern). It can be configured with ZLE_QAL_SILENT_DUMP_FILE or disabled setting this env var to /dev/null
  • last-quiet-accept-line bound to C-x C-k: restore to the prompt the last command that was run with `quiet/silent-accept-line``

Optionaly status code of the quietly runned command can be display. To do so, set ZLE_QAL_STATUS_DISPLAY to true, on or yes. (QAL stands for Quiet Accept Line)

Also note, after running a command, the eventual commands that where pushed with an ESC-Q are restored.

Installation

Just source quiet-accept-line content, or if you use a plugin manager set adrieankhisbe/zsh-quiet-accept-line as plugin:

  • for antigen, just add zsh-quiet-accept-line to your bundles as adrieankhisbe/zsh-quiet-accept-line antigen bundle adrieankhisbe/zsh-quiet-accept-line
  • same for antidote and antibody
  • for zplug, add zplug "adrieankhisbe/zsh-quiet-accept-line"

Configuration

Keys can be configured based on the following variables and relatable defaults: ZLE_QAL_QUIET_KEY (^X^M), ZLE_QAL_SILENT_KEY (^X^J), ZLE_QAL_COMPACT_KEY, ZLE_QAL_PAGER_KEY/ZLE_QAL_PAGER_KEY2 (^X^\C-M/\e^\C-M) and ZLE_QAL_LAST_KEY(^X^K).

Output of the status code can be customized with the following variable:

  • ZLE_QAL_STATUS_DURATION: how long status is displayed, blocking the prompt (default 0.5s)
  • ZLE_QAL_STATUS_OK: what is output for successful command (default green βœ” with prompt color escape %{%})
  • ZLE_QAL_STATUS_KO: what is output for failing command (default red βœ– with prompt color escape %{%}) note that status is saved to ZLE_QAL_STATUS variable

As mention in usage, some behavior can be configured, notably:

  • ZLE_QAL_COMMAND: command to pipe command logs for quiet-accept-line
  • ZLE_QAL_PAGER: pager for pager-accept-line, default to $PAGER
  • ZLE_QAL_SILENT_DUMP_FILE default to (/tmp/zsh-quiet-accept-line-silent-$$.log), disable with /dev/null
  • ZLE_QAL_COMPACT_PROMPT: compact prompt for compact-accept-line default %B$%b

About

This plugin was driven by the need to improve tmux-resurrect zsh history saving that was poluting terminal with fc commands. After some research I end up on the following stack overflow question, that inspired the initial implementation.