How to write commands with default variables for terminal or default app (Browser, Terminal) so it would work on any Ubuntu or Debian?
For example Ubuntu mate has mate-terminal How to write commands that would open in each distro with befault terminal and browser? So in this command line wouldnt be mate-terminal and firefox but some wrapper of them for any distro user default apps of terminal or browser.
mate-terminal -- bash -c 'sleep 2; dpkg -S "\/bin/$(xprop WM_CLASS | cut -d "\"" -f2)"; sleep 5; firefox'how to find default app variables or wrappers so that command would be running in any distro terminal apps? How to find also default browser or text editor variables?
23 Answers
If you need to run the same command on multiple platforms / distributions there is a workaround which involves writing customized copies of the same command and separating them with the || operator which will try to execute the next command if the first command fails.
Example
Command for mate-terminal:
mate-terminal -- bash -c 'sleep 2; echo "hi"; sleep 5; firefox'Command for gnome-terminal:
gnome-terminal -- bash -c 'sleep 2; echo "hi"; sleep 5; firefox'Command that will run on either terminal:
mate-terminal -- bash -c 'sleep 2; echo "hi"; sleep 5; firefox' || gnome-terminal -- bash -c 'sleep 2; echo "hi"; sleep 5; firefox'Command that will run on either terminal and launch either firefox, google-chrome or chromium:
mate-terminal -- bash -c 'sleep 2; echo "hi"; sleep 5; firefox || google-chrome || chromium' || gnome-terminal -- bash -c 'sleep 2; echo "hi"; sleep 5; firefox || google-chrome || chromium'This will however require looking into target platforms to find out how to correctly run the command.
Best of luck
2I do not know much about how different distribution set their preferred apps for web browser and terminal emulator, but I do for Xfce desktop environment. Maybe you can do the same with other DEs, if you install exo-utils package.
The preferred applications would be set by running
exo-preferred-applicationsand your example command (purpose of which is unknown to me) would be formulated like this:
exo-open --launch TerminalEmulator bash -c 'sleep 2; dpkg -S "\/bin/$(xprop WM_CLASS | cut -d "\"" -f2)"; sleep 5; exo-open --launch WebBrowser; read'read is needed because the web browser might close with the terminal window.
Here is rewrite of your command using Debian's alternatives system:
x-terminal-emulator -e bash -c 'sleep 2; dpkg -S "\/bin/$(xprop WM_CLASS | cut -d "\"" -f2)"; sleep 5; x-www-browser'Note the use of -e for the command the terminal emulator should run.
If you would like to change the default terminal emulator you would run
sudo update-alternatives --config x-terminal-emulatorRespectively, to change the default web browser you would run
sudo update-alternatives --config x-www-browser 2