Skip to content

Instantly share code, notes, and snippets.

@scragg0x
Last active February 18, 2026 21:20
Show Gist options
  • Select an option

  • Save scragg0x/8eb7ebf1ae5a05e2b9454de790fe9de9 to your computer and use it in GitHub Desktop.

Select an option

Save scragg0x/8eb7ebf1ae5a05e2b9454de790fe9de9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# setup-cosmic-shortcut.sh
# Ensures a custom keyboard shortcut exists in COSMIC's config
set -e
CONFIG_DIR="$HOME/.config/cosmic/com.system76.CosmicSettings.Shortcuts/v1"
CONFIG_FILE="$CONFIG_DIR/custom"
SHORTCUT_KEY='(
modifiers: [
Ctrl,
],
key: "space",
description: Some("Handy"),
)'
SHORTCUT_VALUE='Spawn("/usr/bin/handy --toggle-transcription")'
# --- Create config dir if missing ---
mkdir -p "$CONFIG_DIR"
# --- If file doesn't exist, create it from scratch ---
if [ ! -f "$CONFIG_FILE" ]; then
echo "Creating new shortcuts config..."
cat > "$CONFIG_FILE" <<EOF
{
(
modifiers: [
Ctrl,
],
key: "space",
description: Some("Handy"),
): Spawn("/usr/bin/handy --toggle-transcription"),
}
EOF
echo "Created $CONFIG_FILE"
exit 0
fi
# --- If file exists, check if shortcut is already there ---
if grep -q '"space"' "$CONFIG_FILE" && grep -q "handy" "$CONFIG_FILE"; then
echo "Shortcut already exists, nothing to do."
exit 0
fi
# --- Insert shortcut before the closing brace ---
echo "Adding shortcut to existing config..."
# Back up existing config
cp "$CONFIG_FILE" "$CONFIG_FILE.bak"
echo "Backed up existing config to $CONFIG_FILE.bak"
# Insert the new shortcut before the last closing brace
sed -i 's/^}$/ (\n modifiers: [\n Ctrl,\n ],\n key: "space",\n description: Some("Handy"),\n ): Spawn("\/usr\/bin\/handy --toggle-transcription"),\n}/' "$CONFIG_FILE"
echo "Shortcut added."
echo ""
echo "You may need to log out and back in, or restart COSMIC settings for changes to take effect."
echo "Current config:"
cat "$CONFIG_FILE"
#!/bin/bash
# setup-ydotool.sh - Install and configure ydotool on Pop!_OS / Ubuntu
set -e
echo "=== ydotool setup ==="
# --- Dependencies ---
echo "[1/5] Installing dependencies..."
sudo apt install -y cmake libevdev-dev scdoc git
# --- uinput ---
echo "[2/5] Setting up uinput..."
sudo modprobe uinput
# Make uinput load on boot
echo "uinput" | sudo tee /etc/modules-load.d/uinput.conf > /dev/null
# Set uinput permissions
echo 'KERNEL=="uinput", GROUP="input", MODE="0660"' | sudo tee /etc/udev/rules.d/60-uinput.rules > /dev/null
sudo udevadm control --reload-rules
sudo udevadm trigger
# Add user to input group
sudo usermod -aG input "$USER"
echo " Added $USER to input group (will take full effect after logout/login)"
# --- Build & install ydotool ---
echo "[3/5] Building ydotool from source..."
BUILD_DIR="$(mktemp -d)/ydotool"
git clone https://github.com/ReimuNotMoe/ydotool "$BUILD_DIR"
cd "$BUILD_DIR"
mkdir build && cd build
cmake ..
make -j"$(nproc)"
sudo make install
# --- systemd user service for ydotoold ---
echo "[4/5] Setting up ydotoold as a systemd user service..."
systemctl --user daemon-reload
systemctl --user enable ydotoold
systemctl --user start ydotoold
# --- Shell profile setup ---
echo "[5/5] Configuring shell environment..."
PROFILE_LINE='export YDOTOOL_SOCKET="/run/user/$(id -u)/.ydotool_socket"'
for RC in "$HOME/.bashrc" "$HOME/.zshrc"; do
if [ -f "$RC" ]; then
if ! grep -q "YDOTOOL_SOCKET" "$RC"; then
echo "$PROFILE_LINE" >> "$RC"
echo " Added YDOTOOL_SOCKET to $RC"
else
echo " YDOTOOL_SOCKET already set in $RC, skipping"
fi
fi
done
# Apply to current session
export YDOTOOL_SOCKET="/run/user/$(id -u)/.ydotool_socket"
# --- Test ---
echo ""
echo "=== Testing ydotool ==="
sleep 1
if ydotool type "Test" 2>/dev/null; then
echo "ydotool is working correctly!"
else
echo "Test failed. You may need to log out and back in for group changes to take effect."
echo "Then run: ydotool type 'Test'"
fi
echo ""
echo "=== Done ==="
echo "Note: If this is your first install, log out and back in to apply input group permissions."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment