Add proj launcher script

This commit is contained in:
Taryel Hlontsi 2025-01-26 19:20:45 +01:00
parent b2293be2da
commit 2ade8fc386
1 changed files with 110 additions and 0 deletions

110
proj-launcher.sh Executable file
View File

@ -0,0 +1,110 @@
#!/usr/bin/env bash
#############################################################
# Author: Taryel Hlontsi, 2025
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>
#############################################################
doc=$(cat <<'EOF'
NOTES:
This will create a desktop entry and a simlink to the executable
in user's home directory.
It will allow to add the launcher to the bar
EOF
)
#############################################################
# SETUP SECTION
#############################################################
set -e
set -o pipefail
#############################################################
# HELPER FUNCTIONS
#############################################################
info() {
GREEN='\033[1;32m'
NC='\033[0m'
echo -e "${GREEN}${1}${NC}"
}
trace() {
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${YELLOW}${1}${NC}"
}
warn() {
PURPLE='\033[1;35m'
NC='\033[0m'
echo -e "${PURPLE}${1}${NC}"
}
error() {
RED='\033[1;31m'
NC='\033[0m'
echo -e "${RED}${1}${NC}"
}
#############################################################
# RUN SECTION
#############################################################
echo $(date +'%Y-%m-%d %H:%M')
info "$doc"
user=$(whoami)
if [ $user == root ]; then
error "You should NOT be using a root account"
exit 1
fi
read -p "The app name [default: My App]: " name
name=${name:-My App}
read -p "Executable name [default: emacs]: " exe
exe=${exe:-emacs}
read -p "New executable name [default: emacs-my-app]: " new_exe
new_exe=${new_exe:-emacs-my-app}
read -p "Icon file path or name [default: help-browser]: " icon
icon=${icon:-help-browser}
read -p "Project path to open: " proj
info 'Adding desktop entry'
cat <<EOF | tee $HOME/.local/share/applications/$new_exe.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name=$name
Icon=$icon
Exec=$new_exe $proj
Comment=Open $name in $exe
Categories=Development;TextEditor;
Terminal=false
StartupWMClass=$new_exe
StartupNotify=true
EOF
info "Adding a link to $exe"
ln -sf $(which $exe) $HOME/.local/bin/$new_exe
info "Updating desktop database"
update-desktop-database
info "Bye!"
exit 0