dotfiles/fake_home/.rofi-list-git-repos.sh

54 lines
1.2 KiB
Bash
Raw Normal View History

2023-02-18 17:52:24 -05:00
#!/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 file_exists() {
project="$1"
file="$2"
files=($project/$file)
if [ -e "${files[0]}" ]; then
return 0
else
return 1
fi
}
function open_project() {
project="$1"
if file_exists "$project" "pom.xml"; then
open_app "idea" "$project"
elif file_exists "$project" "package.json"; then
open_app "webstorm" "$project"
elif file_exists "$project" "cargo.toml" || file_exists "$project" "*.c"; then
open_app "clion" "$project"
elif file_exists "$project" "*.csproj"; then
open_app "rider" "$project"
elif file_exists "$project" "*.py"; then
open_app "pycharm" "$project"
elif file_exists "$project" "*.go"; then
open_app "goland" "$project"
else
open_app "idea" "$project"
fi
}
if [[ "$1" == "" ]]; then
for dir in $(echo ${GIT_DIRS[*]}); do
if [ -e "$dir" ]; then
find $dir -maxdepth 1 -mindepth 1 -type d
fi
done
else
open_project "$1"
fi