diff --git a/plugins/almostontop/README.md b/plugins/almostontop/README.md new file mode 100644 index 00000000..3a38e0c4 --- /dev/null +++ b/plugins/almostontop/README.md @@ -0,0 +1,13 @@ +# almostontop + +## Description +almostontop zsh plugin. It clears previous command output every time before new command +executed in shell. Insipred by [`alwaysontop`](https://github.com/swirepe/alwaysontop) plugin for bash + +## Usage +source `almostontop.plugin.zsh` file and enjoy! + +[![asciicast](https://asciinema.org/a/8rkdwvnp7atjseesp7n74nsyr.png)](https://asciinema.org/a/8rkdwvnp7atjseesp7n74nsyr) + +## Author +[Sergey Valiev](https://github.com/Valiev) diff --git a/plugins/almostontop/almostontop.plugin.zsh b/plugins/almostontop/almostontop.plugin.zsh new file mode 100644 index 00000000..9959261b --- /dev/null +++ b/plugins/almostontop/almostontop.plugin.zsh @@ -0,0 +1,59 @@ +if [ "x$ALMOSONTOP" = "xfalse" ]; then + # doing nothing here +else + ALMOSONTOP=true +fi + +function almostontop_preexec +{ + if [ "x$ALMOSONTOP" = "xtrue" ]; then + clear + # print PROMPT and command itself on the top + echo "$(print -P $prompt)$fg[green]${(z)1}$reset_color" + fi +} + +autoload -U add-zsh-hook +add-zsh-hook preexec almostontop_preexec + +function almostontop +{ + # Help message if there no args + if [ $# -eq 0 ]; then + almostontop_usage + fi + + local arg=$1 + if [ "x$arg" = "xon" ]; then + ALMOSONTOP=true + fi + + if [ "x$arg" = "xoff" ]; then + ALMOSONTOP=false + fi + + if [ "x$arg" = "xtoggle" ]; then + if [ "x$ALMOSONTOP" = "xtrue" ]; then + almostontop off + else + almostontop on + fi + fi +} + +function almostontop_usage +{ + cat <<-EOF +Usage: almostontop + +Commands: + on Enables almostontop plugin + off Disables almostontop plugin + toggle Toggles almostontop plugin + +Description: + almostontop clears previous command output every time before new command + executed in shell. Insipred by 'alwaysontop' plugin for bash: + https://github.com/swirepe/alwaysontop +EOF +}