all repos

dotfiles @ 4fe83e65e0c5620e114a49152351c7719606ab14

i use rach linux btw

dotfiles/config/todo/actions/url (view raw)

1
#!/usr/bin/env bash
2
action=$1
3
shift
4
5
if [[ $action == "usage" ]]; then
6
  echo "url [task_number] - opens link in the task"
7
  exit 0
8
fi
9
10
item=$1
11
if [[ ! "$item" =~ ^[0-9]+$ ]]; then
12
  echo "$item: invalid item number"
13
  exit 1
14
fi
15
16
URL_REGEX="\b(?:https?:\/\/)?(?:[\w-]+\.)+[a-z]{2,}(?:\/[\w\-./?%&=:#@+]*)?"
17
URL=$(sed "$item!d" "$TODO_FILE" | grep -Po "$URL_REGEX")
18
19
if [[ -z "$URL" ]]; then
20
  echo "No URL found in task $item"
21
  exit 1
22
fi
23
24
if [[ ! "#URL" =~ ^(?!https?:\/\/) ]]; then
25
  URL="https://$URL"
26
fi
27
28
echo "$URL"
29
xdg-open "$URL" &>/dev/null