You are not logged in.

#1 2016-12-24 20:54:23

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Using command-line text-editors as bl-text-editor

The bl-text-editor alternative offers the chance for BunsenLabs users to unify their $EDITOR [1] configuration to a single location.

For more on this system, see:

Openbox Main Menu → Help → Bunsen Help Files → About Bunsen Alternatives

The standard option is set to geany and can be changed with:

Openbox Main Menu → System → Edit Debian Alternatives

Unfortunately, this method does not work if a command line editor (such as nano or ed) is preferred sad

Instead, a wrapper script must be used to start a terminal with the editor running inside it.

First, create the wrapper "script" (it's just one line really):

sudo tee /usr/local/bin/bl-cli-editor <<'!'
x-terminal-emulator -T "BunsenLabs Text Editor" -e editor "$@"
!
sudo chmod +x /usr/local/bin/bl-cli-editor

The "$@" bit passes all arguments (such as the name of the file to be edited) to /etc/alternatives/editor and allows the thunar right-click shortcuts to work properly.

Then add the script as a bl-text-editor alternative:

sudo update-alternatives --install /usr/bin/bl-text-editor bl-text-editor /usr/local/bin/bl-cli-editor 50

This should auto-select the bl-cli-editor wrapper unless other, higher-priority, alternatives have been installed; if that is the case, force the setting with:

sudo update-alternatives --set bl-text-editor /usr/local/bin/bl-cli-editor

The GUI could be used instead to add the new option:

Openbox Main Menu → System → Edit Debian Alternatives

Then select bl-text-editor and click on the Add button and browse to /usr/local/bin/bl-cli-editor

Finally, to set the actual program that is to be used for /etc/alternatives/editor, run:

sudo update-alternatives --config editor

Now enjoy a real editor for your BunsenLabs alternative glasses

[1] well, $VISUAL, to be specific.

Last edited by Head_on_a_Stick (2016-12-29 19:43:41)


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#2 2016-12-24 21:15:39

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: Using command-line text-editors as bl-text-editor

Note

The above method describes a system-wide configuration, for user-level settings simply place the bl-cli-editor wrapper script at ~/bin/bl-text-editor instead (ie, re-name the file).

Last edited by Head_on_a_Stick (2016-12-25 20:25:18)


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#3 2016-12-25 03:34:46

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,111
Website

Re: Using command-line text-editors as bl-text-editor

Nice idea!
I wondered whether your script needed a header or not.

Head_on_a_Stick wrote:
sudo tee /usr/local/bin/viminator <<'!'
x-terminal-emulator -e vim "$@"
!
sudo chmod +x /usr/local/bin/viminator

I guess without a #!/bin/sh (or /bin/zsh or whatever) it will revert to the user's default shell? ( ie bash in most cases ) Or maybe the system default, sh?


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#4 2016-12-25 11:33:02

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: Using command-line text-editors as bl-text-editor

johnraff wrote:

I wondered whether your script needed a header or not.

As I understood it, an executable file doesn't need a shebang but I'm probably subtly wrong about that big_smile

I guess without a #!/bin/sh (or /bin/zsh or whatever) it will revert to the user's default shell? ( ie bash in most cases ) Or maybe the system default, sh?

I think that it is executed from the user's login shell, as listed in /etc/passwd.

I just tried

echo $0 > shell.txt

in demenu in my OpenBSD system and:

Puffy: ~ $ cat shell.txt              
/bin/ksh

which is my login shell (but also my interactive shell so this is not conclusive).


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#5 2016-12-25 11:58:43

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: Using command-line text-editors as bl-text-editor

Thinking about this, it may be better to specify /etc/alternatives/editor rather than vim itself and unify the configuration within the alternatives paradigm:

x-terminal-emulator -e editor "$@"

The desired terminal-based editor ($VISUAL) could then be changed with:

sudo update-alternatives --config editor

This is also the (default) editor that is used by `apt edit-sources`, `visudo`, `vipw`, et al smile

I will check if this actually works later...

EDIT: yes, it works perfectly, I will update the OP.

Last edited by Head_on_a_Stick (2016-12-25 15:54:49)


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#6 2016-12-26 03:10:23

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,111
Website

Re: Using command-line text-editors as bl-text-editor

Super neat!


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#7 2016-12-27 01:48:05

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,111
Website

Re: Using command-line text-editors as bl-text-editor

Maybe we could put this into bunsen-configs so bl-cli-editor shows in the alternatives list by default? (Give it a lower priority than Geany though.)
If we add a bl-cli-editor.desktop in /usr/share/applications with appropriate mime-type settings, then file-managers and the like will offer it in the "open with" context menus even if it isn't the bl-text-editor alternative. cool


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#8 2016-12-27 01:54:21

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: Using command-line text-editors as bl-text-editor

^ Yes, that sounds great, good ideas smile


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#9 2016-12-29 19:42:22

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: Using command-line text-editors as bl-text-editor

Slight modification to the bl-cli-editor wrapper:

x-terminal-emulator -T "BunsenLabs Text Editor" -e editor "$@"

2016_12_29_193810_643x54_scrot.png
glasses


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#10 2017-01-14 07:52:18

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,111
Website

Re: Using command-line text-editors as bl-text-editor

All seems to be working nicely. A small addition to bl-alternatives gets bl-cli-editor added to the candidates for bl-text-editor automatically. Unfortunately 'man bl-cli-editor' returns not-found (of course). Either we write a small man page, or symlink it to 'man editor'.

Just as proof of concept I added this bl-cli-editor.desktop to /usr/share/applications:

[Desktop Entry]
Version=1.0
Type=Application
Name=BL CLI Editor
Comment=The BunsenLabs terminal text editor.
GenericName=Text Editor
Exec=bl-cli-editor %F
TryExec=editor
Icon=accessories-text-editor
Terminal=false
Categories=Development;Utility;TextEditor;
MimeType=text/plain;text/x-chdr;text/x-csrc;text/x-c++hdr;text/x-c++src;text/x-java;text/x-dsrc;text/x-pascal;text/x-perl;text/x-python;application/x-php;application/x-httpd-php3;application/x-httpd-php4;application/x-httpd-php5;application/xml;text/html;text/css;text/x-sql;text/x-diff;

It's basically copied from bl-text-editor.desktop, but it shows up in Thunar's context menu for text files, and opens them in (in my case) nano perfectly. cool
If you can suggest any tweaks, please do.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#11 2017-01-15 06:15:56

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,111
Website

Re: Using command-line text-editors as bl-text-editor

^specifically, for now I've used accessories-text-editor as the icon, which is the same as that of bl-text-editor. Maybe there's a more appropriate, but widely available, icon?

Also, could the Comment be improved?


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#12 2017-01-15 11:10:11

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: Using command-line text-editors as bl-text-editor

johnraff wrote:

Either we write a small man page, or symlink it to 'man editor'.

I think we should symlink to editor(1)

could the Comment be improved?

"BunsenLabs command-line text editor", perhaps?

But your version is fine smile

In respect of the icon, accessories-text-editor seems appropriate to me.

Last edited by Head_on_a_Stick (2017-01-15 11:10:50)


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#13 2017-01-17 02:58:01

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,111
Website

Re: Using command-line text-editors as bl-text-editor

Managed to squeeze this into bunsen-configs along with the other "deuterium" improvements, so when the new package hits the repos (soon) then bl-cli-editor should be available on all BL desktops. It appears as a choice for bl-text-editor, and if chosen then 'man bl-text-editor' redirects to whatever is selected as Debian "editor". cool


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#14 2018-03-12 16:19:27

martix
Kim Jong-un Stunt Double
Registered: 2016-02-19
Posts: 1,267

Re: Using command-line text-editors as bl-text-editor

Head_on_a_Stick wrote:

Openbox Main Menu → System → Edit Debian Alternatives

Then select bl-text-editor and click on the Add button and browse to /usr/local/bin/bl-cli-editor

Finally, to set the actual program that is to be used for /etc/alternatives/editor, run:

sudo update-alternatives --config editor

Just for my understanding: It is about having editor as bl-text-editor, i.e. both the same, wherever a text (or similar) file is opened?

As you add bl-cli-editor as alternative and choose it as default for bl-text-editor. So the same editor for both, bl-text and bl-cli.

P.S.: If I'm not mistaken, that last step can be achieved in the same galterantives window (used in the step before), just scrolling down to "editor" and set it there.

Offline

#15 2018-03-12 20:11:17

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: Using command-line text-editors as bl-text-editor

martix wrote:

Just for my understanding: It is about having editor as bl-text-editor, i.e. both the same, wherever a text (or similar) file is opened?

Yes, that's right — the same editor will be used both for the thunar right-click edit option and also for any command line stuff such as visudo.


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#16 2018-03-12 23:33:52

martix
Kim Jong-un Stunt Double
Registered: 2016-02-19
Posts: 1,267

Re: Using command-line text-editors as bl-text-editor

@HoaS I see, thank you for the clarification.

johnraff wrote:

bl-cli-editor should be available on all BL desktops. It appears as a choice for bl-text-editor, and if chosen then 'man bl-text-editor' redirects to whatever is selected as Debian "editor". cool

Ok, I think I get it now. On default bl-text and bl-cli won't be the same, but it'll be easy to configure a cli editor as default for both.

I'm still wondering about the following: Would it be possible to have something like a bl-cli-editor symlink in the /etc/alternatives directory, so when choosing one editor for the cli

sudo update-alternatives --config bl-cli-editor

would work? After seeing bl-file-manager and bl-text-editor I even tried to use that command, but realized there is only editor, which is actually bl-cli-editor (and noticed users running "echo $EDITOR on bash, but there is no output for me).

Offline

#17 2018-03-13 06:00:08

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,111
Website

Re: Using command-line text-editors as bl-text-editor

sudo update-alternatives --config bl-cli-editor

This would not work - bl-cli-editor is not a Debian alternative.
bl-cli-editor is already using the Debian alternative for 'editor' and just opening a terminal to run it in, so it can be used as a substitute for X editors like geany or leafpad.

sudo update-alternatives --config bl-text-editor

This will work, and you can choose bl-cli-editor instead of geany if you want.

'editor' is a debian alternative that points in my case to nano, and more than likely in HoaS's case to vim, so this will work:

sudo update-alternatives --config editor

and you can choose some cli editor.

You can also use menu>System>Edit Debian Alternatives to do this configuration with the GUI galternatives.

$EDITOR is an environment variable that might, or might not, be set. If set, it might resolve to some cli editor like vim or whatever.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#18 2018-03-13 07:45:49

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: Using command-line text-editors as bl-text-editor

$EDITOR (& $VISUAL) aren't used in Debian because it relies on the alternatives system instead.

EDIT: I still set mine anyway:

# ~/.profile
export EDITOR=ed
export VISUAL=vim

glasses

Last edited by Head_on_a_Stick (2018-03-13 07:47:11)


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#19 2018-03-13 08:26:28

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,111
Website

Re: Using command-line text-editors as bl-text-editor

Head_on_a_Stick wrote:

$EDITOR (& $VISUAL) aren't used in Debian

But various applications will use them if they exist.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#20 2018-03-13 14:41:11

martix
Kim Jong-un Stunt Double
Registered: 2016-02-19
Posts: 1,267

Re: Using command-line text-editors as bl-text-editor

@john Thank you for the explanation. My question popped up because it's possible to start the cli editor via bl-cli-editor (and there is also a menu entry in a dynamic menu). Hence using bl-cli-editor for update alternatives is more intuitive. But thanks for the hint regarding debian alternatives. Actually thinking about it there might be still a way though if someone uses alias in bashrc pointing sudo update-alternatives --config bl-cli-editor to sudo update-alternatives --config editor. However it looks this never bothered anyone, no need for a fix then.

@HoaS EDITOR=ed - Just read about it: ed was developed in 1969, "it is the original editor for Unix". I wonder: Why is it good if Editor and Visual are different tools?

Offline

#21 2018-03-13 22:06:02

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: Using command-line text-editors as bl-text-editor

martix wrote:

Why is it good if Editor and Visual are different tools?

Traditionally EDITOR is used for simple files where only quick changes are needed (ed is supreme at this once you're familiar with it) but VISUAL is for coding and suchlike where more extensive editing is required.

Last edited by Head_on_a_Stick (2018-03-13 22:10:33)


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#22 2018-03-14 10:55:59

martix
Kim Jong-un Stunt Double
Registered: 2016-02-19
Posts: 1,267

Re: Using command-line text-editors as bl-text-editor

^I see, good to know about it (it's history too).

Just for the record: I tried the .profile method, but it looks like ranger does not bother about it, nor about the alternatives system. This method works though.

Offline

#23 2018-03-15 03:18:28

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,111
Website

Re: Using command-line text-editors as bl-text-editor

martix wrote:

I tried the .profile method, but it looks like ranger does not bother about it...

LightDM ignores ~/.profile. If you want to set environment variables in an X session use ~/.xsessionrc


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#24 2020-05-04 01:40:04

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,111
Website

Re: Using command-line text-editors as bl-text-editor

Head_on_a_Stick wrote:
johnraff wrote:

Either we write a small man page, or symlink it to 'man editor'.

I think we should symlink to editor(1)

More than 3 years late, but that symlink just went in the code and the next upgrade of bunsen-configs (next week?) should make 'man bl-cli-editor' bring up the man page for whatever is set as 'editor' (probably nano or vim).

Tidying up man pages everywhere right now.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#25 2020-06-11 21:08:49

christopherisnow
Member
Registered: 2018-05-19
Posts: 36

Re: Using command-line text-editors as bl-text-editor

What is the solution to use a CLI editor (e.g. nvim) in place of Geany on Lithium -- haven't the relevant files changed somewhat from previous versions of BL?

I would also be curious to change my default file browser to ranger. I suppose this is analogous.

Would love to (1) leave kb shortcuts as they are, and (2) have different default terminal window sizes for different apps. Currently x-terminal-emulator opens at a 1/4-screen size with `Ctl+t` but I would prefer for nvim and ranger to be full-screen.

Bonus points if terminals running nvim or ranger would show up in the tint2 panel with their own icon and/or current file path, so I could distinguish them from all the other random open terminals!

Thanks in advance.

Last edited by christopherisnow (2020-06-11 21:12:49)

Offline

Board footer

Powered by FluxBB