Skip to content

Commit

Permalink
Remove needs for get_ipython
Browse files Browse the repository at this point in the history
  • Loading branch information
royreznik committed Dec 30, 2023
1 parent 1de6b31 commit 5fca11e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions greps/greps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import argparse
import subprocess

from IPython.core.getipython import get_ipython
from IPython.core.magic import (
Magics,
magics_class,
Expand Down Expand Up @@ -29,23 +28,23 @@ def get_args_parser() -> argparse.ArgumentParser:
@line_magic # type: ignore[misc]
def greps(self, params: str = "") -> str:
parser = self.get_args_parser()
ipython = get_ipython() # type: ignore[no-untyped-call]
args = parser.parse_args(params.split())
grep_args = " ".join(args.grep_args)
line = args.line
assert self.shell, "Shell isn't Initialized"

if line is None:
if len(ipython.history_manager.output_hist_reprs) < 1:
if len(self.shell.history_manager.output_hist_reprs) < 1:
raise ValueError("Output history is empty")
output_line = list(
sorted(ipython.history_manager.output_hist_reprs.keys())
sorted(self.shell.history_manager.output_hist_reprs.keys())
)[-1]
else:
if line not in ipython.history_manager.output_hist_reprs:
if line not in self.shell.history_manager.output_hist_reprs:
raise ValueError(f"There is no output for line: {line}")
output_line = line

last_output = ipython.history_manager.output_hist_reprs[output_line]
last_output = self.shell.history_manager.output_hist_reprs[output_line]
output = subprocess.run(
f'echo "{last_output}" | grep {grep_args}',
shell=True,
Expand Down

0 comments on commit 5fca11e

Please sign in to comment.