Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
149 lines (124 sloc) 3.69 KB
## Open man page as PDF
pman () { man -t "${1}" | open -f -a "Preview"; }
# traverse the directory hierarchy up until finds a gradlew file and executes
# it with arguments supplied by user
gdw() {
_GDW_DIR=$(pwd)
while [ "$_GDW_DIR" != "/" ]; do
if [ -f "$_GDW_DIR/gradlew" ]; then
_GDW_EXEC="$_GDW_DIR/gradlew --stacktrace"
if [ -f $_GDW_DIR/init.gradle ]; then
_GDW_EXEC="$_GDW_EXEC -I $_GDW_DIR/init.gradle"
fi
$_GDW_EXEC "$@"
return $?
break;
fi
_GDW_DIR=$(dirname $_GDW_DIR)
echo $_GDW_DIR
done
}
## initialize maven wrapper
mvnwinit() {
if [ $# -eq 0 ]
then
mvn -N io.takari:maven:wrapper
else
mvn -N io.takari:maven:wrapper -Dmaven=$1
fi
}
mvnw() {
if [[ $1 == "init" ]]
then
mvnwinit $2
elif [[ -f mvnw ]]
then
./mvnw "$@"
return $?
else echo "No maven wrapper available for this project! Run mvnw init first."
fi
}
## Resets SVN working copy, reverting all changed files and removing all unversioned files. Usage: svn reset
svn() {
if [[ $@ == "reset" ]];
then
command svn revert --recursive . && svn status | grep ^\? | cut -c9- | xargs rm -r;
else command svn "$@";
fi;
}
## Show the location of a linked program
ref() { readlink $(which "${1}"); }
## Switching between different Java versions
usejava() {
if [ $# -eq 0 ]
then
echo "JAVA_HOME: $JAVA_HOME"
else
OLD_JAVA_HOME=$JAVA_HOME
if [[ $1 < 9 ]]
then
NEW_JAVA_HOME=`/usr/libexec/java_home -v 1.$1`
else
NEW_JAVA_HOME=`/usr/libexec/java_home -v $1`
fi
if [[ $? == 0 ]]
then
echo "Setting JAVA_HOME to: $NEW_JAVA_HOME"
export JAVA_HOME=$NEW_JAVA_HOME
export PATH=${PATH//$OLD_JAVA_HOME/$NEW_JAVA_HOME}
else echo "Java 1.$1 is not available! JAVA_HOME: $JAVA_HOME"
fi
fi
}
## Output MANIFEST for the given jar
manifest() { unzip -q -c "${1}" META-INF/MANIFEST.MF; }
## Output LINCENSE file for the given jar
license() { unzip -q -c "${1}" META-INF/LICENSE.txt; }
## Get svn keywords
gkw() { svn pg svn:keywords ${1}; }
## Set svn keywords
skw() { svn ps svn:keywords "Date Author Id Revision HeadURL" ${1}; }
## auto detect git ignore
## requires bash 4!
## Note that bash 4 has to be defined as login shell. On Mac OS this has to be
## done via System preferences > Users > right click our profil picture > extended options
gitignore() {
declare -A files
files["pom.xml"]=maven
files["build.gradle"]=gradle
files["build.sbt"]=sbt
files["Cargo.toml"]=rust
for file in "${!files[@]}"
do
if [[ -f $file ]]
then
echo "Adding $file files to .gitignore."
gibo ${files[$file]} >> .gitignore
fi
done
}
# Create a README.md file for the current directory
readme() {
project_name=$(basename $PWD)
cat > README.md << EOF
# $project_name
Welcome to $project_name!
## Contribution policy
Contributions via GitHub pull requests are gladly accepted from their original author. Along with any pull requests, please state that the contribution is your original work and that you license the work to the project under the project's open source license. Whether or not you state this explicitly, by submitting any copyrighted material via pull request, email, or other means you agree to license the material under the project's open source license and warrant that you have the legal authority to do so.
## License
This code is open source software licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0.html).
EOF
}
## Push current git project to github
githubinit() {
hub create $(basename $PWD)
git push -u origin master
}
## Initialize a new project
projectinit () {
alv2
gitignore
readme
git this
githubinit
}