我想删除光标后的所有内容;不仅是当前行,还有当前位置之后的每个剩余字符。
例如tput sc; ll; tput rc
:
root@test:~# tput sc; ll; tput rc
root@test:~# {CURRENT_CURSOR_POSITION}
drwx------ 5 root root 4096 Feb 23 16:34 ./
drwxr-xr-x 25 root root 4096 Jul 1 2021 ../
-rw------- 1 root root 59 Feb 23 16:34 .bash_history
-rw-r--r-- 1 root root 3106 Dec 5 2019 .bashrc
drwxr-xr-x 3 root root 4096 Feb 8 17:07 .local/
-rw-r--r-- 1 root root 161 Dec 5 2019 .profile
drwxr-xr-x 3 root root 4096 Jun 21 2021 snap/
drwx------ 2 root root 4096 Feb 22 11:56 .ssh/
-rw------- 1 root root 12976 Feb 8 17:07 .viminfo
这会将光标留在第二行,输出为ll
剩余。
我正在寻找一种方法
使用删除每一行,
tput el
直到它到达保存的位置,所以命令链是:tput sc; ll; while_deleting; tput rc
。这可能会调用tput el
每一行,这似乎是多余的,但应该没问题。返回保存位置后删除所有内容。
我研究了很多答案,例如如何在 shell 中删除光标后的所有字符、Bash: delete from cursor until end of line with a keyboard shortcut等等,但所有答案都集中在删除当前行,而不是休息。