feat: add create new project to project menu
This commit is contained in:
@@ -2,26 +2,72 @@
|
|||||||
|
|
||||||
projects=$(find ~/src -maxdepth 1 -type d -not -path ~/src | xargs -I {} basename {})
|
projects=$(find ~/src -maxdepth 1 -type d -not -path ~/src | xargs -I {} basename {})
|
||||||
projects="$projects"$'\n'"dotfiles"
|
projects="$projects"$'\n'"dotfiles"
|
||||||
|
projects="$projects"$'\n'"new"
|
||||||
|
|
||||||
selected=$(echo "$projects" | rofi -dmenu -p "Select project:")
|
selected=$(echo "$projects" | rofi -dmenu -p "Select project:")
|
||||||
|
|
||||||
if [[ -n "$selected" ]]; then
|
create_new_project() {
|
||||||
if [[ "$selected" == "dotfiles" ]]; then
|
local project_name
|
||||||
project_path="$HOME/dotfiles"
|
project_name=$(rofi -dmenu -p "Enter new project name:")
|
||||||
else
|
|
||||||
project_path="$HOME/src/$selected"
|
if [[ -z "$project_name" ]]; then
|
||||||
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local project_path="$HOME/src/$project_name"
|
||||||
|
|
||||||
if [[ -d "$project_path" ]]; then
|
if [[ -d "$project_path" ]]; then
|
||||||
ghostty --working-directory="$project_path" -e bash -c "
|
notify-send "Error" "Project $project_name already exists"
|
||||||
# Check if tmux session already exists
|
return
|
||||||
if tmux has-session -t '$selected' 2>/dev/null; then
|
|
||||||
tmux attach-session -t '$selected'
|
|
||||||
else
|
|
||||||
tmux new-session -s '$selected' -c '$project_path'
|
|
||||||
fi
|
|
||||||
"
|
|
||||||
else
|
|
||||||
notify-send "Error" "Project directory $project_path does not exist"
|
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
mkdir -p "$project_path"
|
||||||
|
cd "$project_path"
|
||||||
|
notify-send "Success" "Created new project: $project_name"
|
||||||
|
|
||||||
|
ghostty --working-directory="$project_path" -e bash -c "
|
||||||
|
open_project() {
|
||||||
|
local name=\"\$1\"
|
||||||
|
local path=\"\$2\"
|
||||||
|
if tmux has-session -t \"\$name\" 2>/dev/null; then
|
||||||
|
tmux attach-session -t \"\$name\"
|
||||||
|
else
|
||||||
|
tmux new-session -s \"\$name\" -c \"\$path\"
|
||||||
|
fi
|
||||||
|
}; open_project '$project_name' '$project_path'"
|
||||||
|
}
|
||||||
|
|
||||||
|
open_existing_project() {
|
||||||
|
local name="$1"
|
||||||
|
local path="$2"
|
||||||
|
|
||||||
|
if [[ ! -d "$path" ]]; then
|
||||||
|
notify-send "Error" "Project directory $path does not exist"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
ghostty --working-directory="$path" -e bash -c "
|
||||||
|
open_project() {
|
||||||
|
local name=\"\$1\"
|
||||||
|
local path=\"\$2\"
|
||||||
|
if tmux has-session -t \"\$name\" 2>/dev/null; then
|
||||||
|
tmux attach-session -t \"\$name\"
|
||||||
|
else
|
||||||
|
tmux new-session -s \"\$name\" -c \"\$path\"
|
||||||
|
fi
|
||||||
|
}; open_project '$name' '$path'"
|
||||||
|
}
|
||||||
|
|
||||||
|
[[ -z "$selected" ]] && exit 0
|
||||||
|
|
||||||
|
case "$selected" in
|
||||||
|
"new")
|
||||||
|
create_new_project
|
||||||
|
;;
|
||||||
|
"dotfiles")
|
||||||
|
open_existing_project "$selected" "$HOME/dotfiles"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
open_existing_project "$selected" "$HOME/src/$selected"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|||||||
Reference in New Issue
Block a user