#!/bin/bash GIT_DIRS=("$HOME/work" "$HOME/projects" "$HOME/git" "$HOME/WebStormProjects" "$HOME/RiderProjects") function open_app() { application="$1" project="$2" exe=$(grep "Exec" "$HOME/.local/share/applications/jetbrains-$application.desktop" | sed 's/.*"\([^"]*\)".*/\1/') $exe "$project" &> /dev/null & } function get_icon { application=$1 grep "Icon" "$HOME/.local/share/applications/jetbrains-$application.desktop" | sed 's/Icon=//' } function file_exists() { project="$1" file="$2" files=($project/$file) if [ -e "${files[0]}" ]; then return 0 else return 1 fi } function get_project_type() { project="$1" if file_exists "$project" "pom.xml"; then echo "idea" elif file_exists "$project" "package.json"; then echo "webstorm" elif file_exists "$project" "cargo.toml" || file_exists "$project" "*.c"; then echo "clion" elif file_exists "$project" "*.csproj"; then echo "rider" elif file_exists "$project" "*.py"; then echo "pycharm" elif file_exists "$project" "*.go"; then echo "goland" else echo "idea" fi } if [[ "$1" == "" ]]; then for dir in $(echo ${GIT_DIRS[*]}); do if [ -e "$dir" ]; then projects=$(find $dir -maxdepth 1 -mindepth 1 -type d) for project in $projects; do echo -en "$project\0icon\x1f$(get_icon "$(get_project_type "$project")")\n" done fi done else open_app "$(get_project_type "$1")" "$1" fi