Last active
April 30, 2019 16:44
-
-
Save AkshayRaj/8bc39e45a8df23283c47cbd81dc9e100 to your computer and use it in GitHub Desktop.
Utility Bash Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#### color codes | |
RESTORE=$(echo -en '\033[0m') | |
RED=$(echo -en '\033[00;31m') | |
GREEN=$(echo -en '\033[00;32m') | |
YELLOW=$(echo -en '\033[00;33m') | |
BLUE=$(echo -en '\033[00;34m') | |
MAGENTA=$(echo -en '\033[00;35m') | |
PURPLE=$(echo -en '\033[00;35m') | |
CYAN=$(echo -en '\033[00;36m') | |
LIGHTGRAY=$(echo -en '\033[00;37m') | |
LRED=$(echo -en '\033[01;31m') | |
LGREEN=$(echo -en '\033[01;32m') | |
LYELLOW=$(echo -en '\033[01;33m') | |
LBLUE=$(echo -en '\033[01;34m') | |
LMAGENTA=$(echo -en '\033[01;35m') | |
LPURPLE=$(echo -en '\033[01;35m') | |
LCYAN=$(echo -en '\033[01;36m') | |
WHITE=$(echo -en '\033[01;37m') | |
# Test | |
#echo ${RED}RED${GREEN}GREEN${YELLOW}YELLOW${BLUE}BLUE${PURPLE}PURPLE${CYAN}CYAN${WHITE}WHITE${RESTORE} | |
ARG=123 | |
function foo{ | |
args | |
:string test | |
echo ${test} | |
} | |
echo "$(foo) ${ARG}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### sync origin with upstream #### | |
function syncFork() { | |
if [ -z "$(git status --porcelain)" ]; then | |
# Working directory clean | |
currentBranch=$(git symbolic-ref --short -q HEAD) | |
checkoutMaster | |
if [ $currentBranch != "master" ] | |
then | |
git checkout $currentBranch | |
fi | |
else | |
# Uncommitted changes | |
echo -e "\033[31m[ERROR] - Unstaged changes in directory. Please commit or stash them and continue with syncing.\033[m" | |
git status | |
fi | |
} | |
#### rebase current branch with latest changes from upstream #### | |
function rebaseThis() { | |
syncFork && git rebase master | |
} | |
#### checkout master branch with latest changes from upstream #### | |
function checkoutMaster() { | |
if [ -z "$(git status --porcelain)" ]; then | |
# Working directory clean | |
currentBranch=$(git symbolic-ref --short -q HEAD) | |
if [ -z "$currentBranch" ] || [ $currentBranch != "master" ]; then | |
echo "[\033[34mINFO\033[m] - Checking out master.." | |
git checkout master | |
fi | |
echo "[\033[34mINFO\033[m] - Pulling upstream and updating origin.." | |
git pull upstream master:master && git push origin master | |
else | |
# Uncommitted changes | |
echo -e "\033[31m[ERROR] - Unstaged changes in directory. Please commit or stash them before checking out master.\033[m" | |
git status | |
fi | |
} | |
#### create commit with unstaged changes and open an interactive shell #### | |
function createSquashCommit() { | |
git add . | |
git commit -am"SQUASH-ME" && git rebase -i HEAD~2 | |
} | |
## https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux | |
## Use this template - [\033[34mREPLACE-ME\033[m] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# WF 2018-07-12 | |
# find out the class versions with in jar file | |
# see https://stackoverflow.com/questions/3313532/what-version-of-javac-built-my-jar | |
# uncomment do debug | |
# set -x | |
#ansi colors | |
#http://www.csc.uvic.ca/~sae/seng265/fall04/tips/s265s047-tips/bash-using-colors.html | |
blue='\033[0;34m' | |
red='\033[0;31m' | |
green='\033[0;32m' # '\e[1;32m' is too bright for white bg. | |
endColor='\033[0m' | |
# | |
# a colored message | |
# params: | |
# 1: l_color - the color of the message | |
# 2: l_msg - the message to display | |
# | |
color_msg() { | |
local l_color="$1" | |
local l_msg="$2" | |
echo -e "${l_color}$l_msg${endColor}" | |
} | |
# | |
# error | |
# | |
# show an error message and exit | |
# | |
# params: | |
# 1: l_msg - the message to display | |
error() { | |
local l_msg="$1" | |
# use ansi red for error | |
color_msg $red "Error: $l_msg" 1>&2 | |
exit 1 | |
} | |
# | |
# show the usage | |
# | |
usage() { | |
echo "usage: $0 jarfile" | |
# -h|--help|usage|show this usage | |
echo " -h|--help: show this usage" | |
exit 1 | |
} | |
# | |
# showclassversions | |
# | |
showclassversions() { | |
local l_jar="$1" | |
jar -tf "$l_jar" | grep '.class' | while read classname | |
do | |
class=$(echo $classname | sed -e 's/\.class$//') | |
class_version=$(javap -classpath "$l_jar" -verbose $class | grep 'major version' | cut -f2 -d ":" | cut -c2-) | |
class_pretty=$(echo $class | sed -e 's#/#.#g') | |
case $class_version in | |
45.3) java_version="java 1.1";; | |
46) java_version="java 1.2";; | |
47) java_version="java 1.3";; | |
48) java_version="java 1.4";; | |
49) java_version="java5";; | |
50) java_version="java6";; | |
51) java_version="java7";; | |
52) java_version="java8";; | |
53) java_version="java9";; | |
54) java_version="java10";; | |
*) java_version="x${class_version}x";; | |
esac | |
echo $java_version $class_pretty | |
done | |
} | |
# check the number of parameters | |
if [ $# -lt 1 ] | |
then | |
usage | |
fi | |
# start of script | |
# check arguments | |
while test $# -gt 0 | |
do | |
case $1 in | |
# -h|--help|usage|show this usage | |
-h|--help) | |
usage | |
exit 1 | |
;; | |
*) | |
showclassversions "$1" | |
esac | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment