Skip to content

Instantly share code, notes, and snippets.

@PofMagicfingers
Last active October 1, 2018 14:09
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 PofMagicfingers/ac5632aec07051c66882267f5a319463 to your computer and use it in GitHub Desktop.
Save PofMagicfingers/ac5632aec07051c66882267f5a319463 to your computer and use it in GitHub Desktop.
shortcuts to Redmine with rofi
#!/bin/bash
config_file=$HOME/.config/redmine
if [ ! -f $config_file ]; then
cat << Usage
Please add your REDMINE_API_KEY and REDMINE_URL
into a file at ~/.config/redmine
REDMINE_API_KEY="apikey"
REDMINE_URL="https://server.com"
Usage
exit 2;
fi
# source config file
. $config_file
function launcher
{
rofi -dmenu -i -p $@
}
function open_redmine
{
xdg-open "$REDMINE_URL/$1"
}
function open_redmine_project
{
open_redmine "projects/$1/$2"
}
function get_issues
{
ISSUES=$(\
curl -m2 -H "X-Redmine-API-Key: $REDMINE_API_KEY" $REDMINE_URL/projects/$1/issues.json?sort=updated_on_desc | \
jq '.issues | map("#\(.id)§\(.subject)") | .[]' | \
xargs -I '{}' echo {} | \
column -s '§' -t
)
ISSUE=$(echo -e "All issues\n$ISSUES" | launcher "Issue")
if [ ! -z "$ISSUE" ]; then
ISSUE_N=$(echo $ISSUE | sed 's/[^0-9]*//g')
if [[ -z $ISSUE_N ]]; then
open_redmine_project $1 "issues"
else
open_redmine "issues/$ISSUE_N"
fi
fi
}
function get_project
{
PROJECT=$(\
curl -m2 -H "X-Redmine-API-Key: $REDMINE_API_KEY" $REDMINE_URL/projects.json | \
jq '.projects | map("\(.identifier)§\(.name)") | .[]' | \
xargs -I '{}' echo {} | \
column -s '§' -t | \
launcher "Project" | \
tr -s ' ' | \
cut -d' ' -f1 \
)
if [[ ! -z "$PROJECT" ]]; then
OPTIONS="Dashboard\nIssues\n go to issue\n new issue\nWiki"
OPTION=$(echo -e $OPTIONS | launcher "Go to" | tr -s ' ')
if [ ! -z "$OPTION" ]; then
case $OPTION in
Dashboard)
open_redmine_project $PROJECT
;;
Issues)
get_issues $PROJECT
;;
*go*to*issue)
open_redmine "issues/$(launcher 'Issue #')"
;;
*new*issue*)
open_redmine_project $PROJECT "issues/new"
;;
Wiki)
open_redmine_project $PROJECT "wiki"
;;
*)
open_redmine_project $PROJECT $option
;;
esac
fi
fi
}
get_project
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment