-
-
Notifications
You must be signed in to change notification settings - Fork 0
more utils #10
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
base: master
Are you sure you want to change the base?
more utils #10
Changes from 19 commits
b878c90
4051ab8
c32e36f
bedb464
1bd181f
10dbca9
fdfa17e
e588ca9
f68b13a
710e372
3ab6688
59f2909
4bd5f8f
811966b
7948269
9894062
7e1fbcd
c84bc54
7fde93b
84adfeb
0e55404
4c91c9f
86f9582
823d704
528c4de
017f03e
0b550f2
c144b48
321f2eb
23448b5
d3ba6d0
ad27325
69bb6e5
1feddca
148e53e
8b77455
d19c681
75b01d4
2a68d15
5d8c128
1efd3cf
c5a52ef
f33d04b
aacd810
ccb916a
f90b899
4e864bb
382e6fc
85b24a2
e636771
0474076
10f5827
aaeb456
ebd609b
cd3f541
e8f85b5
e500314
e396037
162cbb7
fea9cdf
5c861d2
4d1de78
385ac32
092da21
469bf52
4e8b686
f400314
71cb689
8397183
1804786
b0dffad
cec3fb0
ee76127
c53e4d1
903375d
9e85908
386de31
f075309
6b06c88
2a29266
da6c659
49bcd99
9b35a92
73dcf48
75fe57d
7012d30
cad71ff
19e51a3
b8a0c7f
c087c80
12ad4e2
a29b992
b9e6b84
26b9ab6
86b7c2a
9ce9b97
ecdd0cb
4e87d9a
cb94d5c
fc4a5e8
c30781f
c21d80f
bb83b6e
d7bbf11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -70,13 +70,15 @@ A set of functions for the **F**riendly **I**nteractive **Sh**ell (fish). This i | |||||||||||||||||||||||||
| - **`gitb`**: make a new git branch; | ||||||||||||||||||||||||||
| - **`gitc`**: make a git commit (short for `git commit -am`); | ||||||||||||||||||||||||||
| - **`gitcp`**: commit with the given parameters, and push the changes; | ||||||||||||||||||||||||||
| - **`gitcpr`**: commit with the given parameters, push the changes and open a pull request on *GitHub*; | ||||||||||||||||||||||||||
| - **`gitd`**: calculate the git difference and work with a pager to read the full response; | ||||||||||||||||||||||||||
| - **`gitf`**: alias for `git fetch`; | ||||||||||||||||||||||||||
| - **`gith`**: checkout a given branch; | ||||||||||||||||||||||||||
| - **`gitm`**: move a given file in a git repository; | ||||||||||||||||||||||||||
| - **`gitmaster`**: checkout the master branch (and stash work in progress if any); | ||||||||||||||||||||||||||
| - **`gitmastertag`**: checkout the master branch, pull from remote, tag the commit and push the tag to the repository; | ||||||||||||||||||||||||||
| - **`gitp`**: pushes the changes to the remote repository (short for `git push`); | ||||||||||||||||||||||||||
| - **`gitpr`**: open a pull request on *GitHub*; | ||||||||||||||||||||||||||
| - **`gitremote`**: add the remote as origin with the given `GIT_PREFIX` and the name of the directory as git project; | ||||||||||||||||||||||||||
| - **`gits`**: prints the status of the current Git repository (short for `git status`); | ||||||||||||||||||||||||||
| - **`gitt`**: make a git tag and push the tag; | ||||||||||||||||||||||||||
|
|
@@ -131,6 +133,10 @@ A set of functions for the **F**riendly **I**nteractive **Sh**ell (fish). This i | |||||||||||||||||||||||||
| - **`natrix-env`**: run a Python program in the natrix environment; | ||||||||||||||||||||||||||
| - **`numpy`**: start a Python shell with `numpy` imported; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### O | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - **`otp`**: generate/configure One Time Passwords (OTPs) with pass-extension-otp; | ||||||||||||||||||||||||||
|
Comment on lines
+148
to
+150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation for new section O. The ### O
- - **`otp`**: generate/configure One Time Passwords (OTPs) with pass-extension-otp;
+ - **`otp`**: generate/configure One Time Passwords (OTPs) with pass-extension-otp;📝 Committable suggestion
Suggested change
Suggested change
🧰 Tools🪛 markdownlint-cli2 (0.18.1)144-144: Unordered list indentation (MD007, ul-indent) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### P | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - **`pandas`**: start a Python shell with `numpy` and `pandas` imported; | ||||||||||||||||||||||||||
|
|
@@ -151,6 +157,7 @@ A set of functions for the **F**riendly **I**nteractive **Sh**ell (fish). This i | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### R | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - **`rabbitdoc`**: ask [*CodeRabbit*](https://github.com/coderabbitai) to generate docstrings for the latest pull request; | ||||||||||||||||||||||||||
| - **`redo`**: redo a command until the exit code is 0; | ||||||||||||||||||||||||||
| - **`remake`**: a loop to remake certain products with a Makefile; | ||||||||||||||||||||||||||
| - **`rmake`**: walk up the filetree until it finds a Makefile; | ||||||||||||||||||||||||||
|
|
@@ -185,6 +192,7 @@ A set of functions for the **F**riendly **I**nteractive **Sh**ell (fish). This i | |||||||||||||||||||||||||
| - **`taskd`**: set the task with the given id as done; | ||||||||||||||||||||||||||
| - **`taskflush`**: set all expired tasks to done; | ||||||||||||||||||||||||||
| - **`teeth`**: help cleaning teeth; | ||||||||||||||||||||||||||
| - **`timeprompt`**: wait for a given amount of time, or until the person hits a key exits with 1 if the user interrupted; | ||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify the description of The current phrasing is awkward: "wait for a given amount of time, or until the person hits a key exits with 1 if the user interrupted." Consider revising for clarity: - - **`timeprompt`**: wait for a given amount of time, or until the person hits a key exits with 1 if the user interrupted;
+ - **`timeprompt`**: wait for a given amount of time or until a key is pressed; exits with 1 if the user interrupted;📝 Committable suggestion
Suggested change
🧰 Tools🪛 markdownlint-cli2 (0.18.1)203-203: Unordered list indentation (MD007, ul-indent) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| - **`timestamp`**: get a string that specifies date and time, used for filenames mainly; | ||||||||||||||||||||||||||
| - **`todo`**: add or inspect to a todo list; | ||||||||||||||||||||||||||
| - **`truthful`**: check if at least one of the given Python literals or JSON values has truthiness `true`; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| function eggs --description 'wait until the eggs are fully cooked in the water boiler' | ||
| measurelog cooking.eggs.boiled true & | ||
| echo -e 'takes \e[1m7%\e[0m of the home battery' | ||
| waitfor 1500 '🥚 eggs' '🥚 ' | ||
| waitfor 1500 '' '🥚 eggs' '🥚 ' | ||
| here_is_the_news | ||
| end |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,6 @@ | ||||||||||
| function gitcpr --description 'commit with the given parameters, push the changes and open a pull request on GitHub' | ||||||||||
| set message (echo "$argv") | ||||||||||
| git commit -am $argv; | ||||||||||
|
Comment on lines
+2
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Commit message handling breaks for multi-word messages. Quote and join argv.
- set message (echo "$argv")
- git commit -am $argv;
+ set -l message (string join " " -- $argv)
+ git commit -am "$message" || return $statusNote: keeping 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| gitp | ||||||||||
| gitpr $argv | ||||||||||
|
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Gate subsequent steps on success; bubble up failures. Ensure push succeeds before opening a PR, and forward exit codes to the caller. - gitp
- gitpr $argv
+ gitp || return $status
+ gitpr $argv📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| end | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,4 @@ | ||||||
| function gitpr --description 'open a pull request on GitHub' | ||||||
| set title (echo "$argv") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Join argv safely for multi-word titles.
- set title (echo "$argv")
+ set -l title (string join " " -- $argv)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| firefox (gh pr create --title "$title" --body "$title" 2>&1 | tail -n 1) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid parsing gh output and hard dependency on Firefox; use
- firefox (gh pr create --title "$title" --body "$title" 2>&1 | tail -n 1)
+ if test -z "$title"
+ gh pr create --fill --web
+ else
+ gh pr create --title "$title" --body "$title" --web
+ end
+ return $status🤖 Prompt for AI Agents |
||||||
| end | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| function household --description 'wait until a household device has finished with info' -a time -a emoji -a name -a energy -a water | ||
| echo -e "takes \e[1m$energy%\e[0m of the home battery and \e[1m"$water"ℓ\e[0m water" | ||
| waitfor $time "$emoji $name" "$emoji " | ||
| waitfor $time '' "$emoji $name" "$emoji " | ||
| here_is_the_news | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| #!/bin/bash | ||
|
|
||
| curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid deprecated apt-key; use signed-by keyrings for Yarn too.
-curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
+curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo gpg --dearmor -o /usr/share/keyrings/yarn-archive-keyring.gpg
@@
-echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
+echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/yarn-archive-keyring.gpg] https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.listAlso applies to: 6-6 🤖 Prompt for AI Agents |
||
| curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg | ||
|
|
||
| echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list | ||
| echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list | ||
|
|
||
| sudo add-apt-repository ppa:tatokis/alarm-clock-applet | ||
|
|
||
| sudo apt-get update | ||
| sudo apt-get install -y alarm-clock-applet apt-file agrep certbot cloc curl cvc4 djinn fish git git-filter-repo git-lfs gnuplot-nox haskell-stack hlint hoogle ipython3 jq lambdabot ledger lynx nodeenv nodejs npm pandoc pdfsam powerline pv pylint python-wxtools python3-pytest rename sdate sox supervisor swi-prolog-core tig tox xdotool yarn zbar-tools z3 | ||
| sudo apt-get install -y alarm-clock-applet apt-file agrep certbot cloc curl cvc4 djinn fish gh git git-filter-repo git-lfs gnuplot-nox haskell-stack hlint hoogle ipython3 jq lambdabot ledger lynx nodeenv nodejs npm pandoc pass-extension-otp pdfsam powerline pv pylint python-wxtools python3-pytest rename sdate sox supervisor swi-prolog-core tig tox xdotool yarn zbar-tools z3 | ||
| sudo snap install upscayl | ||
| git lfs install | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| function otp --wraps='pass otp' --description 'generate/configure One Time Passwords (OTPs) with pass-extension-otp' | ||
| pass otp $argv | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| function rabbitdoc --description 'ask CodeRabbit.ai to generate docstrings for the latest pull request' | ||
| firefox (gh pr comment (gh pr list --json number --jq '.[0].number') -b '@coderabbitai generate docstrings') | ||
| end |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,3 @@ | ||||||||||||||
| function timeprompt --description 'wait for a given amount of time, or until the person hits a key exits with 1 if the user interrupted' -a time | ||||||||||||||
| ! bash -c "read -n 1 -t '$time'" | ||||||||||||||
| end | ||||||||||||||
|
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: use Fish’s “not” instead of “!” and fix description grammar Fish doesn’t support bash-style “!” for negation. Use not to invert the exit status. Also tighten the description grammar. Apply: -function timeprompt --description 'wait for a given amount of time, or until the person hits a key exits with 1 if the user interrupted' -a time
- ! bash -c "read -n 1 -t '$time'"
+function timeprompt --description 'wait for a given amount of time, or until the person presses a key; exits with 1 if the user interrupted' -a time
+ not bash -c "read -n 1 -t $time"
endNotes:
📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| function vitamins --description 'take our daily vitamins and magnesium' | ||
| waitfor 90 '💊 vitamins' '💊 ' | ||
| waitfor 90 '' '💊 vitamins' '💊 ' | ||
| measurelog health.vitamins true | ||
| hydrate 33cl | ||
| end |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||
| function waitfor --description 'wait a certain amount of time, or until the user hits ENTER' -a time -a label -a desc -a keydown -a until -a step | ||||||||||||||||
| function waitfor --description 'wait a certain amount of time, or until the user hits ENTER' -a time -a allow -a label -a desc -a keydown -a until -a step | ||||||||||||||||
| set es 0 | ||||||||||||||||
| if [ -n "$keydown" ] | ||||||||||||||||
| keycolor (string split , "$keydown") 255 & | ||||||||||||||||
| end | ||||||||||||||||
|
|
@@ -16,27 +17,39 @@ function waitfor --description 'wait a certain amount of time, or until the user | |||||||||||||||
| set oldval 256 | ||||||||||||||||
| set oldn 8 | ||||||||||||||||
| set time (math "round($time)") | ||||||||||||||||
| for i in (seq "$time" "-$step" "$until") | ||||||||||||||||
| set txt (timeformat "$i") | ||||||||||||||||
| set cur (date '+%s') | ||||||||||||||||
| set tar (math "$cur + $time") | ||||||||||||||||
| while test "$cur" -lt "$tar" | ||||||||||||||||
| set cur (date '+%s') | ||||||||||||||||
| set rmd (math "$tar - $cur") | ||||||||||||||||
| set txt (timeformat "$rmd") | ||||||||||||||||
|
Comment on lines
25
to
28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix TOCTOU bug in loop condition and restore The loop tests an outdated Refactor to:
Apply this diff: set tar (math "$cur + $time")
-while test "$cur" -lt "$tar"
- set cur (date '+%s')
- set rmd (math "$tar - $cur")
+set stop (math "$tar - $until")
+while test (date '+%s') -lt "$stop"
+ set cur (date '+%s')
+ set rmd (math "max(0, $stop - $cur)")
set txt (timeformat "$rmd")Optional: To avoid oversleeping near the end, consider sleeping no longer than the remaining time: sleep (math "min($step, $rmd)")🤖 Prompt for AI Agents |
||||||||||||||||
| set n (string length "$txt") | ||||||||||||||||
| if [ "$n" -lt "$oldn" ] | ||||||||||||||||
| # erase previous one if length differs | ||||||||||||||||
| echo -en ' \e[8D' | ||||||||||||||||
| end | ||||||||||||||||
|
Comment on lines
23
to
26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Erasure logic is brittle; clear to end-of-line instead of printing 8 spaces Hard-coding 8 spaces will leave artifacts when the new text is shorter by more than 8. Clear EOL. Apply this diff: - if [ "$n" -lt "$oldn" ]
- # erase previous one if length differs
- echo -en ' \e[8D'
- end
+ if [ "$n" -lt "$oldn" ]
+ printf "\e[0K"
+ end📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| set cl (math "min(255, 4*$i)") | ||||||||||||||||
| set cl (math "min(255, 4*$rmd)") | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Negative Due to the TOCTOU bug (lines 26-27), This will be resolved by fixing the TOCTOU bug and clamping set rmd (math "max(0, $stop - $cur)")Also applies to: 45-45 🤖 Prompt for AI Agents |
||||||||||||||||
| echo -en "\e[1m\e[38;2;255;$cl;"$cl"m$txt\e[0m\e["$n"D" | ||||||||||||||||
|
||||||||||||||||
| echo -en "\e[1m\e[38;2;255;$cl;"$cl"m$txt\e[0m\e["$n"D" | |
| printf "\e[1m\e[38;2;255;%d;%dm%s\e[0m\e[%dD" $cl $cl $txt $n |
🤖 Prompt for AI Agents
In waitfor.fish around line 32, the echo command mixes quoted and unquoted
tokens which can cause word-splitting and break ANSI SGR parameters; replace the
echo invocation with a single-argument printf to avoid splitting and ensure the
entire escape sequence is emitted atomically. Construct the printf format so
escape codes and variables are expanded in one string (use a single format
string and pass variables as needed), ensure any numeric variables are not
subject to word splitting, and use the appropriate escape-sequence
interpretation flag so the SGR sequence, the text, and the final cursor-move
code are printed as one intact argument.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| function walking --description 'register a walk' | ||
| waitfor 2100 '🚶 walking' '🚶 ' | ||
| waitfor 2100 '' '🚶 walking' '🚶 ' | ||
| measurelog activity.walking (activity_survey) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid executing unpinned remote scripts in CI; replace with a local validator or pin to a commit.
curl-ing and executing a remote script from a moving branch (master) is a supply-chain risk and makes builds non-deterministic. Prefer a local validator (no network), or at minimum fetch a specific commit and verify integrity.
Preferred fix: replace the remote script with a Python-based JSON validation that fails the job on invalid JSON.
Alternative (if you must keep the remote script):
📝 Committable suggestion
🤖 Prompt for AI Agents