feat: update MANPAGER and alias, rename gptc script and improve logic

This commit is contained in:
Arthur K. 2025-01-09 19:16:46 +03:00
parent 7cf6ef3017
commit a101c908ca
Signed by: wzray
GPG key ID: B97F30FDC4636357
3 changed files with 25 additions and 14 deletions

View file

@ -44,7 +44,7 @@ GOPATH="${HOME}/.local/share/go"
GPG_TTY="$(tty)" GPG_TTY="$(tty)"
JAVA_HOME="/usr/lib/jvm/java-23-openjdk" JAVA_HOME="/usr/lib/jvm/java-23-openjdk"
LESS="--wheel-lines 3 --mouse" LESS="--wheel-lines 3 --mouse"
MANPAGER="sh -c 'col -bx | bat -l man -p'" MANPAGER="sh -c 'col -bx | bat -l man -p --theme Monokai\ Extended'"
MANROFFOPT="-c" MANROFFOPT="-c"
MTR_OPTIONS="-t" MTR_OPTIONS="-t"
SSH_ASKPASS="${HOME}/.local/bin/scripts/pinentry-askpass" SSH_ASKPASS="${HOME}/.local/bin/scripts/pinentry-askpass"

View file

@ -57,7 +57,7 @@ alias ll="ls -lh"
alias lt="ls --color=always --icon=always -lt" alias lt="ls --color=always --icon=always -lt"
# set bat as help pager # set bat as help pager
alias -g -- --help='--help 2>&1 | bat --language=help --style=plain' alias -g -- --help='--help 2>&1 | bat --language=help --style=plain --theme Monokai\ Extended'
# useful cd aliases # useful cd aliases
alias ..="cd ../" alias ..="cd ../"

View file

@ -2,22 +2,25 @@
import os import os
import subprocess import subprocess
import sys
import requests import requests
from sys import stderr
def die(r: str): def die(r: str):
print(r, file=stderr) print(r, file=sys.stderr)
exit(1) exit(1)
def cleanup_backtics(msg: str, depth: int) -> str: def strip_equal(msg: str, substring: str, n_max: int) -> str:
if depth <= 0 or msg[0] != '`' or msg[-1] != '`': if n_max <= 0 or msg[0] != substring or msg[-1] != substring:
return msg return msg
return cleanup_backtics(msg[1:-1], depth - 1) return strip_equal(msg[1:-1], substring, n_max - 1)
def cleanup_string(s: str) -> str: def cleanup_string(s: str) -> str:
return cleanup_backtics(s.replace('\n','').strip(), 4) return strip_equal(s.replace('\n','').strip(), '`', 4)
PROMPT="""You are an assistant that helps user to write semantic commit messages. You will be presented with git diff of the code. Write a single short, concise and meaningful message to describe changes that were made. You can only write a single commit message for the entire diff. The single message that you write has to include ALL the changes, that exist in the diff. You can't skip anything.
# globals
PROMPT="""You are an assistant that helps user to write semantic commit messages. You will be presented with git diff of the code. Write a single short, concise and meaningful message to describe changes that were made. You can only write a single commit message for the entire diff. The single message that you write has to include ALL the changes, that exist in the diff. You can't skip anything. Git commit messages are LIMITED TO 72 CHARACTERS. YOUR MESSAGE COULD NOT BE LONGER THAN 72 CHARACTERS.
Semantic commit messages are a structured way of writing commit messages to clearly describe the purpose and scope of changes in a project. They follow a standardized format, using a prefix that conveys the intent of the change. Semantic commit messages are a structured way of writing commit messages to clearly describe the purpose and scope of changes in a project. They follow a standardized format, using a prefix that conveys the intent of the change.
@ -46,10 +49,18 @@ with open(f"{os.environ['HOME']}/.secrets/openai.secret") as f:
KEY=f.readline().strip() KEY=f.readline().strip()
ps = subprocess.Popen(["git", "diff", "--staged"], stdout = subprocess.PIPE) ps = subprocess.Popen(["git", "diff", "--staged"], stdout = subprocess.PIPE)
diff = ps.stdout and ps.stdout.read().decode('utf-8').strip() DIFF = ps.stdout and ps.stdout.read().decode('utf-8').strip()
if not diff or diff == "": if not DIFF or DIFF == "":
die("Nothing to commit!") die("Nothing to commit!")
# arguemnt parsing
N: int = 5
argv = iter(sys.argv[1:])
for arg in argv:
if arg == "-n":
N = int(next(argv))
r = requests.post("https://api.openai.com/v1/chat/completions", headers={'Authorization': f'Bearer {KEY}'}, json = { r = requests.post("https://api.openai.com/v1/chat/completions", headers={'Authorization': f'Bearer {KEY}'}, json = {
"model": "gpt-4o-mini", "model": "gpt-4o-mini",
"messages": [ "messages": [
@ -67,7 +78,7 @@ r = requests.post("https://api.openai.com/v1/chat/completions", headers={'Author
"content": [ "content": [
{ {
"type": "text", "type": "text",
"text": diff, "text": DIFF,
} }
] ]
}, },
@ -76,8 +87,8 @@ r = requests.post("https://api.openai.com/v1/chat/completions", headers={'Author
"type": "text" "type": "text"
}, },
"temperature": 1, "temperature": 1,
"max_completion_tokens": 2048, "max_completion_tokens": 72,
"n": 5, "n": N,
"top_p": 1, "top_p": 1,
"frequency_penalty": 0, "frequency_penalty": 0,
"presence_penalty": 0 "presence_penalty": 0