feat(plugins): add --help to all plugins

This commit is contained in:
2026-03-24 00:23:07 +02:00
parent 59a0ff5b04
commit 05921b7d69
31 changed files with 575 additions and 12 deletions

View File

@@ -1,6 +1,13 @@
#!/usr/bin/env zsh
# Build a release APK from a Flutter project and optionally install on a remote device.
build-apk() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: build-apk"
echo "Build a release APK from the current Flutter project and optionally install on a remote device."
return 0
fi
set -euo pipefail
# --- Helpers ---
@@ -81,7 +88,14 @@ build-apk() {
esac
}
# Pair with an Android device over wireless debugging.
adb-pair-device() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: adb-pair-device [device_octet] [port] [pairing_code]"
echo "Pair with an Android device at 192.168.68.<octet>:<port> using a pairing code."
return 0
fi
device_octet="$1"
device_port="$2"
pairing_code="$3"
@@ -108,7 +122,14 @@ adb-pair-device() {
}
}
# Connect to an Android device over ADB TCP/IP.
adb-connect-device() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: adb-connect-device [device_octet] [port]"
echo "Connect to an Android device at 192.168.68.<octet>:<port> via ADB."
return 0
fi
device_octet="$1"
device_port="$2"
@@ -132,7 +153,14 @@ adb-connect-device() {
}
}
# Install the release APK from the current Flutter project via ADB.
adb-flutter-install() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: adb-flutter-install"
echo "Install the release APK from the nearest Flutter project onto a connected device."
return 0
fi
proj_file="$(find-up pubspec.yaml)"
if [[ -z "$proj_file" ]]; then
echo "pubspec.yaml not found in any parent directory"

View File

@@ -2,8 +2,14 @@
export USE_COLORS=$(tput colors 2>/dev/null)
# colors
# Print text with a specified color or style attribute.
# Usage: echo_color [-n] <color|style|0-255> <text...>
function echo_color() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: echo_color [-n] <color|style|0-255> <text...>"
echo "Print text with a specified color or terminal attribute."
return 0
fi
if [[ -z "$USE_COLORS" || "$USE_COLORS" -lt 8 ]]; then
echo "$@"
return
@@ -41,7 +47,14 @@ function echo_color() {
echo -e $n "$(tput $a $c)$@$(tput sgr0)"
}
# Display all 256 terminal colors (cached).
# Usage: all_colors [-f]
all_colors() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: all_colors [-f]"
echo "Display all 256 terminal colors. Use -f to force regenerate the cache."
return 0
fi
cache_file="$DOTFILES/plugins/.cache/colors.cache"
if [[ "$1" == "-f" ]]; then
rm -f $cache_file
@@ -62,6 +75,7 @@ all_colors() {
cat $cache_file
}
# Convenience aliases for common color outputs.
alias test_colors="msgcat --color=test"
alias cecho="echo_color"
alias echo_gray="echo_color gray"

View File

@@ -1,8 +1,16 @@
#!/usr/bin/env zsh
# Suggest a command using GitHub Copilot. Optionally specify a type with -t.
cos() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: cos [-t type] <query>"
echo "Suggest a command using GitHub Copilot."
echo " -t type Suggestion type (shell, git, gh)"
return 0
fi
if [[ $# -eq 0 ]]; then
echo_red "Usage: cos [-t type] <query>"
return 1
fi
if [[ $1 == "-t" ]]; then
@@ -19,16 +27,24 @@ cos() {
fi
}
# Explain a command using GitHub Copilot.
coe() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: coe <query>"
echo "Explain a command using GitHub Copilot."
return 0
fi
if [[ $# -eq 0 ]]; then
echo_red "Usage: coe <query>"
return 1
fi
query="$@"
gh copilot explain "$query"
}
alias coss="cos -t shell"
alias cosg="cos -t git"
alias cosh="cos -t gh"
# Shorthand aliases for cos with preset types.
alias coss="cos -t shell" # Suggest a shell command
alias cosg="cos -t git" # Suggest a git command
alias cosh="cos -t gh" # Suggest a GitHub CLI command

View File

@@ -2,7 +2,13 @@
# OSX defaults overrides
# Write a global macOS default setting. No-op on non-Mac systems.
write_default() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: write_default <name> <value>"
echo "Write a global macOS default setting (defaults write -g)."
return 0
fi
if ! is_mac; then
return 0
fi

View File

@@ -2,6 +2,11 @@
# open docker logs for specified container
docker-log() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: docker-log <container> [args...]"
echo "Open docker logs for specified container"
return 0
fi
image="$1"
shift
docker logs --follow $@ "$image"
@@ -9,6 +14,11 @@ docker-log() {
# docker exec command for specified container
docker-exec() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: docker-exec <container> <executable> [args...]"
echo "Docker exec command for specified container"
return 0
fi
image="$1"
executable="$2"
shift 2
@@ -18,6 +28,11 @@ docker-exec() {
# open docker bash shell for specified container
docker-bash() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: docker-bash <container> [args...]"
echo "Open docker bash shell for specified container"
return 0
fi
image="$1"
shift
docker-exec "$image" /bin/bash $@
@@ -25,6 +40,11 @@ docker-bash() {
# open docker sh shell for specified container
docker-sh() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: docker-sh <container> [args...]"
echo "Open docker sh shell for specified container"
return 0
fi
image="$1"
shift
docker-exec "$image" /bin/sh $@
@@ -32,6 +52,11 @@ docker-sh() {
# get path of docker volume
docker-volume-path() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: docker-volume-path <volume>"
echo "Get path of docker volume"
return 0
fi
image="$1"
shift
docker volume inspect "$image" | jq -r '.[0].Mountpoint'
@@ -39,6 +64,11 @@ docker-volume-path() {
# cd to docker volume
docker-volume-cd() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: docker-volume-cd <volume>"
echo "cd to docker volume"
return 0
fi
image="$1"
shift
cd $(docker-volume-path "$image")

View File

@@ -3,6 +3,14 @@
# edit a dotfile script and source if there were changes
# supports autocomplete for any editable files
dfe() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: df [-n] [-q] <dotfile>"
echo "Edit a dotfile script and source if there were changes"
echo "For .zsh files, the extension is optional"
echo " -n: do not source the file after editing"
echo " -q: do not print any messages"
return 0
fi
if [[ $# -eq 0 ]]; then
echo "Usage: df [-n] [-q] <dotfile>"
echo "Edit a dotfile script and source if there were changes"
@@ -63,6 +71,12 @@ dfe() {
# source a dotfile script
# supports autocomplete for any editable files
dfs() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: dfs [-q] <dotfile>"
echo "Source a dotfile script"
echo " -q: do not print any messages"
return 0
fi
if [[ $# -eq 0 ]]; then
echo "Usage: dfs [-q] <dotfile>"
echo "Source a dotfile script"
@@ -102,6 +116,14 @@ dfs() {
# same as rc, but for plugin files
dfpe() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: dfp [-n] [-q] <plugin file>"
echo "Edit a dotfile plugin script and source if there were changes"
echo "For .zsh files, the extension is optional"
echo " -n: do not source the file after editing"
echo " -q: do not print any messages"
return 0
fi
local flags=()
# Parse arguments
@@ -128,6 +150,12 @@ dfpe() {
# same as dfs, but for plugin files
dfps() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: dfps [-q] <plugin file>"
echo "Source a dotfile plugin script"
echo " -q: do not print any messages"
return 0
fi
local flags=()
# Parse arguments

View File

@@ -1,6 +1,13 @@
#!/usr/bin/env zsh
# build a Flutter APK and optionally install to a remote ADB device
build-apk() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: build-apk"
echo "Build a Flutter APK and optionally install to a remote ADB device"
return 0
fi
set -euo pipefail
# --- Helpers ---

View File

@@ -2,7 +2,7 @@
# search for a file in a directory
search-file() {
if [[ $# -eq 0 ]]; then
if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: search-file [dir] <file>"
echo "Search for a file in a directory (recursively)"
return 1
@@ -21,7 +21,7 @@ search-file() {
# find a file in the current directory or on one of its ancestors.
# usefule for finding project root based on config file (e.g. package.json, pubspec.yaml, pyproject.toml)
find-up() {
if [[ $# -eq 0 ]]; then
if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: find-up <file>"
echo "Finds a file in the current directory or on one of its ancestors"
return 1
@@ -43,6 +43,11 @@ find-up() {
# open project directory
prjd() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: prjd [subdir]"
echo "Open project directory"
return 0
fi
sub="$@"
if [[ -z "$sub" ]]; then
read sub
@@ -53,6 +58,11 @@ prjd() {
# open project directory in nvim
prj() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: prj [subdir]"
echo "Open project directory in nvim"
return 0
fi
pushd "$(wd path dv)/$@"
nvim .
popd
@@ -60,12 +70,22 @@ prj() {
# copy file to clipboard
pbfile() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: pbfile <file>"
echo "Copy file contents to clipboard"
return 0
fi
file="$1"
more $file | pbcopy | echo "=> $file copied to clipboard."
}
# remove the home directory from a path
strip-home() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: strip-home [-e] <path>"
echo "Remove the home directory from a path"
return 0
fi
repl="~"
if [[ "$1" == "-e" ]]; then
repl=""
@@ -75,7 +95,13 @@ strip-home() {
echo ${dir/$HOME/$repl}
}
# list the largest files in the current directory (excluding .git)
largest-files() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: largest-files [count]"
echo "List the largest files in the current directory (excluding .git)"
return 0
fi
c="10"
if [[ -n "$1" ]]; then
c="$1"
@@ -83,11 +109,18 @@ largest-files() {
find . -type f -not -path './.git/*' -exec du -h {} + | sort -hr | head -n "$c"
}
# list the largest directories in the current directory (excluding .git)
largest-dirs() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: largest-dirs [count]"
echo "List the largest directories in the current directory (excluding .git)"
return 0
fi
c="10"
if [[ -n "$1" ]]; then
c="$1"
fi
find . -type d -name ".git" -prune -o -type d -exec du -sh {} + | sort -rh | head -n "$c"
}
# alias for largest-dirs
alias largest-folders='largest-dirs'

View File

@@ -352,6 +352,8 @@ function grename() {
fi
}
# Internal helper: search for an open PR in chenasraf/homebrew-tap by title
# and add the "pr-pull" label if not already present.
function _gtp_label() {
local search="$1"
local pr_data
@@ -373,7 +375,16 @@ function _gtp_label() {
echo "Added \"pr-pull\" label to PR #$pr_number"
}
# Search for an open PR in chenasraf/homebrew-tap by title and add the "pr-pull" label.
function gtp() {
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
echo "Usage: gtp <search_term>"
echo ""
echo "Search for an open PR in chenasraf/homebrew-tap whose title matches"
echo "<search_term> and add the \"pr-pull\" label to it."
return 0
fi
if [[ -z "$1" ]]; then
echo "Usage: gtp <search_term>"
return 1
@@ -385,7 +396,20 @@ function gtp() {
fi
}
# Find a release PR in chenasraf/<repo>, wait for checks to pass, merge via
# rebase, then poll for a homebrew-tap PR and add the "pr-pull" label.
function grl() {
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
echo "Usage: grl <repo_name> [tap_search_term]"
echo ""
echo "Find an open release PR (titled \"chore release\") in chenasraf/<repo_name>,"
echo "wait for all CI checks to pass, merge it via rebase, then poll for a"
echo "matching homebrew-tap PR and add the \"pr-pull\" label."
echo ""
echo "If <tap_search_term> is omitted, <repo_name> is used to search the tap PR."
return 0
fi
if [[ -z "$1" ]]; then
echo "Usage: grl <repo_name> [tap_search_term]"
return 1

View File

@@ -1,6 +1,13 @@
#!/usr/bin/env zsh
# get the latest tag from a GitHub repository
get-gh-latest-tag() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: get-gh-latest-tag [-f|--filter <jq_filter>] <repo>"
echo "Get the latest tag from a GitHub repository"
echo " -f, --filter: jq filter expression to select a specific tag"
return 0
fi
if [[ $# -gt 1 ]]; then
case $1 in
--filter | -f)
@@ -19,11 +26,25 @@ get-gh-latest-tag() {
fi
}
# clone a chenasraf GitHub repo with submodules
gclc() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: gclc <repo>"
echo "Clone a chenasraf GitHub repo with submodules"
return 0
fi
git clone --recurse-submodules git@github.com:chenasraf/$1.git
}
# get the download URL for the latest release asset from a GitHub repository
get-gh-latest-release() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: get-gh-latest-release <repo> <filename>"
echo "Get the download URL for the latest release asset from a GitHub repository"
echo " filename: the name of the file to download"
echo " may contain {tag} to be replaced with the latest tag"
return 0
fi
if [[ $# -lt 2 ]]; then
echo "Usage: get-gh-latest-release <repo> <filename>"
echo " filename: the name of the file to download"

View File

@@ -1,6 +1,13 @@
#!/usr/bin/env zsh
# create a new private GitHub repo and initialize it locally
create-repo() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: create-repo [REPO_NAME]"
echo "Create a new private GitHub repo and initialize it locally"
echo " REPO_NAME can be passed as an argument or set as an environment variable"
return 0
fi
if [[ -z "$REPO_NAME" ]]; then
printf "Repository name: "
read -r REPO_NAME

View File

@@ -6,6 +6,15 @@
# gpge -o out.gpg file.csv # -> explicit output file
# echo "secret" | gpge -o s.asc # -> stdin to output (use --armor in $EXTRA)
gpge() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Encrypt to your 1Password-stored fingerprint."
echo "Usage:"
echo " gpge file.csv # -> creates file.csv.gpg"
echo " gpge -o out.gpg file.csv # -> explicit output file"
echo ' echo "secret" | gpge -o s.asc # -> stdin to output (use --armor in $EXTRA)'
return 0
fi
local fp
fp=$(op item get 'gpg key' --format json --fields 'Fingerprint' \
| jq -r .value | tr -d '\n') || { echo "Fingerprint not found" >&2; return 1; }
@@ -28,6 +37,15 @@ gpge() {
# gpgd -o out.csv path/to/file.gpg # -> outputs to out.csv
# cat file.gpg | gpgd -o out.csv # -> reads from stdin
gpgd() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Decrypt a GPG-encrypted file using the passphrase from 1Password."
echo "Usage:"
echo " gpgd path/to/file.csv.gpg # -> outputs to path/to/file.csv"
echo " gpgd -o out.csv path/to/file.gpg # -> outputs to out.csv"
echo " cat file.gpg | gpgd -o out.csv # -> reads from stdin"
return 0
fi
local pass
pass=$(op item get 'gpg key' --format json --fields password --reveal \
| jq -r .value | tr -d '\n') || {

View File

@@ -4,6 +4,13 @@
# returns 0 if confirmed or typed Y, 1 if not
# flags: -c <color> or --color <color>
ask() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Ask for confirmation before running a command, Y is default."
echo "Returns 0 if confirmed or typed Y, 1 if not."
echo "Usage: ask [-c <color>] <question>"
echo "Flags: -c <color> or --color <color>"
return 0
fi
if [[ $# -eq 0 ]]; then
echo_red "Usage: ask [-c <color>] <question>"
return 1
@@ -25,6 +32,12 @@ ask() {
# ask for confirmation before running a command, N is default
# returns 0 if typed Y, 1 if not
ask_no() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Ask for confirmation before running a command, N is default."
echo "Returns 0 if typed Y, 1 if not."
echo "Usage: ask_no <question>"
return 0
fi
echo -n "$1 [y/N] "
read REPLY
if [[ $REPLY =~ ^[Yy]$ ]]; then
@@ -35,6 +48,11 @@ ask_no() {
# get user input and output it
get_user_input() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Get user input and output it."
echo "Usage: get_user_input <prompt>"
return 0
fi
echo -n "$1 "
read REPLY
echo $REPLY

View File

@@ -14,6 +14,14 @@ killproc() {
local -a rest
for arg in "$@"; do
case "$arg" in
-h|--help)
echo "Kill processes by (partial) name with optional confirmation."
echo "Usage: killproc [-f|--force] <name fragment>"
echo "Examples:"
echo " killproc node"
echo ' killproc --force "my-long-running script.py"'
return 0
;;
-f|--force) force=1 ;;
--) shift; rest+=("$@"); break ;;
-*) print -u2 "killproc: unknown option: $arg"; return 2 ;;

View File

@@ -1,6 +1,14 @@
#!/usr/bin/env zsh
# list exported functions from given files, excluding internal/unset ones
list_exported_functions() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: list_exported_functions <file>..."
echo " Lists exported function names from the given shell script files."
echo " Functions that are unset or internal (prefixed with _) are excluded."
return 0
fi
local file
for file in "$@"; do
# Get unset functions from this file
@@ -23,7 +31,14 @@ list_exported_functions() {
done
}
# list all shell functions from dotfiles plugins
hscl() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: hscl"
echo " Lists all exported shell functions from dotfiles plugins."
return 0
fi
# Get the plugins directory (directory of this script)
local plugins_dir="$DOTFILES/plugins"
@@ -34,7 +49,14 @@ hscl() {
list_exported_functions "${script_files[@]}"
}
# interactive function selector using fzf
hsc() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: hsc"
echo " Interactively select a shell function using fzf and prefill it in the shell."
return 0
fi
selected=$(hscl | sort -u | fzf --prompt="Select function: ")
# If a function was selected, prefill it in the shell

View File

@@ -2,6 +2,13 @@
# convert markdown to html and output to stdout
md2html() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: md2html [filename]"
echo " Converts a markdown file to HTML and outputs to stdout."
echo " Defaults to README.md if no filename is provided."
return 0
fi
file=${1:-README.md}
if [[ ! -f $(which pandoc) ]]; then
echo "Pandoc not installed. Please install pandoc first."

View File

@@ -3,7 +3,13 @@
NC_VERSION_FILE="$HOME/.nc-dev-version"
NC_DEV_DIR="$HOME/Dev/nextcloud-docker-dev"
# set or reset the Nextcloud dev version
nc-dev-use() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nc-dev-use [version]"
echo "Set or reset the Nextcloud dev version"
return 0
fi
local version="$1"
if [[ -z "$version" ]]; then
version="$(tr -d '\n' < $NC_VERSION_FILE)"
@@ -19,7 +25,13 @@ nc-dev-use() {
echo "Set Nextcloud dev version to: $version"
}
# get the current Nextcloud dev version
nc-dev-get-version() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nc-dev-get-version"
echo "Get the current Nextcloud dev version"
return 0
fi
local version
version="$(tr -d '\n' < $NC_VERSION_FILE)"
if [[ -z "$version" ]]; then
@@ -28,7 +40,13 @@ nc-dev-get-version() {
echo "$version"
}
# start the Nextcloud dev container for a given version
nc-dev-start() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nc-dev-start [version]"
echo "Start the Nextcloud dev container for a given version"
return 0
fi
local version="$1"
nc-dev-use "$version"
version="$(nc-dev-get-version)"
@@ -37,19 +55,35 @@ nc-dev-start() {
popd
}
# stop the Nextcloud dev container
alias nc-dev-stop="pushd \$NC_DEV_DIR && docker compose stop; popd"
# Nextcloud AIO aliases
alias nc-aio="sudo docker exec --user www-data -it nextcloud-aio-nextcloud"
alias nc-aio-occ="nc-aio php occ"
alias nc-aio-debug="nc-aio-occ config:system:set debug --type bool --value"
# Nextcloud dev aliases
alias nc-dev="docker exec --user www-data -it nextcloud-\$(nc-dev-get-version)-1"
alias nc-dev-occ="nc-dev php occ"
# tail the Nextcloud dev log file
nc-dev-logs() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nc-dev-logs [args...]"
echo "Tail the Nextcloud dev log file"
return 0
fi
docker exec --user www-data nextcloud-$(nc-dev-get-version)-1 tail $@ /var/www/html/data/nextcloud.log
}
# tail and pretty-print the Nextcloud dev log as JSON
nc-dev-pretty-logs() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nc-dev-pretty-logs [args...]"
echo "Tail and pretty-print the Nextcloud dev log as JSON"
return 0
fi
# Forward all args (e.g., -f) to nc-dev-logs
nc-dev-logs "$@" | while IFS= read -r line; do
printf '%s\n' "$line" | jq -C -c --unbuffered .
@@ -57,7 +91,13 @@ nc-dev-pretty-logs() {
done
}
# rsync Nextcloud data from remote server to external drive
nc-backup() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nc-backup"
echo "Rsync Nextcloud data from remote server to external drive"
return 0
fi
drive="/Volumes/2T SSD"
if [ ! -d "$drive/Nextcloud/" ]; then
echo "Mount the 2T SSD first!"
@@ -73,14 +113,26 @@ nc-backup() {
find "$drive" -type f -name '._*' -exec rm -f -- {} +
}
# force update a Nextcloud AIO app
nc-aio-force-update() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nc-aio-force-update <app_name>"
echo "Force update a Nextcloud AIO app"
return 0
fi
app_name="$1"
nc-aio-occ config:app:set core lastupdatedat 0
nc-aio-occ config:app:set "$app_name" last_updated 0
nc-aio-occ app:update "$app_name"
}
# put Nextcloud AIO into maintenance mode and run the updater
nc-aio-upgrade() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nc-aio-upgrade"
echo "Put Nextcloud AIO into maintenance mode and run the updater"
return 0
fi
nc-aio-occ maintenance:mode --on
nc-aio php updater/updater.phar --no-interaction
}
@@ -102,7 +154,13 @@ _nc_read_cfg_via_awk() {
' "$NC_CFG_PATH"
}
# start a local proxy to the Nextcloud AIO database container
nc-enable-db-proxy() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nc-enable-db-proxy"
echo "Start a local proxy to the Nextcloud AIO database container"
return 0
fi
# 1) Read values from config.php using the proven awk filter
local DBTYPE="" DBHOST_RAW="" DBUSER="" DBPASS="" DBNAME=""
while IFS='=' read -r k v; do
@@ -188,7 +246,13 @@ nc-enable-db-proxy() {
echo "When done, run: nc-disable-db-proxy"
}
# stop the Nextcloud AIO database proxy
nc-disable-db-proxy() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nc-disable-db-proxy"
echo "Stop the Nextcloud AIO database proxy"
return 0
fi
if docker rm -f "$NC_PROXY_NAME" >/dev/null 2>&1; then
echo "Proxy stopped."
else

View File

@@ -4,6 +4,11 @@ source "${0:A:h}/string_utils.zsh"
# return 0 or 1 based on result of command
int_res() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: int_res <command...> <pattern>"
echo "Return 0 or 1 based on result of command"
return 0
fi
# get all but last
c=$(($# - 1))
out="$(lcase $(bash -c "${@:1:$c}"))"
@@ -17,8 +22,10 @@ int_res() {
# select random number between min and max
rand() {
if [[ $# -eq 0 ]]; then
if [[ "$1" == "-h" || "$1" == "--help" || $# -eq 0 ]]; then
echo_red "Usage: rand [min = 0] <max>"
echo_red "Select random number between min and max"
[[ "$1" == "-h" || "$1" == "--help" ]] && return 0
return 1
fi
if [[ $# -eq 1 ]]; then
@@ -33,9 +40,10 @@ rand() {
# select random line from file
randline() {
if [[ $# -eq 0 ]]; then
if [[ "$1" == "-h" || "$1" == "--help" || $# -eq 0 ]]; then
echo_red "Usage: randline <file>"
echo_red "Select a random line from a file"
[[ "$1" == "-h" || "$1" == "--help" ]] && return 0
return 1
fi
linenum=$(($RANDOM % $(wc -l <$1) + 1))
@@ -45,5 +53,10 @@ randline() {
# select random element from arguments
# NOTE always keep this function last, breaks syntax highlighting
randarg() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: randarg <arg1> [arg2] [arg3] ..."
echo "Select random element from arguments"
return 0
fi
echo "${${@}[$RANDOM % $# + 1]}"
}

View File

@@ -1,6 +1,12 @@
#!/usr/bin/env zsh
# run nx commands from the project root
nx() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nx [args...]"
echo "Run nx commands from the project root"
return 0
fi
local d="$(dirname $(find-up package.json))"
pushd "$d" > /dev/null
"$d/nx" "$@"

View File

@@ -1,6 +1,12 @@
#!/usr/bin/env zsh
# send a prompt to a local ollama instance
ollama-prompt() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: ollama-prompt <prompt>"
echo "Send a prompt to a local ollama instance"
return 0
fi
prompt="$@"
endpoint="http://localhost:11434"
@@ -19,11 +25,23 @@ ollama-prompt() {
echo
}
# open the Open WebUI interface in the browser
openwebui() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: openwebui"
echo "Open the Open WebUI interface in the browser"
return 0
fi
open "http://localhost:3300"
}
# create and start a new Open WebUI docker container
openwebui-create() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: openwebui-create"
echo "Create and start a new Open WebUI docker container"
return 0
fi
docker run -d \
-p 3300:8080 \
--add-host=host.docker.internal:host-gateway \
@@ -33,6 +51,12 @@ openwebui-create() {
ghcr.io/open-webui/open-webui:main
}
# start an existing Open WebUI docker container
openwebui-start() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: openwebui-start"
echo "Start an existing Open WebUI docker container"
return 0
fi
docker start open-webui
}

View File

@@ -4,10 +4,22 @@ source "${0:A:h}/number_utils.zsh"
# show all man entries under a specific section
# e.g. mansect 7
mansect() { man -aWS ${1?man section not provided} \* | xargs basename | sed "s/\.[^.]*$//" | sort -u; }
mansect() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: mansect <section>"
echo "Show all man entries under a specific section"
return 0
fi
man -aWS ${1?man section not provided} \* | xargs basename | sed "s/\.[^.]*$//" | sort -u
}
# mkdir -p then navigate to said directory
mkcd() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: mkcd <dir>"
echo "Create a directory and navigate to it"
return 0
fi
mkdir -p -- "$1" && cd -P -- "$1"
}
@@ -28,8 +40,9 @@ is_linux() {
if is_mac; then
run-parts() {
verbose=0
if [[ $# -eq 0 ]]; then
echo "Usage: run-parts <dir>"
if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: run-parts [-v] <dir>"
echo "Run all executable scripts in a directory in order"
return 1
fi
if [[ $1 == "-v" ]]; then
@@ -51,6 +64,11 @@ fi
# enable touchID usage for sudo.
# doesn't work inside a tmux session
enable_touchid_sudo() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: enable_touchid_sudo"
echo "Enable Touch ID usage for sudo (doesn't work inside tmux)"
return 0
fi
# Navigate to the directory containing the PAM configuration files
pushd /etc/pam.d
@@ -84,6 +102,11 @@ enable_touchid_sudo() {
# disable touchID usage for sudo and reverts back to default sudo configuration
disable_touchid_sudo() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: disable_touchid_sudo"
echo "Disable Touch ID usage for sudo and revert to default configuration"
return 0
fi
# Navigate to the directory containing the PAM configuration files
pushd /etc/pam.d
@@ -107,6 +130,11 @@ disable_touchid_sudo() {
# returns a string based on current arch
# usage: archmatch -l "linux" -mA "mac_arm" -mI "mac_intel" -m "all_macs"
archmatch() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: archmatch -l <linux> -mA <mac_arm> -mI <mac_intel> -m <all_macs>"
echo "Return a string based on current architecture"
return 0
fi
while [[ "$#" -gt 0 ]]; do
case $1 in
-l | --linux)

View File

@@ -2,6 +2,12 @@
# sets pnpm version on closest package.json to current version
set-pnpm-pkg-version() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: set-pnpm-pkg-version"
echo "Sets pnpm version on closest package.json to current version"
return 0
fi
fl=$(find-up package.json)
if [[ -z $fl ]]; then
echo_red "No package.json found"

View File

@@ -2,11 +2,23 @@
# reload entire shell
reload-zsh() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: reload-zsh"
echo "Reload entire shell"
return 0
fi
source $HOME/.zshrc
}
# find out which process is listening on a specific port
listening() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: listening [pattern]"
echo "Find out which process is listening on a specific port"
return 0
fi
if [[ $# -eq 0 ]]; then
lsof -iTCP -sTCP:LISTEN -n -P
elif [[ $# -eq 1 ]]; then
@@ -18,6 +30,12 @@ listening() {
# kill process listening on a specific port
kill-listening() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: kill-listening <port>"
echo "Kill process listening on a specific port"
return 0
fi
if [[ $# -eq 0 ]]; then
echo "Usage: kill-listening <port>"
return 1
@@ -27,6 +45,13 @@ kill-listening() {
# run a command and report the time it took
bench() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: bench [-v] <command>"
echo "Run a command and report the time it took"
echo " -v: verbose output"
return 0
fi
if [[ $# -eq 0 ]]; then
echo_red "Usage: bench [-v] <command>"
return 1

View File

@@ -88,6 +88,13 @@ _sc_collect_make() {
# interactive script runner
sc() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: sc"
echo "Interactive script runner"
echo "Collects scripts from package.json, pyproject.toml, and Makefile, then lets you pick one with fzf"
return 0
fi
local lines=()
local pkg_json

View File

@@ -22,6 +22,13 @@ function spinner() {
# (that way it works for any locale as long as the font supports the characters)
local LC_CTYPE=C
# Show help
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
echo "Usage: spinner [-N] <command> [args...]"
echo " -N Select spinner style 0-11 (default: random)"
return 0
fi
# Parse optional -<number> to select spinner style
local spin_index
if [[ "$1" =~ ^-([0-9]+)$ ]]; then

View File

@@ -1,7 +1,19 @@
# start the SSH server (macOS remote login)
function ssh-server-start() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: ssh-server-start"
echo "Start the SSH server (macOS remote login)"
return 0
fi
sudo systemsetup -setremotelogin on
}
# stop the SSH server (macOS remote login)
function ssh-server-stop() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: ssh-server-stop"
echo "Stop the SSH server (macOS remote login)"
return 0
fi
sudo systemsetup -setremotelogin off
}

View File

@@ -2,6 +2,11 @@
# output the main pubkey file or use $1 to output a specific one
pubkey_file() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: pubkey_file [key_name]"
echo "Output the main pubkey file or use key_name to output a specific one"
return 0
fi
file="$HOME/.ssh/id_casraf.pub"
if [[ $# -eq 1 ]]; then
file="$HOME/.ssh/id_$1.pub"
@@ -11,12 +16,22 @@ pubkey_file() {
# copy pubkey to clipboard, use $1 to specify a specific key
pubkey() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: pubkey [key_name]"
echo "Copy pubkey to clipboard, use key_name to specify a specific key"
return 0
fi
file=$(pubkey_file $1)
more $file | pbcopy | echo "=> Public key copied to clipboard."
}
# add pubkey to allowed signers
allow-signing() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: allow-signing [key_name]"
echo "Add pubkey to allowed signers"
return 0
fi
file=$(pubkey_file $1)
if [[ ! -f $file ]]; then
echo_red "Public key file not found: $file"

View File

@@ -2,17 +2,32 @@
# example echo '1' | prepend 'result: '
prepend() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: echo '1' | prepend 'result: '"
echo "Prepend a string to stdin"
return 0
fi
echo -n "$@"
cat -
}
# transform to lowercase
lcase() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: lcase <text>"
echo "Transform text to lowercase"
return 0
fi
echo "$@" | tr '[:upper:]' '[:lower:]'
}
# transform to uppercase
ucase() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: ucase <text>"
echo "Transform text to uppercase"
return 0
fi
echo "$@" | tr '[:lower:]' '[:upper:]'
}
@@ -31,6 +46,11 @@ find-replace() {
# join strings with delimiter
strjoin() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: strjoin <delimiter> <string>..."
echo "Join strings with delimiter"
return 0
fi
if [[ $# -eq 0 ]]; then
echo_red "Usage: strjoin <delimiter> <string>..."
return 1
@@ -43,6 +63,11 @@ strjoin() {
# short xarg
# usage: xrg "[args]" "[template with {}]"
xrg() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: xrg \"[args]\" \"[template with {}]\""
echo "Short xarg - run a template command for each argument"
return 0
fi
if [[ $# -ne 2 ]]; then
echo_red "Usage: xrg \"[args]\" \"[template with {}]\""
fi
@@ -51,6 +76,11 @@ xrg() {
# encode a uri component
uriencode() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: uriencode <string>"
echo "Encode a URI component"
return 0
fi
len="${#1}"
for ((n = 0; n < len; n++)); do
c="${1:$n:1}"
@@ -82,7 +112,13 @@ posix_compliant() {
# decode a uri component
alias uridecode=posix_compliant
# center text in terminal
center() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: center <text>"
echo "Center text in terminal"
return 0
fi
if [[ $# -eq 0 ]]; then
echo_red "Usage: center <text>"
return 1
@@ -91,7 +127,13 @@ center() {
print_centered "$@"
}
# print a horizontal rule across the terminal
hr() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: hr"
echo "Print a horizontal rule across the terminal"
return 0
fi
print_centered "-" "-"
}

View File

@@ -1,6 +1,12 @@
#!/usr/bin/env zsh
# export links from a Nextcloud Talk chat as GPG-encrypted file
nctalk-export-links() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nctalk-export-links [chat_id]"
echo "Export links from a Nextcloud Talk chat as GPG-encrypted file"
return 0
fi
FPR="$(op item get 'gpg key' --format json --fields 'Fingerprint' | jq -r .value | tr -d '\n')"
CHAT="${1:-y9osnnt2}"
@@ -21,7 +27,13 @@ nctalk-export-links() {
[ $? -eq 0 ] && echo "Exported to $HOME/Downloads/talk-export-$(date +%Y%m%d).csv.gpg"
}
# decrypt a Nextcloud Talk export file
nctalk-decrypt() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: nctalk-decrypt [filename]"
echo "Decrypt a Nextcloud Talk export file"
return 0
fi
FILE="${1:-talk-export-$(date +%Y%m%d).csv.gpg}"
gpg --decrypt \
--batch --yes --pinentry-mode loopback \

View File

@@ -1,3 +1,11 @@
#!/usr/bin/env zsh
ta() { [[ -n "$1" ]] && tmux attach -t "$1" || tmux attach; }
# attach to a tmux session, or the most recent one if no name is given
ta() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: ta [session_name]"
echo "Attach to a tmux session, or the most recent one if no name is given"
return 0
fi
[[ -n "$1" ]] && tmux attach -t "$1" || tmux attach
}

View File

@@ -2,7 +2,14 @@
SCAFFOLDS_DIR="$DOTFILES/scaffolds"
# scaffold a project from a template
tpl() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: tpl <template> [name] [args...]"
echo "Scaffold a project from a template"
echo "Aliases: ef=editorfile, gh=github, ghp=github.pnpm"
return 0
fi
declare -A tpl_aliases=(
ef "editorfile"
gh "github"