From 51be9846c13ceab37e0cebd34f862066b915f2ce Mon Sep 17 00:00:00 2001 From: karamelmar Date: Sat, 4 Dec 2021 09:47:50 +0100 Subject: [PATCH] bash2zsh history import (ruby) --- bash_to_zsh_history.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 bash_to_zsh_history.rb diff --git a/bash_to_zsh_history.rb b/bash_to_zsh_history.rb new file mode 100644 index 0000000..f56989f --- /dev/null +++ b/bash_to_zsh_history.rb @@ -0,0 +1,32 @@ + +################################################################# +# = 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