This commit is contained in:
2025-11-12 18:17:47 +08:00
parent d934541f8e
commit 6617db5d44
22 changed files with 305 additions and 1 deletions

View File

@@ -17,8 +17,9 @@ stow -v git -D
Target (`-t`) defaults to the parent of `pwd`, so if you clone this repo not in `$HOME` then you MUST explicitly provide `-t ~` or `-t $HOME` every time.
## Documentation
## Documentation and sources
* <https://www.gnu.org/software/stow/manual/stow.html>
* <https://tamerlan.dev/how-i-manage-my-dotfiles-using-gnu-stow/>
* <https://gist.github.com/andreibosco/cb8506780d0942a712fc>
* https://github.com/jimeh/git-aware-stow

3
utils/.local/bin/clock Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
watch -tn 1 date '+%l:%M:%S%p'

18
utils/.local/bin/copy Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e
set -u
if hash pbcopy 2>/dev/null; then
exec pbcopy
elif hash xclip 2>/dev/null; then
exec xclip -selection clipboard
elif hash putclip 2>/dev/null; then
exec putclip
else
rm -f /tmp/clipboard 2> /dev/null
if [ $# -eq 0 ]; then
cat > /tmp/clipboard
else
cat "$1" > /tmp/clipboard
fi
fi

26
utils/.local/bin/dc Executable file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/env bash
CONTAINER="my-container" # the name of the container in which to 'exec' something
CONFIG="$(dirname $([ -L $0 ] && readlink -f $0 || echo $0))/docker-compose.yml" # path to compose yml file
CMD="docker-compose -f $CONFIG" # docker-compose command
APP_URL='http://localhost:8000/'
open_browser() {
if which xdg-open > /dev/null; then
xdg-open "$1" </dev/null >/dev/null 2>&1 & disown
elif which gnome-open > /dev/null; then
gnome-open "$1" </dev/null >/dev/null 2>&1 & disown
fi
}
case "$1" in
'' | 'help' ) echo -e "Provide one of operations: \t start, stop, up, down, restart, rebuild, open";
echo "Otherwise all args will be passed to 'docker exec -ti $CONTAINER ...'" ;;
'open' ) open_browser $APP_URL ;;
'up' ) $CMD up -d --build ;; # build and start containers
'down' ) $CMD down --remove-orphans ;; # stop and remove containers
'start' ) $CMD start ;; # start containers
'stop' ) $CMD stop ;; # stop containers
'restart' ) $CMD stop && $CMD start ;; # restart containers
'rebuild' ) $CMD down --remove-orphans && $CMD up -d --build ;; # rebuild containers
* ) docker exec -ti $CONTAINER $@ # exec anything in container
esac

22
utils/.local/bin/extract Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
if [ -f "$1" ]; then
case "$1" in
*.tar.bz2) tar -jxvf "$1" ;;
*.tar.gz) tar -zxvf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.dmg) hdiutil mount "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar -xvf "$1" ;;
*.tbz2) tar -jxvf "$1" ;;
*.tgz) tar -zxvf "$1" ;;
*.zip) unzip "$1" ;;
*.ZIP) unzip "$1" ;;
*.pax) cat "$1" | pax -r ;;
*.pax.Z) uncompress "$1" --stdout | pax -r ;;
*.rar) unrar x "$1" ;;
*.Z) uncompress "$1" ;;
*) echo "'$1' cannot be extracted/mounted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi

3
utils/.local/bin/flushdns Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
sudo resolvectl flush-caches

69
utils/.local/bin/httpcode Executable file
View File

