all repos

dotfiles @ 152c5ba

my dotfiles

config/todo/actions/url (view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/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 == "" ]]; then
  TODOTXT_VERBOSE=0 $TODO_FULL_SH ls @url
  exit 0
fi

if [[ ! "$item" =~ ^[0-9]+$ ]]; then
  echo "provided [task_number] is invalid: $item"
  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