Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: /usr/bin/printf



2009/2/13 Matthew Flaschen <matthew.flaschen@xxxxxxxxxx>:
> Nikolai Weibull wrote:
>> On Fri, Feb 13, 2009 at 04:25, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>>
>>> The problem is that $1 is first expanded by the command parser and then
>>> passed to "print".
>>
>>> The (q) tells zsh to insert a backslash before any special characters
>>> that appear in the value of $1, including the backslash in "\n".  Then
>>> "print" strips the extra backslashes off again and the final output is
>>> the original string.
>>
>> Couldn't one use the -r switch to print as well?
>
> Well, it can't be used for the whole thing, because some escapes are
> supposed to be used.  I tested, and:
>
> preexec () { print -Pn "\e]0;%n@%m: "; print -rn "$1"; print -n "\a" }
>
> does works I'm not really sure why there's a \a at the end anyway.  I
> presume this doesn't mean system bell here.

The \a is the endcode for the title setting command, it is just an
arbitrary value really, as much as \e and ] are. That said, I don't
think this command works if you put literal \a on your command line.
This is what I use:

#for changing a *term title
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
}

To be honest, I can't say off hand what all those parts do, they're
sort of stacked on top of eachother until it stopped letting anything
through.

My actual preexec() calls it like this:
if [ "$#1" -gt 512 ];then 1=${1[1,512]}; fi
ct -e "$TTY:t [$1] {`print -P "%100<...<%~%<<"`} `strftime "%x %T"
$EPOCHSECONDS`"

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author