#!/bin/sh - # written by Bruno F. Fontes, 2022-10-18 HELP=" Start all your environments CMD parameters available: -m, --menu, show a menu to choose your scripts [default] -a, --add, add a new starta script -r, --remove, remove the script -h, --help, shows this help " FOLDER="$HOME/.local/etc/starta" MENU=0 addScript() { [ -z $NAME ] && echo "No script name provided. Exiting..." && exit 1 mkdir -p "$FOLDER" SCRIPT="${FOLDER}/${NAME}" touch "$SCRIPT" chmod +x "$SCRIPT" echo "#!/bin/sh" >> "$SCRIPT" echo "" >> "$SCRIPT" echo "# Add your code here..." >> "$SCRIPT" $EDITOR "$SCRIPT" echo "Script installed! Type \"starta ${NAME}\" to start it" exit 0 } removeScript() { [ -z $NAME ] && echo "No script name provided. Exiting..." && exit 1 SCRIPT="${FOLDER}/${NAME}" if [ -f "$SCRIPT" ] then echo -n "Are you sure you want to delete the script '${NAME}' (y/N)? " read -r -s -n 1 echo if [ "$REPLY" = "y" ] then rm -- "$SCRIPT" && echo "Script '$SCRIPT' removed!" exit 0 fi echo "Operation aborted..." exit 1 fi echo "Script not found" exit 1 } listScripts() { list=$(command ls "$FOLDER" 2>/dev/null) || error=1 [ -z $list ] && error=1 if [ $error ] then echo "No scripts found! Add one with the '--add' option" exit 1 fi echo "$list" | less exit 0 } # argument handling if [ -z $1 ] then MENU=1 else case $1 in -a|--add) NAME="$2" addScript ;; -r|--remove) NAME="$2" removeScript exit 0 ;; -h|--help) echo -e "$HELP" exit 0 ;; -m|--menu) MENU=1 ;; -l|--list) listScripts ;; *) NAME="$1" ;; esac fi if [ $MENU ] then option=$($0 --list | zenity --list --text "Choose the script to start" --column "Scripts" --title "Starta" 2>/dev/null) [ -z $option ] && echo "No script selected. Aborting..." && exit 0 NAME="$option" fi SCRIPT="${FOLDER}/${NAME}" if [ -f "$SCRIPT" ] then "$SCRIPT" else echo "Script not found. Use the '--list' option to see the available scripts" exit 1 fi