Skip to content

Instantly share code, notes, and snippets.

@shirobachi
Last active March 5, 2023 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirobachi/1e088bcb3794e956e1730219b3d371fb to your computer and use it in GitHub Desktop.
Save shirobachi/1e088bcb3794e956e1730219b3d371fb to your computer and use it in GitHub Desktop.
Taskwarrior-tui copy to clipboard

copy-to-clipboard

Thanks for stepping by!
This is not perfect but it work (on my machine) any problem you welcome to share in comments :)

How it work

It search in task's description and annotations urls, phones and emails, then let you choose whitch to copy to clipboard with rofi. It will show uniq values of:

  • task description (title)
  • task's annotations
  • found emails, phone, mails

Installation

Required packages: rofi

sudo pacman -S rofi    # arch
sudo apt install rofi  # ubuntu

Downloading script

With autoupdate

[[ -f $HOME/.zshrc ]] && FILE=$HOME/.zshrc || FILE=$HOME/.bashrc;
echo '[[ ! -f /tmp/task_copy_to_clipboard.sh ]] && curl -s https://gist.githubusercontent.com/SimonHryszko/1e088bcb3794e956e1730219b3d371fb/raw/db6d2e2a9a9149353b7443d7909cb3954e08b477/task_copy_to_clipboard.sh -o /tmp/task_copy_to_clipboard.sh; chmod +x /tmp/task_copy_to_clipboard.sh' >> "$FILE";

I don't trust you to let auto-update

That's good, there is no reason to trust me, try this

  1. Download below script to anylocation you want
  2. Add execution permissions via chmod +x FILE_LOCATION

Testing

Type this /tmp/task_copy_to_clipboard.sh 1 # change file location if not choosed auto-update

Should show rofi with at least task description (title)

Integration with taskwarrior-tui

If you want to 1 trigger script and choose auto-update then:

echo 'uda.taskwarrior-tui.shortcuts.1=/tmp/task_copy_to_clipboard.sh' >> "$HOME"/.taskrc

In other words:
To taskwarrior config file (default: ~/.tashrc) add following line
```sh
uda.taskwarrior-tui.shortcuts.1=/tmp/task_copy_to_clipboard.sh

where uda.taskwarrior-tui.shortcuts.1 mean that 1 will trigger script
and /tmp/task_copy_to_clipboard.sh is file location of script

Other

I share it free of charge. You can use it, modify it, redistribute it, sell it, whatever you want. Any problem you welcome to share in comments or even chat with me on discord shirobachi#3663 :) If you like it, you can buy me a coffee :)

#!/bin/bash
ID=$(task _id "$1")
SEP="|"
ANNOTATIONS=$(task _get "$ID.description")$SEP
echo "UUID: $1"
echo "ID: $ID"
echo "SEP: $SEP"
echo "ANNOTATIONS: $ANNOTATIONS"
i=1
# while true; do
while true; do
temp=$(task _get "$ID.annotations.$i.description")
i=$((i + 1))
if [ -z "$temp" ]; then
break
else
ANNOTATIONS+="$temp$SEP"
# Check if temp contains phone number via regex \ [0-9-+()]{3,10}
REG_PHONE="[0-9][0-9\ \-]{3,20}" # use any work like 'or' b/w phone numbers
REG_URL="(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]\.[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]"
REG_EMAIL="[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}"
PHONE=$(echo "$temp" | grep -Eo "$REG_PHONE")
[[ -n $PHONE ]] && ANNOTATIONS+="$PHONE$SEP"
URL=$(echo "$temp" | grep -Eo "$REG_URL")
[[ -n $URL ]] && ANNOTATIONS+="$URL$SEP"
EMAIL=$(echo "$temp" | grep -Eo "$REG_EMAIL")
[[ -n $EMAIL ]] && ANNOTATIONS+="$EMAIL$SEP"
fi
done
# echo -e "$(echo "$ANNOTATIONS" | tr $SEP '\n' | uniq)"
echo -e "$(echo "$ANNOTATIONS" | tr $SEP '\n' | uniq)" | rofi -dmenu -p "Copy to clipboard" | xclip -selection clipboard
[[ ! -f /tmp/task_copy_to_clipboard.sh ]] && curl -s https://raw.githubusercontent.com/abhishekbanthia/Public-APIs/master/Taskwarrior/task_copy_to_clipboard.sh > /tmp/task_copy_to_clipboard.sh && chmod +x /tmp/task_copy_to_clipboard.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment