From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19896 invoked by alias); 20 Jan 2015 19:33:43 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19758 Received: (qmail 24046 invoked from network); 20 Jan 2015 19:33:40 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=gvQ5nEEYacYk9KF40KONQVEpnKoem+D/LIy/VlJMnqk=; b=RQOx4Lfchb/tT5nFI7iM1JwQmKQapGAlypWiPP+KBJv5ElKMmXtqgWGtuNz6heShPg oF5IB757POcFvlnQnJyiGGJIAMejSVRCjskAVGpx11ueGOKOhw44jfyGq3ZEDqkwNSOk Iy7D7oiR8PUf3aKEukuIpzm5ueiiYZzYxFrW3lbjIK7oVagjQHiv9pXFCu4Jlts9uxWf QWY1gqZCZiBSR6V8m6RTc/0cQeBQzvxRz++c1KYDL0lSkFkDPuQSVeN6Cs2fk3qcekO5 nME5QWXz0zxs67vU2sUxNVEtJq5cBMiLhpCJarABn8ZeGmilJ1lqNF0TBHLs2rHvY5Eb ZQcg== MIME-Version: 1.0 X-Received: by 10.53.7.230 with SMTP id df6mr15043245vdd.64.1421782415927; Tue, 20 Jan 2015 11:33:35 -0800 (PST) Sender: ethersoft@gmail.com In-Reply-To: References: Date: Tue, 20 Jan 2015 14:33:35 -0500 X-Google-Sender-Auth: i9VtLApVBcIBCRP29_r_jlD8iug Message-ID: Subject: Re: Saving commands from a session From: Vin Shelton To: Mikael Magnusson Cc: "zsh-users@zsh.org" Content-Type: text/plain; charset=UTF-8 On Mon, Jan 12, 2015 at 12:19 PM, Mikael Magnusson wrote: > On Mon, Jan 12, 2015 at 6:01 PM, Vin Shelton wrote: >> In addition to saving commands in .zhistory, I like to save commands >> by session, so I can save and later search the sequence of commands I >> executed at a particular time. In order to do this, in .zlogout I >> compared all commands in history against the date and time of the >> first command saved: >> >> # Get the date and time of the first command in the shell history. >> fc -lin -$HISTCMD -$((HISTCMD-1)) | read d t cmd >> >> # Ignore all commands that have the same date and time. >> # They were read in when the shell started. >> fc -lin -$HISTCMD | grep -v "^$d $t" >> $outfile >> >> I was never terribly impressed by the elegance of this solution, but >> it worked, more or less (I believe it could drop the first command or >> two I entered if they happened to have the same date and time as the >> start of the shell). >> >> However, I recently started using >> >> setopt EXTENDED_HISTORY >> >> and this has the effect of keeping the original date and time the >> command was executed in .zhistory, so when the historical commands are >> read into the shell, they no longer all have the same date and time. >> >> Is there a more elegant way to save only those commands that have been >> executed in this instance of the shell? > > Maybe you want to write out each entry incrementally from > zshaddhistory() instead? Zsh does track which history entries are > "local" and which are imported from history, but I don't believe you > can directly access this information. Thanks, Mikael. I followed your advice and am now using zshaddhistory(). Regards, Vin