Skip to content

Commit 87597de

Browse files
committed
Add extract-urls function
1 parent f9e2061 commit 87597de

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

.zshrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,19 @@ dedent() {
738738
echo "Removed leading whitespace from clipboard content"
739739
}
740740

741+
# Extract URLs from unstructured text (stdin or args).
742+
urls() {
743+
local input
744+
if (( $# > 0 )); then
745+
input="$*"
746+
else
747+
input="$(cat)"
748+
fi
749+
print -r -- "$input" | grep -oE '(https?|ftp|file)://[^[:space:]<>"'\''`]+' \
750+
| sed -E 's/[.,;:!?)\]}>]+$//' \
751+
| awk '!seen[$0]++'
752+
}
753+
741754
# ZSH-SPECIFIC COMPLETION {{{1
742755

743756
# Add new Zsh Completions repo

0 commit comments

Comments
 (0)