helpThe GNU Bourne-Again SHell - Support: sr #109679, Save current working directory in...

 
 

sr #109679: Save current working directory in history

Submitted by:  Steven Willis <onlynone>
Submitted on:  Thu 09 May 2019 05:53:44 PM UTC
Votes:  1  
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  None
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

Fri 31 Dec 2021 06:16:59 AM UTC, comment #1: 

I like this idea, but I wonder if it doesn't go far enough.

Ideally I would like to be able to replay the actions just given the recorded shell history, and the same starting files, and the same user input. I realise that's an unrealistic goal to automate, but I'd like there to be enough clues that a human reading the history can step through it and be reasonably sure of what happened.

I would prioritize putting the shell PID in the history before the cwd.

I would also like:

  • exit status of the last command, plus explanations for failed builtins
  • sub-second precision on the timestamps, so that (with suitable adjustment to the record delimiter) it becomes feasible to sort entries;
  • recording any major state changes such new cwd, new umask, variables after assignments, readonly/export/unexport/unset variables, etc.
  • recording the original raw as-typed input (in addition to the expanded form after history expansions that's currently recorded);
Martin D Kealey <kurahaupo>
Thu 09 May 2019 05:53:44 PM UTC, original submission:  

It would be nice if bash could save and display the directory where a command from its history was run.

I have a patch which adds the path as a string in the `HIST_ENTRY` struct and reads and writes it after the timestamp in the comment line in the history file.

The modified history file looks like:

    #1557421027 /Users/me/projects/bash
    cd lib
    #1557421028 /Users/me/projects/bash/lib
    ls
    #1557421033 /Users/me/projects/bash/lib
    echo i am in lib
    #1557421034 /Users/me/projects/bash/lib
    ls
    #1557421037 /Users/me/projects/bash/lib
    cd readline/
    #1557421038 /Users/me/projects/bash/lib/readline
    ls
    #1557421041 /Users/me/projects/bash/lib/readline
    cd ..
    #1557421042 /Users/me/projects/bash/lib
    ls
    #1557421043 /Users/me/projects/bash/lib
    cd ..
    #1557421044 /Users/me/projects/bash
    echo

The patch doesn't change the output when `history` is run, but having it display the path in parens just before the command would be useful. It also doesn't change any functionality when running a command from the history, but one could imagine having the ability to first change directory of the saved command before re-execution. It also depends on timestamp saving to be turned on as I didn't add a different boolean for cwd path saving. I just wanted to get feedback before going any farther.

Steven Willis <onlynone>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #46890:  add_cwd_to_history.patch added by onlynone (7KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by kurahaupo (Posted a comment)
  • -email is unavailable- added by kurahaupo (Voted in favor of this item)
  • -email is unavailable- added by onlynone (Submitted the item)
  •  

    There is 1 vote so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

     

     

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-12-31 kurahaupo Carbon-Copy- => Added kurahaupo
    2019-05-09 onlynone Attached File- => Added add_cwd_to_history.patch, #46890

    Back to the top


    Powered by Savane 3.9