-
-
Save goyalankit/a1c88bfc69107f93cda1 to your computer and use it in GitHub Desktop.
################################################################# | |
# = 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 |
clean, simple and fast - thx
Personally I found awk and PERL to be to heavy weight :) So I went for
cat ~/.bash_history | cut -d' ' -f1- | sort | uniq | xargs -I % echo ": $(date +%s):0;" % >> ~/.zsh_history
Personally I found awk and PERL to be to heavy weight :) So I went for
cat ~/.bash_history | cut -d' ' -f1- | sort | uniq | xargs -I % echo ": $(date +%s):0;" % >> ~/.zsh_history
This worked like a charm on OSX Catalina from bash to zsh.
Script is working for me. Ubuntu 20.20. History moved. Thank you!
Guys ;)
cp ~/.bash_history ~/.zsh_history
works
Probably zsh wrote some import from just cmdlines in history
Since I didn't see trusty old sed
, here's one I made with my friend sed
cat ~/.bash_history | uniq | sed "s/^/\: $(date +%s)\:0;/" >> ~/.zsh_history
Since I didn't see trusty old
sed
, here's one I made with my friendsed
cat ~/.bash_history | uniq | sed "s/^/\: $(date +%s)\:0;/" >> ~/.zsh_history
Works a treat. Cheers.
Thanks a lot brother.
Awesome work! Thank you!