Files
omarchy/default/bash/functions
David Heinemeier Hansson 755633cd95 Documentation
2025-08-03 20:07:46 +02:00

89 lines
2.5 KiB
Plaintext

# Compression
compress() { tar -czf "${1%/}.tar.gz" "${1%/}"; }
alias decompress="tar -xzf"
# Write iso file to sd card
iso2sd() {
if [ $# -ne 2 ]; then
echo "Usage: iso2sd <input_file> <output_device>"
echo "Example: iso2sd ~/Downloads/ubuntu-25.04-desktop-amd64.iso /dev/sda"
echo -e "\nAvailable SD cards:"
lsblk -d -o NAME | grep -E '^sd[a-z]' | awk '{print "/dev/"$1}'
else
sudo dd bs=4M status=progress oflag=sync if="$1" of="$2"
sudo eject $2
fi
}
# Format an entire drive for a single partition using ext4
format-drive() {
if [ $# -ne 2 ]; then
echo "Usage: format-drive <device> <name>"
echo "Example: format-drive /dev/sda 'My Stuff'"
echo -e "\nAvailable drives:"
lsblk -d -o NAME -n | awk '{print "/dev/"$1}'
else
echo "WARNING: This will completely erase all data on $1 and label it '$2'."
read -rp "Are you sure you want to continue? (y/N): " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
sudo wipefs -a "$1"
sudo dd if=/dev/zero of="$1" bs=1M count=100 status=progress
sudo parted -s "$1" mklabel gpt
sudo parted -s "$1" mkpart primary ext4 1MiB 100%
sudo mkfs.ext4 -L "$2" "$([[ $1 == *"nvme"* ]] && echo "${1}p1" || echo "${1}1")"
echo "Drive $1 formatted and labeled '$2'."
fi
fi
}
# Create a desktop launcher for a web app
web2app() {
if [ "$#" -ne 3 ]; then
echo "Usage: web2app <AppName> <AppURL> <IconURL> (IconURL must be in PNG -- use https://dashboardicons.com)"
return 1
fi
local APP_NAME="$1"
local APP_URL="$2"
local ICON_URL="$3"
local ICON_DIR="$HOME/.local/share/applications/icons"
local DESKTOP_FILE="$HOME/.local/share/applications/${APP_NAME}.desktop"
local ICON_PATH="${ICON_DIR}/${APP_NAME}.png"
mkdir -p "$ICON_DIR"
if ! curl -sL -o "$ICON_PATH" "$ICON_URL"; then
echo "Error: Failed to download icon."
return 1
fi
cat > "$DESKTOP_FILE" <<EOF
[Desktop Entry]
Version=1.0
Name=$APP_NAME
Comment=$APP_NAME
Exec=chromium --new-window --ozone-platform=wayland --app="$APP_URL" --name="$APP_NAME" --class="$APP_NAME"
Terminal=false
Type=Application
Icon=$ICON_PATH
StartupNotify=true
EOF
chmod +x "$DESKTOP_FILE"
}
web2app-remove() {
if [ "$#" -ne 1 ]; then
echo "Usage: web2app-remove <AppName>"
return 1
fi
local APP_NAME="$1"
local ICON_DIR="$HOME/.local/share/applications/icons"
local DESKTOP_FILE="$HOME/.local/share/applications/${APP_NAME}.desktop"
local ICON_PATH="${ICON_DIR}/${APP_NAME}.png"
rm "$DESKTOP_FILE"
rm "$ICON_PATH"
}