Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature advice: collect history to an output text file #487

Open
deepcomp2023 opened this issue Mar 17, 2023 · 1 comment
Open

New feature advice: collect history to an output text file #487

deepcomp2023 opened this issue Mar 17, 2023 · 1 comment

Comments

@deepcomp2023
Copy link

deepcomp2023 commented Mar 17, 2023

First of all this tool is great for work under shell, thanks for your great job!

While for most of people, we often need to get the past query history for review. Could you add such as feature that collection the history input and output to a text file? And hopefully this is configurable but not inputting the filename every time.

Just for your reference and thanks.

@guites
Copy link

guites commented Jul 15, 2023

edit: I created a version that uses sqlite3: https://github.com/guites/transl

Hey, I'm doing just what you said by wrapping my calls to trans in another script, which in turn calls the original trans program, allowing me to save what I've used as inputs and the output to a separate file.

Here's an example using Python

# trans.py
import subprocess
import sys

# switch the first argument (the .py filename)
# with a call to the actual `trans` executable
args = ["trans"] + sys.argv[1:]

result = subprocess.run(
    args,
    stdout=subprocess.PIPE,
    stderr=subprocess.STDOUT,
    text=True
)

# print the output as expected
print(result.stdout)

# save input and output to a file
with open("logs.txt", "a") as file:
    file.write(str(args) + "\n\n")
    file.write(result.stdout)
    file.write("\n\n=========================\n")

you can then call python3 trans.py instead of trans, ex.

python3 trans_wrap.py fr: "je suis français"
python3 trans_wrap.py pt-br:en "e é assim que fica o script" -speak

and the output would be saved to "logs.txt"

cat logs.txt

['trans', 'fr:', 'je suis français']

je suis français

I am French

Translations of je suis français
[ Français -> English ]

je suis français
    I am French, I'm French


=========================
['trans', 'pt-br:en', 'e é assim que fica o script', '-speak']

e é assim que fica o script

and this is how the script looks

Translations of e é assim que fica o script
[  -> English ]

e é assim que fica o script
    , and this is how the script looks like


=========================

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants