Skip to content

Instantly share code, notes, and snippets.

@qinshulei
Created April 27, 2015 07:12
Show Gist options
  • Select an option

  • Save qinshulei/1e33991f727fe2238500 to your computer and use it in GitHub Desktop.

Select an option

Save qinshulei/1e33991f727fe2238500 to your computer and use it in GitHub Desktop.
open url through command line through xdotool to quick switch
#!/bin/bash
#: Title : open_doc.sh
#: Usage : open_doc.sh workflow
#: Synopsis : a tool for quick open doc
#: Date : 2015-02-13 11:23:04
#: Author : shulei
#: version : 1.0
#: Description : use xdotool to quick swith to a project relative url
#: Required : target => which target
#: Options : -i
#########################################################################################
# ---------------------- import lib -------------------------------------------------#
#########################################################################################
import() {
local __ORIGIN_PATH__="$PWD"
script_path="${0%/*}" # remove the script name ,get the path
script_path=${script_path/\./$(pwd)} # if path start with . , replace with $PWD
cd "${script_path}"
# import bsfl lib
source ./bsfl
cd "$__ORIGIN_PATH__"
}
import
#########################################################################################
# ---------------------- main function -------------------------------------------------#
#########################################################################################
main() {
cd_to_script_path
init_params "$@"
print_params
## start process
do_process
}
#####################################################################################
#-------------------------------logic function--------------------------------------#
#####################################################################################
show_usage() {
cat <<- _EOF_
A tool script for quick switch to the url site
Examples:
$ open_doc.sh workflow
_EOF_
exit 1
}
init_params() {
## init parameters
## constant and deault value
MESSAGE_ENABLED=no
items=()
target=
init_value_from_env
init_value_from_opts "$@"
## check the parameters
if is_null_or_empty target;then
if is_null_or_empty TARGET;then
show_usage
die 1 "must input the target!"
else
#use env target
target="${TARGET}"
fi
fi
}
init_value_from_env() {
## base on enviroment , set default items value .
is_true ITEM_ENABLED && items[${#items[*]}]=Item
}
init_value_from_opts() {
## parse command-line options
while getopts "hmi:" var
do
case $var in
m) MESSAGE_ENABLED=y
;;
h) show_usage
;;
i)
if contains ${items[*]} "${OPTARG}";then
option_enabled MESSAGE_ENABLED && printf "env has contains this items : %s \n" "${OPTARG}"
else
items[${#items[*]}]=${OPTARG}
fi
;;
esac
done
shift $(( OPTIND - 1 ))
target=${1}
}
print_params(){
option_enabled MESSAGE_ENABLED && printf "selected items : %s\n" "${items[*]}"
option_enabled MESSAGE_ENABLED && printf "target : %s\n" "${target}"
}
do_process(){
if [[ $target == "jelly" ]];then
open_site "http://commons.apache.org/proper/commons-jelly/tags.html"
elif [[ $target == "workflow" ]];then
open_site "https://github.com/jenkinsci/workflow-plugin"
elif [[ $target == "jira" ]];then
open_site "https://issues.jenkins-ci.org/"
elif [[ $target == "jexl" ]];then
open_site "http://commons.apache.org/proper/commons-jexl/reference/syntax.html"
elif [[ $target == "test" ]];then
open_site "http://192.168.65.49:8080/jenkins"
elif [[ $target == "prototype" ]];then
open_site "http://api.prototypejs.org/"
elif [[ $target == "yui" ]];then
open_site "http://yui.github.io/yui2/docs/yui_2.9.0_full/docs/"
elif [[ $target == "yui docs" ]];then
open_site "http://yui.github.io/yui2/docs/yui_2.9.0_full/"
elif [[ $target == "stapler" ]];then
open_site "http://stapler.kohsuke.org/jelly-taglib-ref.html"
elif [[ $target == "material" ]];then
open_site "http://fezvrasta.github.io/bootstrap-material-design/"
elif [[ $target == "element" ]];then
open_site "http://fezvrasta.github.io/bootstrap-material-design/bootstrap-elements.html"
elif [[ $target == "xstream" ]];then
open_site "http://xstream.codehaus.org/"
elif [[ $target == "hibernate" ]];then
open_site "http://hibernate.org/orm/documentation/"
elif [[ $target == "editor" ]];then
open_site "http://epiceditor.com/"
else
open_site "https://github.com/jenkinsci/workflow-plugin"
fi
}
#####################################################################################
#----------------------------common function ---------------------------------------#
#####################################################################################
cd_to_script_path() {
## Script path
script_path="${0%/*}" # remove the script name ,get the path
script_path=${script_path/\./$(pwd)} # if path start with . , replace with $PWD
cd "${script_path}"
}
function open_site(){
swap_to_chrome
open_wait_test_site $1
}
function swap_to_chrome(){
# swap to chrome
CHROME_PID=$( xdotool search --limit 1 --name "Google Chrome" )
xdotool windowactivate $CHROME_PID
xdotool sleep 1
}
function open_wait_test_site(){
## change foucs to fix the flash prevent all the keys
# the chrome left page location === x:88 y:485 screen:0 window:65011765
xdotool mousemove 88 485
xdotool click --clearmodifiers 1
xdotool sleep 1
# fill the location
xdotool key --clearmodifiers ctrl+t
xdotool sleep 1
xdotool type "$(printf $1)"
xdotool sleep 1
xdotool key --clearmodifiers --delay 100 "KP_Enter"
xdotool sleep 2
}
### ------------------------ start -----------------------------
__ORIGIN_PATH__="$PWD"
main "$@"
cd "$__ORIGIN_PATH__"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment