Skip to content

Instantly share code, notes, and snippets.

@denzuko
Last active January 3, 2016 10:29
Show Gist options
  • Select an option

  • Save denzuko/8449370 to your computer and use it in GitHub Desktop.

Select an option

Save denzuko/8449370 to your computer and use it in GitHub Desktop.
Added documentation and finalized release version on 1.0
#!/bin/sh
###############################################################################
# $Id$
# elvis: IMS tickets -- Search for a ticket within IMS
# version 0.1 by Dwight Spencer (@denzuko) <[email protected]>
# version 0.2 by Dwight Spencer (@denzuko) <[email protected]>
# - Fixes some param issues
# version 0.3 by Dwight Spencer (@denzuko) <[email protected]>
# - Replaced google in the param check to ims
# version 1.0 by Dwight Spencer (@denzuko) <[email protected]>
# - Full params intergrated
# - search command alone goes to owned tickets while with a query searches
# all of ims
# - Quick commands implmented:
# * use -c to create a ticket
# * use -v to view open tickets
# *use -m to view owned tickets
###############################################################################
. surfraw || exit 1
BASEURI="https://ims.firehost.com/tickets"
w3_config_hook () {
def SURFRAW_ims_search search
}
w3_usage_hook () {
cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description: Search for a ticket within IMS
Local options:
-search= Specialized search on topic
view | View Ticket by id
create | Search current create tickets
open | Search current open tickets
unassigned | Search current unassigned tickets
scheduled | Search current scheduled tickets
pending | Search current pending tickets
resolved | Search current resolved tickets
other | Search current other tickets
Environment: SURFRAW_ims_search
EOF
w3_global_usage
}
w3_parse_option_hook () {
opt="$1"
#optarg="echo $2| tr '[:upper:]' '[:lower:]'"
optarg="$2"
case "$opt" in
-s*=*) setopt SURFRAW_ims_search "$optarg";;
-v*) setopt SURFRAW_ims_search "";;
-c*) setopt SURFRAW_ims_search create;;
-m*) setopt SURFRAW_ims_search my;;
-o*) setopt SURFRAW_ims_search open;;
*) return 1 ;;
esac
return 0
}
w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments
escaped_args=`w3_url_of_arg $w3_args`
if [ -z "$w3_args" ]; then
case "$SURFRAW_ims_search" in
v*) PARAM="/view/${escaped_args}";;
c*) PARAM="/create";;
u*) PARAM="/unassigned";;
sched*) PARAM="/scheduled";;
p*) PARAM="/pending";;
r*) PARAM="/resolved";;
open) PARAM="/";;
other) PARAM="/other";;
*) PARAM="/my";;
esac
else
case "$SURFRAW_ims_search" in
v*) PARAM="";;
c*) PARAM="/create";;
m*) PARAM="/my";;
o*) PARAM="/";;
*) PARAM="/search?q=${escaped_args}"
esac
fi
w3_browse_url "${BASEURI}${PARAM}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment