Skip to content

Instantly share code, notes, and snippets.

@JasonSKK
Last active June 14, 2025 17:51
Show Gist options
  • Save JasonSKK/211aa13a339e57035ed2806b7630c090 to your computer and use it in GitHub Desktop.
Save JasonSKK/211aa13a339e57035ed2806b7630c090 to your computer and use it in GitHub Desktop.
Wrapper for ZSH that lets xdg-open accept a single wildcard pattern
open() {
local resolved=() arg matches
for arg in "$@"; do
if [[ "$arg" == *[\*\?\[]* ]]; then
matches=(${(f)"$(print -l -- ${~arg})"}) # Zsh-compatible glob expansion
if (( ${#matches[@]} == 0 )); then
printf 'xdg-open: no match for pattern %s\n' "$arg" >&2
return 1
fi
resolved+=("${matches[@]}")
else
resolved+=("$arg")
fi
done
for file in "${resolved[@]}"; do
command xdg-open "$file" &
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment