Reputation: 150
How do you open a plain text file in the user's default text editor for terminal in a bash script? xdg-open will open the file in the default gui editor, is there an equivalent for terminal editors?
Upvotes: 1
Views: 1284
Reputation: 11220
If the system is properly configured, editor
should do the job.
For instance, on my debian system, editor is configured to use nano.
$ update-alternatives --display editor
editor - auto mode
link currently points to /bin/nano
/bin/nano - priority 40
slave editor.1.gz: /usr/share/man/man1/nano.1.gz
/usr/bin/emacs23 - priority 0
slave editor.1.gz: /usr/share/man/man1/emacs.emacs23.1.gz
/usr/bin/vim.basic - priority 30
slave editor.1.gz: /usr/share/man/man1/vim.1.gz
slave editor.fr.1.gz: /usr/share/man/fr/man1/vim.1.gz
slave editor.it.1.gz: /usr/share/man/it/man1/vim.1.gz
slave editor.pl.1.gz: /usr/share/man/pl/man1/vim.1.gz
slave editor.ru.1.gz: /usr/share/man/ru/man1/vim.1.gz
/usr/bin/vim.tiny - priority 10
slave editor.1.gz: /usr/share/man/man1/vim.1.gz
slave editor.fr.1.gz: /usr/share/man/fr/man1/vim.1.gz
slave editor.it.1.gz: /usr/share/man/it/man1/vim.1.gz
slave editor.pl.1.gz: /usr/share/man/pl/man1/vim.1.gz
slave editor.ru.1.gz: /usr/share/man/ru/man1/vim.1.gz
Current 'best' version is '/bin/nano'.
I was expecting it to use the environnement variable EDITOR, but obviously it's not the case, at least on Debian.
Upvotes: 3