From cf0b717e4252625774d9d44a2c60e6e79b8659de Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Tue, 16 Jul 2024 20:31:59 +0900 Subject: [PATCH] add help.py --- help/README.md | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 help/README.md diff --git a/help/README.md b/help/README.md new file mode 100644 index 0000000..5ddf79f --- /dev/null +++ b/help/README.md @@ -0,0 +1,78 @@ +## `help.py` +```python +#!/usr/bin/python3 + +import sys, requests, textwrap, json, rich, os, getpass, socket, os +from rich import print + +if __name__ == "__main__": + prompt = ' '.join(sys.argv[1:]) + if prompt.strip(): + response = requests.post( + f'http://localhost:8080/completion', + json={ + 'prompt': textwrap.dedent(f"""{{'user_request': {prompt}}} + Provide a bash script (simple, mostly one-liner) + {{'analyzed_user_intent': '...(in English)', 'bash_program': '[^\s]+(without argument)' 'script': '...(will be executed as-is, without modification)', 'description': '... (in Korean)' }} + format의 JSON으로 응답하시오."""), + 'json_schema': {} + } + ).json() + response = json.loads(response['content']) + print() + print(f"\t[yellow1]({response['analyzed_user_intent']})") + print() + print(f"\t[spring_green1]$ {response['script']}") + print() + print(f"\t[sky_blue1]- {response['description']}") + print() + print('\t[sky_blue1]실행하시겠습니까? (y/N)', end='') + user = input('') + script = response['script'] + + if len(user) and user[0] == 'y': + user = getpass.getuser() + hostname = socket.gethostname() + pwd = os.getcwd().replace(f'/home/{user}', '~') + head = f'[bright_green]{user}@{hostname}[white]:[bright_blue]{pwd}[spring_green1]$ ' + + print(f'\n{head}{script}') + print() + os.system(script) +``` + +```sh +$ alias help='python3 ./help.py' +$ help 이 폴더 안에 있는 .md 파일 다 찾기 + + (The user wants to find all .md files in the current directory.) + + $ find . -name '*.md' + + - 현재 디렉토리에 있는 모든 .md 파일을 찾습니다. + + 실행하시겠습니까? (y/N)y + +w@j:~/hub/book$ find . -name '*.md' + +./style-guide.md +./CONTRIBUTING.md +./README.md +./.github/ISSUE_TEMPLATE/bug_report.md +./.github/ISSUE_TEMPLATE/new_translation.md +./TODO.md +./first-edition/src/functions.md +./first-edition/src/documentation.md +./first-edition/src/guessing-game.md +./first-edition/src/primitive-types.md +./first-edition/src/conditional-compilation.md +./first-edition/src/the-stack-and-the-heap.md +./first-edition/src/choosing-your-guarantees.md +./first-edition/src/if-let.md +./first-edition/src/concurrency.md +./first-edition/src/match.md +./first-edition/src/method-syntax.md +./first-edition/src/getting-started.md + +... +``` \ No newline at end of file