aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2026-12-02 18:54:14 -0800
committerEugene Triguba <hello@eugenetriguba.com>2026-12-02 18:54:14 -0800
commitd3e5432e003c5a2ea9849b3e80706ec2cb1a013a (patch)
tree42e8c09d0fa8bf33742a367875bbf685ea84ebfe
parentAdd simple readme (diff)
downloaddotfiles-d3e5432e003c5a2ea9849b3e80706ec2cb1a013a.zip
Add bin dir
Diffstat (limited to '')
-rwxr-xr-xbin/get-password37
-rwxr-xr-xbin/optimize-image85
2 files changed, 122 insertions, 0 deletions
diff --git a/bin/get-password b/bin/get-password
new file mode 100755
index 0000000..67c07e7
--- /dev/null
+++ b/bin/get-password
@@ -0,0 +1,37 @@
+#!/bin/sh
+set -o errexit
+set -o nounset
+
+VAULT="Private"
+CREDENTIAL=""
+
+main() {
+ parse_args "$@"
+ op read "op://$VAULT/$CREDENTIAL/password"
+}
+
+parse_args() {
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --vault)
+ VAULT="$2"
+ shift 2
+ ;;
+ --credential)
+ CREDENTIAL="$2"
+ shift 2
+ ;;
+ *)
+ echo "Usage: $0 [--vault <name>] --credential <name>"
+ exit 1
+ ;;
+ esac
+ done
+
+ if [ -z "$CREDENTIAL" ]; then
+ echo "Invalid or empty CREDENTIAL" >&2
+ exit 1
+ fi
+}
+
+main "$@"
diff --git a/bin/optimize-image b/bin/optimize-image
new file mode 100755
index 0000000..af0fed1
--- /dev/null
+++ b/bin/optimize-image
@@ -0,0 +1,85 @@
+#!/bin/sh
+set -o errexit
+set -o nounset
+
+quality=85
+source_img_path=""
+result_img_path=""
+
+main() {
+ parse_args "$@"
+
+ original_size=$(get_file_size "$source_img_path")
+ echo "Optimizing: $source_img_path -> $result_img_path (quality: $quality%)"
+ magick "$source_img_path" -strip -quality "${quality}%" "$result_img_path"
+ new_size=$(get_file_size "$result_img_path")
+ echo "File size: $original_size -> $new_size"
+}
+
+parse_args() {
+ while [ $# -gt 0 ]; do
+ case $1 in
+ --quality)
+ if [ -n "$2" ] && [ "$2" -ge 1 ] && [ "$2" -le 100 ] 2>/dev/null; then
+ quality="$2"
+ shift 2
+ else
+ echo "Error: --quality requires a number between 1 and 100"
+ exit 1
+ fi
+ ;;
+ -h | --help)
+ print_usage
+ exit 0
+ ;;
+ -*)
+ echo "Error: Unknown option $1"
+ print_usage
+ exit 1
+ ;;
+ *)
+ if [ -z "$source_img_path" ]; then
+ source_img_path="$1"
+ else
+ echo "Error: Too many arguments"
+ print_usage
+ exit 1
+ fi
+ shift
+ ;;
+ esac
+ done
+
+ if [ -z "$source_img_path" ]; then
+ echo "Error: source image path is required"
+ print_usage
+ exit 1
+ fi
+
+ if [ ! -f "$source_img_path" ]; then
+ echo "Error: Source file '$source_img_path' does not exist"
+ exit 1
+ fi
+
+ result_img_path="${source_img_path%.*}.webp"
+}
+
+print_usage() {
+ echo "Usage: $0 [OPTIONS] <source-img-path>"
+ echo ""
+ echo "Options:"
+ echo " --quality <value> Set quality (1-100, default: 85)"
+ echo " -h, --help Show this help message"
+ echo ""
+ echo "Examples:"
+ echo " $0 input.jpg"
+ echo " $0 --quality 90 input.jpg"
+ echo " $0 --quality 80 input.png"
+}
+
+get_file_size() {
+ du -h "$1" | awk '{ print $1 }'
+}
+
+main "$@"
+