Skip to content

Instantly share code, notes, and snippets.

@rbobillot
Last active July 20, 2017 12:57
Show Gist options
  • Save rbobillot/8c2d1a2f0f50e078eceaba81e548b77a to your computer and use it in GitHub Desktop.
Save rbobillot/8c2d1a2f0f50e078eceaba81e548b77a to your computer and use it in GitHub Desktop.
#!/bin/bash
function show_usage {
echo "
This is a small script to change default IntelliJ's desktop binary
"
echo -e " usage: \033[92mbash $0 \033[93mpath/to/idea\033[0m\n"
}
function find_candidates {
echo -en " looking for candidates..."
candidates=$(
for i in `find / -name idea.sh 2> /dev/null`
do
echo -en "\033[93m$(dirname `dirname $i`)\033[0m "
done
)
echo -e "\033[2K\r candidates:"
for i in `echo $candidates | tr ' ' '\n' | sort` ; do echo " $i" ; done
echo
}
function replace_idea_home_in_shrc {
idea_home=$1
for shrc in `find $HOME \( -iname '.*shrc' -or -iname '.profile' \)`
do
replace=`printf "$idea_home" | awk '{gsub("/","\/",$1);print $1}'`
sed -i "s/[/a-zA-Z]*idea-I[CU]-[0-9.]*/$replace/g" $shrc
done
}
function replace_idea_home_in_desktop {
idea_home=$1
desk_conf=$2
if [[ ! -f $desk_conf ]]
then
echo -e "\e[91mError\e[0m: $desk_conf: not found\n"
echo "Here are the available conf file(s) you can modify: (put them in this script)"
for i in `ls $(dirname $desk_conf)/*.desktop`; do echo " $i"; done
else
replace=`printf "$idea_home" | awk '{gsub("/","\/",$1);print $1}'`
sed -i "s/[/a-zA-Z]*idea-I[CU]-[0-9.]*/$replace/g" $desk_conf &&
echo -e "\e[92mDone\e[0m !" ||
echo -e "\e[91mUnknown Error\e[0m !"
fi
}
function change_defaut_intellij {
candidate=$1
if [[ -z $candidate || ! -d $candidate || ! $candidate =~ "idea" ]]
then
show_usage
find_candidates
else
idea_home="`dirname $candidate`/`basename $candidate`"
desk_conf="${HOME}/.local/share/applications/jetbrains-idea.desktop"
replace_idea_home_in_shrc $1
replace_idea_home_in_desktop $idea_home $desk_conf
fi
}
change_defaut_intellij $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment