Last active
June 14, 2025 17:51
-
-
Save JasonSKK/211aa13a339e57035ed2806b7630c090 to your computer and use it in GitHub Desktop.
Wrapper for ZSH that lets xdg-open accept a single wildcard pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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