jarun/nnn

Hardlink Creation Reversion

SturmB opened this issue · 3 comments

Environment details (Put x in the checkbox along with the information)

  • Operating System: Synology's flavor of Linux
  • Desktop Environment:
  • Terminal Emulator:
  • Shell:
  • Custom desktop opener (if applicable):
  • Program options used:
  • Configuration options set:
  • Plugins are installed
  • Issue exists on nnn master

Exact steps to reproduce the issue

Select one file, then try to create a hardlink to that file in a different folder with 'n', then 'h'.

Expected:

The 'name' field is pre-filled with the same name as the selected file.

Actual:

The 'name' field is blank.

Notes:

This was an issue in older versions that I brought up in #1505. It was fixed in PR #1507. It now seems to have been reverted.

The discussion about the reversion seems to indicate that the cur/sel prompt that appears after the path/name prompt makes it confusing. As a software engineer, I agree with that, but I've always chosen 's' and never had a problem.

The conversation also states that 'the user can provide the destination_directory/target_filename for selection while she is still inside the directory where she has selected. No need to navigate to the destination directory.' While this may be true, it would require either typing out the entire path and filename at the prompt, which could be extremely long and potentially include typos, or a combination of typing and copy/pasting. Both of these workarounds seem to be a step backward regarding usability.

Could we get this feature put back in? Perhaps compromise by allowing '@' to be used even with single-file selections as was proposed in the original issue?

Perhaps compromise by allowing '@' to be used even with single-file selections as was proposed in the original issue?

The problem is someone may literally want to create a hardlink with the name @.

Does the following patch work for you?

diff --git a/src/nnn.c b/src/nnn.c
index f1a2ee74..5af2b1b7 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -7704,7 +7704,7 @@ nochange:
                                if (r == 'f' || r == 'd')
                                        tmp = xreadline(tmp, messages[MSG_NEW_PATH]);
                                else if (r == 's' || r == 'h')
-                                       tmp = xreadline(NULL,
+                                       tmp = xreadline((nselected == 1 && cfg.prefersel) ? xbasename(pselbuf) : NULL,
                                                messages[nselected <= 1 ? MSG_NEW_PATH : MSG_LINK_PREFIX]);
                                else
                                        tmp = NULL

Note that for the patch to work as expected, you have to use the program option -u use selection (no prompt) so that selection is always preferred over the currently hovered file.

I decided to go ahead with the approach in the diff.