diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2023-03-27 10:13:40 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2023-03-27 10:13:40 +0800 |
| commit | efa77f6016446187fce494ac4a13c6a0d719e77e (patch) | |
| tree | 10de02536ebc9947b01f6c2cfe1a683a95dd33e1 /bin | |
| parent | 13881f9a0a133b66a80064dbb6f1c62adf26e71f (diff) | |
Add keybinding for banner
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/unix/center_text.sh | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/bin/unix/center_text.sh b/bin/unix/center_text.sh new file mode 100755 index 0000000..6e3b9b2 --- /dev/null +++ b/bin/unix/center_text.sh | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | |||
| 3 | echo '\e[5 q' | ||
| 4 | |||
| 5 | while read -r -e text; do | ||
| 6 | tput cuu1 civis | ||
| 7 | |||
| 8 | width="$(tput cols)" | ||
| 9 | left=$(( ($width - ${#text}) /2 )) | ||
| 10 | right=$(( $width - $left - ${#text} )) | ||
| 11 | |||
| 12 | echo -en '\r' | ||
| 13 | eval "printf ' %.0s' {1..$left}" | ||
| 14 | echo -n $text | ||
| 15 | eval "printf ' %.0s' {1..$right}" | ||
| 16 | done | ||