Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Clint Hepner Newsgroups: gnu.bash.bug Subject: Re: [FR] save command times and exit status in history automatically Date: Thu, 7 Nov 2019 17:05:53 -0500 Lines: 67 Approved: bug-bash@gnu.org Message-ID: References: <8e19b0fc-4183-90fa-b067-9da636998d6f@case.edu> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3601.0.10\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1573164364 12583 209.51.188.17 (7 Nov 2019 22:06:04 GMT) X-Complaints-To: action@cs.stanford.edu Cc: "bash.bug list" To: Daniel Colascione Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=v4giP4ev4KI7MN/SFLlsFh5JKsUvBPyHNYqyDmoLiyI=; b=CntmkPbEiTI5X8mtNd3YxgcmPpTSDsTgy0XkaZ/kD6FS6YHwY6Q/mq54rkWoNciXkA v6wHPiXC5GIpmaxq2xHYI19UVVa68BbaJv9hOu3lic+ixBBv9LItLIGncDdSAhgQ1tDZ EKpBeAzNUyhDRilKpHAlo/jXFc2ViwiQJsjaf4sqw3onumToVYx4Gmtk1vz+oKs9VTIS fAyaemIR8PIu4Xsoa1UnVXKM6hyiHpb8C33tFhD+wPTPL6CUTUrr5ZwLl7IQ5gAsj+Eg fdX1H3705IUFzMaMC9/qT/ms1HhA1pcJW6BjRMDPvTKSoZv1bQtMc6p4t/zsveByQSZu OjHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=v4giP4ev4KI7MN/SFLlsFh5JKsUvBPyHNYqyDmoLiyI=; b=Jy5g99XazPk6vaW9/ms1/EIgav+OXwdJhMbbgRpUXcCWInkB0P/DYaokh/gvlI5dOr deiYLeVlHxy4dqSsIbyIcAwiqYf5iCDENPyju08DaBpw7ApqNmLOQMzydJU7wI9u6aI4 iu/MC4slMSKPVVgRlBFgNq9jLC8fxWBVK2ZYbnRHo0k7wpcSDzgJwshzYTyB/QW4KNxi aEQc+xPWpkRabVjAjYg5dAgUFpY2Iqc9IurgVlYYITFVTGPcDtnpzAB7inbuJGlNqooP vg02UajXpP6YGSJRbgv4AjuAKTvNtD5Mls1Wa0Re5Xs9Ba2rB+InYUrLYtlSv7YkRuAl FJmA== X-Gm-Message-State: APjAAAVtiuWw5HI83MHpwfirKrypbMwyx8yVnZr2HxGigYdsFAOLTdHV XdFE+fIrn2TRbrpHS0TkCk9JhbX3 X-Google-Smtp-Source: APXvYqyZAQZgzqqNhfK9F2bIHyUJ4CIdNS9THakw/D6sV7Q9WfJ1zvt/O3t8bqONF8yt7QdLuDKxDA== X-Received: by 2002:a0d:d307:: with SMTP id v7mr4463402ywd.300.1573164357411; Thu, 07 Nov 2019 14:05:57 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3601.0.10) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::c2c X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <8e19b0fc-4183-90fa-b067-9da636998d6f@case.edu> Xref: csiph.com gnu.bash.bug:15575 > On 2019 Nov 7 , at 3:18 p, Daniel Colascione wrote: > > On Thu, Nov 7, 2019 at 12:09 PM Chet Ramey wrote: >> >> On 11/5/19 12:49 PM, Daniel Colascione wrote: >>> Right now, bash history saves only the command line actually executed. >> >> This isn't quite the case. What it saves is the line returned from >> readline, before it's expanded or executed. > > Fair enough. > >>> Why not also, optionally, save command execution times and exit >>> statuses? This information is practically free to collect. >> >> Because by the time you gather this information, the command has already >> been saved completely. >> >> There have been various proposals to extend the timestamp with additional >> information, but it's all data you can gather when the timestamp is saved >> before the command is executed. > > That's how history works today, yes. I'm wondering whether it'd be > possible to maintain an auxiliary history that included not only the > command lines read, but also their execution time and outcome. Doing > something in PROMPT_COMMAND doesn't seem quite accurate. Maybe what I > really want is something like $?, but instead of containing exit > status, it would contain information from a struct rusage (derived > from wait4) for the last command. Or something like that anyway. The > larger point is that the shell could gather this information > proactively almost for free and I don't think user code running in > existing shell extension points can do the same job. > Conceptually, this is quite a leap. Right now, the history list doesn't require *any* effort beyond logging the input. What you are suggesting may be readily accessible, but it's still *additional* work that must be done. Furthermore, a few issues off the top of my head: * How would handle background jobs? Would they appear in the order they are started, or the order they are completed? * Suppose I start a loop like for x in 1 2 3; do someCommand "$x" done Do you want to store the result of the for loop? Each of the commands run in the loop? What would that look like? * Would you want some way of linking the result of a `wait -n` command with the command it waited for? What would that look like? * Would you want to store *any* output from a command in your log? I think the design of such a feature would require a lot of careful thought to be useful. -- Clint