Skip to content

Commit

Permalink
Merge remote-tracking branch 'artur-shaik/attach_with_vifm' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlatow committed Nov 15, 2016
2 parents 480e6bc + c1fab65 commit cd98c4b
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,27 @@ or even

$ taskopen pro:taskwarrior +bug \\notes

#Scripts

##attach_vifm

Script helps to attach file to taskwarrior's task from command line or with `vifm`. It can attach file to existed task. Or it can create task for existed file.

Usage:

```
attach_vifm -f file_name -t task_id
```

If you omit `file_name`, `vifm` will be executed. If you omit `task_id`, you will be asked to enter title for new task.

Commands can be added to vifmrc:

```
command attachnew attach_vifm -f %d/%f
command attach attach_vifm -t %a -f %d/%f
```

#Contributions

Thanks to the following:
Expand Down
96 changes: 96 additions & 0 deletions scripts/attach_vifm
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash

# This script attaches file to taskwarrior's task,
# that can be open with taskopen script.
#
# Also, script can create task before attaching file
# to it.
#
# Requires: taskwarrior, taskopen, vifm, getopt
#
# For parameters run: attach_to_task --help
#
# Commands can be added to vifmrc:
# command attachnew attach_to_task -f %d/%f
# command attach attach_to_task -t %a -f %d/%f

usage() {
echo "Usage: $(basename $0) [-t task_id] [-f filepath]"
}

SHORT=t:f:h
LONG=task:,file:,help

PARSED=$(getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@")
if [[ $? != 0 ]]; then
exit 2
fi

eval set -- "$PARSED"

while true; do
case "$1" in
-t|--task)
task_id="$2"
number='^[0-9]+'
if ! [[ $task_id =~ $number ]]; then
echo "Wrong task id"
exit 1
fi
shift 2
;;
-f|--file)
file_name=$(readlink -f "$2")
if ! [[ -f $file_name ]]; then
echo "Not a file"
exit 1
fi
shift 2
;;
-h|--help)
usage
exit
;;
--)
shift
break
;;
esac
done

if [[ "$task_id" == "" ]]; then
echo -n "Create task (with options): "
read -r task_title
if [[ "$task_title" == "" ]]; then
echo "Cancel"
exit
fi
task_id=$(task add $task_title | grep 'Created' | sed 's/Created task \([0-9]\+\)/\1/g')
if [[ $? -ne 0 || "$task_id" == "" ]]; then
echo "Error creating task"
exit 1
fi
fi

if [[ "$file_name" == "" ]]; then
if [[ ! -x $(which vifm) ]]; then
echo "Please, install vifm"
exit 1
fi
file_name=$(vifm -c only --choose-files -)
if [[ "$file_name" == "" ]]; then
echo "Cancel"
exit
fi
fi

desc=$(task $task_id info | awk '$0 ~ /^Description/ {print substr($0, index($0,$2))}')
echo "Attaching to task $task_id '$desc'."
echo -n "Type a label: "
read -r label
annotation=""
if [[ "$label" != "" ]]; then
annotation="$label: "
fi

task $task_id annotate -- "$annotation$file_name"

0 comments on commit cd98c4b

Please sign in to comment.