You are not logged in.

#1 2013-05-22 18:46:22

dodo3773
Member
Registered: 2011-03-17
Posts: 818

[SOLVED] zsh command is echoed back in tty

When I am in a tty and type a command such as "ls" I get:

$ ls
lsDirectory/
$

instead of

$ ls
Directory/
$

This is an annoyance. It has something to do with an option in my zshrc but I am not sure which one (I tried removing it to verify and yeah that's it). When I am in a terminal inside of X I do not have this issue. It is also not an issue in bash. Here is my .zshrc file:

NOPRECMD=1
function precmd() {
    print -Pn "\e]2;%~\a"
}

preexec () {
print -Pn "\e]2;%~ :  $1\a"
}

# Auto Completion And Additional Settings
autoload -U compinit
compinit
zstyle ':completion:*' menu select
export HISTFILE=~/.zsh_history
export HISTSIZE=50000
export SAVEHIST=50000
eval `dircolors -b`

setopt autopushd pushdminus pushdsilent pushdtohome
setopt autocd
setopt cdablevars
setopt ignoreeof
setopt interactivecomments
setopt nobanghist
#setopt noclobber
setopt HIST_REDUCE_BLANKS
setopt HIST_IGNORE_SPACE
setopt SH_WORD_SPLIT
setopt nohup
setopt completealiases
setopt correct
#setopt correctall


#Colored Prompt
autoload -U promptinit
promptinit

#Colors
autoload -U colors && colors
zstyle ':completion:*:default'         list-colors ${(s.:.)LS_COLORS}


# allow approximate
zstyle ':completion:*' completer _complete _match _approximate
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:approximate:*' max-errors 1 numeric
#zstyle ':completion:*' special-dirs true
#zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' list-dirs-first true
#Cache
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path ~/.zsh/cache

# tab completion for PID :D
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always

#compdef _gnu_generic 
#zstyle ':completion:*:processes-names' command  'ps c -u ${USER} -o command | uniq'


compdef _pids cpulimit

compdef _pids ps
compdef _pids appuptime

# cd not select parent dir
zstyle ':completion:*:cd:*' ignore-parents parent pwd

#Special Keys
typeset -g -A key
#bindkey '^[[3' backward-kill-word trying to figure out ctrl+backspace...still
bindkey "\eOH" beginning-of-line
bindkey "\eOF" end-of-line
bindkey "\e[H" beginning-of-line
bindkey "\e[F" end-of-line

bindkey '^?' backward-delete-char
bindkey '^[[1~' beginning-of-line
bindkey '^[[5~' up-line-or-history
bindkey '^[[3~' delete-char
bindkey '^[[4~' end-of-line
bindkey '^[[6~' down-line-or-history
bindkey '^[[A' up-line-or-search
bindkey '^[[D' backward-char
bindkey '^[[B' down-line-or-search
bindkey '^[[C' forward-char 
# completion in the middle of a line
bindkey '^i' expand-or-complete-prefix

#Directory Colors
LS_COLORS='rs=0:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:';
export LS_COLORS

#History Search
bindkey "^[[A" history-search-backward
bindkey "^[[B" history-search-forward

source /home/dodo3773/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
#source /home/dodo3773/.zsh/plugins/safe-paste.plugin.zsh
fpath=( $HOME/.zsh/functions $fpath )
PATH=$PATH:/home/dodo3773/Documents/Scripts
DONTSETRPROMPT=1
if [ ${UID} -ne 0 ]; then
PS1="%{%F{white}%}%~ %{%F{green}%}>> %{%f%}"
RPROMPT='%{%F{green}%}[%{%F{red}%}%"%?%{%F{green}%}]'
else
PS1="%{%F{red}%}%~ %{%F{green}%}>> %{%f%}"
RPROMPT='%{%F{green}%}[%{%F{red}%}%"%?%{%F{green}%}]'
fi

Last edited by dodo3773 (2013-05-22 19:08:12)

Offline

#2 2013-05-22 18:52:17

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,209

Re: [SOLVED] zsh command is echoed back in tty

Cute.  I have a hunch.  What if you logged into to tty, start a tmux or screen session, from inside the session, start X, open a terminal window and attach to the tmux or screen session, open another terminal window that uses zsh, enter a command in that shell.  Does the command echo to the tmux or screen session?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2013-05-22 18:57:16

dodo3773
Member
Registered: 2011-03-17
Posts: 818

Re: [SOLVED] zsh command is echoed back in tty

ewaller wrote:

Cute.  I have a hunch.  What if you logged into to tty, start a tmux or screen session, from inside the session, start X, open a terminal window and attach to the tmux or screen session, open another terminal window that uses zsh, enter a command in that shell.  Does the command echo to the tmux or screen session?

I do not use tmux or screen and I am not sure what you mean really. I will try to comment out one "setopt" option a a time I guess until I can figure it out. Just thought someone else might have come across this issue too. I tried changing my PROMPT variables and that wasn't it.

Offline

#4 2013-05-22 18:58:31

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,095
Website

Re: [SOLVED] zsh command is echoed back in tty

ewaller, if I understood correctly, wasn't trying to troubleshoot a problem with tmux or screen, but rather use them as tools to troubleshoot the problem itself.

All the best,

-HG

Offline

#5 2013-05-22 19:01:13

dodo3773
Member
Registered: 2011-03-17
Posts: 818

Re: [SOLVED] zsh command is echoed back in tty

HalosGhost wrote:

ewaller, if I understood correctly, wasn't trying to troubleshoot a problem with tmux or screen, but rather use them as tools to troubleshoot the problem itself.

All the best,

-HG

Oh okay. I think it may take me more time to set those up than figure it out though. I tried changing my setopt options and looking at my ls colors and commenting those out but that didn't work either. I will post back when I figure it out.

Offline

#6 2013-05-22 19:02:36

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [SOLVED] zsh command is echoed back in tty

the precmd and preexec print virtual terminal escape codes.  These are processed in X-based virtual terminals, not not in ttys.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#7 2013-05-22 19:03:26

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,209

Re: [SOLVED] zsh command is echoed back in tty

It is not really important.  What it all does is allow you to see messages that are sent to the tty when you have X sitting on top of it.  In both cases, I bet the commands are being echoed to the tty, you just cannot see that inside of X.

Edit:  Trumped by Trilby's undoubtedly correct answer.  In which case, my guess would be wrong, characters would not appear in the tmux session

Last edited by ewaller (2013-05-22 19:05:26)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#8 2013-05-22 19:07:47

dodo3773
Member
Registered: 2011-03-17
Posts: 818

Re: [SOLVED] zsh command is echoed back in tty

@Trilby @ewaller

Yep that was the error. Thanks Trilby. I removed precmd and preexec and it works normally in tty. Marking as solved. Is there anyway to do a if then for tty vs X terminal in .zshrc? I am googling that now.

Edit: Nevermind. Got it. "if [[ $(tty) == /dev/pts* ]]; then" should work. Just need to figure out how to put the functions inside it and it should work.

Last edited by dodo3773 (2013-05-22 19:21:46)

Offline

#9 2013-05-22 19:33:33

dodo3773
Member
Registered: 2011-03-17
Posts: 818

Re: [SOLVED] zsh command is echoed back in tty

Okay got it:

preexec () {
if [[ $(tty) == /dev/pts* ]]; then
print -Pn "\e]2;%~ :  $1\a"
fi
}

Thanks guys.

Offline

#10 2013-05-22 19:34:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [SOLVED] zsh command is echoed back in tty

or `if [[ "$TERM" == "linux" ]];` which has a couple minor advantages.  First it doesn't need to spawn another subprocess, and second, if you ever *do* end up using tmux/screen/fbterm in a tty, then you'll still have the "window" title (tab) set in those envrionments too.

EDIT: my suggested condition is of the opposite logic, so use an else, !, or not-equal comparison.

My bashrc has a number of settings in one good size if/then/else/fi block for settings that should differ between virtual terminals and ttys.  I don't know if you can define functions inside conditionals ... I doubt it, but I guess I've never really tried.  If possible, this would be handy so the conditional doesn't have to be evaluated every time the preexec is called.

Last edited by Trilby (2013-05-22 19:37:44)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#11 2013-05-22 19:59:27

dodo3773
Member
Registered: 2011-03-17
Posts: 818

Re: [SOLVED] zsh command is echoed back in tty

Oh okay. Thanks for the tip. I changed it to this:

function precmd() {
if [[ $TERM != linux ]]; then
    print -Pn "\e]2;%~\a"
fi
}

preexec () {
if [[ $TERM != linux ]]; then
print -Pn "\e]2;%~ :  $1\a"
fi
}

Offline

Board footer

Powered by FluxBB