################################################################# | |
# = This script transfers bash history to zsh history | |
# = Change bash and zsh history files, if you don't use defaults | |
# | |
# = Usage: ruby bash_to_zsh_history.rb | |
# | |
# = Author: Ankit Goyal | |
################################################################# | |
# change if you don't use default values | |
BASH_HISTORY_FILE_PATH="#{ENV['HOME']}/.bash_history" | |
ZSH_HISTORY_FILE_PATH="#{ENV['HOME']}/.zsh_history" | |
# Read the bash history file | |
bash_hist_file = File.read(BASH_HISTORY_FILE_PATH) | |
# Get the list of commands from bash history hile | |
command_list = bash_hist_file.split("\n") | |
# Open the zsh history file | |
zsh_hist_file = File.open(ZSH_HISTORY_FILE_PATH, "a") | |
# Get timestamp required for zsh history file format and update the history file | |
time = Time.now.to_i | |
command_list.each do |command| | |
time += 1 | |
zsh_hist_file.write(": #{time}:0;#{command}\n") | |
end | |
# Close the file | |
zsh_hist_file.close |
This comment has been minimized.
This comment has been minimized.
Worked phenomenally, thank you! |
This comment has been minimized.
This comment has been minimized.
Just what I was looking for ! Thank you !! |
This comment has been minimized.
This comment has been minimized.
Thanks ! |
This comment has been minimized.
This comment has been minimized.
Perfect! |
This comment has been minimized.
This comment has been minimized.
This command seems to ignore the timestamps in the ~/.bash_history file? |
This comment has been minimized.
This comment has been minimized.
I'm getting:
Did anyone else have this issue? My EDIT: Solution:
I tried this, but I think it was before I increased ZSH history limit, so it was mangling my history to 10k lines. From my
|
This comment has been minimized.
This comment has been minimized.
Works fine and fast! Thank you! |
This comment has been minimized.
This comment has been minimized.
Awesome script! Worked like a charm. Thank you for sharing! |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Thank you! For anyone else who uses this, if you get |
This comment has been minimized.
This comment has been minimized.
Thank you for the script, it worked! Only thing I had to modify is the 19070* 2018-04-08 15:45 git pull
19071* 2018-04-08 15:45 makepkg -sci # <--- old .bash_history
19072* 2018-04-08 12:55 bash # <--- new .zsh_history
19073* 2018-04-08 12:52 echo $SHELL Just changing it to 10534 2018-04-08 12:58 git pull
10535 2018-04-08 12:58 makepkg -sci # <--- old .bash_history
10536 2018-04-08 13:14 bash # <--- new .zsh_history
10537 2018-04-08 13:14 echo $SHELL |
This comment has been minimized.
This comment has been minimized.
If you have invalid UTF-8 sequences in your
|
This comment has been minimized.
This comment has been minimized.
Thank you. |
This comment has been minimized.
This comment has been minimized.
one line command: |
This comment has been minimized.
This comment has been minimized.
Almost... |
This comment has been minimized.
This comment has been minimized.
Thanks, it's work |
This comment has been minimized.
This comment has been minimized.
I was surprised to see the top Google results for this are Ruby and Python scripts, huh! Then I missed the
Then wrote a Perl command that I ran under Bash so Zsh would not be running and conflict (from Zsh, I ran
|
This comment has been minimized.
This comment has been minimized.
Thanks, it's work fine! |
This comment has been minimized.
This comment has been minimized.
awesome dude |
This comment has been minimized.
This comment has been minimized.
Thanks, works perfectly. |
This comment has been minimized.
This comment has been minimized.
Worked perfectly. Worth noting that you should remember to increase your SAVEHIST value first. |
This comment has been minimized.
This comment has been minimized.
Cool! This is a node script version https://gist.github.com/marchrius/71f858c2b032f037d286cbf2394ad8a7 |
This comment has been minimized.
This comment has been minimized.
getting this error message - anyone have a solution? ./bash_to_zsh_history.rb: line 15: syntax error near unexpected token Ruby version is ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19] |
This comment has been minimized.
This comment has been minimized.
@robertstrom You probably copy-pasted the script wrong. There's an extra |
This comment has been minimized.
This comment has been minimized.
Worked perfectly! Thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks bigplum & gimpf,
just what I needed on a VM without ruby installed |
This comment has been minimized.
This comment has been minimized.
Thanks for the script |
This comment has been minimized.
This comment has been minimized.
Awesome work! Thank you! |
This comment has been minimized.
This comment has been minimized.
clean, simple and fast - thx |
This comment has been minimized.
This comment has been minimized.
Personally I found awk and PERL to be to heavy weight :) So I went for
|
This comment has been minimized.
This comment has been minimized.
This worked like a charm on OSX Catalina from bash to zsh. |
This comment has been minimized.
This comment has been minimized.
Script is working for me. Ubuntu 20.20. History moved. Thank you! |
This comment has been minimized.
This comment has been minimized.
Guys ;) |
This comment has been minimized.
Thx the script is fast and good