Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fish): use abbr instead of alias #348

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

folliehiyuki
Copy link
Contributor

@folliehiyuki folliehiyuki commented Feb 6, 2024

Check list

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation

Description

  • Switch from aliases to abbreviations, as I suggested in feat(completions): add completion for fish #344 (comment)
  • string collect returns 1 on empty argument, so it's used here to avoid repeating if else end blocks. Another benefit is that the output of string collect is ensured to be a single string. From string --help:

string collect collects its input into a single output argument, without splitting the output when used in a command substitution. This is useful when trying to collect multiline output from another
command into a variable. Exit status: 0 if any output argument is non-empty, or 1 otherwise.

This PR is marked as breaking change, since abbr behaves differently from alias. It can only be used in the interactive command line (so putting exec glo into your scripts won't work).

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation change

Test environment

  • Shell
    • bash
    • zsh
    • fish
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Others:

Copy link
Collaborator

@cjappl cjappl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is a MASSIVE improvement. I have not tested it yet (but will do so after some chatting).

I especially like the extreme reduction in duplication, having "one source of truth" for commands and completions etc.

I'm worried mainly about affecting the user's $PATH in a way that is invasive. I would be surprised if I sourced a plugin and my PATH was affected.

"$FORGIT" ignore_get $argv
end
# Add `git-forgit` command to PATH
fish_add_path -ga "$FORGIT_INSTALL_DIR/bin"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to do this without affecting the user's $PATH? That seems like it could be a little invasive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can replace git-forgit in the abbreviations with $FORGIT. Completion shouldn't be affected, but the expanded command line might look a bit ugly (fish expands the full path of $FORGIT_INSTALL_DIR/bin/git-forgit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meaning when you expand the abbreviation?

It would expand:

ga

becomes

$FORGIT_INSTALL_DIR/bin/git-forgit add

For the user?

Instead of

git forgit add

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added git-forgit alias to the full-path command, so hopefully it'll solve the "lengthy command line" problem.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Let me try this out for a bit and get a feel for it before merging. Overall code structure wise it's a big improvement, just going to perform some testing to make sure I understand it and there aren't any gotchas.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still testing this! It's definitely a change as a user, but easy to adapt to. It also de-duplicates the code so much, which is a huge positive.

@folliehiyuki folliehiyuki force-pushed the fish-use-abbr branch 2 times, most recently from bc52129 to 1bd66bb Compare February 7, 2024 03:27
@@ -2,10 +2,8 @@

set INSTALL_DIR (dirname (dirname (status -f)))
set -x FORGIT_INSTALL_DIR "$INSTALL_DIR/conf.d"
set -x FORGIT "$FORGIT_INSTALL_DIR/bin/git-forgit"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this line cannot change, this is auto-replaced in our homebrew script, so it should stay as it is! I would revert this entire section (5-8)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjappl The line has just been moved (to line 8), why can't it be auto-replaced there now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it could but it would need testing with the homebrew formula to make sure it still works. If this change can be done with keeping the original structure in place it's one less thing to check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the 2nd commit modifying the variable.

Copy link
Collaborator

@cjappl cjappl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think let's run with this for now. I think the code maintenance is substantially improved and the minor backwards compatability stuff (not being able to use abbreviations in scripts for fish) is easily fixable by clients.

I'm going to merge and we can always revert if there is a riot.

Thanks again for the fix on this, I had no idea the power of abbr !

@cjappl cjappl merged commit 038cce2 into wfxr:master Mar 5, 2024
4 checks passed
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.

3 participants