Created
July 2, 2024 15:55
-
-
Save bdmorin/89a815ed6d65aa6add8de8a864a3b71b to your computer and use it in GitHub Desktop.
fish history to zsh history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# default verbose | |
import os | |
import time | |
from pathlib import Path | |
def convert_fish_to_zsh_history(): | |
fish_history_path = Path.home() / '.local/share/fish/fish_history' | |
zsh_history_path = Path.home() / '.zsh_history' | |
if not fish_history_path.exists(): | |
print(f"Fish history file not found at {fish_history_path}") | |
return | |
command_count = 0 | |
with fish_history_path.open('r') as fish_file, zsh_history_path.open('w') as zsh_file: | |
current_command = "" | |
timestamp = "" | |
for line in fish_file: | |
line = line.strip() | |
if line.startswith('- cmd:'): | |
current_command = line[7:].strip() | |
elif line.startswith(' when:'): | |
timestamp = line[8:].strip() | |
if current_command and timestamp: | |
unix_timestamp = int(timestamp) | |
zsh_timestamp = f": {unix_timestamp}:0;" | |
zsh_file.write(f"{zsh_timestamp}{current_command}\n") | |
command_count += 1 | |
current_command = "" | |
timestamp = "" | |
print(f"Conversion complete. {command_count} commands converted.") | |
print(f"Zsh history saved to {zsh_history_path}") | |
if __name__ == "__main__": | |
convert_fish_to_zsh_history() | |
print("You probably have to run 'fc -R ~/.zsh_history' for changes to take effect") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment