From e7f76b451dba75bbc01a52a57b2486d1a19ea9f5 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Sat, 11 Oct 2025 00:47:58 +0300 Subject: [PATCH] feat: move atuin scripts to plugins --- aliases.zsh | 2 +- plugins/common/android.zsh | 141 ++++++++++++++++++ plugins/common/flutter.zsh | 0 plugins/common/github.zsh | 12 ++ ...unctions.zsh => list_functions.plugin.zsh} | 0 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100755 plugins/common/android.zsh mode change 100644 => 100755 plugins/common/flutter.zsh create mode 100755 plugins/common/github.zsh rename plugins/{list_functions.zsh => list_functions.plugin.zsh} (100%) mode change 100644 => 100755 diff --git a/aliases.zsh b/aliases.zsh index 625e67f6..15fb0f23 100755 --- a/aliases.zsh +++ b/aliases.zsh @@ -136,7 +136,7 @@ alias trn="tmux rename-session -t" alias tk="trm" alias tks="tmux kill-server" alias txp="tx p" -alias tls="tx ls -s" +alias tls='command -v node >/dev/null || eval "$(fnm env)"; tx ls -s' # unsorted diff --git a/plugins/common/android.zsh b/plugins/common/android.zsh new file mode 100755 index 00000000..63944c26 --- /dev/null +++ b/plugins/common/android.zsh @@ -0,0 +1,141 @@ +#!/usr/bin/env zsh + +build-apk() { + set -euo pipefail + + # --- Helpers --- + die() { + echo "Error: $*" >&2 + exit 1 + } + + # --- Ensure we're at project root --- + [[ -f "pubspec.yaml" ]] || die "pubspec.yaml not found. Run this from your Flutter project root." + + # --- Extract name and version from pubspec.yaml (top-level keys) --- + name="$(awk ' + /^[[:space:]]*#/ {next} + /^[[:space:]]*name:[[:space:]]*/ {sub(/^[[:space:]]*name:[[:space:]]*/,""); print; exit} +' pubspec.yaml)" + version="$(awk ' + /^[[:space:]]*#/ {next} + /^[[:space:]]*version:[[:space:]]*/ {sub(/^[[:space:]]*version:[[:space:]]*/,""); print; exit} +' pubspec.yaml)" + + [[ -n "${name:-}" ]] || die "Could not parse 'name' from pubspec.yaml" + [[ -n "${version:-}" ]] || die "Could not parse 'version' from pubspec.yaml" + + # Sanitize for filename: spaces -> '-', plus '+' -> '-' + safe_name="$(echo "$name" | tr ' ' '-')" + safe_version="$version" # "$(echo "$version" | tr ' ' '-' | sed 's/+/-/g')" + + echo "App name: $name" + echo "App version: $version" + + # --- Build APK (release) --- + echo "Building APK..." + flutter build apk + + # --- Locate the newest APK produced by Flutter --- + echo "Locating built APK..." + apk_path="$(find build/app/outputs -type f -name '*.apk' -printf '%T@ %p\n' 2>/dev/null | sort -nr | head -n1 | cut -d' ' -f2-)" + [[ -n "${apk_path:-}" && -f "$apk_path" ]] || die "No APK found in build/app/outputs" + + echo "Found APK: $apk_path" + + # --- Copy to release/apk as {name}-{version}.apk --- + mkdir -p release/apk + dest="release/apk/${safe_name}-${safe_version}.apk" + cp -f "$apk_path" "$dest" + echo "Copied to: $dest" + + # --- Ask whether to connect to remote device --- + printf "Connecting to remote device and install? [y/N] " + read -r install_remote + case "${install_remote:-}" in + y | Y | yes | YES) + # Device host byte and port with defaults if user just hits enter + printf "Enter device (last octet of 192.168.68.X) [default 100]: " + read -r device_octet + device_octet="${device_octet:-100}" + printf "Enter adb TCP/IP port [default 5555]: " + read -r port + port="${port:-5555}" + target="192.168.68.${device_octet}:${port}" + + command -v adb >/dev/null 2>&1 || die "adb not found. Please install Android Platform Tools." + echo "Connecting to $target ..." + adb connect "$target" || die "Failed to connect to $target" + + echo "Pushing APK to /sdcard/Downloads on $target ..." + adb -s "$target" push "$dest" /sdcard/Downloads/ || die "adb push failed" + + echo "Installing via flutter to $target ..." + flutter install -d "$target" + + echo "Done." + ;; + *) + echo "Skipping remote connect/install. Done." + ;; + esac +} + +adb-pair-device() { + device_octet="$1" + device_port="$2" + pairing_code="$3" + + if [[ -z "$device_octet" ]]; then + printf "Device octet (last octet of 192.168.68.X): " + read -r device_octet + fi + + if [[ -z "$device_port" ]]; then + printf "Device adb TCP/IP port [default 5555]: " + read -r device_port + device_port="${device_port:-5555}" + fi + + if [[ -z "$pairing_code" ]]; then + printf "Pairing code (from Developer Options > Wireless debugging > Pair device with pairing code): " + read -r pairing_code + fi + + adb pair 192.168.68."$device_octet":"$device_port" --pairing-code "$pairing_code" || { + echo "Pairing failed" + return 1 + } +} + +adb-connect-device() { + device_octet="$1" + device_port="$2" + + if [[ -z "$device_octet" ]]; then + printf "Device octet (last octet of 192.168.68.X) [default 100]: " + read -r device_octet + fi + + if [[ -z "$device_port" ]]; then + printf "Device adb TCP/IP port [default 5555]: " + read -r device_port + fi + + adb connect 192.168.68."$device_octet":"$device_port" || { + echo "Connection failed" + return 1 + } +} + +adb-flutter-install() { + proj_file="$(find-up pubspec.yaml)" + if [[ -z "$proj_file" ]]; then + echo "pubspec.yaml not found in any parent directory" + return 1 + fi + proj_dir="$(dirname "$proj_file")" + pushd "$proj_dir" || return 1 + adb install -r build/app/outputs/apk/release/app-release.apk + popd || return 1 +} diff --git a/plugins/common/flutter.zsh b/plugins/common/flutter.zsh old mode 100644 new mode 100755 diff --git a/plugins/common/github.zsh b/plugins/common/github.zsh new file mode 100755 index 00000000..9b260456 --- /dev/null +++ b/plugins/common/github.zsh @@ -0,0 +1,12 @@ +#!/usr/bin/env zsh + +create-repo() { + if [[ -z "$REPO_NAME" ]]; then + printf "Repository name: " + read -r REPO_NAME + fi + + gh repo create "$REPO_NAME" --private --disable-wiki || exit 1 + git init || echo "Local repo already initialized" + git remote add origin "git@github.com:chenasraf/$REPO_NAME.git" || exit 1 +} diff --git a/plugins/list_functions.zsh b/plugins/list_functions.plugin.zsh old mode 100644 new mode 100755 similarity index 100% rename from plugins/list_functions.zsh rename to plugins/list_functions.plugin.zsh