linux to edit files, the commonly used ones are vi/vim, emacs, and also gedit -- of course, everyone has their own preferences.

emacs, vi and the like are naturally used in the console, nice and clean.

But when it comes to gedit, because it uses an X display, the console gets flooded with all kinds of warning.

Since we're writing code, we often navigate to some directory in the shell, then open a file with a single vi/emacs/gedit command and start editing.

Without plugins, gedit is actually quite clean. Once plugins get involved, all sorts of errors and warnings pop up unexpectedly. Especially those damned environment parameters -- ignore doesn't do much, and unless you specifically deal with them, who cares. But if you don't tweak it,

Bash
$ gedit xxx.c

Then a flood of warnings follows. Really annoying.

Solution:

1. Write a bash script to open gedit in the background

Create a new file named edit or whatever.
Content:
Bash
#!/bin/sh
nohup  gedit ${1+"$@"}  >/dev/null 2>&1

Explanation: i) nohup, opens in the background ii) >/dev/null 2>&1 redirects both output and error messages to the void (/dev/null) iii) {1+"@"} the arguments you pass For example, if you type

Bash
$ edit -a -b -c -d
it is equivalent to
Bash
$ nohup gedit -a -b -c -d  >/dev/null 2>&1

Make It Executable
Bash
$ chmod +x edit

Then move it to /usr/bin, ~/bin, or wherever you like, as long as the directory is in your PATH.

From now on, whenever you want to edit something, just run

Bash
edit file_name

and you're done. It works exactly like gedit, only without error messages.

2. alias

Edit `.bash_profile` or `.bashrc`
Add the following command:
Bash
alias gedit='gedit -b'
Log Out and Back In
Now your `gedit` command will carry the `-b` option by default.

The meaning of -b, according to its built-in usage:

  -b, --background                  Run gedit in the background

Compared to option 1, the upside of option 2 is that you don't have to change the command you type. The downside is that your gedit always comes with -b attached, and if you ever want to get rid of it, you'll have to remove the alias and log out and back in. Not very convenient.

Compared to option 2, option 1 is more universal. gedit can be wrapped this way, and so can any other program — though if you do the same with console programs, all the prompts and messages disappear.

Back to coding...