|
| 1 | +From 121ba93b2860b7ee6bbe2430c818bba2da822a8e Mon Sep 17 00:00:00 2001 |
| 2 | + |
| 3 | +Date: Sun, 29 Dec 2024 20:15:29 +0100 |
| 4 | +Subject: [PATCH] Fixes & improvements |
| 5 | + |
| 6 | +--- |
| 7 | + zsh_history_to_fish/command.py | 14 ++++++++++---- |
| 8 | + 1 file changed, 10 insertions(+), 4 deletions(-) |
| 9 | + |
| 10 | +diff --git a/zsh_history_to_fish/command.py b/zsh_history_to_fish/command.py |
| 11 | +index 4d8a12d..136c553 100644 |
| 12 | +--- a/zsh_history_to_fish/command.py |
| 13 | ++++ b/zsh_history_to_fish/command.py |
| 14 | +@@ -19,7 +19,12 @@ |
| 15 | + |
| 16 | + def read_history(input_file): |
| 17 | + command = ZSH_HISTORY_READER.format(input_file) |
| 18 | +- p = subprocess.run(command, capture_output=True, shell=True, encoding='utf8') |
| 19 | ++ lines: list[str] = [] |
| 20 | ++ try: |
| 21 | ++ p = subprocess.run(command, capture_output=True, shell=True, encoding='utf8', check=True) |
| 22 | ++ except Exception as e: |
| 23 | ++ print(f'An exception occurred while reading history: {e}') |
| 24 | ++ sys.exit(1) |
| 25 | + lines = p.stdout.splitlines() |
| 26 | + yield from map(lambda x: x.replace('\\n', '\n'), lines) |
| 27 | + |
| 28 | +@@ -48,11 +53,11 @@ def display_changed(zsh, fish): |
| 29 | + def writer_factory(output_file, dry_run): |
| 30 | + if dry_run: |
| 31 | + yield lambda x: None |
| 32 | +- print(f'No file has been written.') |
| 33 | ++ print('No file has been written.') |
| 34 | + return |
| 35 | + |
| 36 | +- with open(output_file, 'a') as out: |
| 37 | +- yield lambda x: out.write(x) |
| 38 | ++ with open(output_file, 'a', encoding='utf8') as out: |
| 39 | ++ yield out.write |
| 40 | + print(f'\nFile "{output_file}" has been written successfully.') |
| 41 | + |
| 42 | + |
| 43 | +@@ -74,6 +79,7 @@ def exporter(input_file, output_file, dry_run, no_convert): |
| 44 | + converter = (lambda x: x) if no_convert else naive_zsh_to_fish |
| 45 | + changed = [] |
| 46 | + with writer_factory(output_file, dry_run) as writer: |
| 47 | ++ i = 0 |
| 48 | + for i, (timestamp, command_zsh) in enumerate(parse_history(input_file)): |
| 49 | + command_fish = converter(command_zsh) |
| 50 | + fish_history = f'- cmd: {command_fish}\n when: {timestamp}\n' |
0 commit comments