tools -> scripts

This commit is contained in:
2025-11-14 10:44:57 +08:00
parent 0493f18b18
commit c7449f4acb
70 changed files with 369 additions and 2 deletions

View File

@@ -6,6 +6,6 @@
# Wayland KDE: https://www.reddit.com/r/kde/comments/11vrbwc/how_do_i_rotate_the_screen_on_kde_with_wayland/
# kscreen-doctor --outputs
OUTPUT='HDMI-0'
DIRECTION="$1" # (left|right|normal|inverted)
OUTPUT='HDMI-A-1'
[ "$1" ] && DIRECTION="$1" || DIRECTION="normal" # (left|right|normal|inverted)
kscreen-doctor "output.$OUTPUT.rotation.$DIRECTION"

6
scripts/utils/clock Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
exec watch -tn 1 date '+%l:%M:%S%p'

18
scripts/utils/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

0
tools/dc → scripts/utils/dc Normal file → Executable file
View File

69
scripts/utils/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
scripts/utils/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
scripts/utils/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
scripts/utils/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"
"$EDITOR" "$1"

73
scripts/utils/note Executable file
View File

@@ -0,0 +1,73 @@
#!/usr/bin/env bash
# Note taking tool
#
# Usage:
# note [name] - Create a new note with optional name (defaults to "New note")
# note -e|--edit [name] - Edit an existing note by name
#
# Arguments explanation:
# [name] - Note filename (without extension) and title
# -e, --edit [name] - Edit existing note by name
#
# Detailed usage:
# note - Creates "New note" with current timestamp
# note my-idea - Creates note titled "my-idea"
# note my-idea "My Great Idea" - Creates note file "my-idea" but titled "My Great Idea"
# note -e my-idea - Edits existing note with name "my-idea"
#
# Notes are stored as markdown files in ~/notes/ with timestamps
# When multiple notes have the same name, you'll be prompted to select which one to edit
arg1="$1"
arg2="$2"
path="$HOME/notes"
[[ ! -d "$path" ]] && mkdir -p "$path"
shopt -s nullglob
files=("$path"/*.md)
shopt -u nullglob
case "$arg1" in
-e|--edit)
[[ -z "$arg2" ]] && {
echo "Note name is required"
exit 1
}
# shellcheck disable=SC2207
found=($(echo "${files[@]}" | grep -P "[0-9]{10}-$arg2.md"))
[[ ${#found[@]} -eq 0 ]] && {
echo "Note with name '$arg2' not found."
echo "Create it with using 'note $arg2'"
exit
}
[[ ${#found[@]} -eq 1 ]] && {
nano "${found[0]}"
exit
}
PS3="Select a note to edit: "
select selection in "${found[@]}" "Exit"; do
[[ "$selection" == "Exit" ]] && exit
[[ -f "$selection" ]] && {
nano "$selection"
exit
}
continue
done
;;
*)
[[ -z "$arg2" ]] && arg2="${arg1:-New note}"
file="$path/$(date +%s)-$arg1.md"
cat <<EOF > "$file"
# $arg2
Note taken: $(date '+%d.%m.%Y %H:%M:%S')
EOF
nano "$file"
;;
esac

45
scripts/utils/notes Executable file
View File

@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -e
set -o pipefail
# Notes listing tool
#
# Purpose:
# Lists all markdown notes stored in ~/notes/ directory
#
# Usage:
# notes - Display all available notes
#
# Output:
# - Shows filenames of all .md files in ~/notes/
# - If no notes exist or directory is empty, displays "Empty"
# - Provides hint to use 'note -e' for editing
#
# Example output:
# 1703123456-my-idea.md
# 1703123789-shopping-list.md
# 1703124012-project-notes.md
#
# Use 'note -e' to edit existing notes
path="$HOME/notes"
[[ ! -d "$path" ]] && {
echo "Empty"
exit 0
}
shopt -s nullglob
files=("$path"/*.md)
shopt -u nullglob
[[ "${#files}" -eq 0 ]] && {
echo "Empty"
exit 0
}
for file in "${files[@]}"; do
echo "${file/$path\//}"
done
echo
echo "Use 'note -e' to edit existing notes"

3
scripts/utils/now Executable file
View File

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

13
scripts/utils/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

13
scripts/utils/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
scripts/utils/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
scripts/utils/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
scripts/utils/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
scripts/utils/trash Executable file
View File

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

8
scripts/utils/tryna Executable file
View File

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

8
scripts/utils/trynafail Executable file
View File

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

14
scripts/utils/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
scripts/utils/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