From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16167 invoked by alias); 29 Nov 2017 15:57:26 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42059 Received: (qmail 23215 invoked by uid 1010); 29 Nov 2017 15:57:26 -0000 X-Qmail-Scanner-Diagnostics: from cventin.lip.ens-lyon.fr by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(140.77.13.17):SA:0(-1.9/5.0):. Processed in 2.303008 secs); 29 Nov 2017 15:57:26 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: vincent@vinc17.net X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Date: Wed, 29 Nov 2017 16:46:29 +0100 From: Vincent Lefevre To: zsh-workers@zsh.org Subject: Re: zsh generates invalid UTF-8 encoding in the history Message-ID: <20171129154629.GA17931@cventin.lip.ens-lyon.fr> Mail-Followup-To: zsh-workers@zsh.org References: <20161005114848.GA1125@cventin.lip.ens-lyon.fr> <161006113112.ZM16191@torch.brasslantern.com> <20161007085709.GA7369@zira.vinc17.org> <161007100137.ZM19673@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <161007100137.ZM19673@torch.brasslantern.com> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/1.9.1-7188-vl-r99863 (2017-11-29) Hi, This is a bit old, but... On 2016-10-07 10:01:37 -0700, Bart Schaefer wrote: > On Oct 7, 10:57am, Vincent Lefevre wrote: > } And how can one cleanly append history lines to a history file? > } I was using "cat some_file >> ~/.zhistory", which seems to work, > > It'll work as long as there are no 0x83 bytes in some_file. > > To be completely safe, you need to do something like this: > > # Pass input file as $1, output as $2 > append_plain_file_to_history_file() { > emulate -LR zsh > local -a entries > > # Implementation issue: read -r ignores backslash-newline > # folding, but without -r embedded backslashes are stripped, > # which seems a bigger problem. Fix up $entries later. > > IFS=$'\n' read -r -d '' -A entries <$1 > (( $#entries )) || return > > # Must supply a file name here to set HISTSIZE and SAVEHIST > fc -pa /dev/null $#entries $(( SAVEHIST + $#entries )) > > while (( $#entries )); do > if [[ "$entries[1]" == *\\ ]]; then > entries[1,2]=( ${entries[1]%\\}$'\n'${entries[2]} ) > else > print -S $entries[1] There should be a -r option: print -r -S $entries[1] otherwise \r yields a CR character. > shift 1 entries > fi > done > fc -A ${2:-$HISTFILE} > > # Reset SAVEHIST to avoid attempting to lock /dev/null > SAVEHIST=0 # fc -p makes this implicitly local > } -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)