From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6641 invoked by alias); 12 Jan 2015 17:02:05 -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: 19734 Received: (qmail 25405 invoked from network); 12 Jan 2015 17:01:51 -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:date:message-id:subject:from:to:content-type; bh=GU8MhflA3nS5yvgwqmDu8dvKocX83MvxktApbVC6BbI=; b=fb4MVZS+DVpI12pBGABfxWZNnhj32fo9PJ1D/nU+MK7Lrk5ulWrurj6IL7L6MmxXa9 1wLs+BKihOKPlWe+W4PUshwIwuTveWiVZxvv7Le6tFcLyW6YSdoyJREnmGGZixERX2pa RCduKDTuCf3XHXJpN8X/pqTuAUV9Rdr81YhZEo5gPitBRHpTGc3tNgbWxq8GaAILZuHH zoQ9q38WCtCb2LZvIIJcfXqNH3V/XcdUYZWQ8KrPi5kMIZIjET1pwJe9FITFXM7KEiWl TW3oxUYbHdt4tdRgCZOAlfJgp6Tv9gipc0tU+OpAtiXnCb6Qx8hx2qJpgetuXpIw3h0d L5bw== MIME-Version: 1.0 X-Received: by 10.221.58.204 with SMTP id wl12mr18114390vcb.78.1421082107227; Mon, 12 Jan 2015 09:01:47 -0800 (PST) Sender: ethersoft@gmail.com Date: Mon, 12 Jan 2015 12:01:47 -0500 X-Google-Sender-Auth: 1RTxuXHHvdoLikj1geYGD4i3Q98 Message-ID: Subject: Saving commands from a session From: Vin Shelton To: "zsh-users@zsh.org" Content-Type: text/plain; charset=UTF-8 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? Thanks in advance, Vin Shelton