简体   繁体   English

Tmux pad 格式字符串

[英]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:电池百分比值可以是:

  1. Between 0% and 9% (One Digit).介于 0% 和 9%(一个数字)之间。
  2. Between 11% and 99% (Two Digits).在 11% 到 99% 之间(两位数)。
  3. Exactly 100% (Three Digits).正好 100%(三位数)。

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.

相关问题 使用任意字符串向左或向右填充string.format(不是padleft或padright) - Pad left or right with string.format (not padleft or padright) with arbitrary string 正则表达式。 检查并填充字符串以确保使用了某些字符串格式 - RegEx. Check and pad string to ensure certain string format is used 如何用零填充二进制字符串? - How to pad a binary string with zeros? 用 0 向左填充字符串的最简单方法是什么? - What is the easiest way to pad a string with 0 to the left? 如何格式化日期并用空格填充它? - How do I format a date and also pad it with spaces? 如何填充整数,以便在结果字符串中显示n个字符? - How to pad an integer so that n characters are displayed in the resulting string? C ++可以setw和setfill填充字符串的结尾? - C++ can setw and setfill pad the end of a string? 如何在 Haskell 中填充整数的字符串表示? - How do I pad string representations of integers in Haskell? Tmux:如何使用选择树过滤当前的 session windows 并格式化 output 以显示没有主机名的 windows 名称 - Tmux: How to filter the current session windows using choose-tree and format the output to show windows names without hostname String.format 或类似格式的正确格式字符串 - Correct format string for String.format or similar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM