zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Peter Stephenson <pws@csr.com>,
	Kawabata Taichi <kawabata.taichi@gmail.com>
Cc: "Zsh Users' List" <zsh-users@zsh.org>
Subject: Re: Fw: ZSH history file VS. UTF-8 data
Date: Wed, 2 Mar 2011 11:00:45 +0100	[thread overview]
Message-ID: <AANLkTi=9ARVQeU556YcrSB9=x4MmFU7=RqdxZ8GxgxUv@mail.gmail.com> (raw)
In-Reply-To: <20110302094336.62001793@pwslap01u.europe.root.pri>

> Dear sir,
>
> I'm sorry to disturb you.
>
> I've been a user of ZSH  for a long time and I really
> appreciate for the developer of this great software.
>
> Recently, I've got one trouble in ZSH history file, and as I tried to
> solve it by
> surveying Webs and Sources, with no help.  As of it, knowing that this
> disturbs you,
> I'm trying to ask for any help.
>
> The trouble is as follows:
>
> When I try to use UTF-8 file name in shell command, ZHS history file
> seems to save
> it with "meta code".
>
> For example, executing
>  $ ls \346\226\207\345\255\227  (octal expression of "ls 文字”)
> results in histfile
>  $ ls \346\203\266\203\247\2\345\255\203\267
>
> That is, when 0x80-0x9F characters are used, then always 0x83 Meta
> character is inserted and following character is bit shifted, resulting
> garbage history.
>
> Any way to avoid this situation?
>
> Any help is really appreciated,

This isn't a bug, the history file is saved in metafied format. If you
want to print it outside zsh you can use this simple program.

#define Meta ((char) 0x83)

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>

/* from zsh utils.c */
char *unmetafy(char *s, int *len)
{
  char *p, *t;

  for (p = s; *p && *p != Meta; p++);
  for (t = p; (*t = *p++);)
    if (*t++ == Meta)
      t[-1] = *p++ ^ 32;
  if (len)
    *len = t - s;
  return s;
}

int main(int argc, char *argv[]) {
  char *line = NULL;
  size_t size;

  while (getline(&line, &size, stdin) != -1) {
    unmetafy(line, NULL);
    printf("%s", line);
  }

  if (line) free(line);
  return EXIT_SUCCESS;
}


-- 
Mikael Magnusson


  reply	other threads:[~2011-03-02 10:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-02  9:43 Peter Stephenson
2011-03-02 10:00 ` Mikael Magnusson [this message]
2011-03-02 10:37 ` lilydjwg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTi=9ARVQeU556YcrSB9=x4MmFU7=RqdxZ8GxgxUv@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=kawabata.taichi@gmail.com \
    --cc=pws@csr.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).