Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Substituting newline on a string
- X-seq: zsh-users 12993
- From: "Mikael Magnusson" <mikachu@xxxxxxxxx>
- To: quijotista@xxxxxxxxx
- Subject: Re: Substituting newline on a string
- Date: Tue, 1 Jul 2008 19:47:58 +0200
- Cc: zsh-users@xxxxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=OIfQ5Pg9aFBS7exy4+efg58HqhW+zm5JG5J6eqKHk+E=; b=vBF//XtdlpPKUoCiEfwX5bEkiQKzyTW6MkDbBYmwzpmjnjaX28a+qT0SvoFpb+xALd HXNzQsuYwbVjgocjAD5//IGMHfrslhprePH7QCaoYsRTooUlsOVkW53Z+GMdwaaZVML/ o8hdAorWwCsRpm0mB+opYXwhNRCA/RRJJa8nQ=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=p7t1JNcH5L6gibN06C0Kvo9GOe+NIGBZdxzxhSjZ4/CJmwa7YRCoS4THqskpiizg8m +SJlD7wW8Xv6YbwNok+eNV4+Yfx100jyT4Cd9oDso0xrTzbydez4IxZf0ftKWVmLJ3oN ty1GAaTBlnth1LbNxvBpY2gAW/1mJRiEgh4wc=
- In-reply-to: <150460.34757.qm@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <150460.34757.qm@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
2008/7/1 Javier Alvarado <quijotista@xxxxxxxxx>:
> I have a seemingly trivial problem that I have not be able to solve. How do I replace a newline in a string with somethinge else, like ' ' (or better yet '\n')?
>
> I've tried
>
> cmd=${1/$/ /}
> cmd=${1/\n/ /}
> cmd=${1/\r/ /}
>
> plus any thing else I could think of without success.
>
> In case it matters, I'm trying to put the command being executed into my xterm title bar from preexec() and I want to be able to handle multi-line commands.
>
> Thanks for any help.
My function for this has some possibly rxvt-unicode specific bits in it, but
maybe it helps.
function ct() {
local MATCH
if [[ "$1" = "-e" ]]; then
#nulls terminate the string when printed, so change them
printf '\e]0;%s\007' ${${${2//$'\x00'/\^@}//
/\\n}//(#m)[$'\x00'-$'\x1f']/$'\x16'$MATCH}
elif [[ "$1" = "-t" ]]; then
pts="$2"
ct -e "$3" > /dev/pts/$pts
else
ct -e "$*"
fi
}
Instead of that crazy printf, you can try this other crazy printf:
printf '\e]0;%s\007' ${${2//
/\\n}//(#m)[$'\x00'-$'\x1f']/${(V)MATCH}}
Also, pasting that I realize that the answer to your question is either
what Frank said, or:
cmd=${1/
/ /}
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author