Bash script to open or close gnome-terminal with a single keybinding
Instead of this:


function terminal_process {
  # Is gnome-terminal already running
  echo $( ps aux | grep $TERMINAL_EMULATOR | grep -v grep)
}



You don't need the echo, you can let the standard output simply go through:

terminal_process() {
  # Is gnome-terminal already running
  ps aux | grep $TERMINAL_EMULATOR | grep -v grep
}


The same goes for get_terminal_window too.

Notice that I also changed the wording style of the function definition. This is the recommended style in bash,
I suggest to apply this to all your functions.



You can actually go even further. [[ -z $(terminal_process) ]] is actually a text comparison, checking if the output of the command as a string is empty. Instead of that, it would be better to use the exit code of the function, like this:

if ! terminal_process; then
    # ...


This works, because the exit of grep will be success (= 0) if it matched something (process exists), and failure (non-zero) if it didn't match.

However, when using the function like this, since the output of grep is not captured within a $(...), it will be printed on stdout, which you probably want to avoid. You can easily suppress that by adding the -q flag:

terminal_process() {
  # Is gnome-terminal already running
  ps aux | grep $TERMINAL_EMULATOR | grep -qv grep
}




This can also be simplified:


echo $(($width_percent*$1/100)) $(($height_percent*$2/100))



Like this:

echo $((width_percent * $1 / 100)) $((height_percent * $2 / 100))