小编Zoe*_*wll的帖子

在两个单独的流中显示 stdout 和 stderr

我正在寻找一种在视觉上分离 stdout 和 stderr 的方法,这样它们就不会交错,从而可以轻松识别它们。理想情况下,stdout 和stderr 在显示它们的屏幕上会有不同的区域,例如在不同的列中。例如,输出看起来像这样:

~$ some command
some useful output info
ERROR: an error
more output
ERROR: has occurred
another message
~$ 
Run Code Online (Sandbox Code Playgroud)

而是看起来像这样:

~$ some command          |
some useful output info  |
more output              |  ERROR: an error
another message          |  ERROR: has occurred
~$                       |
Run Code Online (Sandbox Code Playgroud)

command-line terminal

18
推荐指数
1
解决办法
1977
查看次数

将 rprompt 与提示顶部对齐

我最近对 ​​zsh 感到非常兴奋,并让自己成为一个奢侈的提示,但我一直在努力调整我的 RPROMPT。我有这样的输出:

    | [14:59:44] git:(master)                           |
    | /home/zoey/.oh-my-zsh                             |
    | yes, zoey? :                           2016-05-26 |
Run Code Online (Sandbox Code Playgroud)

其中|代表终端边缘。我想要的是日期与时间垂直对齐;就其所在的位置而言,它很容易被长命令覆盖,而 git 信息不太可能变得很长。

RPROMPT的垂直位移有什么办法吗?最好是初学者级别的 zsh,因为我习惯于 bash,但如果需要,我可以复制粘贴内容。

这是我的相关部分.zshrc

# show all but the last dir in the current path
function trim_pwd
{
    echo $(pwd | sed -e "s:/$::;s:[^/]*$::")
} 
setopt PROMPT_SUBST
# red for error, green for ok
ERRCOL='%(?:%F{green}:%F{red})'
PROMPT='${ERRCOL}[%f%B%F%D{%H:%M:%S}%f%b${ERRCOL}]%f %B$(git_prompt_info)%b
%F{green}%n%f@%F{yellow}%m%f:%F{blue}$(trim_pwd)%B%1/%b%f
%F{magenta}yes, %Bzoey%b?%f : '
RPROMPT='%F%D{%Y-%m-%d}%f'
# update clock per second
TRAPALRM() {
    zle reset-prompt
}
TMOUT=1
Run Code Online (Sandbox Code Playgroud)

如果我删除所有格式化的东西,只显示简单的提示:

setopt …
Run Code Online (Sandbox Code Playgroud)

prompt zsh

8
推荐指数
1
解决办法
3623
查看次数

shell 读取错误处理输入按键

我正在安装一个相对较新的 Linux Mint,直到现在我才注意到任何重大问题,我意识到我无法使用任何交互式读取用户输入的命令行工具。它不是像我期望的那样通过消耗一行输入来处理回车键,而是将^M字符序列打印到终端并继续提示输入。
例如git add -p

Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? y^M
Run Code Online (Sandbox Code Playgroud)

经过更多测试后,我意识到所有 shellread操作都在执行此操作(在zsh和 中bash),并且sh完全无法使用。

zsh 和 bash:

$ read test
value^M^C
$
Run Code Online (Sandbox Code Playgroud)

嘘:

$ echo "test"^M^C
$ exit^M^M^M^C
$
Run Code Online (Sandbox Code Playgroud)

我打开了一个新终端,它似乎没有受到影响,所以我没有被困在这里,但我很想知道发生了什么使这个终端表现得如此。如果人们有理论,我会将损坏的打开一段时间以进行测试。

read

4
推荐指数
1
解决办法
216
查看次数

标签 统计

command-line ×1

prompt ×1

read ×1

terminal ×1

zsh ×1