Skip to content

Fixed lacy prompt behaviour when no args are provided#57

Closed
bladeacer wants to merge 1 commit intotimothebot:mainfrom
bladeacer:main
Closed

Fixed lacy prompt behaviour when no args are provided#57
bladeacer wants to merge 1 commit intotimothebot:mainfrom
bladeacer:main

Conversation

@bladeacer
Copy link
Copy Markdown

Fixes #52 .

Not sure if you want more robust logic with this.

@bladeacer bladeacer requested a review from timothebot as a code owner January 15, 2026 08:07
@bladeacer
Copy link
Copy Markdown
Author

hmm I should probably amend the commit message to be more in line with existing conventions.

@timothebot
Copy link
Copy Markdown
Owner

Hm, I think the best way would be to do: cd <nothing>, as maybe you select some cd tool that does something different than cd ~.
In that case, we'd have to change the shell scripts though.

This would be an empty check then instead of checking for ~.

if [ "$new_path" = "~" ]; then
        {{ cd }} ~

What do you think?

@bladeacer
Copy link
Copy Markdown
Author

so far from testing base cd and zoxide seem to have the same behaviour when provided with no args.

if customising and modifying that behaviour matters you can consider including a config file.

@bladeacer
Copy link
Copy Markdown
Author

like you mentioned earlier, shell specific scripts are brittle by nature, and this is better handled by the parser itself.

if you want to customise the nothing arg behaviour you can consider loading from a yaml or some other config file, or even a set environment variable.

would take a bit more work with the parser but that would take a bit more work.

as for empty string check in the shell script, that was what I tried to include in #56 .

Cheers, bladeacer

@bladeacer
Copy link
Copy Markdown
Author

I personally prefer having a config file, as you can load from $XGD_CONFIG or some other standard location.

A config schema also lets you be flexible with lacy regardless of shell. At the end of the day, the config file would be better as a separate issue altogether.

Like the parser empty string check it would also be something that the author and current maintainers can discuss.

@timothebot
Copy link
Copy Markdown
Owner

Hm I am usually a fan of config files but I don't see the need for one here. I'm planning to switch to env variables eventually.

But that is all besides the issue here.

I think lacy should return an empty result if nothing is found.

The logic in the script would then just check if the result is empty.

Idk why I'm checking arg == ~ rn, that doesn't seem to matter.
I'll take a closer look soon, currently bit busy with exams (and playing Hytale lol).

@bladeacer
Copy link
Copy Markdown
Author

Basically the check is there to have default behaviour when lacy prompt is passed no args e.g. just running y. The behaviour of going to user's home directory when no args are given is consistent with other similar tools like base cd and zoxide.

Did you vibe code a bit here, or were the two pull requests not up to standard?

@timothebot
Copy link
Copy Markdown
Owner

What two PRs do you mean? I used AI for the initial shell scripts, yes.

if [ "$new_path" = "~" ]; then
        {{ cd }} ~
    {% if custom_fuzzy.enabled %}elif [[ "$new_path" == *$'\n'* ]]; then
        selected=$(printf "%s\n" "$new_path" | {{ custom_fuzzy.cmd }})
        [ -n "$selected" ] && {{ cd }} "$selected"
    {% endif %}elif [ -d "$new_path" ]; then
        {{ cd }} "$new_path" || return
    else
        echo "Error: No matching directory found for '$*'"
    fi

This code made sense a few versions ago, but is def outdated now.

We don't need to check if the target directory exists. This limits the functionality you might want to give to other apps.

That means, whatever single result we get, we can just pass to {{cd}}.
So we also don't require the ~ check anymore.

But yes, now that im writing this I see that lacy prompt "" should not return nothing because lacy prompt "not existing query" also does.

So two questions:

  1. what should a not existing query print to the console?
  2. Should the result of entering nothing be configurable or just hardcoded ~? (stupid question)

Sorry for the formatting, im currently on my phone^^

@bladeacer
Copy link
Copy Markdown
Author

What two PRs do you mean? I used AI for the initial shell scripts, yes.

if [ "$new_path" = "~" ]; then
        {{ cd }} ~
    {% if custom_fuzzy.enabled %}elif [[ "$new_path" == *$'\n'* ]]; then
        selected=$(printf "%s\n" "$new_path" | {{ custom_fuzzy.cmd }})
        [ -n "$selected" ] && {{ cd }} "$selected"
    {% endif %}elif [ -d "$new_path" ]; then
        {{ cd }} "$new_path" || return
    else
        echo "Error: No matching directory found for '$*'"
    fi

This code made sense a few versions ago, but is def outdated now.

We don't need to check if the target directory exists. This limits the functionality you might want to give to other apps.

That means, whatever single result we get, we can just pass to {{cd}}. So we also don't require the ~ check anymore.

But yes, now that im writing this I see that lacy prompt "" should not return nothing because lacy prompt "not existing query" also does.

So two questions:

1. what should a not existing query print to the console?

2. Should the result of entering nothing be configurable or just hardcoded ~? (stupid question)

Sorry for the formatting, im currently on my phone^^

The PRs as in #57 and #55 , which were made (admittedly hastily) with the amount of information I had at that point in time.

  1. If you really want to tell the user, then just a error message to stdout, generally the programme should exit with an error code of 1 and specify the reason why, though it should not outright crash. Exiting with error code 0 is for stuff like help text and successful execution, at least in the context of command line tools iirc. Either that or you can ask the user to pick their choice with a fuzzy picker / or ~. Imo I would split the behaviour of those between something like --verbose and making the helpful messages opt in behaviour. To me, the default behaviour should not be too far off from existing well established tools, because additional user friction makes folk unwilling to fully switch to lacy.
  2. Not a stupid question btw. Considering how your tool is meant to be a drop in replacement to cd or zoxide, imo as an end user I would expect mostly consistent behaviour with existing tools. I cd or z without args quite a bit to quickly go back to my $HOME directory, so I would expect the tool when I am using it to largely behave the same.
  3. If you are concerned with "the functionality you might want to give to other apps" and having toggleable options (opt in or out as flags). The "traditional" way is with command line flags e.g. --verbose. The "modern" way (albeit bloated for the nature of lacy, imo it should be zero config. You can set environment variables, though you might eventually get to a point where you have so many that it necessitates a config file.

@timothebot
Copy link
Copy Markdown
Owner

I won't change the shell scripts for now. I think the error message is fine. If you want anything else, you can always just edit it yourself.
The ~ check is still required because [ -d "~" ] returns false. :/

In #59, I changed the output to either ~ or, if set, $LACY_NO_ARGS_PATH. I think this is a good solution for now.

@bladeacer bladeacer closed this Jan 18, 2026
@bladeacer
Copy link
Copy Markdown
Author

bladeacer commented Jan 18, 2026

I won't change the shell scripts for now. I think the error message is fine. If you want anything else, you can always just edit it yourself. The ~ check is still required because [ -d "~" ] returns false. :/

In #59, I changed the output to either ~ or, if set, $LACY_NO_ARGS_PATH. I think this is a good solution for now.

is "The ~ check is still required because [ -d "~" ] returns false. :/" still true for the code after #59 is merged?

imo like with #59 the immediate fix is nice, but input validation should not so much be handled by the shell script but rather fully by the parser. this will help with support for other shells.

cheers, bladeacer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No arguments goes to the wrong directory

2 participants