1

Synchronize history across bash sessions

 1 year ago
source link: https://gist.github.com/jan-warchol/89f5a748f7e8a2c9e91c9bc1b358d3ec
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

This script sounds very interesting. But what am I supposed to do with the script? What do I have to configure how to use this?
Thanks

Author

jan-warchol commented on Aug 12, 2019

edited

@dkadioglu save and source it in your shell configuration file (usually ~/.bashrc on Linux, ~/.bash_profile on Mac) - like this:

source sync-history.sh

Let me know if you need more detailed instructions.

Thank you very much, works so far. One thing though: It seems, that the deletion of entries (history -d offset) is not possible anymore. At least for me, whichever item I delete, it still appears in the history. I tried to find a solution for that, without success so far. Do you have any idea?

hoefkensj commented on Jul 15

@dkadioglu save and source it in your shell configuration file (usually ~/.bashrc on Linux, ~/.bash_profile on Mac) - like this:

source sync-history.sh

Let me know if you need more detailed instructions.

hi there i stumbled on this, and just wanted to mention that instead of using source sync-history.sh there is a safer way to do this :

[[ -r /path/to/file.sh ]] && . /path/to/file.sh

explanation:

  • [[ -r checks fi the file that follows is readable and returns True if so

  • && executes only if the command before returns True (or exit status 0 = success)

  • . is somewhat shorthad for source (note there is a spacebehind the '.' so '. '

result : tests is if the file exists and is readable before sourcing it.

you can combine it with:

 FILE="nohup.out"  ; [[ -r $FILE ]] && .  $FILE ; [[ ! -e   $FILE ]] && echo "! Waring $FILE not found "

wich will give you a warning if you somhow in the future accidently rename or move the file.

if you have your bash rc split up in multiple files (like i have to create some order in the chaos) you can use:

for conf in $(ls /opt/local/scripts/rc/bash/[3-9]??_*) ; do 
    printf "Loading: $(basename $conf)"
    [[ -r "${conf}" ]] && source "${conf}" 
    printf '\x1b[40G\x1b[32mDONE\x1b[0m\n'
done

wich will in this case find all the files that start with a digit from 3-9 (my dir contents look like :bash 000_bashrc.conf 100_includes.conf 201_opts.conf 221_binds.conf ... 701_exports.conf hoefkens.bash_history ... an the loop is called from within includes (wich so the 000 and 1* , 2* dont need to get loaded
and source them one by one printing a success message to stdout
starting a new tty session thus looks like:
Screenshot_20220715_225318

@hoefkensj Thank you very much for the helpful tip and the improvement!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK