mirror of
https://github.com/olexsmir/dotfiles.git
synced 2026-01-15 08:41:34 +02:00
todo: add action for opening urls in todos
This commit is contained in:
parent
e5f2273627
commit
4fe83e65e0
2 changed files with 39 additions and 0 deletions
29
config/todo/actions/url
Executable file
29
config/todo/actions/url
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env bash
|
||||
action=$1
|
||||
shift
|
||||
|
||||
if [[ $action == "usage" ]]; then
|
||||
echo "url [task_number] - opens link in the task"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
item=$1
|
||||
if [[ ! "$item" =~ ^[0-9]+$ ]]; then
|
||||
echo "$item: invalid item number"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
URL_REGEX="\b(?:https?:\/\/)?(?:[\w-]+\.)+[a-z]{2,}(?:\/[\w\-./?%&=:#@+]*)?"
|
||||
URL=$(sed "$item!d" "$TODO_FILE" | grep -Po "$URL_REGEX")
|
||||
|
||||
if [[ -z "$URL" ]]; then
|
||||
echo "No URL found in task $item"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! "#URL" =~ ^(?!https?:\/\/) ]]; then
|
||||
URL="https://$URL"
|
||||
fi
|
||||
|
||||
echo "$URL"
|
||||
xdg-open "$URL" &>/dev/null
|
||||
Loading…
Add table
Add a link
Reference in a new issue