[英]Tmux pad format string
I want to pad a format string to a certain length.我想将格式字符串填充到一定长度。 For example, the Tmux Battery plugin introduces the battery_percentage
format string.例如, Tmux Battery插件引入了battery_percentage
格式字符串。 I can use this in the status bar as #{battery_percentage}
.我可以在状态栏中将其用作#{battery_percentage}
。 The battery percentage values can be:电池百分比值可以是:
I want the format string to always be displayed 3 digits, padded with spaces at the end, how can I achieve that?我希望格式字符串始终显示 3 位数字,最后用空格填充,我该如何实现?
I saw that there is the format #{pN:variable}
in this page , but it did not work when I tried to use it with format strings, even though at the end they are variables.我看到 此页面中有格式#{pN:variable}
,但是当我尝试将它与格式字符串一起使用时它不起作用,即使最后它们是变量。 Maybe I just did not know how to use it, I don't know...也许我只是不知道如何使用它,我不知道......
Looking at the plugin startup code, battery.tmux , you can see that ${battery_percentage}
is actually converted to #($CURRENT_DIR/scripts/battery_percentage.sh)
, which is a request to run a script.查看插件启动代码battery.tmux ,您可以看到${battery_percentage}
实际上被转换为#($CURRENT_DIR/scripts/battery_percentage.sh)
,这是运行脚本的请求。 I don't know if #{p3:#(...)}
can be made to work since this is not a simple variable.我不知道#{p3:#(...)}
是否可以工作,因为这不是一个简单的变量。
You could always edit the plugin shell script to return the padded string (assuming tmux keeps the leading spaces).您始终可以编辑插件shell 脚本以返回填充的字符串(假设 tmux 保留前导空格)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.