@@ -0,0 +1,69 @@
#!/usr/bin/env bash
set -e
set -u
statuses="100 Continue
101 Switching Protocols
102 Processing
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content
207 Multi-Status
208 Already Reported
300 Multiple Choices
301 Moved Permanently
302 Found
303 See Other
304 Not Modified
305 Use Proxy
307 Temporary Redirect
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Large
415 Unsupported Media Type
416 Request Range Not Satisfiable
417 Expectation Failed
418 I'm a teapot
420 Blaze it
422 Unprocessable Entity
423 Locked
424 Failed Dependency
425 No code
426 Upgrade Required
428 Precondition Required
429 Too Many Requests
431 Request Header Fields Too Large
449 Retry with
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported
506 Variant Also Negotiates
507 Insufficient Storage
509 Bandwidth Limit Exceeded
510 Not Extended
511 Network Authentication Required"
if [ $# -eq 0 ]; then
echo "$statuses"
else
echo "$statuses" | grep -i --color=never "$@"
fi

5
utils/.local/bin/len Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e
set -u
echo -n "$@" | wc -c | awk '{print $1}'

6
utils/.local/bin/line Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
set -u
lineno="$1"; shift
sed -n "${lineno}p" -- "$@"

23
utils/.local/bin/mksh Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
if [ ! $# -eq 1 ]; then
echo 'mksh takes one argument' 1>&2
exit 1
elif [ -e "$1" ]; then
echo "$1 already exists" 1>&2
exit 1
fi
echo '#!/usr/bin/env bash
set -e
set -u
set -o pipefail
' > "$1"
chmod u+x "$1"
nano "$1"

3
utils/.local/bin/now Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
date '+%d.%m.%Y %H:%M:%S'

13
utils/.local/bin/pasta Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
set -u
if hash pbpaste 2>/dev/null; then
exec pbpaste
elif hash xclip 2>/dev/null; then
exec xclip -selection clipboard -o
elif [[ -e /tmp/clipboard ]]; then
exec cat /tmp/clipboard
else
echo ''
fi

6
utils/.local/bin/perm Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# TODO permissions via arguments
find . -type f -exec chmod 0664 {} +
find . -type d -exec chmod 0775 {} +

13
utils/.local/bin/running Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
set -u
process_list="$(ps -eo 'pid command')"
if [[ $# != 0 ]]; then
process_list="$(echo "$process_list" | grep -Fiw "$@")"
fi
echo "$process_list" |
grep -Fv "${BASH_SOURCE[0]}" |
grep -Fv grep |
GREP_COLORS='mt=00;35' grep -E --colour=auto '^\s*[[:digit:]]+'

8
utils/.local/bin/scratch Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
file="$(mktemp)"
echo "Editing $file"
exec "$EDITOR" "$file"

25
utils/.local/bin/serve Executable file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
port='8888'
if [ $# -eq 1 ]; then
port="$1"
fi
if hash php 2>/dev/null; then
exec php -S "localhost:$port"
elif hash python3 2>/dev/null; then
exec python3 -m http.server "$port"
elif hash python 2>/dev/null; then
major_version="$(python -c 'import platform as p;print(p.python_version_tuple()[0])')"
if [[ "$major_version" == '3' ]]; then
exec python -m http.server "$port"
else
exec python -m SimpleHTTPServer "$port"
fi
else
echo 'unable to start HTTP server' 1>&2
exit 1
fi

11
utils/.local/bin/timer Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
sleep "$1"
notify-send 'Timer complete!' \
-u normal \
-t 10000 \
-i clock \
-a 'Timer script'

6
utils/.local/bin/trash Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
gio trash "$@"

8
utils/.local/bin/tryna Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -u
"$@"
while [[ "$?" -eq 0 ]]; do
sleep 0.5
"$@"
done

8
utils/.local/bin/trynafail Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -u
"$@"
while [[ "$?" -ne 0 ]]; do
sleep 0.5
"$@"
done

14
utils/.local/bin/url2md Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
curl "https://r.jina.ai/$1" \
-sS \
-H "DNT: 1" \
-H "X-Base: final" \
-H "X-Engine: direct" \
-H "X-Md-Em-Delimiter: *" \
-H "X-Md-Heading-Style: setext" \
-H "X-Md-Link-Reference-Style: collapsed" \
-H "X-Md-Link-Style: referenced"

13
utils/.local/bin/waitfor Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
if hash systemd-inhibit 2>/dev/null; then
systemd-inhibit \
--who=waitfor \
--why="Awaiting PID $1" \
tail --pid="$1" -f /dev/null
else
tail --pid="$1" -f /dev/null
fi