diff --git a/README.md b/README.md new file mode 100644 index 0000000..d995d3a --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# shrtrun + +**shrtrun** is a lightweight shell-based launcher utility that lets you execute commands or trigger custom actions (like searches) using a prefix system. It uses `rofi` for user input and supports configurable settings via a simple `.conf` file. + +--- + +## ✨ Features + +- Run arbitrary shell commands +- Google and YouTube search with prefix commands +- Configurable browser and search engines +- Uses `rofi` as the input interface +- Minimal logging for debugging +- Notification support (via `notify-send`) + +--- + +## 📦 Requirements + +Make sure the following dependencies are installed: + +- `bash` (default on most systems) +- `rofi` – for the graphical input menu +- `xdg-open` – to open URLs with the default browser +- `notify-send` (optional) – for desktop notifications + +**Install on Debian/Ubuntu:** + +```bash +sudo apt update +sudo apt install rofi xdg-utils libnotify-bin diff --git a/launcher.sh b/launcher.sh new file mode 100644 index 0000000..b303d3f --- /dev/null +++ b/launcher.sh @@ -0,0 +1,119 @@ +#!/bin/bash + +# Configuration +CONFIG_DIR="$HOME/.config/shrtrun" +CONFIG_FILE="$CONFIG_DIR/config.conf" + +# Create config directory if it doesn't exist +mkdir -p "$CONFIG_DIR" + +# Create default config if it doesn't exist +if [ ! -f "$CONFIG_FILE" ]; then + cat > "$CONFIG_FILE" << EOF +# Quick Launcher Configuration +log_file: /logs/shrtrun.log +browser: firefox +search_engine: https://duckduckgo.com/?q= +youtube_search: https://www.youtube.com/results?search_query= +EOF +fi + +# Function to read config values +get_config_value() { + key=$1 + default=$2 + # Use awk for more reliable parsing with : as delimiter + value=$(awk -F': ' -v key="$key" '$1 == key {print $2}' "$CONFIG_FILE") + if [ -z "$value" ]; then + echo "$default" + else + echo "$value" + fi +} + +# Get configuration values +BROWSER=$(get_config_value "browser" "firefox") +SEARCH_ENGINE=$(get_config_value "search_engine" "https://duckduckgo.com/?q=") +YOUTUBE_SEARCH=$(get_config_value "youtube_search" "https://www.youtube.com/results?search_query=") +LOG_FILE=$(get_config_value "log_file" "/.logs/shrtrun.log") + +# Check if log file exists +if [ ! -f "$LOG_FILE" ]; then + touch "$LOG_FILE" +fi + +# Function to show notifications +show_notification() { + title="$1" + message="$2" + + if command -v notify-send &> /dev/null; then + notify-send "$title" "$message" + else + echo "$title: $message" >> "$LOG_FILE" + fi +} + +# Get user input from rofi +USER_INPUT=$(rofi -dmenu -p "Run:") + +# Exit if user didn't enter anything +if [ -z "$USER_INPUT" ]; then + exit 0 +fi + +# Log the input +echo "$(date): User input: '$USER_INPUT'" >> "$LOG_FILE" + +# Source the environment +source "$HOME/.profile" 2>/dev/null +source "$HOME/.bashrc" 2>/dev/null +source "$HOME/.bashrc_aliases" 2>/dev/null + +# Check for command +if [[ "$USER_INPUT" == \!* ]]; then + # Extract command type and query + CMD_TYPE="${USER_INPUT:1:1}" + QUERY="${USER_INPUT:2}" + + case "$CMD_TYPE" in + g) + # Format the search URL + SEARCH_URL="${SEARCH_ENGINE}${QUERY// /+}" + echo "$(date): Opening search URL: $SEARCH_URL" >> "$LOG_FILE" + + # Try multiple methods to open the browser + if command -v "$BROWSER" &> /dev/null; then + "$BROWSER" "$SEARCH_URL" & + elif command -v xdg-open &> /dev/null; then + xdg-open "$SEARCH_URL" & + else + # Try common browsers + for browser in firefox google-chrome chromium-browser brave-browser; do + if command -v "$browser" &> /dev/null; then + "$browser" "$SEARCH_URL" & + break + fi + done + fi + disown + ;; + y) + # YouTube search + YOUTUBE_URL="${YOUTUBE_SEARCH}${QUERY// /+}" + echo "$(date): Opening YouTube search: $YOUTUBE_URL" >> "$LOG_FILE" + xdg-open "$YOUTUBE_URL" &>/dev/null & + disown + ;; + *) + show_notification "Unknown Command" "The command '$CMD_TYPE' is not recognized" + ;; + esac +else + # Execute regular command + echo "$(date): Executing command: $USER_INPUT" >> "$LOG_FILE" + + # Execute in background and disown + eval "$USER_INPUT" &>/dev/null & + disown +fi \ No newline at end of file