feat: update zsh environment variables, refactor gdc script, add gptc script, and modify xr script handling

This commit is contained in:
Arthur K. 2025-01-08 17:28:11 +03:00
parent ecd0b37009
commit 7cf6ef3017
Signed by: wzray
GPG key ID: B97F30FDC4636357
4 changed files with 115 additions and 14 deletions

View file

@ -25,9 +25,18 @@ XDG_DATA_HOME="${HOME}/.local/share"
XDG_CONFIG_HOME="${HOME}/.config"
XDG_STATE_HOME="${HOME}/.local/state"
XDG_CACHE_HOME="${HOME}/.cache"
XDG_DESKTOP_DIR="$HOME/"
XDG_DOWNLOAD_DIR="$HOME/Downloads"
XDG_TEMPLATES_DIR="$HOME/"
XDG_PUBLICSHARE_DIR="$HOME/"
XDG_DOCUMENTS_DIR="$HOME/"
XDG_MUSIC_DIR="$HOME/"
XDG_PICTURES_DIR="$HOME/"
XDG_VIDEOS_DIR="$HOME/"
# default configs
ANDROID_HOME="${HOME}/.local/share/android"
ANDROID_USER_HOME="${HOME}/.local/share/android-home"
BAT_THEME="TwoDark"
EDITOR="/usr/bin/nvim"
GNUPGHOME='~/.local/share/gnupg'

View file

@ -43,10 +43,6 @@ case "$1" in
;;
esac
if [ "$#" -lt "1" ]; then
die "Missing date!"
fi
export GIT_AUTHOR_DATE="${date}"
export GIT_COMMITTER_DATE="${date}"

96
.local/bin/scripts/gptc Executable file
View file

@ -0,0 +1,96 @@
#!/usr/bin/env python3
import os
import subprocess
import requests
from sys import stderr
def die(r: str):
print(r, file=stderr)
exit(1)
def cleanup_backtics(msg: str, depth: int) -> str:
if depth <= 0 or msg[0] != '`' or msg[-1] != '`':
return msg
return cleanup_backtics(msg[1:-1], depth - 1)
def cleanup_string(s: str) -> str:
return cleanup_backtics(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.
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.
The general structure is:
```
<type>: <short description>
```
- **Type**: Specifies the kind of change (e.g., `feat` for a new feature, `fix` for a bug fix, `docs` for documentation updates, `ci` for updates to the CI/CD pipeline, `chore` for something less usefull).
- **Short Description**: A concise summary of the change.
For example:
- feat: add OAuth2 support
- fix: resolve dropdown alignment issue
- docs: update README.md
- ci: fix `test/windows` pipeline
The `short description` in the commit message should concisely describe the changes that this commit contains. The `short description` should not be a filename. Do not use the same `short description` for every patch in a whole patch series (where a patch series is an ordered sequence of multiple, related patches).
Bear in mind that the `short description` of your commit becomes a globally-unique identifier for that patch. It propagates all the way into the `git changelog`. The `short description` may later be used in developer discussions which refer to the patch. People will want to google for the `short description` to read discussion regarding that patch. It will also be the only thing that people may quickly see when, two or three months later, they are going through perhaps thousands of patches using tools such as `gitk` or `git log --oneline`.
Use the "`" (backtick) symbol when referring to certain parts of code in your commit message."""
with open(f"{os.environ['HOME']}/.secrets/openai.secret") as f:
KEY=f.readline().strip()
ps = subprocess.Popen(["git", "diff", "--staged"], stdout = subprocess.PIPE)
diff = ps.stdout and ps.stdout.read().decode('utf-8').strip()
if not diff or diff == "":
die("Nothing to commit!")
r = requests.post("https://api.openai.com/v1/chat/completions", headers={'Authorization': f'Bearer {KEY}'}, json = {
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": [
{
"type": "text",
"text": PROMPT,
}
]
},
{
"role": "user",
"content": [
{
"type": "text",
"text": diff,
}
]
},
],
"response_format": {
"type": "text"
},
"temperature": 1,
"max_completion_tokens": 2048,
"n": 5,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0
})
if r.status_code != 200:
die(f"status code: {r.status_code}\n{r.text}")
choices = '# ' + '\n# '.join(map(lambda x: cleanup_string(x['message']['content']), r.json()['choices']))
fd = os.memfd_create("file.txt")
fd_wrapper = os.fdopen(fd, mode="w+")
fd_wrapper.write(choices)
fd_wrapper.flush()
fd_path = f"/proc/{os.getpid()}/fd/{fd}"
os.system(f"git commit -v -e -F- < {fd_path}")

View file

@ -27,15 +27,15 @@ if [[ -z "${EXT_MON}" ]]; then
change_dpi 192 48
else
:
# xrandr --rmmode "${INT_RES}"
# # shellcheck disable=all
# xrandr --newmode $(echo $INT_MODELINE) # this is a hack to make xrandr recognize the resolution
# xrandr --addmode eDP-1 "${INT_RES}"
# xrandr --output eDP-1 --pos 2560x400 --mode "${INT_RES}" --output "${EXT_MON}" --pos 0x0 --mode "2560x1440" --rate 144 --primary
# change_dpi 96 24
# xinput --map-to-output "UGTABLET 6 inch PenTablet Mouse" "${EXT_MON}"
# xinput --map-to-output "UGTABLET 6 inch PenTablet Pen (0)" "${EXT_MON}"
# xinput --map-to-output "UGTABLET 6 inch PenTablet Eraser (0)" "${EXT_MON}"
xrandr --rmmode "${INT_RES}"
# shellcheck disable=all
xrandr --newmode $(echo $INT_MODELINE) # this is a hack to make xrandr recognize the resolution
xrandr --addmode eDP-1 "${INT_RES}"
xrandr --output eDP-1 --pos 2560x400 --mode "${INT_RES}" --output "${EXT_MON}" --pos 0x0 --mode "2560x1440" --rate 144 --primary
change_dpi 96 24
xinput --map-to-output "UGTABLET 6 inch PenTablet Mouse" "${EXT_MON}"
xinput --map-to-output "UGTABLET 6 inch PenTablet Pen (0)" "${EXT_MON}"
xinput --map-to-output "UGTABLET 6 inch PenTablet Eraser (0)" "${EXT_MON}"
fi
"${HOME}/.config/X11/autostart"
exec "${HOME}/.config/X11/autostart"