Arrow navigation and backward text edition when typing Evomaintenance comment #13

Open
opened 2021-07-27 12:11:24 +02:00 by whirigoyen · 7 comments
Owner

Could we use "read -e" when available (e.g. in bash), instead of just read ?

Pseudo-code :

if shell_is_bash :
    read -e
else:
    read
Could we use "read -e" when available (e.g. in bash), instead of just read ? Pseudo-code : ~~~ if shell_is_bash : read -e else: read ~~~
Owner

This issue is already tracked in issue #10. Let's keep talking about it over there.

This issue is already tracked in issue #10. Let's keep talking about it over there.
Owner

Reopened since I confused #10 with this one.

Your suggestion is great and can be implemented easily without depending on an external binary such as readline. I hope we can fix this quickly!

Reopened since I confused #10 with this one. Your suggestion is great and can be implemented easily without depending on an external binary such as `readline`. I hope we can fix this quickly!
whirigoyen changed title from Possibilité de revenir en arrière dans le read du commentaire de l'Evomaintenance to Arrow navigation and backward text edition when typing Evomaintenance comment 2021-08-10 09:38:44 +02:00
Author
Owner

For the if condition, it seems that we can use the following commands to know if bash is available :

  • echo "${BASH_VERSION}" : empty if no bash available
  • bash --version : exit code != 0 if no bash available

However, a better option would be to directly test the availability of "read -e" by testing the exit code of the following command :

echo "" | read -e > /dev/null 2>&1

Then, we could write (with an alias in this snippet) :

echo "" | read -e > /dev/null 2>&1
if [ $? -eq 0 ]
    then alias read='read -e'
fi
# do the job
unalias read
For the if condition, it seems that we can use the following commands to know if bash is available : * echo "${BASH_VERSION}" : empty if no bash available * bash --version : exit code != 0 if no bash available However, a better option would be to directly test the availability of "read -e" by testing the exit code of the following command : ``` echo "" | read -e > /dev/null 2>&1 ``` Then, we could write (with an alias in this snippet) : ~~~ echo "" | read -e > /dev/null 2>&1 if [ $? -eq 0 ] then alias read='read -e' fi # do the job unalias read ~~~
Owner

Each time I tried to find a reliable test of the running shell, I've found edge cases.

Testing for the real availability of the tool or feature we need is a way better approach.
For example, I often prefer testing for the presence of a command (eg. command -v foo) rather than testing if the corresponding package is installed.

Each time I tried to find a reliable test of the running shell, I've found edge cases. Testing for the real availability of the tool or feature we need is a way better approach. For example, I often prefer testing for the presence of a command (eg. `command -v foo`) rather than testing if the corresponding package is installed.
Author
Owner

Anther idea proposed by Ludovic is - when available - to open vim ot the system default editor (like git commit does).
This would enable the maintener to give more info in the maintenance log if needed and would be much more user friendly than the current read command.

Anther idea proposed by Ludovic is - when available - to open vim ot the system default editor (like git commit does). This would enable the maintener to give more info in the maintenance log if needed and would be much more user friendly than the current read command.
Owner

Having a full fledge editor when writing evomaintenance can be usefuled in some case, but would probably an hindrance to use it all the time. So having a shortcut from the read/readline input to swith to a true editor seems a good middle ground.

Having a full fledge editor when writing evomaintenance can be usefuled in some case, but would probably an hindrance to use it *all the time*. So having a shortcut from the read/readline input to swith to a true editor seems a good middle ground.
Owner

However, a better option would be to directly test the availability of "read -e" by testing the exit code of the following command :

echo "" | read -e > /dev/null 2>&1

Then, we could write (with an alias in this snippet) :

echo "" | read -e > /dev/null 2>&1
if [ $? -eq 0 ]
    then alias read='read -e'
fi
# do the job
unalias read

Or we could use the if correctly like so:

if printf '\n' | read -e _ >/dev/null 2>&1
	then alias read='read -e'
fi

As the if conditionnal check the exit status being 0 already.

> However, a better option would be to directly test the availability of "read -e" by testing the exit code of the following command : > > ``` > echo "" | read -e > /dev/null 2>&1 > ``` > > Then, we could write (with an alias in this snippet) : > ~~~ > echo "" | read -e > /dev/null 2>&1 > if [ $? -eq 0 ] > then alias read='read -e' > fi > # do the job > unalias read > ~~~ Or we could use the if correctly like so: ``` if printf '\n' | read -e _ >/dev/null 2>&1 then alias read='read -e' fi ``` As the if conditionnal check the exit status being 0 already.
Sign in to join this conversation.
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: evolix/evomaintenance#13
No description provided.