Skip to content

Instantly share code, notes, and snippets.

@yogeshpaliyal
Created July 29, 2025 20:07
Show Gist options
  • Select an option

  • Save yogeshpaliyal/2834090fcbf495bb2bb10ec7259a73d5 to your computer and use it in GitHub Desktop.

Select an option

Save yogeshpaliyal/2834090fcbf495bb2bb10ec7259a73d5 to your computer and use it in GitHub Desktop.
adbl() {
# Check if fzf is installed
if ! command -v fzf &> /dev/null; then
echo "Error: fzf is not installed. Please install it to use this function."
echo "e.g., brew install fzf"
return 1
fi
local HISTORY_FILE=~/.adbl_history
# Create the history file if it doesn't exist
touch "$HISTORY_FILE"
local uri
# If an argument is passed, use it directly.
if [ -n "$1" ]; then
uri="$1"
else
# Otherwise, show the fzf history selector.
# --print-query prints the query and then the selection.
# We take the last line of the output (`tail -n 1`), which is the selection
# if one is made, or the query itself if the user just presses Enter.
uri=$(fzf --tac --height 40% --border --prompt="Select or type a new deeplink > " \
--header="[Enter] to select, [Esc] to cancel." \
--print-query < "$HISTORY_FILE" | tail -n 1)
fi
# Exit if the user cancelled fzf or the URI is empty
if [ -z "$uri" ]; then
echo "No deeplink selected."
return 1
fi
# Execute the adb command
echo "Executing: adb shell am start -W -a android.intent.action.VIEW -d \"$uri\""
adb shell am start -W -a android.intent.action.VIEW -d "$uri"
# If the command was successful, save the URI to history (if it's not already there)
if [ $? -eq 0 ]; then
# Use grep to check if the exact line already exists
if ! grep -q -F -x "$uri" "$HISTORY_FILE"; then
echo "$uri" >> "$HISTORY_FILE"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment