-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintellij-current-task
executable file
·101 lines (91 loc) · 3.62 KB
/
intellij-current-task
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
if [ ${#funcstack} -gt 1 ]; then
# file is being sourced, hopefully by p10k. Add the p10k prompt function.
function prompt_idea_task() {
# ${(%):-%x} is zsh for "the path script that defined this function" (in other words, this file). See: https://stackoverflow.com/a/28336473/1076640
current_task="$("${(%):-%x}" 2>/dev/null || true)"
local task_icon_1=$'\uf4a0' # task list variant 1
local task_icon_2=$'\ueb67' # task list variant 2
local task_icon_3=$'\uf0ae' # task list variant 3
local task_icon_4=$'\ue7b5' # intellij icon
[ -n "$current_task" ] && p10k segment -t "$current_task" -f magenta -i "${IDEA_TASK_ICON:-${task_icon_1}}"
}
else
options_dir="$HOME/.config/yshavit-scripts"
options_json="$options_dir/intellij-tasks.json"
if [ ! -e "$options_json" ]; then
mkdir -p "$options_dir"
echo '{}' > "$options_json"
fi
# file is being run as a script
source "$(dirname "$0")/lib/common.sh"
is_installed xmlstarlet || err '<brew install xmlstarlet>'
idea_dir="$("$ys_scripts_home/find-in-ancestry" .idea || true)"
if [ -z "$idea_dir" ]; then
exit # not in an intellij dir
fi
current_changelist="$(xmlstarlet sel -t -v "//component[@name='TaskManager']/task[@active='true']/@id" "$idea_dir/workspace.xml")"
changelist_branch_name="$(xmlstarlet sel -t -v "//component[@name='TaskManager']/task[@active='true']/branch[not(@original)]/@name" "$idea_dir/workspace.xml")"
changelist_idea_desc="$(xmlstarlet sel -t -v "//component[@name='TaskManager']/task[@active='true']/@summary" "$idea_dir/workspace.xml")"
changelist_desc="$(cat "$options_json" | jq -r '.tasks[$key].description // $defaultval' --arg key "$current_changelist" --arg defaultval "$changelist_idea_desc")"
first_arg="${1:-}"
if [ "$first_arg" == --edit ]; then
action=edit
shift
elif [ "$first_arg" == --use-default ]; then
action=use-default
shift
else
action=output
fi
function color {
color="$1"
shift
printf "\033[%sm%s\033[0m" "$color" "$*"
}
script_name="$(basename "$0")"
case "$action" in
output)
printf ''
if [ "$current_changelist" == Default ]; then
printf '%s' "$current_changelist"
else
if [ "$changelist_branch_name" == "$(git rev-parse --abbrev-ref HEAD)" ]; then
printf ' %s' "$current_changelist"
else
printf '%s: %s' "$current_changelist" "$changelist_desc"
fi
fi
{
echo
color 90 '(Run "'
color 36 "$script_name --edit [description]"
color 90 '" to edit the task description or "'
color 36 "$script_name --use-default"
color 90 '" to use the defafault.)'
echo
} >&2
;;
edit)
new_desc="$*"
if [ -z "$new_desc" ]; then
echo "IDEA task description is: $(color 36 "$changelist_idea_desc")"
if [ "$changelist_desc" == "$changelist_idea_desc" ]; then
echo "That's the currently configured description for $script_name, too."
else
echo "Current description for $script_name is: $(color 36 "$changelist_desc")"
fi
printf 'New description? '
printf "\033[36m"
read new_desc
printf "\033[0m"
fi
cat "$options_json" | jq '.tasks[$key].description |= $newvalue' --arg key "$current_changelist" --arg newvalue "$new_desc" > "${options_json}.tmp"
mv "${options_json}.tmp" "$options_json"
;;
use-default)
cat "$options_json" | jq 'del(.tasks[$key].description)' --arg key "$current_changelist" > "${options_json}.tmp"
mv "${options_json}.tmp" "$options_json"
;;
esac
fi