[UPD] script open_terminal: support OSX

This commit is contained in:
Mathieu Benoit 2023-12-02 14:10:52 -05:00
parent 8632c1501d
commit addb636042

View file

@ -1,26 +1,47 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Open a new gnome-terminal with different path on new tab # Open a new gnome-terminal with different path on new tab
working_path=`readlink -f .` working_path=$(readlink -f .)
paths=( paths=(
"${working_path}/" "${working_path}/"
"${working_path}/addons/TechnoLibre_odoo-code-generator" # "${working_path}/addons/TechnoLibre_odoo-code-generator"
"${working_path}/addons/TechnoLibre_odoo-code-generator-template" # "${working_path}/addons/TechnoLibre_odoo-code-generator-template"
"${working_path}/addons/ERPLibre_erplibre_addons" "${working_path}/addons/ERPLibre_erplibre_addons"
"${working_path}/addons/OCA_server-tools" # "${working_path}/addons/OCA_server-tools"
) )
cmd_before="cd "
# when change directory, open a new tab with command to execute
cmd_after=";gnome-terminal --tab -- bash -c 'git status;bash';"
#cmd_after=";gnome-terminal --tab;"
LONGCMD="" first_iteration=true
for t in "${paths[@]}"; do if [[ "${OSTYPE}" == "linux-gnu" ]]; then
LONGCMD+=${cmd_before}${t}${cmd_after} cmd_before="cd "
done cmd_after_first=";gnome-terminal --tab -- bash -c 'source ./.venv/bin/activate;git status;bash';"
cmd_after=";gnome-terminal --tab -- bash -c 'git status;bash';"
LONGCMD=""
for t in "${paths[@]}"; do
if $first_iteration; then
LONGCMD+="${cmd_before}${t}${cmd_after_first}"
first_iteration=false
else
LONGCMD+="${cmd_before}${t}${cmd_after}"
fi
done
gnome-terminal --window -- bash -c "${LONGCMD}"
elif [[ "${OSTYPE}" == "darwin"* ]]; then
paths=("${paths[@]:1}")
#echo $LONGCMD # Initialisation de la commande osascript
osascript_command="osascript -e 'tell application \"Terminal\"'"
# Open all terminal from paths list # Boucle pour ajouter des commandes pour ouvrir de nouveaux onglets et exécuter les scripts batch
#echo "gnome-terminal --window -- bash -c \"${LONGCMD}\"" for t in "${paths[@]}"; do
gnome-terminal --window -- bash -c "${LONGCMD}" if $first_iteration; then
osascript_command+=" -e 'tell application \"System Events\" to keystroke \"t\" using {command down}' -e 'delay 0.1' -e 'do script \"cd ${t}; source ./.venv/bin/activate; git status\" in front window'"
first_iteration=false
else
osascript_command+=" -e 'tell application \"System Events\" to keystroke \"t\" using {command down}' -e 'delay 0.1' -e 'do script \"cd ${t}; git status\" in front window'"
fi
done
osascript_command+=" -e 'end tell'"
# Exécution de la commande osascript
eval "$osascript_command"
fi