Skip to content

Commit c6d7985

Browse files
authored
zsh-history-to-fish: fix runtime error via patch (NixOS#371249)
2 parents cb61d04 + fc6fd61 commit c6d7985

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
From 121ba93b2860b7ee6bbe2430c818bba2da822a8e Mon Sep 17 00:00:00 2001
2+
From: zjeffer <[email protected]>
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'

pkgs/by-name/zs/zsh-history-to-fish/package.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ python3.pkgs.buildPythonApplication rec {
2525
"zsh_history_to_fish"
2626
];
2727

28+
patches = [
29+
# Patch from currently-unmerged PR, fixing runtime error.
30+
# Should be removed when PR is merged or error is otherwise fixed.
31+
# Check https://github.com/rsalmei/zsh-history-to-fish/pull/15 if you're in the future
32+
./fix-runtime-error.patch
33+
];
34+
2835
meta = with lib; {
2936
description = "Bring your ZSH history to Fish shell";
3037
homepage = "https://github.com/rsalmei/zsh-history-to-fish";

0 commit comments

Comments
 (0)