Is there a good way to test whether I am logging into a text shell or starting a GUI session in my .bashrc? For example, to set my editor to gedit if in gnome and emacs if using a command line.
+9
A:
Your DISPLAY
variable will be set if you're logged in to an X session.
Edit: So, this (untested) code should work:
[ -n "${DISPLAY}" ] && export EDITOR=gedit || export EDITOR=emacs
Fixed based on comments.
eduffy
2009-09-15 00:29:18
Actually, you need to either leave off the -z or swap the editors.
Dennis Williamson
2009-09-15 00:54:04
Replacing -z with -n would also work.
Michael E
2009-09-15 14:36:15
Whoops .. thanks.
eduffy
2009-09-16 03:15:50
FYI. [ is actually a command. If you're using bash, the preferred method is [[.
Jeremy Cantrell
2009-09-28 18:32:53
+2
A:
Using bash conventions:
if [[ $DISPLAY ]]; then
export EDITOR=gedit
else
export EDITOR=emacs
fi
Jeremy Cantrell
2009-09-15 14:31:02