Skip to content

Instantly share code, notes, and snippets.

@andrewcchen
Last active August 29, 2015 14:18
Show Gist options
  • Save andrewcchen/35ec0cf93954d28de86a to your computer and use it in GitHub Desktop.
Save andrewcchen/35ec0cf93954d28de86a to your computer and use it in GitHub Desktop.
A Multi-Configuration Launcher for Eclipse
#!/bin/bash
# A Multi-Configuration Launcher for Eclipse
array_contains () {
local array="$1[@]"
local seeking=$2
local in=1
for element in "${!array}"; do
if [[ $element == $seeking ]]; then
in=0
break
fi
done
return $in
}
array_remove () {
local array="$1"
local seeking=$2
local index=1
for element in $(eval echo \${$array[@]}); do
if [[ $element == $seeking ]]; then
unset $array[$index]
fi
((index++))
done
}
is_an_eclipse_dir() {
local path=$1
if [[ $path = /* || $path =~ ^\. || ! -d $path || -e $path/.noeclipse ]]; then
return 1
else
return 0
fi
}
valid_dirs=('')
while IFS= read -r -u3 -d $'\0' dir; do
dir=${dir%%/}
dir=${dir##./}
is_an_eclipse_dir $dir
if [ $? -eq 0 ]; then
valid_dirs+=($dir)
fi
done 3< <(find -mindepth 1 -maxdepth 1 -type d -print0)
choice=""
if [ $# -eq 0 ]; then
if [ -f .eclipse_launcher_last_choice ]; then
last=$(cat .eclipse_launcher_last_choice)
array_contains valid_dirs $last
if [ $? -eq 0 ]; then
array_remove valid_dirs $last
valid_dirs[0]=$last
fi
fi
while [[ -z $choice ]]; do
choice=$(zenity --entry \
--title "Eclipse Launcher" \
--text "Select a configuration." \
--entry-text "${valid_dirs[@]}")
if [ $? -eq 1 ]; then
exit 1
fi
is_an_eclipse_dir $choice
if [ $? -eq 1 ]; then
if [[ -z $choice || $choice =~ ^\. || -e $choice ]]; then
zenity --error \
--text "\"$choice\" is invalid"
choice=""
else
zenity --question \
--text "\"$choice\" does not exist, do you want to create it now?"
if [ $? -eq 1 ]; then
choice=""
fi
fi
fi
done
echo "$choice" > .eclipse_launcher_last_choice
else
choice="$1"
fi
echo "Launching Eclipse..."
eclipse \
-configuration "$choice/configuration" \
-data "$choice/workspace"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment