From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7837 invoked by alias); 7 Oct 2016 17:01:12 -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: X-Seq: 39587 Received: (qmail 25316 invoked from network); 7 Oct 2016 17:01:12 -0000 X-Qmail-Scanner-Diagnostics: from mail-pf0-f176.google.com 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(209.85.192.176):SA:0(0.0/5.0):. Processed in 0.581393 secs); 07 Oct 2016 17:01:12 -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=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at brasslantern.com does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=S6ZwXpmJ0zGEvYTnOTo1QozadVYmeCsV8UoseQ4cq/4=; b=AWBivuZ6T2ma7PNSvB0hsTxeXqbMfSNVePGJRzPXmUjdCuHNWHjK+twHTOgPUW6Tr6 gZ3GTStc8yOULn6qkFeqeg8F2ItqkTkXcM2ufrbgOTffakNDOVzwBXS1KRNtEki5UTLX kTndz/q9frIgABXesu9qke5DA7JJJ7cSk5SLvCZisZoZ7azZ4VRGxKkIXmMaZBfrKzwG B9MZONy9GHt2gbKZ4NKpx7ci02kUkQwVg1A0K04CuyIeVa7j4YLptqLO8Fbqo2mixTi0 MMOXWNklNKHoZSZVDhM+VMK3f2Sdc9NQvcrlprRnuCw5k61fzpKBHfSRq4nQJNAHR/eL G/cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=S6ZwXpmJ0zGEvYTnOTo1QozadVYmeCsV8UoseQ4cq/4=; b=JaX7eXJD8GoHjV9fQLc//SHhKViOP3qdoPiScDZUfsFAZ4L0R79dO8O8uovAkXbMFi 0x+RQ15OH+08DZhMwwXKY+H6vzAONUMoA013lDfhQbzJT+SQNT+C0nBN5pmEYYel5GHK RPx+AKx7hldgT8JduuwbPALLaUnheOUclDLjAJl88WVVXKT/W25nUmkRkslr2sPLmi1y x+PmwgNGsxulEQ9Y+nR3+jlZUBQxSb2RY/oa0S5ttdazcWOTbhaT++5VkFFa4k4nKHHT i1zQFczGkizGvTFKhJJbiKdTIYyaP42KhhNk8fT/O3NJZm23jVJnyxrKdWr+9tZSdmzJ tRDg== X-Gm-Message-State: AA6/9Rmf6+s6jcFZ+MDk8BpGewNntBzSrh3/1DWAuA7ZGMQ2UpF+cI/B0J38FQid+PjRog== X-Received: by 10.98.64.136 with SMTP id f8mr37896727pfd.49.1475859664257; Fri, 07 Oct 2016 10:01:04 -0700 (PDT) From: Bart Schaefer Message-Id: <161007100137.ZM19673@torch.brasslantern.com> Date: Fri, 7 Oct 2016 10:01:37 -0700 In-Reply-To: <20161007085709.GA7369@zira.vinc17.org> Comments: In reply to Vincent Lefevre "Re: zsh generates invalid UTF-8 encoding in the history" (Oct 7, 10:57am) References: <20161005114848.GA1125@cventin.lip.ens-lyon.fr> <161006113112.ZM16191@torch.brasslantern.com> <20161007085709.GA7369@zira.vinc17.org> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: zsh generates invalid UTF-8 encoding in the history MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Oct 7, 10:57am, Vincent Lefevre wrote: } Subject: Re: zsh generates invalid UTF-8 encoding in the history } } Thanks. Note that it is not clear in the man page whether the } least recent starts at 0 or at 1. And when -r is used, whether } one should use or the reverse. Indeed, the use of "first last" in the doc is a bit confusing, and so is the interpretation of the numbers by the command. It's always most then least recent; but since negative numbers count backwards from the most recent (largest number) and the default behavior is described in terms of using negative offsets, it can be confusing. } 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] 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 }