简体   繁体   English

ZSH'粘性'提示

[英]ZSH 'Sticky' Prompt

I have my ZSH theme outputting the status of my Vagrant/VBox VMs using RPROMPT='$(vbox_status)' in my .zsh-theme file (where vbox_status calls a script which outputs what's running ), like so: 我的ZSH主题在我的.zsh-theme文件中使用RPROMPT='$(vbox_status)'输出我的Vagrant / VBox VM的状态(其中vbox_status调用一个输出正在运行的脚本的脚本 ),如下所示:

ZSH主题

However, I'm wondering if there's a way I can make this output 'sticky' so that, rather than outputting at the end of every single line, it will stay at the position indicated by the arrow and simply update itself whenever a new line is output above. 但是,我想知道是否有一种方法可以使这个输出“粘性”,这样,它不会在每一行的末尾输出,而是保持在箭头指示的位置,只需在新行时自行更新在上面输出。

eg. 例如。

在此输入图像描述

You can do this with a command called tput . 您可以使用名为tput的命令执行此操作。

I have made a basic script which puts a string in the corner of the screen which will get you started. 我已经制作了一个基本脚本,它将一个字符串放在屏幕的一角,这将让你开始。 You can make it much nicer by erasing things and highlighting or whatever but this is a starting point: 你可以通过擦除东西和突出显示或其他任何东西来使它更好,但这是一个起点:

#!/bin/bash
screen_w=$(tput cols)   # Get screen width.
screen_h=$(tput lines)  # Get screen height.
str=$*                  # String to put in corner.
string_w=${#str}
let "x = $screen_w - $string_w"

tput sc               # Save current position
tput cup $screen_h $x # Move to corner
echo -ne $str         # Put string in the corner
tput rc               # Go back to saved position.
echo " >"             # Some kind of prompt

So you can set your prompt to run this like this (I called the above script pr.sh) 所以你可以设置你的提示来运行这个(我称之为上面的脚本pr.sh)

PS1=$(pr.sh $(date))

It might be different in zsh but I'm sure you can work that part out. 它可能在zsh有所不同,但我相信你可以解决这个问题。 Just change the $(date) part to your status command. 只需将$(date)部分更改为status命令即可。 (pr.sh must be on your path) (pr.sh必须在你的道路上)

This is a bit clunky, but it will get you started. 这有点笨拙,但它会让你开始。 There is almost no limit to what you can do with tput ! 你可以用tput做什么几乎没有限制!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM